From ced4e5d10e8bc62b5e3daf19eb7e918460b3073e Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 7 Dec 2025 19:16:06 +0100 Subject: [PATCH] POC on the generator --- bin_efo/src/commands/generate.rs | 64 ++++++++++++++- bin_efo/src/main.rs | 2 +- lib_efo/src/entity/implementations.rs | 8 +- lib_efo/src/lib.rs | 8 +- lib_efo/src/naming.rs | 68 ++++++++++++++++ lib_efo/src/stats/implementations.rs | 43 ++++++++++ naming.json | 108 +++++++++++++++++++++++++- 7 files changed, 288 insertions(+), 13 deletions(-) diff --git a/bin_efo/src/commands/generate.rs b/bin_efo/src/commands/generate.rs index c878639..b071ce8 100644 --- a/bin_efo/src/commands/generate.rs +++ b/bin_efo/src/commands/generate.rs @@ -1,18 +1,76 @@ //! Subcommand for fast generating ideas and displaying them //! This module does not add any structure (that would be either the prerogative of the bulk generator or the individual modules) -use clap::Subcommand; +use clap::{Args, Subcommand}; +use lib_efo::{Displayable, error::EpochError, naming::NAMING}; use crate::error::AppError; /// The types of examples to generate #[derive(Subcommand, Debug)] pub enum GenCmd { /// Generate a character - Character, + Character(Qty), + /// Events + Event(Qty), + /// Town + Town(Qty), + /// Exotic name + Exotic(Qty), +} + +#[derive(Args, Debug)] +pub struct Qty { + /// Amount of entities to generate + #[arg(short, long, default_value_t = 1)] + number: usize, + /// Full print + #[arg(long, action = clap::ArgAction::SetFalse, default_value_t = true)] + short: bool, } /// Handle all the generation pub fn gen_handler(cmd: &GenCmd) -> Result<(), AppError> { - let _ = cmd; + match cmd { + GenCmd::Character(args) => handle_chr(args)?, + GenCmd::Event(args) => handle_event(args)?, + GenCmd::Town(args) => handle_town(args)?, + GenCmd::Exotic(args) => handle_exotic(args)?, + } + Ok(()) +} + +/// Prints exotic name +fn handle_exotic(args: &Qty) -> Result<(), EpochError> { + for _ in 0..args.number { + println!("{}", NAMING.generate_exotic_character_name()) + } + Ok(()) +} + +/// Prints town +fn handle_town(args: &Qty) -> Result<(), EpochError> { + for _ in 0..args.number { + println!("{}", NAMING.generate_town_name()) + } + Ok(()) +} + +/// Print events +fn handle_event(args: &Qty) -> Result<(), EpochError> { + for _ in 0..args.number { + println!("{}", NAMING.random_event_idea()?.oneline_display()); + } + Ok(()) +} + +/// Print a character name +fn handle_chr(args: &Qty) -> Result<(), EpochError> { + for _ in 0..args.number { + if args.short { + println!("{}", NAMING.generate_long_character_name()) + } else { + println!("{}", NAMING.generate_character_name()) + } + } Ok(()) } diff --git a/bin_efo/src/main.rs b/bin_efo/src/main.rs index e86fc23..1fdb4fe 100644 --- a/bin_efo/src/main.rs +++ b/bin_efo/src/main.rs @@ -71,8 +71,8 @@ enum TopLevelCmd { // Chr(commands::chr::ChrCmd), // Town(commands::town::TownCmd), // Link(commands::link::LinkCmd), - #[command(subcommand)] /// Generate random structures and display them + #[command(subcommand)] Gen(GenCmd), } diff --git a/lib_efo/src/entity/implementations.rs b/lib_efo/src/entity/implementations.rs index 67f67d7..84efe83 100644 --- a/lib_efo/src/entity/implementations.rs +++ b/lib_efo/src/entity/implementations.rs @@ -70,18 +70,14 @@ impl Displayable for Entity { ); let line2 = format!( - "β”‚ └─ Faction: {}{}{}{} β”‚ Effect: {} {}, Stats: πŸ‘₯ {} | πŸ’° {} | πŸ›‘οΈ {} | πŸ—οΈ {}{}", + "β”‚ └─ Faction: {}{}{}{} β”‚ Effect: {} {}, Stats: {}", self.metadata.faction, capital, governor, prestige, self.effect_nature.to_symbol(), self.effect_bounds.to_symbol(), - self.stats.demographics, - self.stats.economy, - self.stats.military, - self.stats.infrastructure, - " " + self.stats.to_symbol() ); format!("{}\n{}", line1, line2) diff --git a/lib_efo/src/lib.rs b/lib_efo/src/lib.rs index ce4cbdc..eef263f 100644 --- a/lib_efo/src/lib.rs +++ b/lib_efo/src/lib.rs @@ -70,10 +70,14 @@ where /// directly on a vector of displayable items. pub trait Displayable { /// Return a fully-described string representation. - fn print_full(&self); + fn print_full(&self) { + self.print_short() + } /// Return a short, user-friendly string. - fn print_short(&self); + fn print_short(&self) { + println!("{}", self.oneline_display()) + } /// Return a one-liner string, suitable for embedding in a collection /// representation (e.g. a `Vec`). Implementations should avoid diff --git a/lib_efo/src/naming.rs b/lib_efo/src/naming.rs index 6ff4d3b..d9e230f 100644 --- a/lib_efo/src/naming.rs +++ b/lib_efo/src/naming.rs @@ -1,5 +1,6 @@ //! Autonaming generator //! Supposed to be loaded with the world if needed +use crate::stats::Symbols; use once_cell::sync::Lazy; use rand::prelude::*; use serde::{Deserialize, Serialize}; @@ -7,10 +8,12 @@ use std::fs; use std::io; use std::path::{Path, PathBuf}; +use crate::Displayable; use crate::entity::EffectApplication; use crate::entity::EffectBounds; use crate::entity::EntityDuration; use crate::error::EpochError; +use crate::stats::EntityType; use crate::stats::StatPair; /// The structure that holds everything we need for name generation. @@ -30,6 +33,14 @@ pub struct NamingData { /// Name prefixes pub character_prefixes: Vec, + // Exotics names + /// Exotic name prefixes + pub exotic_prefixes: Vec, + /// Exotic infixes + pub exotic_infixes: Vec, + /// Exotic suffixes + pub exotic_suffixes: Vec, + /// A list of event ideas and characteristic associated to it pub event_ideas: Vec, } @@ -57,6 +68,28 @@ pub struct EventDescription { pub effect_bounds: EffectBounds, } +impl Displayable for EventDescription { + fn oneline_display(&self) -> String { + let (description, _) = self.description.split_at(110.min(self.description.len())); + let line1 = format!( + "β”œβ”€ {} {} ──────> {}{} \n\ + β”‚ β”œβ”€ {}", + self.name, + EntityType::Event.to_symbol(), + self.duration.to_symbol(), + self.effect_bounds.to_symbol(), + description, + ); + + let mut line2 = "β”‚ └─ Stats: ".to_string(); + for effect in &self.stats { + line2.push_str(&format!("{}:{} ", effect.stat.to_symbol(), effect.value,)); + } + + format!("{line1}\n{line2}") + } +} + impl NamingData { /// Load the data from the supplied path. /// If the file does **not** exist, a default (embedded) version is written @@ -148,8 +181,43 @@ impl NamingData { parts.join(" ") } + + /// Generate a exotic character name + #[allow(clippy::unwrap_used)] + pub fn generate_exotic_character_name(&self) -> String { + let mut rng = rand::rng(); + + // Pick a random number of syllables for the *first* part + let first_len = rng.random_range(2..=4); + let pref: &String = self.exotic_prefixes.choose(&mut rng).unwrap(); + let pref2: &String = self.exotic_prefixes.choose(&mut rng).unwrap(); + + let first: String = (0..first_len) + .map(|_| self.exotic_infixes.choose(&mut rng).unwrap()) + .cloned() + .collect(); + + // Same for the *last* part + let last_len = rng.random_range(1..=3); + let last: String = (0..last_len) + .map(|_| self.exotic_infixes.choose(&mut rng).unwrap()) + .cloned() + .collect(); + + // Combine with a space – you could also use a hyphen or nothing + format!("{pref}{} {pref2}{}", &first, &last) + } } +// /// Helper to capitalize the first letter of a word +// fn capitalize(word: &str) -> String { +// let mut chars = word.chars(); +// match chars.next() { +// None => String::new(), +// Some(first) => first.to_ascii_uppercase().to_string() + chars.as_str(), +// } +// } + /// The JSON that ships with the binary. /// `include_str!` pulls the file at compile time. const DEFAULT_JSON_STR: &str = include_str!("../naming.json"); diff --git a/lib_efo/src/stats/implementations.rs b/lib_efo/src/stats/implementations.rs index d0e022c..b75284c 100644 --- a/lib_efo/src/stats/implementations.rs +++ b/lib_efo/src/stats/implementations.rs @@ -1,5 +1,6 @@ //! All traits implementatition for the main structs are deffered here +use colored::Colorize; use std::str::FromStr; use crate::entity::EffectApplication; @@ -288,5 +289,47 @@ impl Symbols for EffectBounds { } } +impl Symbols for OverallStats { + fn to_symbol(&self) -> String { + format!( + "ο“½ {} |πŸ’° {} |ο„² {} |σ°‘’ {}", + self.demographics, self.economy, self.military, self.infrastructure + ) + } +} + +impl Symbols for ListStats { + fn to_symbol(&self) -> String { + match self { + ListStats::Demographics => "ο“½".blue(), + ListStats::Population => "ξΆ’".normal(), + ListStats::Growthrate => "".normal(), + ListStats::Crime => "σ±€£".normal(), + ListStats::Happiness => "ο„˜".normal(), + ListStats::Economy => "πŸ’°".blue(), + ListStats::Food => "󰔬".normal(), + ListStats::Industry => "🏭".normal(), + ListStats::Science => "σ°§‘".normal(), + ListStats::Trade => "".normal(), + ListStats::Social => "󱕹".blue(), + ListStats::Culture => "🎭".normal(), + ListStats::Education => "πŸ“š".normal(), + ListStats::Tourism => "πŸ–οΈ".normal(), + ListStats::Influence => "🌍".normal(), + ListStats::Military => "πŸͺ–".blue(), + ListStats::Army => "ο„²".normal(), + ListStats::Strength => "σ°ž‡".normal(), + ListStats::Fortification => "πŸ”’".normal(), + ListStats::Threat => "⚑".normal(), + ListStats::Infrastructure => "πŸ—οΈ".blue(), + ListStats::Bureaucracy => "πŸ›οΈ".normal(), + ListStats::Transportation => "󰔬".normal(), + ListStats::Sprawl => "πŸ™οΈ".normal(), + ListStats::Health => "".normal(), + } + .to_string() + } +} + #[cfg(test)] pub(crate) mod test; diff --git a/naming.json b/naming.json index a52eba0..d4d2fe8 100644 --- a/naming.json +++ b/naming.json @@ -421,6 +421,112 @@ "Seer", "Master" ], + + "exotic_prefixes": [ + "Ar", + "Bel", + "Zel", + "Kyn", + "Nai", + "Vyr", + "Sera", + "Jor", + "Lun", + "Yara", + "Esh", + "Mor", + "Kael", + "Tar", + "Lyr", + "Dra", + "Qin", + "Thal", + "Oryn", + "Sil", + "Vex", + "Gor", + "Rin", + "Zan" + ], + "exotic_infixes": [ + "en", + "ae", + "or", + "is", + "sen", + "kar", + "ju", + "ja", + "ur", + "ai", + "ir", + "an", + "el", + "Γ«l", + "Γ¦l", + "Γ¦r", + "Ε‚u", + "Δ‘j", + "Γ€l", + "in", + "eu", + "ai", + "aΓ―", + "io", + "ea", + "oa", + "ui", + "oi", + "ΓΈl", + "ou", + "ea", + "'", + "au" + ], + "exotic_suffixes": [ + "ion", + "ara", + "eth", + "on", + "yr", + "ith", + "dor", + "zen", + "mar", + "fen", + "is", + "al", + "or", + "ex", + "an", + "ul", + "ik", + "en", + "ar", + "ur" + ], + "exotic_syllables": [ + "ra", + "el", + "ka", + "la", + "ma", + "za", + "sha", + "na", + "ta", + "li", + "vi", + "da", + "shi", + "ri", + "lo", + "xi", + "po", + "ke", + "do", + "zo" + ], "event_ideas": [ { "name": "storm_flood", @@ -2357,4 +2463,4 @@ } } ] -} \ No newline at end of file +}