Bunch of work on Option Editor.

This commit is contained in:
Ottermandias 2023-03-27 17:09:19 +02:00
parent 1253079968
commit fbe2ed1a71
21 changed files with 749 additions and 595 deletions

View file

@ -45,13 +45,22 @@ public class CommunicatorService : IDisposable
/// </list> </summary>
public readonly EventWrapper<nint, string, nint> CreatedCharacterBase = new(nameof(CreatedCharacterBase));
/// <summary><list type="number">
/// <summary> <list type="number">
/// <item>Parameter is the type of data change for the mod, which can be multiple flags. </item>
/// <item>Parameter is the changed mod. </item>
/// <item>Parameter is the old name of the mod in case of a name change, and null otherwise. </item>
/// </list> </summary>
public readonly EventWrapper<ModDataChangeType, Mod, string?> ModDataChanged = new(nameof(ModDataChanged));
/// <summary><list type="number">
/// <item>Parameter is the type option change. </item>
/// <item>Parameter is the changed mod. </item>
/// <item>Parameter is the index of the changed group inside the mod. </item>
/// <item>Parameter is the index of the changed option inside the group or -1 if it does not concern a specific option. </item>
/// <item>Parameter is the index of the group an option was moved to. </item>
/// </list> </summary>
public readonly EventWrapper<ModOptionChangeType, Mod, int, int, int> ModOptionChanged = new(nameof(ModOptionChanged));
public void Dispose()
{
CollectionChange.Dispose();
@ -60,5 +69,6 @@ public class CommunicatorService : IDisposable
CreatingCharacterBase.Dispose();
CreatedCharacterBase.Dispose();
ModDataChanged.Dispose();
ModOptionChanged.Dispose();
}
}

View file

@ -71,4 +71,21 @@ public class FilenameService
/// <summary> Obtain the path of the meta file given a mod directory. </summary>
public string ModMetaPath(string modDirectory)
=> Path.Combine(modDirectory, "meta.json");
/// <summary> Obtain the path of the file describing a given option group by its index and the mod. If the index is < 0, return the path for the default mod file. </summary>
public string OptionGroupFile(Mod mod, int index)
=> OptionGroupFile(mod.ModPath.FullName, index, index >= 0 ? mod.Groups[index].Name : string.Empty);
/// <summary> Obtain the path of the file describing a given option group by its index, name and basepath. If the index is < 0, return the path for the default mod file. </summary>
public string OptionGroupFile(string basePath, int index, string name)
{
var fileName = index >= 0
? $"group_{index + 1:D3}_{name.RemoveInvalidPathSymbols().ToLowerInvariant()}.json"
: "default_mod.json";
return Path.Combine(basePath, fileName);
}
/// <summary> Enumerate all group files for a given mod. </summary>
public IEnumerable<FileInfo> GetOptionGroupFiles(Mod mod)
=> mod.ModPath.EnumerateFiles("group_*.json");
}