Export option

- Moved archetype variables into handler
This commit is contained in:
Tony Bark 2025-04-28 11:58:42 -04:00
parent 499782924f
commit 8c33834975
3 changed files with 27 additions and 12 deletions

View file

@ -2,8 +2,8 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<Version>0.5.101</Version> <Version>0.5.102</Version>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<PackAsTool>true</PackAsTool> <PackAsTool>true</PackAsTool>

View file

@ -3,26 +3,34 @@
using PersonaForge; using PersonaForge;
var archetypeList = Archetypes.DefaultArchetypes();
var archetypeDict = new Dictionary<string, Dictionary<string, double>>();
var rootCommand = new RootCommand("PersonaForge: Sims 2 Personality Generator"); var rootCommand = new RootCommand("PersonaForge: Sims 2 Personality Generator");
var nameOption = new Option<string>( var nameOption = new Option<string>(
name: "--name", name: "--name",
description: "Enter a name for the Sim"); description: "Enter a name for the Sim"
);
var archetypeOption = new Option<string>( var archetypeOption = new Option<string>(
name: "--archetype", name: "--archetype",
description: "The archetype template to base traits on", description: "The archetype template to base traits on",
getDefaultValue: () => "Random"); getDefaultValue: () => "Random"
);
var exportOption = new Option<bool>(
name: "--export",
description: "Export the generated profile to a file"
);
rootCommand.AddOption(nameOption); rootCommand.AddOption(nameOption);
rootCommand.AddOption(archetypeOption); rootCommand.AddOption(archetypeOption);
rootCommand.AddOption(exportOption);
rootCommand.SetHandler(async (string name, string archetype) => rootCommand.SetHandler(async (string name, string archetype, bool export) =>
{ {
var traits = PersonalityGen.GenerateRandom(archetypeDict.GetValueOrDefault(archetype)); var archetypeList = Archetypes.DefaultArchetypes();
var archetypeDict = new Dictionary<string, Dictionary<string, double>>();
var traits = PersonalityGen.GenerateRandom(archetypeDict.GetValueOrDefault(archetype, new()));
var profile = new PersonaProfile var profile = new PersonaProfile
{ {
Name = name, Name = name,
@ -30,7 +38,14 @@ rootCommand.SetHandler(async (string name, string archetype) =>
Archetype = archetype Archetype = archetype
}; };
Console.WriteLine(PersonaProfile.ToJson(profile)); Console.WriteLine($"--- Generated Profile ---{Environment.NewLine}{PersonaProfile.ToJson(profile)}");
}, nameOption, archetypeOption);
if (export)
{
var safeName = name.Replace(" ", "_").Replace("\"", "");
await File.WriteAllTextAsync($"{safeName}.json", PersonaProfile.ToJson(profile));
}
}, nameOption, archetypeOption, exportOption);
return await rootCommand.InvokeAsync(args); return await rootCommand.InvokeAsync(args);

View file

@ -42,7 +42,7 @@ With Sims 3 and later, creating personalities is as simple as selecting a trait.
## 📦 Example ## 📦 Example
```shell ```shell
personaforge --name "Max Casey" --archetype "Party Animal" personaforge --name "Max Casey" --archetype "Party Animal" (--export)
``` ```
```json ```json