Skip to content

Commit

Permalink
[+] Config version 2.2 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Dec 2, 2024
1 parent e296bf5 commit e8aba37
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 32 deletions.
1 change: 1 addition & 0 deletions AquaMai.Config.Interfaces/IConfigView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public interface IConfigView
public T GetValueOrDefault<T>(string path, T defaultValue = default);
public bool TryGetValue<T>(string path, out T resultValue);
public bool Remove(string path);
public bool IsSectionEnabled(string path);
public string ToToml();
public IConfigView Clone();
}
20 changes: 20 additions & 0 deletions AquaMai.Config/ConfigView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,24 @@ public IConfigView Clone()
{
return new ConfigView(ToToml());
}

public bool IsSectionEnabled(string path)
{
if (TryGetValue(path, out object section))
{
if (section is bool enabled)
{
return enabled;
}
else if (section is TomlTable table)
{
if (Utility.TomlTryGetValueCaseInsensitive(table, "Disabled", out var disabled))
{
return !Utility.IsTrutyOrDefault(disabled);
}
return true;
}
}
return false;
}
}
3 changes: 2 additions & 1 deletion AquaMai.Config/Migration/ConfigMigrationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class ConfigMigrationManager : IConfigMigrationManager
new List<IConfigMigration>
{
new ConfigMigration_V1_0_V2_0(),
new ConfigMigration_V2_0_V2_1()
new ConfigMigration_V2_0_V2_1(),
new ConfigMigration_V2_1_V2_2(),
}.ToDictionary(m => m.FromVersion);

public string LatestVersion { get; }
Expand Down
22 changes: 1 addition & 21 deletions AquaMai.Config/Migration/ConfigMigration_V2_0_V2_1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,12 @@ public IConfigView Migrate(IConfigView src)
var dst = src.Clone();
dst.SetValue("Version", ToVersion);

if (IsSectionEnabled(src, "Tweaks.ResetTouchAfterTrack"))
if (src.IsSectionEnabled("Tweaks.ResetTouchAfterTrack"))
{
dst.Remove("Tweaks.ResetTouchAfterTrack");
dst.SetValue("Tweaks.ResetTouch.AfterTrack", true);
}

return dst;
}

public bool IsSectionEnabled(IConfigView src, string path)
{
if (src.TryGetValue(path, out object section))
{
if (section is bool enabled)
{
return enabled;
}
else if (section is TomlTable table)
{
if (Utility.TomlTryGetValueCaseInsensitive(table, "Disabled", out var disabled))
{
return !Utility.IsTrutyOrDefault(disabled);
}
return true;
}
}
return false;
}
}
24 changes: 24 additions & 0 deletions AquaMai.Config/Migration/ConfigMigration_V2_1_V2_2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using AquaMai.Config.Interfaces;
using Tomlet.Models;

namespace AquaMai.Config.Migration;

public class ConfigMigration_V2_1_V2_2 : IConfigMigration
{
public string FromVersion => "2.1";
public string ToVersion => "2.2";

public IConfigView Migrate(IConfigView src)
{
var dst = src.Clone();
dst.SetValue("Version", ToVersion);

if (src.IsSectionEnabled("GameSystem.Assets.UseJacketAsDummyMovie"))
{
dst.Remove("GameSystem.Assets.UseJacketAsDummyMovie");
dst.SetValue("GameSystem.Assets.MovieLoader.JacketAsMovie", true);
}

return dst;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,27 @@
namespace AquaMai.Mods.GameSystem.Assets;

[ConfigSection(
en: """
Use the png jacket above as MV if no .dat found in the movie folder.
Use together with `LoadLocalImages`.
""",
zh: """
如果 movie 文件夹中没有 dat 格式的 MV 的话,就用歌曲的封面做背景,而不是显示迪拉熊的笑脸
请和 `LoadLocalImages` 一起用
""")]
public class UseJacketAsDummyMovie
en: "Use mp4 files or the png jacket above as PV if no .dat found in the movie folder.",
zh: "使用封面作为 PV 以及直读 MP4 格式 PV 的选项")]
public class MovieLoader
{
private static VideoPlayer _videoPlayer = null;
[ConfigEntry(
en: """
Use jacket as movie
Use together with `LoadLocalImages`.
""",
zh: """
用封面作为背景 PV
请和 `LoadLocalImages` 一起用
""")]
private static bool jacketAsMovie = true;

[ConfigEntry(
en: "Load MP4 files from LocalAssets",
zh: "从 LocalAssets 中加载 MP4 文件作为 PV")]
private static bool loadMp4Movie = true;

private static VideoPlayer _videoPlayer;

[HarmonyPostfix]
[HarmonyPatch(typeof(GameCtrl), "IsReady")]
Expand Down

0 comments on commit e8aba37

Please sign in to comment.