Zodiac option (buggy)

This commit is contained in:
Tony Bark 2025-04-28 13:56:46 -04:00
parent 0ae58c67fa
commit 45fdf40af2
5 changed files with 55 additions and 15 deletions

View file

@ -1,14 +1,39 @@
namespace PersonaForge; namespace PersonaForge;
public class ArchetypeDefinition public class Archetypes
{ {
public string Name { get; set; } public string Name { get; set; }
public Dictionary<string, double> TraitBiases { get; set; } = new(); public Dictionary<string, double> TraitBiases { get; set; } = new();
// TODO: Load default archetypes from a file or database public static Dictionary<string, double> LoadFromJson(string json)
public static List<ArchetypeDefinition> DefaultArchetypes() => new()
{ {
new ArchetypeDefinition var opt = new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = false
};
var definitions = JsonSerializer.Deserialize<List<Archetypes>>(json, opt);
if (definitions is null)
throw new InvalidOperationException("Failed to deserialize Archetype JSON.");
var traitBiases = new Dictionary<string, double>();
foreach (var def in definitions)
{
foreach (var traitBias in def.TraitBiases)
{
traitBiases[traitBias.Key] = traitBias.Value;
}
}
return traitBiases;
}
// TODO: Load default archetypes from a file or database
public static List<Archetypes> DefaultArchetypes() => new()
{
new Archetypes
{ {
Name = "Grumpy", Name = "Grumpy",
TraitBiases = new Dictionary<string, double> TraitBiases = new Dictionary<string, double>
@ -20,7 +45,7 @@ public class ArchetypeDefinition
{ "Active", 0.5 } { "Active", 0.5 }
} }
}, },
new ArchetypeDefinition new Archetypes
{ {
Name = "Party Animal", Name = "Party Animal",
TraitBiases = new Dictionary<string, double> TraitBiases = new Dictionary<string, double>
@ -32,7 +57,7 @@ public class ArchetypeDefinition
{ "Neat", 0.3 } { "Neat", 0.3 }
} }
}, },
new ArchetypeDefinition new Archetypes
{ {
Name = "Lazy", Name = "Lazy",
TraitBiases = new Dictionary<string, double> TraitBiases = new Dictionary<string, double>
@ -44,7 +69,7 @@ public class ArchetypeDefinition
{ "Active", 0.1 } { "Active", 0.1 }
} }
}, },
new ArchetypeDefinition new Archetypes
{ {
Name = "Shy", Name = "Shy",
TraitBiases = new Dictionary<string, double> TraitBiases = new Dictionary<string, double>
@ -56,7 +81,7 @@ public class ArchetypeDefinition
{ "Active", 0.2 } { "Active", 0.2 }
} }
}, },
new ArchetypeDefinition new Archetypes
{ {
Name = "Energetic", Name = "Energetic",
TraitBiases = new Dictionary<string, double> TraitBiases = new Dictionary<string, double>
@ -68,7 +93,7 @@ public class ArchetypeDefinition
{ "Active", 0.3 } { "Active", 0.3 }
} }
}, },
new ArchetypeDefinition new Archetypes
{ {
Name = "Random", Name = "Random",
TraitBiases = new() TraitBiases = new()

View file

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<Version>0.5.102</Version> <Version>0.5.103</Version>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View file

@ -16,6 +16,11 @@ var archetypeOption = new Option<string>(
getDefaultValue: () => "Random" getDefaultValue: () => "Random"
); );
var zodiacOption = new Option<bool>(
name: "--zodiac",
description: "Use zodiac signs instead of archetypes"
);
var exportOption = new Option<bool>( var exportOption = new Option<bool>(
name: "--export", name: "--export",
description: "Export the generated profile to a file" description: "Export the generated profile to a file"
@ -25,12 +30,22 @@ rootCommand.AddOption(nameOption);
rootCommand.AddOption(archetypeOption); rootCommand.AddOption(archetypeOption);
rootCommand.AddOption(exportOption); rootCommand.AddOption(exportOption);
rootCommand.SetHandler(async (string name, string archetype, bool export) => rootCommand.SetHandler(async (
string name,
string archetype,
bool zodiac,
bool export
) =>
{ {
var archetypeList = Archetypes.DefaultArchetypes(); var definitions = new Dictionary<string, double>();
var archetypeDict = new Dictionary<string, Dictionary<string, double>>();
var traits = PersonalityGen.GenerateRandom(archetypeDict.GetValueOrDefault(archetype, new())); definitions = Archetypes.LoadFromJson("archetypes.json");
if (zodiac)
definitions = Archetypes.LoadFromJson("zodiacs.json");
var traits = PersonalityGen.GenerateRandom(definitions.GetValueOrDefault(archetype, new()));
var profile = new PersonaProfile var profile = new PersonaProfile
{ {
Name = name, Name = name,
@ -46,6 +61,6 @@ rootCommand.SetHandler(async (string name, string archetype, bool export) =>
await File.WriteAllTextAsync($"{safeName}.json", PersonaProfile.ToJson(profile)); await File.WriteAllTextAsync($"{safeName}.json", PersonaProfile.ToJson(profile));
} }
}, nameOption, archetypeOption, exportOption); }, nameOption, archetypeOption, zodiacOption, exportOption);
return await rootCommand.InvokeAsync(args); return await rootCommand.InvokeAsync(args);