Skip to content

Commit

Permalink
Merge pull request #141 from Kylemc1413/beatmap-v4
Browse files Browse the repository at this point in the history
Update for 1.36.0, support for V4 beatmaps and fixes/tweaks
  • Loading branch information
Meivyn authored Apr 21, 2024
2 parents 65096d5 + 95c5f20 commit 56ebb1b
Show file tree
Hide file tree
Showing 19 changed files with 957 additions and 569 deletions.
45 changes: 22 additions & 23 deletions source/SongCore/Collections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public static class Collections
internal static readonly string DataPath = Path.Combine(UnityGame.UserDataPath, nameof(SongCore), "SongCoreExtraData.dat");
internal static readonly ConcurrentDictionary<string, string> LevelHashDictionary = new ConcurrentDictionary<string, string>();
internal static readonly ConcurrentDictionary<string, List<string>> HashLevelDictionary = new ConcurrentDictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
internal static readonly ConcurrentDictionary<string, string> LevelPathDictionary = new ConcurrentDictionary<string, string>();
internal static readonly ConcurrentDictionary<string, StandardLevelInfoSaveData> LevelSaveDataDictionary = new ConcurrentDictionary<string, StandardLevelInfoSaveData>();

internal static BeatmapLevelPack? WipLevelPack;
internal static ConcurrentDictionary<string, ExtraSongData> CustomSongsData = new ConcurrentDictionary<string, ExtraSongData>();
Expand All @@ -45,33 +43,30 @@ public static List<string> levelIDsForHash(string hash)
return HashLevelDictionary.TryGetValue(hash, out var songs) ? songs : new List<string>();
}

[Obsolete("Get the path from the loaded save data instead.", true)]
public static string GetCustomLevelPath(string levelID)
{
return LevelPathDictionary.TryGetValue(levelID, out var path) ? path : string.Empty;
return Loader.CustomLevelLoader._loadedBeatmapSaveData.TryGetValue(levelID, out var loadedSaveData) ? loadedSaveData.customLevelFolderInfo.folderPath : string.Empty;
}

[Obsolete("Get the save data from the loaded save data instead.", true)]
public static StandardLevelInfoSaveData? GetStandardLevelInfoSaveData(string levelID)
{
LevelSaveDataDictionary.TryGetValue(levelID, out var standardLevelInfoSaveData);
return standardLevelInfoSaveData;
Loader.CustomLevelLoader._loadedBeatmapSaveData.TryGetValue(levelID, out var loadedSaveData);
return loadedSaveData.standardLevelInfoSaveData;
}

internal static void AddExtraSongData(string hash, string path, string rawSongData)
internal static void AddExtraSongData(string hash, CustomLevelLoader.LoadedSaveData loadedSaveData)
{
if (!CustomSongsData.ContainsKey(hash))
{
CustomSongsData.TryAdd(hash, new ExtraSongData(rawSongData, path));
CustomSongsData.TryAdd(hash, new ExtraSongData(loadedSaveData));
}
}

public static ExtraSongData? RetrieveExtraSongData(string hash)
{
if (CustomSongsData.TryGetValue(hash, out var songData))
{
return songData;
}

return null;
return CustomSongsData.GetValueOrDefault(hash);
}

public static ExtraSongData.DifficultyData? RetrieveDifficultyData(BeatmapLevel beatmapLevel, BeatmapKey beatmapKey)
Expand Down Expand Up @@ -99,7 +94,11 @@ internal static void LoadExtraSongData()
{
using var reader = new JsonTextReader(new StreamReader(DataPath));
var serializer = JsonSerializer.CreateDefault();
CustomSongsData = serializer.Deserialize<ConcurrentDictionary<string, ExtraSongData>?>(reader) ?? new ConcurrentDictionary<string, ExtraSongData>();
var songData = serializer.Deserialize<ConcurrentDictionary<string, ExtraSongData>?>(reader);
if (songData != null)
{
CustomSongsData = songData;
}
}
catch (Exception ex)
{
Expand All @@ -111,18 +110,10 @@ internal static void LoadExtraSongData()

internal static async Task SaveExtraSongDataAsync()
{
using var writer = new StreamWriter(DataPath);
await using var writer = new StreamWriter(DataPath);
await writer.WriteAsync(JsonConvert.SerializeObject(CustomSongsData, Formatting.None));
}

public static void RegisterCapability(string capability)
{
if (!_capabilities.Contains(capability))
{
_capabilities.Add(capability);
}
}

public static BeatmapCharacteristicSO? RegisterCustomCharacteristic(Sprite icon, string characteristicName, string hintText, string serializedName, string compoundIdPartName,
bool requires360Movement = false, bool containsRotationEvents = false, int sortingOrder = 99)
{
Expand Down Expand Up @@ -171,6 +162,14 @@ public static SeparateSongFolder AddSeparateSongFolder(string name, string folde
return separateSongFolder;
}

public static void RegisterCapability(string capability)
{
if (!_capabilities.Contains(capability))
{
_capabilities.Add(capability);
}
}

public static void DeregisterCapability(string capability)
{
_capabilities.Remove(capability);
Expand Down
Loading

0 comments on commit 56ebb1b

Please sign in to comment.