Program: Allow the user to specify the RNG seed

This commit is contained in:
OatmealDome 2024-08-11 14:04:35 -04:00
parent e684a2c3d0
commit e6b73be0b2
2 changed files with 8 additions and 3 deletions

View File

@ -20,6 +20,7 @@ Options:
--phaseLength <phaseLength> The length of each phase in hours. [default: 4] --phaseLength <phaseLength> The length of each phase in hours. [default: 4]
--scheduleLength <scheduleLength> How long the schedule should be in days. [default: 30] --scheduleLength <scheduleLength> How long the schedule should be in days. [default: 30]
--overridePhases <overridePhases> The override phases file. [] --overridePhases <overridePhases> The override phases file. []
--randomSeed <randomSeed> The seed for the random number generator. []
--version Show version information --version Show version information
-?, -h, --help Show help and usage information -?, -h, --help Show help and usage information
``` ```

View File

@ -1,4 +1,4 @@
using System.CommandLine; using System.CommandLine;
using System.CommandLine.Invocation; using System.CommandLine.Invocation;
using System.Text.Json; using System.Text.Json;
using OatmealDome.BinaryData; using OatmealDome.BinaryData;
@ -71,13 +71,16 @@ Option<int> scheduleLengthOption = new Option<int>("--scheduleLength", () => def
Option<string?> overridePhasesOption = Option<string?> overridePhasesOption =
new Option<string?>("--overridePhases", () => null, "The override phases file."); new Option<string?>("--overridePhases", () => null, "The override phases file.");
Option<uint?> seedOption = new Option<uint?>("--randomSeed", () => null, "The seed for the random number generator.");
Command command = new RootCommand("Generates a new VSSetting BYAMl file.") Command command = new RootCommand("Generates a new VSSetting BYAMl file.")
{ {
lastByamlArg, lastByamlArg,
outputByamlArg, outputByamlArg,
phaseLengthOption, phaseLengthOption,
scheduleLengthOption, scheduleLengthOption,
overridePhasesOption overridePhasesOption,
seedOption
}; };
command.SetHandler(context => Run(context)); command.SetHandler(context => Run(context));
@ -95,8 +98,9 @@ void Run(InvocationContext context)
int phaseLength = context.ParseResult.GetValueForOption(phaseLengthOption); int phaseLength = context.ParseResult.GetValueForOption(phaseLengthOption);
int scheduleLength = context.ParseResult.GetValueForOption(scheduleLengthOption); int scheduleLength = context.ParseResult.GetValueForOption(scheduleLengthOption);
string? overridePhasesPath = context.ParseResult.GetValueForOption(overridePhasesOption); string? overridePhasesPath = context.ParseResult.GetValueForOption(overridePhasesOption);
uint? specifiedSeed = context.ParseResult.GetValueForOption(seedOption);
uint seed = (uint)Environment.TickCount; uint seed = specifiedSeed ?? (uint)Environment.TickCount;
SeadRandom random = new SeadRandom(seed); SeadRandom random = new SeadRandom(seed);
Console.WriteLine("Random seed: " + seed); Console.WriteLine("Random seed: " + seed);