personaforge/PersonaForge.Console/Program.cs
2025-04-29 03:19:23 -04:00

68 lines
1.8 KiB
C#

// .NET 8 C# - Random Sims 2 Personality Allocator
// Clear, minimal, portable, with basic validation.
using PersonaForge;
var rootCommand = new RootCommand("PersonaForge: Sims 2 Personality Generator");
var nameOption = new Option<string>(
name: "--name",
description: "Enter a name for the Sim"
);
var archetypeOption = new Option<string>(
name: "--archetype",
description: "The archetype template to base traits on",
getDefaultValue: () => "Random"
);
var zodiacOption = new Option<bool>(
name: "--zodiac",
description: "Use zodiac signs instead of archetypes"
)
{ IsRequired = false };
var exportOption = new Option<bool>(
name: "--export",
description: "Export the generated profile to a file"
)
{ IsRequired = false };
rootCommand.AddOption(nameOption);
rootCommand.AddOption(archetypeOption);
rootCommand.AddOption(exportOption);
rootCommand.SetHandler(async (
string name,
string archetype,
bool zodiac,
bool export
) =>
{
var archetypeDefs = Archetypes.LoadFromJson("archetypes.json");
var archetypeDict = new Dictionary<string, Dictionary<string, double>>();
if (zodiac)
archetypeDefs = Archetypes.LoadFromJson("zodiacs.json");
var traits = PersonalityGen.GenerateRandom(archetypeDict.GetValueOrDefault(archetype, new()));
var profile = new PersonaProfile
{
Name = name,
Qualities = traits,
Archetype = archetype
};
Console.WriteLine($"--- Generated Profile ---{Environment.NewLine}{PersonaProfile.ToJson(profile)}");
if (export)
{
var safeName = name.Replace(" ", "_").Replace("\"", "");
await File.WriteAllTextAsync($"{safeName}.json", PersonaProfile.ToJson(profile));
}
}, nameOption, archetypeOption, zodiacOption, exportOption);
return await rootCommand.InvokeAsync(args);