diff --git a/ArchetypeDefinition.cs b/Archetypes.cs similarity index 68% rename from ArchetypeDefinition.cs rename to Archetypes.cs index 725cc50..86d3c37 100644 --- a/ArchetypeDefinition.cs +++ b/Archetypes.cs @@ -1,14 +1,39 @@ namespace PersonaForge; -public class ArchetypeDefinition +public class Archetypes { public string Name { get; set; } public Dictionary TraitBiases { get; set; } = new(); - // TODO: Load default archetypes from a file or database - public static List DefaultArchetypes() => new() + public static Dictionary LoadFromJson(string json) { - new ArchetypeDefinition + var opt = new JsonSerializerOptions() + { + PropertyNameCaseInsensitive = false + }; + + var definitions = JsonSerializer.Deserialize>(json, opt); + + if (definitions is null) + throw new InvalidOperationException("Failed to deserialize Archetype JSON."); + + var traitBiases = new Dictionary(); + + 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 DefaultArchetypes() => new() + { + new Archetypes { Name = "Grumpy", TraitBiases = new Dictionary @@ -20,7 +45,7 @@ public class ArchetypeDefinition { "Active", 0.5 } } }, - new ArchetypeDefinition + new Archetypes { Name = "Party Animal", TraitBiases = new Dictionary @@ -32,7 +57,7 @@ public class ArchetypeDefinition { "Neat", 0.3 } } }, - new ArchetypeDefinition + new Archetypes { Name = "Lazy", TraitBiases = new Dictionary @@ -44,7 +69,7 @@ public class ArchetypeDefinition { "Active", 0.1 } } }, - new ArchetypeDefinition + new Archetypes { Name = "Shy", TraitBiases = new Dictionary @@ -56,7 +81,7 @@ public class ArchetypeDefinition { "Active", 0.2 } } }, - new ArchetypeDefinition + new Archetypes { Name = "Energetic", TraitBiases = new Dictionary @@ -68,7 +93,7 @@ public class ArchetypeDefinition { "Active", 0.3 } } }, - new ArchetypeDefinition + new Archetypes { Name = "Random", TraitBiases = new() diff --git a/PersonaForge.csproj b/PersonaForge.csproj index f6e24eb..a44cb36 100644 --- a/PersonaForge.csproj +++ b/PersonaForge.csproj @@ -2,7 +2,7 @@ Exe - 0.5.102 + 0.5.103 net8.0 enable enable diff --git a/Program.cs b/Program.cs index 389ad0b..db9aee6 100644 --- a/Program.cs +++ b/Program.cs @@ -16,6 +16,11 @@ var archetypeOption = new Option( getDefaultValue: () => "Random" ); +var zodiacOption = new Option( + name: "--zodiac", + description: "Use zodiac signs instead of archetypes" +); + var exportOption = new Option( name: "--export", description: "Export the generated profile to a file" @@ -25,12 +30,22 @@ rootCommand.AddOption(nameOption); rootCommand.AddOption(archetypeOption); 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 archetypeDict = new Dictionary>(); + var definitions = new Dictionary(); - 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 { Name = name, @@ -46,6 +61,6 @@ rootCommand.SetHandler(async (string name, string archetype, bool export) => await File.WriteAllTextAsync($"{safeName}.json", PersonaProfile.ToJson(profile)); } -}, nameOption, archetypeOption, exportOption); +}, nameOption, archetypeOption, zodiacOption, exportOption); return await rootCommand.InvokeAsync(args); diff --git a/Archetypes.json b/archetypes.json similarity index 100% rename from Archetypes.json rename to archetypes.json diff --git a/Zodiac.json b/zodiacs.json similarity index 100% rename from Zodiac.json rename to zodiacs.json