Skip to content

Commit

Permalink
Sharpen code
Browse files Browse the repository at this point in the history
  • Loading branch information
AshtonMemer committed Jan 19, 2024
1 parent 2b2ca7b commit 43395fd
Show file tree
Hide file tree
Showing 37 changed files with 485 additions and 500 deletions.
27 changes: 14 additions & 13 deletions Data/Album.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
using System.IO.Compression;
using CustomAlbums.Managers;
using CustomAlbums.Utilities;
using Il2CppPeroPeroGames.GlobalDefines;
using UnityEngine;
using Logger = CustomAlbums.Utilities.Logger;

namespace CustomAlbums.Data
{
public class Album
{
public int Index { get; }
public string Path { get; }
public bool IsPackaged { get; }
public AlbumInfo Info { get; }
public Sprite Cover => this.GetCover();
public AnimatedCover AnimatedCover => this.GetAnimatedCover();
public AudioClip Music => this.GetAudio();
public AudioClip Demo => this.GetAudio("demo");
public Dictionary<int, Sheet> Sheets { get; } = new();

private readonly Utilities.Logger _logger = new(nameof(Album));
private readonly Logger _logger = new(nameof(Album));

public Album(string path, int index)
{
Expand All @@ -30,6 +20,7 @@ public Album(string path, int index)
_logger.Error($"Could not find info.json at: {path}\\info.json");
throw new FileNotFoundException();
}

using var fileStream = File.OpenRead($"{path}\\info.json");
Info = Json.Deserialize<AlbumInfo>(fileStream);
}
Expand Down Expand Up @@ -60,6 +51,16 @@ public Album(string path, int index)
GetSheets();
}

public int Index { get; }
public string Path { get; }
public bool IsPackaged { get; }
public AlbumInfo Info { get; }
public Sprite Cover => this.GetCover();
public AnimatedCover AnimatedCover => this.GetAnimatedCover();
public AudioClip Music => this.GetAudio();
public AudioClip Demo => this.GetAudio("demo");
public Dictionary<int, Sheet> Sheets { get; } = new();

public bool HasFile(string name)
{
if (IsPackaged)
Expand Down Expand Up @@ -114,4 +115,4 @@ private void GetSheets()
}
}
}
}
}
11 changes: 7 additions & 4 deletions Data/AlbumInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public enum HiddenMode
public string Author { get; set; } = string.Empty;
public string LevelDesigner { get; set; } = string.Empty;
public string LevelDesigner1 { get; set; } = string.Empty;
public string LevelDesigner2 { get; set;} = string.Empty;
public string LevelDesigner3 { get; set;} = string.Empty;
public string LevelDesigner2 { get; set; } = string.Empty;
public string LevelDesigner3 { get; set; } = string.Empty;
public string LevelDesigner4 { get; set; } = string.Empty;
public string Bpm { get; set; } = "0";
public string Scene { get; set; } = "scene_01";
Expand All @@ -37,16 +37,19 @@ public Dictionary<int, string> Difficulties
return dict;
}
}

public string Difficulty1 { get; set; } = "0";
public string Difficulty2 { get; set; } = "0";
public string Difficulty3 { get; set; } = "0";
public string Difficulty4 { get; set; } = "0";

public string HideBmsMode { get; set; } = "CLICK";

[JsonConverter(typeof(Converters.NumberConverter))]
public string HideBmsDifficulty { get; set; } = "0";

public string HideBmsMessage { get; set; } = string.Empty;

public string[] SearchTags { get; set; } = Array.Empty<string>();
}
}
}
14 changes: 7 additions & 7 deletions Data/AnimatedCover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ namespace CustomAlbums.Data
{
public class AnimatedCover
{
public Sprite[] Frames { get; }
public int FrameCount => Frames.Length;
public int Width => Frames[0].texture.width;
public int Height => Frames[0].texture.height;
public int FramesPerSecond { get; }

public AnimatedCover(Sprite[] frames, int framesPerSecond)
{
Frames = frames;
FramesPerSecond = framesPerSecond;
}

public Sprite[] Frames { get; }
public int FrameCount => Frames.Length;
public int Width => Frames[0].texture.width;
public int Height => Frames[0].texture.height;
public int FramesPerSecond { get; }
}
}
}
4 changes: 2 additions & 2 deletions Data/AssetIdentifiers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ internal class AssetIdentifiers
"_map2",
"_map3",
"_map4"
};
};
}
}
}
1 change: 0 additions & 1 deletion Data/BmsStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public enum BossState

