Enable trainer saving

untested
This commit is contained in:
Kurt
2022-02-19 17:34:30 -08:00
parent 62a4fbc629
commit 05bbdb98e1
2 changed files with 14 additions and 6 deletions

View File

@@ -21,6 +21,8 @@ public class FolderContainer : IFileContainer
public FolderContainer(string path) => FilePath = path;
public FolderContainer(string path, Func<string, bool> filter) : this(path) => Initialize(filter);
public IReadOnlyList<string> GetPaths() => Paths;
public void Initialize(Func<string, bool>? filter = null)
{
if (Paths.Count > 0)

View File

@@ -55,13 +55,19 @@ public void EditScript()
public void EditTrainers()
{
var folder = ROM.GetFilteredFolder(GameFile.TrainerData).FilePath;
var files = Directory.GetFiles(folder);
var data = files.Select(FlatBufferConverter.DeserializeFrom<TrData8a>).ToArray();
var names = files.Select(Path.GetFileNameWithoutExtension).ToArray();
var cache = new DataCache<TrData8a>(data);
using var form = new GenericEditor<TrData8a>(cache, names, "Trainers", canSave: false);
var folder = ROM.GetFilteredFolder(GameFile.TrainerData);
var cache = new DataCache<TrData8a>(folder)
{
Create = FlatBufferConverter.DeserializeFrom<TrData8a>,
Write = FlatBufferConverter.SerializeFrom,
};
var names = folder.GetPaths().Select(Path.GetFileNameWithoutExtension).ToArray();
using var form = new GenericEditor<TrData8a>(cache, names, "Trainers", canSave: true);
form.ShowDialog();
if (!form.Modified)
return;
cache.Save();
}
public void PopFlat<T1, T2>(GameFile file, string title, Func<T2, string> getName, Action? rand = null, bool canSave = true) where T1 : class, IFlatBufferArchive<T2> where T2 : class