diff --git a/JustDanceEditor.Converter/Converters/ConvertUbiArtToUnity.cs b/JustDanceEditor.Converter/Converters/ConvertUbiArtToUnity.cs index 196c450..0d2e395 100644 --- a/JustDanceEditor.Converter/Converters/ConvertUbiArtToUnity.cs +++ b/JustDanceEditor.Converter/Converters/ConvertUbiArtToUnity.cs @@ -134,8 +134,21 @@ void LoadSongData() // Let's start with the songdesc Logger.Log("Loading SongDesc"); string relativePath = Path.Combine(FileSystem.InputFolders.MapWorldFolder, "songdesc.tpl"); - string path = FileSystem.GetFilePath(relativePath); - SongData.SongDesc = JsonSerializer.Deserialize(FileSystem.ReadWithoutNull(path), options)!; + if (FileSystem.GetFilePath(relativePath, out CookedFile? path)) + SongData.SongDesc = JsonSerializer.Deserialize(FileSystem.ReadWithoutNull(path), options)!; + // Try to load the songdesc from a db + else if (File.Exists(Path.Combine(FileSystem.InputFolders.InputFolder, "jddb.json"))) + { + Logger.Log("Loading songdesc from json"); + SongData.SongDesc = (SongDesc)JsonSerializer.Deserialize(File.ReadAllText(Path.Combine(FileSystem.InputFolders.InputFolder, "jddb.json")), options)!; + } + else if (File.Exists(Path.Combine(FileSystem.InputFolders.InputFolder, "..", "jddb.json"))) + { + Logger.Log("Loading songdesc from json"); + SongData.SongDesc = JsonSerializer.Deserialize(File.ReadAllText(Path.Combine(FileSystem.InputFolders.InputFolder, "..", "jddb.json")), options)!; + } + else + throw new FileNotFoundException("SongDesc not found"); // Get the map name SongData.Name = SongData.SongDesc.COMPONENTS[0].MapName; diff --git a/JustDanceEditor.Converter/UbiArt/ISC.cs b/JustDanceEditor.Converter/UbiArt/ISC.cs index 192ba38..c142883 100644 --- a/JustDanceEditor.Converter/UbiArt/ISC.cs +++ b/JustDanceEditor.Converter/UbiArt/ISC.cs @@ -19,12 +19,12 @@ public static bool GetActorPath(string input, string actorName, [MaybeNullWhen(f foreach (XElement actor in xmlDoc.Descendants("Actor")) { XAttribute? attribute = actor.Attribute("USERFRIENDLY"); - if (attribute != null && (string)attribute == actorName) + if (attribute != null && string.Equals(attribute.Value, actorName, StringComparison.OrdinalIgnoreCase)) { XAttribute? luaAttribute = actor.Attribute("LUA"); if (luaAttribute != null) { - actorPath = (string)luaAttribute; + actorPath = luaAttribute.Value; return true; } } diff --git a/JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs b/JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs new file mode 100644 index 0000000..458eea6 --- /dev/null +++ b/JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs @@ -0,0 +1,51 @@ +namespace JustDanceEditor.Converter.UbiArt; + +// For JDUnlimited server JSON +internal class OnlineSongDesc +{ + public string artist { get; set; } + public Assets assets { get; set; } + public int coachCount { get; set; } + public string credits { get; set; } + public int difficulty { get; set; } + public string lyricsColor { get; set; } + public int lyricsType { get; set; } + public int mainCoach { get; set; } + public float mapLength { get; set; } + public string mapName { get; set; } + public int originalJDVersion { get; set; } + public string parentMapName { get; set; } + public int status { get; set; } + public int sweatDifficulty { get; set; } + public string[] tags { get; set; } + public string title { get; set; } + + // Allow conversion from OnlineSongDesc to SongDesc + public static explicit operator SongDesc(OnlineSongDesc onlineSongDesc) + { + SongDesc songDesc = new() + { + COMPONENTS = + [ + new() + { + Artist = onlineSongDesc.artist, + NumCoach = (uint)onlineSongDesc.coachCount, + MainCoach = onlineSongDesc.mainCoach, + Difficulty = (uint)onlineSongDesc.difficulty, + SweatDifficulty = (uint)onlineSongDesc.sweatDifficulty, + LyricsType = onlineSongDesc.lyricsType, + Title = onlineSongDesc.title, + Credits = onlineSongDesc.credits, + Tags = onlineSongDesc.tags, + Status = onlineSongDesc.status, + OriginalJDVersion = (uint)onlineSongDesc.originalJDVersion, + MapName = onlineSongDesc.mapName, + VideoPreviewPath = onlineSongDesc.assets.videoPreview_HIGHvp9webm + } + ] + }; + + return songDesc; + } +} diff --git a/JustDanceEditor.Converter/UbiArt/Tapes/DanceTape.cs b/JustDanceEditor.Converter/UbiArt/Tapes/DanceTape.cs index 4701bef..fadca8c 100644 --- a/JustDanceEditor.Converter/UbiArt/Tapes/DanceTape.cs +++ b/JustDanceEditor.Converter/UbiArt/Tapes/DanceTape.cs @@ -4,11 +4,5 @@ namespace JustDanceEditor.Converter.UbiArt.Tapes; public class ClipTape { - public string __class { get; set; } = ""; public IClip[] Clips { get; set; } = []; - public int TapeClock { get; set; } - public int TapeBarCount { get; set; } - public int FreeResourcesAfterPlay { get; set; } - public string MapName { get; set; } = ""; - public string SoundwichEvent { get; set; } = ""; } \ No newline at end of file diff --git a/JustDanceEditor.UI/Converting/ConverterDialogue.cs b/JustDanceEditor.UI/Converting/ConverterDialogue.cs index fb68530..405be24 100644 --- a/JustDanceEditor.UI/Converting/ConverterDialogue.cs +++ b/JustDanceEditor.UI/Converting/ConverterDialogue.cs @@ -101,8 +101,13 @@ public static void ConvertAllSongsInFolder() if (!File.Exists(descPath)) { - Logger.Log($"Skipping {song} as it is not a valid song", LogLevel.Important); - continue; + // If there's also no jddb.json in the input folders, skip the song + string jddbPath = Path.Combine(inputFolder, "jddb.json"); + if (!File.Exists(jddbPath)) + { + Logger.Log($"Skipping {song} as it is not a valid song", LogLevel.Important); + continue; + } } // If the song is already cached, skip it