diff --git a/CrossPlatformUI/ViewModels/GenerateRomViewModel.cs b/CrossPlatformUI/ViewModels/GenerateRomViewModel.cs index 20e1c532..b5b4fe56 100644 --- a/CrossPlatformUI/ViewModels/GenerateRomViewModel.cs +++ b/CrossPlatformUI/ViewModels/GenerateRomViewModel.cs @@ -4,6 +4,7 @@ using System.Reactive; using System.Reactive.Disposables; using System.Reactive.Subjects; +using System.IO; using System.Reflection; using System.Text.Json.Serialization; using System.Threading; @@ -96,8 +97,14 @@ async void GenerateSeed() if(!tokenSource.IsCancellationRequested && output.success) { var flags = config.SerializeFlags(); - var basename = $"Z2_{config.Seed}_{flags}"; - var filename = basename + ".nes"; + var version = Assembly.GetEntryAssembly()!.GetName().Version!; + var versionstr = $"{version.Major}.{version.Minor}.{version.Build}"; + var filename = OutputFilenameFormatter.Format(config.OutputFilenameTemplate, flags, config.Seed, randomizer.Hash, version: versionstr); + var basename = Path.GetFileNameWithoutExtension(filename); + if (string.IsNullOrEmpty(basename)) + { + basename = filename; + } await files.SaveGeneratedBinaryFile(filename, output.romdata!, Main.OutputFilePath); #if DEBUG var debugfile = basename + ".mlb"; diff --git a/CrossPlatformUI/ViewModels/RandomizerViewModel.cs b/CrossPlatformUI/ViewModels/RandomizerViewModel.cs index 8e45f03f..17c42d72 100644 --- a/CrossPlatformUI/ViewModels/RandomizerViewModel.cs +++ b/CrossPlatformUI/ViewModels/RandomizerViewModel.cs @@ -28,22 +28,28 @@ public class RandomizerViewModel : ReactiveValidationObject, IRoutableViewModel, [JsonIgnore] public BehaviorSubject FlagsValidSubject = new(true); - private bool IsFlagStringValid(string flags) + private static bool IsFlagStringValid(string flags) => FlagPasteParser.IsValidFlagString(flags); + + private string flagInput = ""; + + [JsonIgnore] + public string FlagInput { - try - { - _ = new RandomizerConfiguration(flags); - return true; - } - catch + get => flagInput; + set { - return false; + var trimmedValue = value?.Trim() ?? ""; + var (extractedFlags, extractedSeed) = FlagPasteParser.Parse(trimmedValue); + + if (Main is not null && !string.IsNullOrEmpty(extractedSeed)) + { + Main.Config.Seed = extractedSeed; + } + + this.RaiseAndSetIfChanged(ref flagInput, extractedFlags ?? trimmedValue); } } - [JsonIgnore] - public string FlagInput { get; set { field = value.Trim(); this.RaisePropertyChanged(); } } = ""; - [JsonIgnore] public string Seed { diff --git a/CrossPlatformUI/ViewModels/Tabs/SpritePreviewViewModel.cs b/CrossPlatformUI/ViewModels/Tabs/SpritePreviewViewModel.cs index 782fe83b..ab7bdf28 100644 --- a/CrossPlatformUI/ViewModels/Tabs/SpritePreviewViewModel.cs +++ b/CrossPlatformUI/ViewModels/Tabs/SpritePreviewViewModel.cs @@ -63,6 +63,12 @@ public BeamSprites BeamSprite set { Main.Config.BeamSprite = value; this.RaisePropertyChanged(); } } + public string OutputFilenameTemplate + { + get => Main.Config.OutputFilenameTemplate; + set { Main.Config.OutputFilenameTemplate = value; this.RaisePropertyChanged(); } + } + public byte spriteTunicColor { get; private set; } public byte spriteSkinTone { get; private set; } public byte spriteOutlineColor { get; private set; } diff --git a/CrossPlatformUI/Views/RandomizerView.axaml b/CrossPlatformUI/Views/RandomizerView.axaml index 9918c202..43dc2d82 100644 --- a/CrossPlatformUI/Views/RandomizerView.axaml +++ b/CrossPlatformUI/Views/RandomizerView.axaml @@ -19,7 +19,7 @@ - +