public static readonly Dictionary<string, BossState> AnimStatesLeft = new()
{

{ "in", BossState.OffScreen },
{ "out", BossState.Idle },
{ "boss_close_atk_1", BossState.Idle },
Expand Down
14 changes: 2 additions & 12 deletions Data/CustomAlbumsSave.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
using Il2CppPeroTools2.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;

namespace CustomAlbums.Data
namespace CustomAlbums.Data
{
public class CustomAlbumsSave
{
Expand All @@ -19,4 +9,4 @@ public class CustomAlbumsSave
public Dictionary<string, Dictionary<int, CustomChartSave>> Highest { get; set; } = new();
public Dictionary<string, List<int>> FullCombo { get; set; } = new();
}
}
}
10 changes: 2 additions & 8 deletions Data/CustomChartSave.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomAlbums.Data
namespace CustomAlbums.Data
{
public class CustomChartSave
{
Expand All @@ -17,4 +11,4 @@ public class CustomChartSave
public int FailCount { get; set; } = 0;
public bool Passed { get; set; } = false;
}
}
}
4 changes: 2 additions & 2 deletions Data/SceneEggs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum SceneEggs
Arknights = 4,
Miku = 5,
BadApple = 129,
Christmas = 999,
Christmas = 999
}
}
}
}
30 changes: 13 additions & 17 deletions Data/Sheet.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
using System.Text;
using System.Text.Json.Nodes;
using System.Text.Json.Nodes;
using CustomAlbums.Utilities;
using Il2CppAssets.Scripts.Database;
using Il2CppAssets.Scripts.GameCore;
using Il2CppAssets.Scripts.Structs;
using Il2CppGameLogic;
using UnityEngine;
using Logger = CustomAlbums.Utilities.Logger;

namespace CustomAlbums.Data
{
public class Sheet
{
public Album ParentAlbum { get; }
public string Md5 { get; }
public string MapName { get; }
public int Difficulty { get; }
public bool TalkFileVersion2 { get; set; } = false;

private readonly Logger _logger = new(nameof(Sheet));

public Sheet(string md5, Album parentAlbum, int difficulty)
Expand All @@ -28,6 +18,12 @@ public Sheet(string md5, Album parentAlbum, int difficulty)
MapName = $"album_{Path.GetFileNameWithoutExtension(parentAlbum.Path)}_map{difficulty}";
}

public Album ParentAlbum { get; }
public string Md5 { get; }
public string MapName { get; }
public int Difficulty { get; }
public bool TalkFileVersion2 { get; set; }

public StageInfo GetStage()
{
using var stream = ParentAlbum.OpenFileStream($"map{Difficulty}.bms");
Expand Down Expand Up @@ -56,21 +52,21 @@ public StageInfo GetStage()
_logger.Msg("Version 2 talk file!");
TalkFileVersion2 = true;
}

talkFile.Remove("version");
var dict = Json
.Il2CppJsonDeserialize<
Il2CppSystem.Collections.Generic.Dictionary<string,
Il2CppSystem.Collections.Generic.List<GameDialogArgs>>>(talkFile.ToJsonString());
stageInfo.dialogEvents = new Il2CppSystem.Collections.Generic.Dictionary<string, Il2CppSystem.Collections.Generic.List<GameDialogArgs>>();
foreach (var dialogEvent in dict)
{
stageInfo.dialogEvents.Add(dialogEvent.Key, dialogEvent.Value);
}
stageInfo.dialogEvents =
new Il2CppSystem.Collections.Generic.Dictionary<string,
Il2CppSystem.Collections.Generic.List<GameDialogArgs>>();
foreach (var dialogEvent in dict) stageInfo.dialogEvents.Add(dialogEvent.Key, dialogEvent.Value);
}
}

GlobalDataBase.dbStageInfo.SetStageInfo(stageInfo);
return stageInfo;
}
}
}
}
17 changes: 7 additions & 10 deletions Data/Talk.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using CustomAlbums.Utilities;
using Il2CppAssets.Scripts.Structs;
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Il2CppSystem.Collections.Generic;
using Il2CppAssets.Scripts.Structs;

namespace CustomAlbums.Data
{
Expand All @@ -17,9 +11,12 @@ public class Talk
public Il2CppSystem.Collections.Generic.List<GameDialogArgs> Japanese { get; set; }
public Il2CppSystem.Collections.Generic.List<GameDialogArgs> Korean { get; set; }

public Il2CppSystem.Collections.Generic.Dictionary<string, Il2CppSystem.Collections.Generic.List<GameDialogArgs>>.Enumerator GetEnumerator()
public Il2CppSystem.Collections.Generic.Dictionary<string,
Il2CppSystem.Collections.Generic.List<GameDialogArgs>>.Enumerator GetEnumerator()
{
var dict = new Il2CppSystem.Collections.Generic.Dictionary<string, Il2CppSystem.Collections.Generic.List<GameDialogArgs>>(5);
var dict =
new Il2CppSystem.Collections.Generic.Dictionary<string,
Il2CppSystem.Collections.Generic.List<GameDialogArgs>>(5);
dict["English"] = English;
dict["ChineseS"] = ChineseS;
dict["ChineseT"] = ChineseT;
Expand All @@ -28,4 +25,4 @@ public class Talk
return dict.GetEnumerator();
}
}
}
}
7 changes: 4 additions & 3 deletions Main.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using CustomAlbums.Managers;
using CustomAlbums.Patches;
using CustomAlbums.Utilities;
using MelonLoader;
using static CustomAlbums.Patches.AnimatedCoverPatch;
using Logger = CustomAlbums.Utilities.Logger;

namespace CustomAlbums
{
Expand Down Expand Up @@ -37,15 +37,16 @@ public override void OnApplicationQuit()
}

/// <summary>
/// This override adds support for animated covers.
/// This override adds support for animated covers.
/// </summary>
public override void OnUpdate()
{
base.OnUpdate();
MusicStageCellPatch.AnimateCoversUpdate();
}

/// <summary>
/// This override adds support for hot reloading.
/// This override adds support for hot reloading.
/// </summary>
public override void OnFixedUpdate()
{
Expand Down
Loading

0 comments on commit 43395fd

Please sign in to comment.