162 lines
No EOL
5.2 KiB
C#
162 lines
No EOL
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Dynamic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using JD.Application.View.Misc;
|
|
using JD.Asset.Types.Map;
|
|
using JD.Collections.Extensions;
|
|
using JD.Timeline.Model;
|
|
|
|
using TeaBox;
|
|
using TeaBox.Macros;
|
|
using TeaBox.Macros.Details;
|
|
using JD.Core;
|
|
using JD.Kernel.StaticHelpers;
|
|
using JD.Kernel.Structs;
|
|
using JD.LogService;
|
|
using JD.Serialization;
|
|
|
|
|
|
namespace Traviata.Source.Macros
|
|
{
|
|
[Module]
|
|
public class KaraokeValidationMacros
|
|
{
|
|
[Macro(ThreadAffinity.ExecuteAsync)]
|
|
[Description("Validates the states of the lyrics of all the Just Dance maps")]
|
|
public static void FindAllRapMaps(IExecutionContext context)
|
|
{
|
|
var maps = Map.AllMaps.Where(ShouldValidateMap).ToList();
|
|
int totalCount = 0;
|
|
int successCount = 0;
|
|
|
|
var steps = maps.Select(map => new { map, step = context.AddStep() }).ToArray();
|
|
foreach (var pair in steps)
|
|
{
|
|
pair.step.Name = $"Validating {pair.map.Name}";
|
|
}
|
|
|
|
foreach (var pair in steps)
|
|
{
|
|
if (context.IsCancelled)
|
|
{
|
|
break;
|
|
}
|
|
|
|
using (pair.step.Start())
|
|
{
|
|
ReportIfHasRap(pair.step, pair.map);
|
|
totalCount++;
|
|
}
|
|
|
|
if (pair.step.State == StepState.Succeeded)
|
|
{
|
|
successCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void ReportIfHasRap(IStep step, Map map)
|
|
{
|
|
bool hasKaraoke = File.Exists(map.KaraokeTapePath);
|
|
|
|
if (hasKaraoke)
|
|
{
|
|
var tape = Tape.CreateTape(map.KaraokeTapePath);
|
|
var rapClip = tape.Clips.OfType<KaraokeClip>()
|
|
.Where(clip => clip.ContentType == KaraokeClip.ContentType_Enum.KaraokeContent_Rap).ToArray();
|
|
|
|
if (rapClip.Any())
|
|
{
|
|
step.LogWarning(new FileLocation(map.KaraokeTapePath, rapClip.Select(x => x.Id).ToList()), "Rap data found", MessageImportance.High);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Macro(ThreadAffinity.ExecuteAsync)]
|
|
[Description("Validates the states of the lyrics of all the Just Dance maps")]
|
|
public static void ValidateAllMaps(IExecutionContext context)
|
|
{
|
|
var maps = Map.AllMaps.Where(ShouldValidateMap).ToList();
|
|
int totalCount = 0;
|
|
int successCount = 0;
|
|
|
|
foreach (var map in maps)
|
|
{
|
|
if (context.IsCancelled)
|
|
{
|
|
break;
|
|
}
|
|
|
|
var step = context.AddStep();
|
|
step.Name = $"Validating {map.Name}";
|
|
|
|
using (step.Start())
|
|
{
|
|
ValidateKaraokeState(step, map);
|
|
totalCount++;
|
|
}
|
|
|
|
if (step.State == StepState.Succeeded)
|
|
{
|
|
successCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static bool ShouldValidateMap(Map map)
|
|
{
|
|
return !map.Name.StartsWith("_") &&
|
|
(map.Folder.ToString().Contains("JD2015") ||
|
|
map.Folder.ToString().Contains("JDCatalog", StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
|
|
public static void ValidateKaraokeState(IExecutionContext context, Map map)
|
|
{
|
|
var fileLocation = new FileLocation(map.KaraokeTapePath);
|
|
bool hasKaraoke = File.Exists(map.KaraokeTapePath);
|
|
|
|
if (map.IsAlternate)
|
|
{
|
|
if (hasKaraoke)
|
|
{
|
|
context.LogError(fileLocation, "Alternate map should not contain a specific Karaoke", MessageImportance.High);
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (!hasKaraoke)
|
|
{
|
|
context.LogWarning(fileLocation, "No Karaoke data found (.ktape file missing)", MessageImportance.High);
|
|
return;
|
|
}
|
|
|
|
var tape = Tape.CreateTape(map.KaraokeTapePath);
|
|
if (tape.Clips.IsEmpty())
|
|
{
|
|
context.LogWarning(new FileLocation(map.KaraokeTapePath), "No Karaoke data found (.ktape file empty)", MessageImportance.High);
|
|
return;
|
|
}
|
|
|
|
var lyrics = new Lyrics();
|
|
lyrics.Load(map.KaraokeLyricsFile);
|
|
using (new LyricsChecker(tape, lyrics, context))
|
|
{
|
|
if (lyrics.CompletionState == LyricsCompletionState.InProgress)
|
|
{
|
|
context.LogWarning(fileLocation, "Karaoke is in progress without any error", MessageImportance.High);
|
|
}
|
|
else if (lyrics.CompletionState == LyricsCompletionState.Completed)
|
|
{
|
|
context.LogMessage(fileLocation, "Karaoke is completed!", MessageImportance.High);
|
|
}
|
|
else
|
|
{
|
|
// Checker has already logged the error.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |