POC on the generator
Build Failed The build failed
Gitea/epoch_forge/pipeline/head There was a failure building this commit Details

This commit is contained in:
Dandaedre 2025-12-07 19:16:06 +01:00
parent d34d89353d
commit ced4e5d10e
7 changed files with 288 additions and 13 deletions

View File

@ -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(())
}

View File

@ -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),
}

View File

@ -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)

View File

@ -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<T>`). Implementations should avoid

View File

@ -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<String>,
// Exotics names
/// Exotic name prefixes
pub exotic_prefixes: Vec<String>,
/// Exotic infixes
pub exotic_infixes: Vec<String>,
/// Exotic suffixes
pub exotic_suffixes: Vec<String>,
/// A list of event ideas and characteristic associated to it
pub event_ideas: Vec<EventDescription>,
}
@ -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");

View File

@ -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;

View File

@ -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 @@
}
}
]
}
}