Adds rng/naming
This commit is contained in:
parent
45d2cc495c
commit
822281db3c
|
|
@ -373,6 +373,8 @@ dependencies = [
|
|||
"env_logger",
|
||||
"log",
|
||||
"miette",
|
||||
"once_cell",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
|
|
@ -484,6 +486,15 @@ dependencies = [
|
|||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||
dependencies = [
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.103"
|
||||
|
|
@ -508,6 +519,35 @@ version = "5.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
||||
dependencies = [
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.12.2"
|
||||
|
|
@ -976,3 +1016,23 @@ name = "wit-bindgen"
|
|||
version = "0.46.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ea879c944afe8a2b25fef16bb4ba234f47c694565e97383b36f3a878219065c"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf955aa904d6040f70dc8e9384444cb1030aed272ba3cb09bbc4ab9e7c1f34f5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
|
||||
#![deny(clippy::unwrap_used)]
|
||||
use clap::{ArgAction, Parser, Subcommand};
|
||||
use lib_efo::naming::NAMING;
|
||||
|
||||
use crate::commands::init::InitCmd;
|
||||
use crate::{commands::epoch::cli_epoch::EpochCmd, error::AppError};
|
||||
|
|
@ -72,6 +73,17 @@ enum TopLevelCmd {
|
|||
/// in stdout and returned as a `miette::Result<()>`.
|
||||
fn main() -> miette::Result<()> {
|
||||
env_logger::init();
|
||||
// 1. Generate a character name
|
||||
let character = NAMING.generate_character_name();
|
||||
println!("Character: {}", character);
|
||||
|
||||
// 2. Generate a town name
|
||||
let town = NAMING.generate_town_name();
|
||||
println!("Town: {}", town);
|
||||
|
||||
// 3. Pick an event idea
|
||||
let event = NAMING.generate_long_character_name();
|
||||
println!("Event idea: {}", event);
|
||||
let cli = Cli::parse();
|
||||
|
||||
if let Err(e) = exec_dispatch(cli) {
|
||||
|
|
|
|||
|
|
@ -15,3 +15,5 @@ derive_more = {workspace = true}
|
|||
cli-table = "0.5.0"
|
||||
uuid = { version = "1.18.1", features = ["serde", "v4"] }
|
||||
colored = "3.0.0"
|
||||
rand = "0.9.2"
|
||||
once_cell = "1.21.3"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,551 @@
|
|||
{
|
||||
"first_names": [
|
||||
"Aeron",
|
||||
"Brienne",
|
||||
"Cedric",
|
||||
"Darya",
|
||||
"Eldon",
|
||||
"Fiora",
|
||||
"Galen",
|
||||
"Hela",
|
||||
"Ivor",
|
||||
"Juno",
|
||||
"Aldric",
|
||||
"Briar",
|
||||
"Caelum",
|
||||
"Dorin",
|
||||
"Elysia",
|
||||
"Fendrel",
|
||||
"Gryphon",
|
||||
"Hector",
|
||||
"Iseult",
|
||||
"Kael",
|
||||
"Lysander",
|
||||
"Morgath",
|
||||
"Nyx",
|
||||
"Odin",
|
||||
"Riven",
|
||||
"Sylvan",
|
||||
"Thorne",
|
||||
"Valen",
|
||||
"Wraith",
|
||||
"Xander",
|
||||
"Yara",
|
||||
"Zarek",
|
||||
"Artemis",
|
||||
"Baldric",
|
||||
"Corvin",
|
||||
"Draven",
|
||||
"Eira",
|
||||
"Fenris",
|
||||
"Gale",
|
||||
"Helios",
|
||||
"Ivy",
|
||||
"Jasper",
|
||||
"Kara",
|
||||
"Luna",
|
||||
"Mira",
|
||||
"Nimrod",
|
||||
"Onyx",
|
||||
"Peregrine",
|
||||
"Quinn",
|
||||
"Aegon",
|
||||
"Brek",
|
||||
"Calandra",
|
||||
"Darrion",
|
||||
"Eryndor",
|
||||
"Fenn",
|
||||
"Galax",
|
||||
"Hestia",
|
||||
"Ilarion",
|
||||
"Jareth",
|
||||
"Kassandra",
|
||||
"Lyris",
|
||||
"Maelor",
|
||||
"Nyssa",
|
||||
"Oren",
|
||||
"Phaedra",
|
||||
"Quillon",
|
||||
"Rhea",
|
||||
"Soren",
|
||||
"Thalia",
|
||||
"Uther",
|
||||
"Vesper",
|
||||
"Wulfric",
|
||||
"Xara",
|
||||
"Yoren",
|
||||
"Zorath",
|
||||
"Aerith",
|
||||
"Baldrick",
|
||||
"Cress",
|
||||
"Dazai",
|
||||
"Elara",
|
||||
"Fira"
|
||||
],
|
||||
"last_names": [
|
||||
"Ashwood",
|
||||
"Blackthorn",
|
||||
"Cinderglow",
|
||||
"Dunwynn",
|
||||
"Everfield",
|
||||
"Frosthelm",
|
||||
"Goldleaf",
|
||||
"Holloway",
|
||||
"Iverson",
|
||||
"Jasper",
|
||||
"Ravencrest",
|
||||
"Stormblade",
|
||||
"Nightshade",
|
||||
"Wraithborne",
|
||||
"Dreadmoor",
|
||||
"Ironhart",
|
||||
"Bloodstone",
|
||||
"Stonegate",
|
||||
"Gloomreach",
|
||||
"Sablewick",
|
||||
"Rookhaven",
|
||||
"Ironcrest",
|
||||
"Bleakmoor",
|
||||
"Thornshield",
|
||||
"Wyrmwood",
|
||||
"Darkwater",
|
||||
"Stormbreaker",
|
||||
"Ebonhart",
|
||||
"Bloodbane",
|
||||
"Eclipseborne",
|
||||
"Firethorn",
|
||||
"Silvershade",
|
||||
"Blackfrost",
|
||||
"Sorrowblade",
|
||||
"Stonehelm",
|
||||
"Gravelock",
|
||||
"Voidwalker",
|
||||
"Nightfall",
|
||||
"Ashenfall",
|
||||
"Ashenridge",
|
||||
"Duskfall",
|
||||
"Thornhaven",
|
||||
"Gloombreaker",
|
||||
"Riftwalker",
|
||||
"Althmar",
|
||||
"Brimstone",
|
||||
"Cinderfall",
|
||||
"Duskbane",
|
||||
"Emberforge",
|
||||
"Frostbane",
|
||||
"Grimsbane",
|
||||
"Ironbark",
|
||||
"Jaggedspire",
|
||||
"Keldrith",
|
||||
"Lament",
|
||||
"Mistveil",
|
||||
"Nightglow",
|
||||
"Oathbreaker",
|
||||
"Palegrave",
|
||||
"Quicksilver",
|
||||
"Riftshard",
|
||||
"Shadowforge",
|
||||
"Thornbane",
|
||||
"Umbral",
|
||||
"Vengeance",
|
||||
"Wraithbane",
|
||||
"Xylander",
|
||||
"Yester",
|
||||
"Zephyr",
|
||||
"Blackfire",
|
||||
"Bloodthorn",
|
||||
"Crimsonveil",
|
||||
"Dreadspire",
|
||||
"Eboncrest",
|
||||
"Firebrand",
|
||||
"Grimshard",
|
||||
"Ironheart",
|
||||
"Javelin",
|
||||
"Krait",
|
||||
"Luminous",
|
||||
"Marrowbone",
|
||||
"Nocturne",
|
||||
"Obsidian",
|
||||
"Pyre",
|
||||
"Quagmire",
|
||||
"Reaver",
|
||||
"Sableheart",
|
||||
"Tidebreaker"
|
||||
],
|
||||
"town_prefixes": [
|
||||
"Ash",
|
||||
"Bright",
|
||||
"Cedar",
|
||||
"Deep",
|
||||
"Elder",
|
||||
"Frost",
|
||||
"Glen",
|
||||
"High",
|
||||
"Iron",
|
||||
"Jade",
|
||||
"Ashen",
|
||||
"Blood",
|
||||
"Cobalt",
|
||||
"Dusk",
|
||||
"Ebon",
|
||||
"Gloom",
|
||||
"Ironforge",
|
||||
"Keen",
|
||||
"Mourn",
|
||||
"Raven",
|
||||
"Storm",
|
||||
"Void",
|
||||
"Wraith",
|
||||
"Night",
|
||||
"Silvers",
|
||||
"Black",
|
||||
"Crimson",
|
||||
"Fire",
|
||||
"Grim",
|
||||
"Briar",
|
||||
"Obsidian",
|
||||
"Shade",
|
||||
"Thorn",
|
||||
"Sable",
|
||||
"Rift",
|
||||
"Dread",
|
||||
"Sorrow",
|
||||
"Bleak",
|
||||
"Eclipse",
|
||||
"Eternity",
|
||||
"Glint",
|
||||
"Gleam",
|
||||
"Hollow",
|
||||
"Lament",
|
||||
"Mire",
|
||||
"Molt",
|
||||
"Nocturne",
|
||||
"Onyx",
|
||||
"Pale",
|
||||
"Rook",
|
||||
"Shimmer",
|
||||
"Stonem",
|
||||
"Stone",
|
||||
"Stonehold",
|
||||
"Stonekeep",
|
||||
"Stoneforge",
|
||||
"Stormfall",
|
||||
"Stormgate",
|
||||
"Stormhold",
|
||||
"Stormreach",
|
||||
"Stormspire",
|
||||
"Stormwind",
|
||||
"Throne",
|
||||
"Twilight",
|
||||
"Valiant",
|
||||
"Valest",
|
||||
"Valer",
|
||||
"Vex",
|
||||
"Vile",
|
||||
"Warden"
|
||||
],
|
||||
"town_suffixes": [
|
||||
"brook",
|
||||
"dale",
|
||||
"field",
|
||||
"haven",
|
||||
"keep",
|
||||
"moor",
|
||||
"port",
|
||||
"reach",
|
||||
"stone",
|
||||
"vale",
|
||||
"forge",
|
||||
"shard",
|
||||
"hollow",
|
||||
"cove",
|
||||
"hall",
|
||||
"watch",
|
||||
"spire",
|
||||
"glade",
|
||||
"cliff",
|
||||
"glen",
|
||||
"tower",
|
||||
"fort",
|
||||
"hold",
|
||||
"bastion",
|
||||
"crypt",
|
||||
"crossing",
|
||||
"crown",
|
||||
"ridge",
|
||||
"fell",
|
||||
"breach",
|
||||
"briar",
|
||||
"bloom",
|
||||
"field",
|
||||
"river",
|
||||
"canyon",
|
||||
"fen",
|
||||
"crag",
|
||||
"gate",
|
||||
"bridge",
|
||||
"watchtower",
|
||||
"watcher",
|
||||
"mire",
|
||||
"waste",
|
||||
"breach",
|
||||
"fall",
|
||||
"crone",
|
||||
"shadow",
|
||||
"veil",
|
||||
"blight",
|
||||
"soul",
|
||||
"night",
|
||||
"storm",
|
||||
"fire",
|
||||
"ice",
|
||||
"iron",
|
||||
"dark",
|
||||
"glimmer",
|
||||
"glare",
|
||||
"scar",
|
||||
"scarred",
|
||||
"spire",
|
||||
"peak",
|
||||
"ridge",
|
||||
"hall",
|
||||
"hold",
|
||||
"spire",
|
||||
"vale",
|
||||
"vale",
|
||||
"haven",
|
||||
"hollow",
|
||||
"breach",
|
||||
"crust"
|
||||
],
|
||||
"character_adjectives": [
|
||||
"the Blind",
|
||||
"the Magnificent",
|
||||
"the Cunning",
|
||||
"the Swift",
|
||||
"the Stoic",
|
||||
"the Fearless",
|
||||
"the Enigmatic",
|
||||
"the Shadow",
|
||||
"the Light",
|
||||
"the Wanderer",
|
||||
"the Unbroken",
|
||||
"the Relentless",
|
||||
"the Ruthless",
|
||||
"the Merciless",
|
||||
"the Devourer",
|
||||
"the Ancient",
|
||||
"the Fallen",
|
||||
"the Immortal",
|
||||
"the Vengeful",
|
||||
"the Stormborn",
|
||||
"the Silent",
|
||||
"the Bloodied",
|
||||
"the Corrupt",
|
||||
"the Darkened",
|
||||
"the Ember",
|
||||
"the Crimson",
|
||||
"the Iron",
|
||||
"the Sable",
|
||||
"the Radiant",
|
||||
"the Tempest",
|
||||
"the Gloom",
|
||||
"the Warlord",
|
||||
"the Titan",
|
||||
"the Behemoth",
|
||||
"the Leviathan",
|
||||
"the Doombringer",
|
||||
"the Wraith",
|
||||
"the Sundered",
|
||||
"the Gloomstalker",
|
||||
"the Blight",
|
||||
"the Harbinger",
|
||||
"the Abyssal",
|
||||
"the Scourge",
|
||||
"the Dread",
|
||||
"the Fury",
|
||||
"the Specter",
|
||||
"the Maw",
|
||||
"the Protector",
|
||||
"the Guardian",
|
||||
"the Champion",
|
||||
"the Savior",
|
||||
"the Reaper",
|
||||
"the Harvester",
|
||||
"the Seeker",
|
||||
"the Whisperer",
|
||||
"the Tempest‑born",
|
||||
"the Iron‑clad",
|
||||
"the Moonlit",
|
||||
"the Sun‑scarred",
|
||||
"the Bone‑choked",
|
||||
"the Frost‑kissed",
|
||||
"the Ashen",
|
||||
"the Shattered",
|
||||
"the Echo‑bound",
|
||||
"the Vile",
|
||||
"the Harsh",
|
||||
"the Unseen",
|
||||
"the Unyielding",
|
||||
"of the North",
|
||||
"of the South",
|
||||
"of the East",
|
||||
"of the West",
|
||||
"of the Dark",
|
||||
"of the Light",
|
||||
"of the Forgotten",
|
||||
"of the Broken",
|
||||
"of the Eternal",
|
||||
"of the Shadowlands",
|
||||
"of the Burning",
|
||||
"of the Frozen",
|
||||
"of the Storm",
|
||||
"of the Depths",
|
||||
"of the Maw",
|
||||
"of the Ashen Sea",
|
||||
"of the Crimson Dawn"
|
||||
],
|
||||
"character_prefixes": [
|
||||
"Sir",
|
||||
"Lady",
|
||||
"Mighty",
|
||||
"Elder",
|
||||
"Grand",
|
||||
"Humble",
|
||||
"Radiant",
|
||||
"Lord",
|
||||
"High",
|
||||
"Royal",
|
||||
"Ancient",
|
||||
"Warden",
|
||||
"Seer",
|
||||
"Master"
|
||||
],
|
||||
"event_ideas": [
|
||||
{
|
||||
"name": "storm_flood",
|
||||
"description": "A sudden storm floods the river, threatening the local farms.",
|
||||
"stats": [
|
||||
{ "stat": "Population", "value": -5 },
|
||||
{ "stat": "Food", "value": -12 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "earthquake",
|
||||
"description": "A massive quake ripples across the continent, cracking roads and collapsing half the cities.",
|
||||
"stats": [
|
||||
{ "stat": "Infrastructure", "value": -15 },
|
||||
{ "stat": "Population", "value": -10 },
|
||||
{ "stat": "Happiness", "value": -8 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "region_blood_monsoon",
|
||||
"description": "A crimson rain falls over the region, poisoning crops and water sources.",
|
||||
"stats": [
|
||||
{ "stat": "Food", "value": -18 },
|
||||
{ "stat": "Health", "value": -12 },
|
||||
{ "stat": "Population", "value": -7 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "town_haunted_market",
|
||||
"description": "Spectral merchants appear, selling wares that vanish upon purchase, driving up prices.",
|
||||
"stats": [
|
||||
{ "stat": "Trade", "value": -9 },
|
||||
{ "stat": "Economy", "value": -6 },
|
||||
{ "stat": "Crime", "value": 4 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "region_darkening_sun",
|
||||
"description": "The sky is forever shrouded in an unnatural pallid dusk, lowering morale and crop yields.",
|
||||
"stats": [
|
||||
{ "stat": "Happiness", "value": -14 },
|
||||
{ "stat": "Food", "value": -10 },
|
||||
{ "stat": "Culture", "value": -5 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "town_giant_earthworm",
|
||||
"description": "A colossal earthworm burrows beneath the town, destabilizing foundations and causing tremors.",
|
||||
"stats": [
|
||||
{ "stat": "Infrastructure", "value": -12 },
|
||||
{ "stat": "Fortification", "value": -8 },
|
||||
{ "stat": "Population", "value": -4 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "region_arcane_surge",
|
||||
"description": "An uncontrollable surge of raw sangressence tears through reality, causing unpredictable effects.",
|
||||
"stats": [
|
||||
{ "stat": "Science", "value": 12 },
|
||||
{ "stat": "Education", "value": 8 },
|
||||
{ "stat": "Population", "value": -6 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "town_mushroom_meteor",
|
||||
"description": "A meteor of colossal fungi explodes over a town, releasing spores that induce vivid hallucinations.",
|
||||
"stats": [
|
||||
{ "stat": "Health", "value": -10 },
|
||||
{ "stat": "Crime", "value": 6 },
|
||||
{ "stat": "Population", "value": -3 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "region_infernal_flood",
|
||||
"description": "Molten rivers run through the region, boiling over cities and devouring forests.",
|
||||
"stats": [
|
||||
{ "stat": "Infrastructure", "value": -20 },
|
||||
{ "stat": "Food", "value": -15 },
|
||||
{ "stat": "Population", "value": -12 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "region_sand_vortex",
|
||||
"description": "A vortex of shifting sands sweeps the region, burying entire nations under dunes.",
|
||||
"stats": [
|
||||
{ "stat": "Infrastructure", "value": -14 },
|
||||
{ "stat": "Population", "value": -16 },
|
||||
{ "stat": "Trade", "value": -10 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "town_fall_of_mages",
|
||||
"description": "A rogue wizard unleashes a catastrophic spell, destroying a town's center and leaving a scar in reality.",
|
||||
"stats": [
|
||||
{ "stat": "Science", "value": -8 },
|
||||
{ "stat": "Population", "value": -10 },
|
||||
{ "stat": "Fortification", "value": -6 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "region_wind_of_gods",
|
||||
"description": "A relentless gale from the gods tears through the region, scattering armies and wrecking supply lines.",
|
||||
"stats": [
|
||||
{ "stat": "Transportation", "value": -12 },
|
||||
{ "stat": "Military", "value": -9 },
|
||||
{ "stat": "Population", "value": -3 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "region_ancient_sunrise",
|
||||
"description": "The sun rises in a crimson glow, amplifying the power of all dark cults and spreading fear.",
|
||||
"stats": [
|
||||
{ "stat": "Crime", "value": 9 },
|
||||
{ "stat": "Happiness", "value": -8 },
|
||||
{ "stat": "Influence", "value": -5 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "town_forest_of_eyes",
|
||||
"description": "A forest that watches every step, slowly siphoning the life force from any who walk through.",
|
||||
"stats": [
|
||||
{ "stat": "Health", "value": -10 },
|
||||
{ "stat": "Crime", "value": 7 },
|
||||
{ "stat": "Population", "value": -5 }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@
|
|||
pub mod error;
|
||||
pub mod entity;
|
||||
pub mod epoch;
|
||||
pub mod naming;
|
||||
pub mod stats;
|
||||
pub mod utils;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,183 @@
|
|||
//! Autonaming generator
|
||||
//! Supposed to be loaded with the world if needed
|
||||
use once_cell::sync::Lazy;
|
||||
use rand::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::stats::StatPair;
|
||||
|
||||
/// The structure that holds everything we need for name generation.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct NamingData {
|
||||
/// First name for characters
|
||||
pub first_names: Vec<String>,
|
||||
/// Last names for characters
|
||||
pub last_names: Vec<String>,
|
||||
/// Good prefixes for towns
|
||||
pub town_prefixes: Vec<String>,
|
||||
/// Good suffixes for town names
|
||||
pub town_suffixes: Vec<String>,
|
||||
|
||||
/// Character adjectives
|
||||
pub character_adjectives: Vec<String>,
|
||||
/// Name prefixes
|
||||
pub character_prefixes: Vec<String>,
|
||||
|
||||
/// A list of event ideas and characteristic associated to it
|
||||
pub event_ideas: Vec<EventDescription>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
/// An event with a description
|
||||
pub struct EventDescription {
|
||||
/// A short and meaninful name (an id of a sort)
|
||||
pub name: String,
|
||||
|
||||
/// A short description of the event
|
||||
pub description: String,
|
||||
|
||||
/// The stats affected by the event, and how much (-20 to +20) (100 being the maximum of a stat, event a change of -10 is meaningful)
|
||||
pub stats: Vec<StatPair>,
|
||||
}
|
||||
|
||||
// /// A generic stat pair with (stat, value), used mainly for clap
|
||||
// /// Accepts two forms
|
||||
// /// 1. "cri 10" (two separate tokens)
|
||||
// /// 2. "cri:10" (one token with a separator)
|
||||
// pub struct StatPair(ListStats, GenericStat);
|
||||
//
|
||||
// pub enum ListStats {
|
||||
// Demographics,
|
||||
// Population,
|
||||
// Growthrate,
|
||||
// Crime,
|
||||
// Happiness,
|
||||
// Economy,
|
||||
// Food,
|
||||
// Industry,
|
||||
// Science,
|
||||
// Trade,
|
||||
// Social,
|
||||
// Culture,
|
||||
// Education,
|
||||
// Tourism,
|
||||
// Influence,
|
||||
// Military,
|
||||
// Army,
|
||||
// Strength,
|
||||
// Fortification,
|
||||
// Threat,
|
||||
// Infrastructure,
|
||||
// Bureaucracy,
|
||||
// Transportation,
|
||||
// Sprawl,
|
||||
// Health,
|
||||
// }
|
||||
|
||||
impl NamingData {
|
||||
/// Load the data from the supplied path.
|
||||
/// If the file does **not** exist, a default (embedded) version is written
|
||||
/// to that path and returned.
|
||||
pub fn load_or_create<P: AsRef<Path>>(path: P) -> io::Result<Self> {
|
||||
let path = path.as_ref();
|
||||
|
||||
if path.exists() {
|
||||
// File exists → read & parse
|
||||
let contents = fs::read_to_string(path)?;
|
||||
let data: Self = serde_json::from_str(&contents)?;
|
||||
Ok(data)
|
||||
} else {
|
||||
// File does *not* exist → create from embedded default
|
||||
let default =
|
||||
serde_json::from_str(DEFAULT_JSON_STR).expect("Default JSON is malformed");
|
||||
// Ensure parent dirs exist
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
let json = serde_json::to_string_pretty(&default)?;
|
||||
fs::write(path, json)?;
|
||||
Ok(default)
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a random **character** name.
|
||||
pub fn generate_character_name(&self) -> String {
|
||||
let mut rng = rand::rng();
|
||||
|
||||
let binding = "Unnamed".into();
|
||||
let first = self.first_names.choose(&mut rng).unwrap_or(&binding);
|
||||
let binding = "".into();
|
||||
let last = self.last_names.choose(&mut rng).unwrap_or(&binding);
|
||||
format!("{} {}", first, last).trim().to_string()
|
||||
}
|
||||
|
||||
/// Generate a random **town** name.
|
||||
pub fn generate_town_name(&self) -> String {
|
||||
let mut rng = rand::rng();
|
||||
let binding = "".into();
|
||||
let prefix = self.town_prefixes.choose(&mut rng).unwrap_or(&binding);
|
||||
let suffix = self.town_suffixes.choose(&mut rng).unwrap_or(&binding);
|
||||
format!("{}{}", prefix, suffix).trim().to_string()
|
||||
}
|
||||
|
||||
// /// Pick a random event idea (you can reuse this or make a dedicated method).
|
||||
// pub fn random_event_idea(&self) -> &str {
|
||||
// let mut rng = rand::rng();
|
||||
// self.event_ideas
|
||||
// .choose(&mut rng)
|
||||
// .map(String::as_str)
|
||||
// .unwrap_or("No Event.")
|
||||
// }
|
||||
|
||||
/// Generates something like:
|
||||
/// “The Magnificent Sir Aurelius Blackthorn the Swift”
|
||||
/// Random adjective, prefix, base name and suffix are all optional.
|
||||
/// If a list is empty, that part is omitted.
|
||||
pub fn generate_long_character_name(&self) -> String {
|
||||
let mut rng = rand::rng();
|
||||
|
||||
// Helper: get a random element or None
|
||||
let adjective = self.character_adjectives.choose(&mut rng).cloned();
|
||||
let prefix = self.character_prefixes.choose(&mut rng).cloned();
|
||||
|
||||
// Base name (first + last)
|
||||
let base = self.generate_character_name();
|
||||
|
||||
// Assemble pieces
|
||||
let mut parts = Vec::new();
|
||||
|
||||
if let Some(pre) = prefix
|
||||
&& rand::random_bool(0.3)
|
||||
{
|
||||
parts.push(pre);
|
||||
}
|
||||
|
||||
parts.push(base);
|
||||
|
||||
if let Some(adj) = adjective
|
||||
&& rand::random_bool(0.3)
|
||||
{
|
||||
parts.push(adj);
|
||||
}
|
||||
|
||||
parts.join(" ")
|
||||
}
|
||||
}
|
||||
|
||||
/// The JSON that ships with the binary.
|
||||
/// `include_str!` pulls the file at compile time.
|
||||
const DEFAULT_JSON_STR: &str = include_str!("../naming.json");
|
||||
|
||||
/// Helper that determines the *runtime* location of the `naming.json` file.
|
||||
fn naming_file_path() -> PathBuf {
|
||||
PathBuf::from("naming.json")
|
||||
}
|
||||
|
||||
/// Global instance that is lazily initialised on first use.
|
||||
pub static NAMING: Lazy<NamingData> = Lazy::new(|| {
|
||||
let path = naming_file_path();
|
||||
NamingData::load_or_create(path).expect("Failed to load naming data")
|
||||
});
|
||||
|
|
@ -286,6 +286,13 @@ pub struct MetaStats {
|
|||
pub prestige: usize,
|
||||
}
|
||||
|
||||
/// A generic stat pair with (stat, value), used mainly for clap
|
||||
/// Accepts two forms
|
||||
/// 1. "cri 10" (two separate tokens)
|
||||
/// 2. "cri:10" (one token with a separator)
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct StatPair(ListStats, GenericStat);
|
||||
|
||||
/// Structure used to indicate position, possess nice helper methods to use as is in the program
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||
pub struct Position(isize, isize);
|
||||
|
|
@ -318,7 +325,7 @@ pub struct SummaryStats {
|
|||
}
|
||||
|
||||
/// Bridge between the CLI and the statistics logic.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum ListStats {
|
||||
Demographics,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use crate::stats::GameStat;
|
|||
use crate::stats::GenericStat;
|
||||
use crate::stats::ListStats;
|
||||
use crate::stats::OverallStats;
|
||||
use crate::stats::StatPair;
|
||||
|
||||
/// Creates a thin, deref‑able wrapper around an inner type.
|
||||
#[macro_export]
|
||||
|
|
@ -207,11 +208,6 @@ impl From<ListStats> for &str {
|
|||
}
|
||||
}
|
||||
|
||||
/// A generic stat pair with (stat, value), used mainly for clap
|
||||
/// Accepts two forms
|
||||
/// 1. "cri 10" (two separate tokens)
|
||||
/// 2. "cri:10" (one token with a separator)
|
||||
pub struct StatPair(ListStats, GenericStat);
|
||||
impl FromStr for StatPair {
|
||||
type Err = EpochError;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue