Going the UI route
This commit is contained in:
parent
970303d5ec
commit
9d9f951e9d
36 changed files with 822 additions and 4 deletions
91
PersonaForge/Archetypes.cs
Normal file
91
PersonaForge/Archetypes.cs
Normal file
|
@ -0,0 +1,91 @@
|
|||
namespace PersonaForge;
|
||||
|
||||
public class Archetypes
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Dictionary<string, double> TraitBiases { get; set; } = new();
|
||||
|
||||
public static List<Archetypes> LoadFromJson(string json)
|
||||
{
|
||||
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.");
|
||||
|
||||
return definitions;
|
||||
}
|
||||
|
||||
public static List<Archetypes> DefaultArchetypes() => new()
|
||||
{
|
||||
new Archetypes
|
||||
{
|
||||
Name = "Grumpy",
|
||||
TraitBiases = new Dictionary<string, double>
|
||||
{
|
||||
{ "Nice", 0.2 },
|
||||
{ "Playful", 0.4 },
|
||||
{ "Outgoing", 0.6 },
|
||||
{ "Neat", 0.7 },
|
||||
{ "Active", 0.5 }
|
||||
}
|
||||
},
|
||||
new Archetypes
|
||||
{
|
||||
Name = "Party Animal",
|
||||
TraitBiases = new Dictionary<string, double>
|
||||
{
|
||||
{ "Outgoing", 0.9 },
|
||||
{ "Playful", 0.8 },
|
||||
{ "Active", 0.7 },
|
||||
{ "Nice", 0.5 },
|
||||
{ "Neat", 0.3 }
|
||||
}
|
||||
},
|
||||
new Archetypes
|
||||
{
|
||||
Name = "Lazy",
|
||||
TraitBiases = new Dictionary<string, double>
|
||||
{
|
||||
{ "Nice", 0.8 },
|
||||
{ "Playful", 0.6 },
|
||||
{ "Outgoing", 0.4 },
|
||||
{ "Neat", 0.2 },
|
||||
{ "Active", 0.1 }
|
||||
}
|
||||
},
|
||||
new Archetypes
|
||||
{
|
||||
Name = "Shy",
|
||||
TraitBiases = new Dictionary<string, double>
|
||||
{
|
||||
{ "Nice", 0.9 },
|
||||
{ "Playful", 0.7 },
|
||||
{ "Outgoing", 0.3 },
|
||||
{ "Neat", 0.5 },
|
||||
{ "Active", 0.2 }
|
||||
}
|
||||
},
|
||||
new Archetypes
|
||||
{
|
||||
Name = "Energetic",
|
||||
TraitBiases = new Dictionary<string, double>
|
||||
{
|
||||
{ "Nice", 0.7 },
|
||||
{ "Playful", 0.6 },
|
||||
{ "Outgoing", 0.5 },
|
||||
{ "Neat", 0.4 },
|
||||
{ "Active", 0.3 }
|
||||
}
|
||||
},
|
||||
new Archetypes
|
||||
{
|
||||
Name = "Random",
|
||||
TraitBiases = new()
|
||||
}
|
||||
};
|
||||
}
|
2
PersonaForge/GlobalUsing.cs
Normal file
2
PersonaForge/GlobalUsing.cs
Normal file
|
@ -0,0 +1,2 @@
|
|||
global using System.Text.Json;
|
||||
global using System.CommandLine;
|
11
PersonaForge/PersonaForge.csproj
Normal file
11
PersonaForge/PersonaForge.csproj
Normal file
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Version>0.5.103</Version>
|
||||
<VersionSuffix>lts</VersionSuffix>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
12
PersonaForge/PersonaProfile.cs
Normal file
12
PersonaForge/PersonaProfile.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
namespace PersonaForge;
|
||||
|
||||
public class PersonaProfile
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Archetype { get; set; } = string.Empty;
|
||||
|
||||
// Fandom Wiki calls them "Qualities," but I use the term "Traits" internally
|
||||
public PersonalityTraits Qualities { get; set; } = new();
|
||||
|
||||
public static string ToJson(PersonaProfile profile) => JsonSerializer.Serialize(profile, new JsonSerializerOptions { WriteIndented = true });
|
||||
}
|
74
PersonaForge/PersonalityGen.cs
Normal file
74
PersonaForge/PersonalityGen.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
namespace PersonaForge;
|
||||
|
||||
public static class PersonalityGen
|
||||
{
|
||||
const int MaxPoints = 10;
|
||||
const int TotalBudget = 25;
|
||||
static readonly Random rng = new();
|
||||
|
||||
public static PersonalityTraits GenerateRandom(Dictionary<string, double>? bias = null)
|
||||
{
|
||||
var profile = PersonalityTraits.Create();
|
||||
var traits = new List<string> { "Outgoing", "Nice", "Playful", "Neat", "Active" };
|
||||
var remaining = TotalBudget;
|
||||
|
||||
if (bias != null)
|
||||
{
|
||||
foreach (var kvp in bias)
|
||||
{
|
||||
var trait = kvp.Key;
|
||||
var points = Convert.ToInt32(kvp.Value);
|
||||
var safePoints = Math.Min(points, MaxPoints);
|
||||
SetTraitPoints(profile, trait, safePoints);
|
||||
remaining -= points;
|
||||
}
|
||||
}
|
||||
|
||||
while (remaining > 0)
|
||||
{
|
||||
var trait = traits[rng.Next(traits.Count)];
|
||||
var current = GetCurrentTraitPoints(profile, trait);
|
||||
if (current < MaxPoints)
|
||||
{
|
||||
var add = (rng.NextDouble() < 0.1) ? Math.Min(2, MaxPoints - current) : 1;
|
||||
add = Math.Min(add, remaining);
|
||||
SetTraitPoints(profile, trait, current + add);
|
||||
remaining -= add;
|
||||
}
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
static int GetCurrentTraitPoints(PersonalityTraits p, string trait) => trait switch
|
||||
{
|
||||
"Outgoing" => p.Outgoing,
|
||||
"Nice" => p.Nice,
|
||||
"Playful" => p.Playful,
|
||||
"Neat" => p.Neat,
|
||||
"Active" => p.Active,
|
||||
_ => 0
|
||||
};
|
||||
|
||||
static void SetTraitPoints(PersonalityTraits p, string trait, int points)
|
||||
{
|
||||
switch (trait)
|
||||
{
|
||||
case "Outgoing":
|
||||
p.Outgoing = points;
|
||||
break;
|
||||
case "Nice":
|
||||
p.Nice = points;
|
||||
break;
|
||||
case "Playful":
|
||||
p.Playful = points;
|
||||
break;
|
||||
case "Neat":
|
||||
p.Neat = points;
|
||||
break;
|
||||
case "Active":
|
||||
p.Active = points;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
14
PersonaForge/PersonalityTraits.cs
Normal file
14
PersonaForge/PersonalityTraits.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace PersonaForge;
|
||||
|
||||
public class PersonalityTraits
|
||||
{
|
||||
public int Neat { get; set; }
|
||||
public int Outgoing { get; set; }
|
||||
public int Active { get; set; }
|
||||
public int Playful { get; set; }
|
||||
public int Nice { get; set; }
|
||||
|
||||
public static PersonalityTraits Create() => new();
|
||||
|
||||
public int TotalPoints() => Outgoing + Nice + Playful + Neat + Active;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue