From 6a9c9a45337e6661e88f0a44007d2e495b9dfc15 Mon Sep 17 00:00:00 2001 From: Tony Bark Date: Mon, 28 Apr 2025 11:45:04 -0400 Subject: [PATCH] CLI tool - Dotnet tool support - Moved profile import/load to after 1.0 --- .config/dotnet-tools.json | 5 +++ GlobalUsing.cs | 1 + PersonaForge.csproj | 10 +++++- Program.cs | 67 +++++++++++++++------------------------ README.md | 5 +-- 5 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 .config/dotnet-tools.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..b0e38ab --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,5 @@ +{ + "version": 1, + "isRoot": true, + "tools": {} +} \ No newline at end of file diff --git a/GlobalUsing.cs b/GlobalUsing.cs index a32a4f6..4b8d20b 100644 --- a/GlobalUsing.cs +++ b/GlobalUsing.cs @@ -1 +1,2 @@ global using System.Text.Json; +global using System.CommandLine; diff --git a/PersonaForge.csproj b/PersonaForge.csproj index 2e18e02..4a25ef0 100644 --- a/PersonaForge.csproj +++ b/PersonaForge.csproj @@ -2,10 +2,18 @@ Exe - 0.4.102 + 0.5.101 net9.0 enable enable + true + personaforge + PersonaForge + + + + + diff --git a/Program.cs b/Program.cs index 4631eb2..1149720 100644 --- a/Program.cs +++ b/Program.cs @@ -3,49 +3,34 @@ using PersonaForge; -Console.WriteLine("=== Welcome to The Sims 2 Personality Generator ==="); - -Console.Write("Enter Sim's name: "); -string name = Console.ReadLine() ?? "Unndanmed Sim"; - -// Move the conversion logic to a separate method -Console.WriteLine("\nAvailable Archetypes:"); var archetypeList = Archetypes.DefaultArchetypes(); var archetypeDict = new Dictionary>(); -foreach (var archetype in archetypeList) + +var rootCommand = new RootCommand("PersonaForge: Sims 2 Personality Generator"); + +var nameOption = new Option( + name: "--name", + description: "Enter a name for the Sim"); + +var archetypeOption = new Option( + name: "--archetype", + description: "The archetype template to base traits on", + getDefaultValue: () => "Random"); + +rootCommand.AddOption(nameOption); +rootCommand.AddOption(archetypeOption); + +rootCommand.SetHandler(async (string name, string archetype) => { - Console.WriteLine($"- {archetype.Name}"); - archetypeDict.Add(archetype.Name, archetype.TraitBiases); -} + var traits = PersonalityGen.GenerateRandom(archetypeDict.GetValueOrDefault(archetype)); + var profile = new PersonaProfile + { + Name = name, + Qualities = traits, + Archetype = archetype + }; -Console.Write("Choose an Archetype (or 'Random'): "); -string archetypeInput = Console.ReadLine() ?? "Random"; -if (!archetypeDict.ContainsKey(archetypeInput)) -{ - Console.WriteLine("Invalid archetype. Using Random."); - archetypeInput = "Random"; -} + Console.WriteLine(PersonaProfile.ToJson(profile)); +}, nameOption, archetypeOption); -Console.WriteLine($"{Environment.NewLine}Generating {archetypeInput} profile..."); -var qualities = PersonalityGen.GenerateRandom(archetypeDict[archetypeInput]); -var profile = new PersonaProfile -{ - Name = name, - Qualities = qualities, - Archetype = archetypeInput -}; - -Console.WriteLine($"{Environment.NewLine}--- Generated Profile ---{Environment.NewLine}{PersonaProfile.ToJson(profile)}"); - -Console.Write("Save profile? (y/n): "); -var saveInput = Console.ReadLine()?.Trim().ToLowerInvariant(); - -if (saveInput == "y") -{ - var safeName = name.Replace(" ", "_").Replace("\"", ""); - File.WriteAllText($"{safeName}.json", PersonaProfile.ToJson(profile)); - Console.WriteLine($"Profile saved as {name}.json"); -} - -Console.WriteLine($"Done. Forge on! 🔥{Environment.NewLine}Press any key to exit..."); -Console.ReadKey(); +return await rootCommand.InvokeAsync(args); diff --git a/README.md b/README.md index c6598d2..f5151fe 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,13 @@ With Sims 3 and later, creating personalities is as simple as selecting a trait. | Phase | Goal | Status | | ----- | ------------------------------------------- | ------ | -| v0.1 | Core random point generator (working) | ✅ | +| v0.1 | Core random point generator | ✅ | | v0.2 | PersonalityProfile class | ✅ | | v0.3 | Interactive JSON export | ✅ | | v0.4 | Archetypes with weighted biases | ✅ | -| v0.5 | Profile import/load from JSON | 🔜 | +| v0.5 | Command line tool | ✅ | | v1.0 | Stable "Release" version with documentation | 🔜 | +| v1.x | Profile import/load from JSON | 🔜 | ## 🧩 Tech Stack