Skip to content

Commit

Permalink
Enhance song loading and add OnlineSongDesc class
Browse files Browse the repository at this point in the history
- Modify ConvertUbiArtToUnity to robustly load SongDesc from multiple sources, throwing FileNotFoundException if all attempts fail.
- Update ISC class to perform case-insensitive comparison for USERFRIENDLY attribute.
- Simplify ClipTape class by removing unused properties.
- Update ConverterDialogue to skip songs if descPath and jddb.json are missing.
- Add OnlineSongDesc class to represent and convert online song descriptions to SongDesc format.
  • Loading branch information
MrKev312 committed Oct 27, 2024
1 parent ef3502f commit af83af5
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 12 deletions.
17 changes: 15 additions & 2 deletions JustDanceEditor.Converter/Converters/ConvertUbiArtToUnity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SongDesc>(FileSystem.ReadWithoutNull(path), options)!;
if (FileSystem.GetFilePath(relativePath, out CookedFile? path))
SongData.SongDesc = JsonSerializer.Deserialize<SongDesc>(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<OnlineSongDesc>(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<SongDesc>(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;
Expand Down
4 changes: 2 additions & 2 deletions JustDanceEditor.Converter/UbiArt/ISC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
51 changes: 51 additions & 0 deletions JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace JustDanceEditor.Converter.UbiArt;

// For JDUnlimited server JSON
internal class OnlineSongDesc
{
public string artist { get; set; }

Check warning on line 6 in JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'artist' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'artist' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public Assets assets { get; set; }

Check warning on line 7 in JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'assets' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 7 in JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'assets' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public int coachCount { get; set; }
public string credits { get; set; }

Check warning on line 9 in JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'credits' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public int difficulty { get; set; }
public string lyricsColor { get; set; }

Check warning on line 11 in JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'lyricsColor' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public int lyricsType { get; set; }
public int mainCoach { get; set; }
public float mapLength { get; set; }
public string mapName { get; set; }

Check warning on line 15 in JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'mapName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public int originalJDVersion { get; set; }
public string parentMapName { get; set; }

Check warning on line 17 in JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'parentMapName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public int status { get; set; }
public int sweatDifficulty { get; set; }
public string[] tags { get; set; }

Check warning on line 20 in JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'tags' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string title { get; set; }

Check warning on line 21 in JustDanceEditor.Converter/UbiArt/OnlineSongDesc.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'title' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

// 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;
}
}
6 changes: 0 additions & 6 deletions JustDanceEditor.Converter/UbiArt/Tapes/DanceTape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; } = "";
}
9 changes: 7 additions & 2 deletions JustDanceEditor.UI/Converting/ConverterDialogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af83af5

Please sign in to comment.