Most of the naming & Generic entity
Build Successful The build was successful
Gitea/epoch_forge/pipeline/head This commit looks good
Details
Build Successful The build was successful
Gitea/epoch_forge/pipeline/head This commit looks good
Details
This commit is contained in:
parent
653ee2307f
commit
08b773698b
|
|
@ -105,6 +105,7 @@ name = "bin_efo"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"colored",
|
||||
"derive_more",
|
||||
"env_logger",
|
||||
"lib_efo",
|
||||
|
|
|
|||
|
|
@ -11,3 +11,4 @@ miette = { version = "7.6.0", features = ["fancy"] }
|
|||
env_logger = "0.11.8"
|
||||
log = "0.4.28"
|
||||
derive_more = { version = "2.0.1", features = ["display", "add"] }
|
||||
colored = "3.0.0"
|
||||
|
|
|
|||
|
|
@ -13,3 +13,4 @@ miette = {workspace = true}
|
|||
env_logger = {workspace = true}
|
||||
log = {workspace = true}
|
||||
derive_more = {workspace = true}
|
||||
colored = {workspace = true}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
//! Module handling the creation of characters
|
||||
|
||||
use lib_efo::entity::{EffectApplication, EffectBounds, EntityDuration};
|
||||
use lib_efo::epoch::epoch_traits::{ConfigWritable, Diffable};
|
||||
use lib_efo::naming::NAMING;
|
||||
use lib_efo::stats::{Position, Symbols};
|
||||
|
|
@ -68,6 +69,18 @@ pub struct EntityArgs {
|
|||
#[arg(long, group = "position")]
|
||||
pub pos: Option<Position>,
|
||||
|
||||
/// The duration of the entity
|
||||
#[arg(long)]
|
||||
pub duration: Option<EntityDuration>,
|
||||
|
||||
/// The bounds of the effect of the entity
|
||||
#[arg(long)]
|
||||
pub bounds: Option<EffectBounds>,
|
||||
|
||||
/// How is the effect of the entity applied
|
||||
#[arg(long)]
|
||||
pub effect: Option<EffectApplication>,
|
||||
|
||||
/// All stats pairs involved
|
||||
pub stats: Vec<StatPair>,
|
||||
}
|
||||
|
|
@ -84,7 +97,7 @@ pub struct EntityArgs {
|
|||
///
|
||||
/// # Returns
|
||||
/// A `Result` indicating success (`Ok(())`) or the encountered `AppError`.
|
||||
pub fn handle_entity_creation(
|
||||
pub fn handle_entity_commands(
|
||||
entity_sub_commands: &EntitySubCommands,
|
||||
e_type: &EntityType,
|
||||
) -> Result<(), AppError> {
|
||||
|
|
@ -112,6 +125,67 @@ pub fn handle_entity_creation(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Function handler for the create subcommand
|
||||
fn handle_create_entity(
|
||||
entity_args: &EntityArgs,
|
||||
e_type: &EntityType,
|
||||
main_epoch: &mut EpochConfig,
|
||||
) -> Result<(), EpochError> {
|
||||
let epoch_info = main_epoch.try_load_current_as_mut()?;
|
||||
let vec_entities: &mut Vec<Entity> = vec_entities_mut(e_type, epoch_info);
|
||||
|
||||
let mut entity = Entity::create_rng(e_type, &entity_args.rng)?;
|
||||
update_stats(entity_args, &mut entity);
|
||||
// Specifying a name means the name needs to be changed
|
||||
// Specifying an id however means nothing and should be ignored
|
||||
|
||||
update_defaults(entity_args, &mut entity);
|
||||
|
||||
info!("Created character: {:#?}", entity);
|
||||
entity.print_full();
|
||||
let message = &crate::success::SuccessMessages::CreatedEntity(
|
||||
entity.name.clone(),
|
||||
entity.entity_type.to_shortest(),
|
||||
entity.id.to_string(),
|
||||
);
|
||||
vec_entities.push(entity);
|
||||
|
||||
// No need to change main epoch that didn't change a serialized field
|
||||
epoch_info.save_with_context("Created entity", &lib_efo::epoch::SaveMode::Erase)?;
|
||||
display_success(message);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Function handler for the delete subcommand
|
||||
fn handle_delete_entity(
|
||||
entity_args: &EntityArgs,
|
||||
e_type: &EntityType,
|
||||
main_epoch: &mut EpochConfig,
|
||||
) -> Result<(), EpochError> {
|
||||
let epoch_info = main_epoch.try_load_current_as_mut()?;
|
||||
|
||||
let vec_entities: &mut Vec<Entity> = vec_entities_mut(e_type, epoch_info);
|
||||
let index = vec_entities
|
||||
.iter()
|
||||
.position(|e| find_by_args(e, entity_args))
|
||||
.ok_or(EpochError::EntityNotFound(
|
||||
e_type.clone(),
|
||||
entity_args.name.clone(),
|
||||
entity_args.id.clone(),
|
||||
))?;
|
||||
|
||||
let entity = vec_entities.swap_remove(index);
|
||||
|
||||
epoch_info.save_with_context("Deleted entity", &lib_efo::epoch::SaveMode::Erase)?;
|
||||
display_success(&crate::success::SuccessMessages::DeletedEntity(
|
||||
entity.name,
|
||||
entity.entity_type.to_shortest(),
|
||||
entity.id.to_string(),
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Function handler for the diff subcommand
|
||||
fn handle_diff_entity(
|
||||
entity_args: &EntityArgs,
|
||||
|
|
@ -136,6 +210,7 @@ fn handle_diff_entity(
|
|||
}
|
||||
|
||||
/// Function handler for the show subcommand
|
||||
// TODO: Add filters else this will become very clustered
|
||||
fn handle_show_entity(
|
||||
entity_args: &EntityArgs,
|
||||
e_type: &EntityType,
|
||||
|
|
@ -143,12 +218,12 @@ fn handle_show_entity(
|
|||
) -> Result<(), EpochError> {
|
||||
let epoch_info = main_epoch.try_load_current()?;
|
||||
if entity_args.name.is_none() && entity_args.id.is_none() {
|
||||
for e in vec_entities(e_type, epoch_info) {
|
||||
e.print_oneline();
|
||||
for entity in vec_entities(e_type, epoch_info) {
|
||||
entity.print_oneline();
|
||||
}
|
||||
} else {
|
||||
let e = find_entity(entity_args, e_type, epoch_info)?;
|
||||
e.print_full();
|
||||
let entity = find_entity(entity_args, e_type, epoch_info)?;
|
||||
entity.print_full();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -168,8 +243,8 @@ fn handle_edit_entity(
|
|||
e_type: &EntityType,
|
||||
main_epoch: &mut EpochConfig,
|
||||
) -> Result<(), EpochError> {
|
||||
let current_epoch = main_epoch.try_load_current_as_mut()?;
|
||||
let vec_entities = vec_entities_mut(e_type, current_epoch);
|
||||
let epoch_info = main_epoch.try_load_current_as_mut()?;
|
||||
let vec_entities = vec_entities_mut(e_type, epoch_info);
|
||||
let entity = vec_entities
|
||||
.iter_mut()
|
||||
.find(|e| find_by_args(e, entity_args))
|
||||
|
|
@ -182,81 +257,36 @@ fn handle_edit_entity(
|
|||
for stat in &entity_args.stats {
|
||||
entity.change_stat(stat.clone());
|
||||
}
|
||||
// TODO: Changing name ?
|
||||
if let Some(duration) = &entity_args.duration {
|
||||
entity.modify_duration(duration.clone());
|
||||
}
|
||||
// // Only update the name if an id was given
|
||||
// if entity_args.id.is_some()
|
||||
// && let Some(name) = &entity_args.name
|
||||
// {
|
||||
// entity.name = name.clone();
|
||||
// }
|
||||
if let Some(effect) = &entity_args.effect {
|
||||
entity.modify_effect_application(effect.clone());
|
||||
}
|
||||
if let Some(bounds) = &entity_args.bounds {
|
||||
entity.modify_effect_bounds(bounds.clone());
|
||||
}
|
||||
|
||||
display_success(&crate::success::SuccessMessages::EditedEntity(
|
||||
entity.print_full();
|
||||
let message = &crate::success::SuccessMessages::EditedEntity(
|
||||
entity.name.clone(),
|
||||
entity.entity_type.to_shortest(),
|
||||
entity.id.to_string(),
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Function handler for the delete subcommand
|
||||
fn handle_delete_entity(
|
||||
entity_args: &EntityArgs,
|
||||
e_type: &EntityType,
|
||||
main_epoch: &mut EpochConfig,
|
||||
) -> Result<(), EpochError> {
|
||||
let epoch_info = main_epoch.try_load_current_as_mut()?;
|
||||
|
||||
let vec_entities: &mut Vec<Entity> = vec_entities_mut(e_type, epoch_info);
|
||||
let index = vec_entities
|
||||
.iter()
|
||||
.position(|e| find_by_args(e, entity_args))
|
||||
.ok_or(EpochError::EntityNotFound(
|
||||
e_type.clone(),
|
||||
entity_args.name.clone(),
|
||||
entity_args.id.clone(),
|
||||
))?;
|
||||
|
||||
let e = vec_entities.swap_remove(index);
|
||||
|
||||
display_success(&crate::success::SuccessMessages::DeletedEntity(
|
||||
e.name,
|
||||
e.entity_type.to_shortest(),
|
||||
e.id.to_string(),
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Function handler for the create subcommand
|
||||
fn handle_create_entity(
|
||||
entity_args: &EntityArgs,
|
||||
e_type: &EntityType,
|
||||
main_epoch: &mut EpochConfig,
|
||||
) -> Result<(), EpochError> {
|
||||
let epoch_info = main_epoch.try_load_current_as_mut()?;
|
||||
let vec_entities: &mut Vec<Entity> = vec_entities_mut(e_type, epoch_info);
|
||||
|
||||
let mut e = Entity::create_rng(e_type, &entity_args.rng)?;
|
||||
update_stats(entity_args, &mut e);
|
||||
// Specifying a name means the name needs to be changed
|
||||
// Specifying an id however means nothing and should be ignored
|
||||
if let Some(name) = &entity_args.name {
|
||||
e.name = name.clone();
|
||||
} else {
|
||||
e.name = NAMING.generate_exotic_character_name();
|
||||
}
|
||||
|
||||
info!("Created character: {:#?}", e);
|
||||
let message = &crate::success::SuccessMessages::CreatedEntity(
|
||||
e.name.clone(),
|
||||
e.entity_type.to_shortest(),
|
||||
e.id.to_string(),
|
||||
);
|
||||
vec_entities.push(e);
|
||||
epoch_info.save_with_context("Deleted entity", &lib_efo::epoch::SaveMode::Erase)?;
|
||||
|
||||
// No need to change main epoch that didn't change a serialized field
|
||||
epoch_info.save_with_context("Created entity", &lib_efo::epoch::SaveMode::Erase)?;
|
||||
display_success(message);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Update the given stats with the given argumenbts
|
||||
/// Note that this function will not change name & id due to the usage variance between caller
|
||||
///
|
||||
fn update_stats(entity_args: &EntityArgs, e: &mut Entity) {
|
||||
if entity_args.delta {
|
||||
for stat in &entity_args.stats {
|
||||
|
|
@ -379,3 +409,73 @@ fn find_by_id<'a>(entities: &'a [Entity], id: &'a String) -> Option<&'a Entity>
|
|||
fn find_by_name<'a>(entities: &'a [Entity], id: &'a String) -> Option<&'a Entity> {
|
||||
entities.iter().find(|e| e.name.starts_with(id))
|
||||
}
|
||||
|
||||
/// Update the default values of the entity with sensible defaults
|
||||
fn update_defaults(entity_args: &EntityArgs, e: &mut Entity) {
|
||||
let entity_type = &e.entity_type;
|
||||
|
||||
let (duration, effect, bounds, name) = match entity_type {
|
||||
EntityType::Character => (
|
||||
lib_efo::entity::EntityDuration::Permanent,
|
||||
lib_efo::entity::EffectApplication::WhenPresent,
|
||||
EffectBounds { min: 20, max: 110 },
|
||||
NAMING.generate_character_name(),
|
||||
),
|
||||
EntityType::Player => (
|
||||
lib_efo::entity::EntityDuration::Permanent,
|
||||
lib_efo::entity::EffectApplication::WhenPresent,
|
||||
EffectBounds { min: 0, max: 120 },
|
||||
NAMING.generate_exotic_character_name(),
|
||||
),
|
||||
EntityType::Town => (
|
||||
lib_efo::entity::EntityDuration::Permanent,
|
||||
lib_efo::entity::EffectApplication::WhenPresent,
|
||||
EffectBounds { min: 20, max: 60 },
|
||||
NAMING.generate_town_name(),
|
||||
),
|
||||
EntityType::Monster => (
|
||||
lib_efo::entity::EntityDuration::Permanent,
|
||||
lib_efo::entity::EffectApplication::WhenPresent,
|
||||
EffectBounds { min: 20, max: 80 },
|
||||
NAMING.generate_calamity_name(),
|
||||
),
|
||||
EntityType::Blocker => (
|
||||
lib_efo::entity::EntityDuration::Permanent,
|
||||
lib_efo::entity::EffectApplication::WhenPresent,
|
||||
EffectBounds { min: 0, max: 120 },
|
||||
NAMING.generate_blocker_name(),
|
||||
),
|
||||
EntityType::Event => (
|
||||
lib_efo::entity::EntityDuration::Duration(1),
|
||||
lib_efo::entity::EffectApplication::PermanentEffectToApply,
|
||||
EffectBounds { min: 10, max: 80 },
|
||||
NAMING.random_event_name(),
|
||||
),
|
||||
};
|
||||
// This is the sensible default for all creatures & characters
|
||||
if let Some(duration) = &entity_args.duration {
|
||||
e.modify_duration(duration.clone());
|
||||
} else {
|
||||
e.modify_duration(duration);
|
||||
}
|
||||
|
||||
if let Some(name) = &entity_args.name {
|
||||
e.name = name.clone();
|
||||
} else {
|
||||
e.name = name;
|
||||
}
|
||||
|
||||
// This is the sensible default for all creatures & characters
|
||||
if let Some(effect) = &entity_args.effect {
|
||||
e.modify_effect_application(effect.clone());
|
||||
} else {
|
||||
e.modify_effect_application(effect);
|
||||
}
|
||||
|
||||
// This is the sensible default for characters
|
||||
if let Some(bounds) = &entity_args.bounds {
|
||||
e.modify_effect_bounds(bounds.clone());
|
||||
} else {
|
||||
e.modify_effect_bounds(bounds);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ fn exec_dispatch(cli: Cli) -> Result<(), AppError> {
|
|||
TopLevelCmd::Show(cmd) => commands::show::handle_show_cmd(&cmd),
|
||||
TopLevelCmd::Gen(cmd) => commands::generate::gen_handler(&cmd),
|
||||
TopLevelCmd::Chr(cmd) => {
|
||||
commands::chr::handle_entity_creation(&cmd, &lib_efo::stats::EntityType::Character)
|
||||
commands::chr::handle_entity_commands(&cmd, &lib_efo::stats::EntityType::Character)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
//! List of all success messages possible
|
||||
|
||||
use colored::*;
|
||||
use derive_more::Display;
|
||||
use lib_efo::epoch::EpochId;
|
||||
|
||||
|
|
@ -33,5 +34,5 @@ pub enum SuccessMessages {
|
|||
|
||||
/// Display the success message to stdout
|
||||
pub fn display_success(message: &SuccessMessages) {
|
||||
println!("{}", message)
|
||||
println!("{}", message.to_string().cyan())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@ log = {workspace = true}
|
|||
derive_more = {workspace = true}
|
||||
cli-table = "0.5.0"
|
||||
uuid = { version = "1.18.1", features = ["serde", "v4"] }
|
||||
colored = "3.0.0"
|
||||
colored = {workspace = true}
|
||||
rand = "0.9.2"
|
||||
once_cell = "1.21.3"
|
||||
|
|
|
|||
|
|
@ -172,6 +172,145 @@
|
|||
"Sableheart",
|
||||
"Tidebreaker"
|
||||
],
|
||||
"mystical_adjectives": [
|
||||
"The Sky Devourer",
|
||||
"World Asunder",
|
||||
"Otherworldly Tormentor",
|
||||
"The Abyssal Maw",
|
||||
"The Nightfall Harbinger",
|
||||
"Storm of the Void",
|
||||
"Echoes of the Unmaking",
|
||||
"The Star‑Cutter",
|
||||
"Realm‑Sunderer",
|
||||
"The Veil‑Shredder",
|
||||
"Giant of the Shadowed Depths",
|
||||
"The Whispering Oblivion",
|
||||
"Crown of the Endless Night",
|
||||
"The Loom‑Breaker",
|
||||
"The Sun‑Wither",
|
||||
"Harbinger of the Broken Veil",
|
||||
"The Gloom‑Harvest",
|
||||
"Of the Otherworldly Pleasure",
|
||||
"The Cataclysmic Resonance",
|
||||
"The Tempest of Erasure",
|
||||
"The Crimson Eclipse",
|
||||
"The Null‑Seeker",
|
||||
"The Rift‑Harvester",
|
||||
"The Desolation King",
|
||||
"The Silent Oblivion",
|
||||
"The Shattered Covenant",
|
||||
"The Veiled Devourer",
|
||||
"The Plague of Eternity",
|
||||
"The Storm‑Wreathed Titan",
|
||||
"The Echo‑Demon",
|
||||
"The Loom‑of‑Night",
|
||||
"The Shard‑Weaver",
|
||||
"The Ember‑Wraith",
|
||||
"The Void‑Warden",
|
||||
"The Twilight Serpent",
|
||||
"The Obsidian Herald",
|
||||
"The Celestial Bane",
|
||||
"The Maw of Forgotten Stars",
|
||||
"The Grief‑Harbinger",
|
||||
"The Fractured Eclipse",
|
||||
"The Devourer of Dawn",
|
||||
"The Rift‑Born Leviathan",
|
||||
"The Wailing Abyss",
|
||||
"The Pulse of Ruin",
|
||||
"The Starless Nightfall",
|
||||
"The Maw‑Of‑Eons",
|
||||
"The Shadow‑Eater",
|
||||
"The Echo‑of‑Despair",
|
||||
"The Void‑Cutter"
|
||||
],
|
||||
"blocker_prefixes": [
|
||||
"Abysmal",
|
||||
"Aetheric",
|
||||
"Ashen",
|
||||
"Avaricious",
|
||||
"Black",
|
||||
"Bleak",
|
||||
"Blood",
|
||||
"Brackish",
|
||||
"Cursed",
|
||||
"Cryptic",
|
||||
"Darkened",
|
||||
"Dread",
|
||||
"Dusk",
|
||||
"Ebon",
|
||||
"Eerie",
|
||||
"Enchanted",
|
||||
"Eternal",
|
||||
"Fallen",
|
||||
"Feral",
|
||||
"Foreboding",
|
||||
"Gloom",
|
||||
"Grim",
|
||||
"Hollow",
|
||||
"Iron",
|
||||
"Lurking",
|
||||
"Mournful",
|
||||
"Obsidian",
|
||||
"Onyx",
|
||||
"Pale",
|
||||
"Phantom",
|
||||
"Plague",
|
||||
"Pyre",
|
||||
"Ragged",
|
||||
"Riven",
|
||||
"Rust",
|
||||
"Shadow",
|
||||
"Sorrow",
|
||||
"Spectral",
|
||||
"Thorn",
|
||||
"Twilight",
|
||||
"Wraith",
|
||||
"Wretched"
|
||||
],
|
||||
"blocker_suffixes": [
|
||||
"Bane",
|
||||
"Blight",
|
||||
"Bloom",
|
||||
"Burst",
|
||||
"Call",
|
||||
"Crown",
|
||||
"Creek",
|
||||
"Dawn",
|
||||
"Depth",
|
||||
"Fall",
|
||||
"Forge",
|
||||
"Forge",
|
||||
"Gloom",
|
||||
"Heart",
|
||||
"Hollow",
|
||||
"Ice",
|
||||
"Knell",
|
||||
"Lament",
|
||||
"Mire",
|
||||
"Night",
|
||||
"Pit",
|
||||
"Reach",
|
||||
"Rift",
|
||||
"Scream",
|
||||
"Shard",
|
||||
"Shade",
|
||||
"Shroud",
|
||||
"Soul",
|
||||
"Spine",
|
||||
"Spire",
|
||||
"Stream",
|
||||
"Storm",
|
||||
"Surge",
|
||||
"Tide",
|
||||
"Thorn",
|
||||
"Veil",
|
||||
"Veil",
|
||||
"Void",
|
||||
"Waste",
|
||||
"Wound",
|
||||
"Wrath",
|
||||
"Yonder"
|
||||
],
|
||||
"town_prefixes": [
|
||||
"Ash",
|
||||
"Bright",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
//! by a type-safe system. For the moment it provides a quick lookup for
|
||||
//! logic that distinguishes creatures, items, terrain, etc.
|
||||
//!
|
||||
use clap::ValueEnum;
|
||||
use derive_more::{Add, Sub};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
|
@ -85,7 +86,7 @@ pub struct EffectBounds {
|
|||
}
|
||||
|
||||
/// How the entity's effect is applied over time.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default, ValueEnum)]
|
||||
pub enum EffectApplication {
|
||||
/// Repeatedly applied every turn while the entity is present.
|
||||
/// Use with caution, as this can produce catastrophic results
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
//! Implementation of all needed traits for the Entity struct
|
||||
mod from_impl;
|
||||
use cli_table::format::{Border, HorizontalLine, Separator, VerticalLine};
|
||||
use cli_table::{Style, WithTitle};
|
||||
use colored::*;
|
||||
|
|
@ -6,7 +7,7 @@ use rand::distr::Distribution;
|
|||
use uuid::Uuid; // [3] - colored-rs examples
|
||||
|
||||
use crate::Displayable;
|
||||
use crate::entity::Entity;
|
||||
use crate::entity::{EffectApplication, EffectBounds, Entity, EntityDuration};
|
||||
use crate::epoch::epoch_traits::Diffable;
|
||||
use crate::error::EpochError;
|
||||
use crate::stats::{EntityType, GenericStat, MetaStats, OverallStats, Position, StatPair, Symbols};
|
||||
|
|
@ -167,35 +168,40 @@ impl Entity {
|
|||
|
||||
// ── Top line: <entity_type> <name>
|
||||
out.push_str(&format!(
|
||||
"[{} {}]\n",
|
||||
self.entity_type.to_symbol().blue().bold(), // entity type
|
||||
self.name.cyan().bold() // name
|
||||
"[{} {} ({})]\n",
|
||||
self.entity_type.to_symbol().blue().bold(),
|
||||
self.name.cyan().bold(),
|
||||
self.id.to_string().blue().bold()
|
||||
));
|
||||
|
||||
// ── Metadata section
|
||||
out.push_str(&indent(0, &format!("├─ {}\n", "metadata".green())));
|
||||
out.push_str(&indent(
|
||||
1,
|
||||
&format!(
|
||||
"├─ {}: {}\n",
|
||||
"position".bright_green(),
|
||||
self.metadata.position.to_symbol()
|
||||
),
|
||||
));
|
||||
out.push_str(&indent(
|
||||
1,
|
||||
&format!(
|
||||
"├─ {}: {:?}\n",
|
||||
"capital".bright_green(),
|
||||
self.metadata.capital
|
||||
),
|
||||
));
|
||||
if self.metadata.capital.is_some() {
|
||||
out.push_str(&indent(
|
||||
1,
|
||||
&format!(
|
||||
"├─ {}: {:?}\n",
|
||||
"capital".bright_green(),
|
||||
self.metadata.capital
|
||||
),
|
||||
));
|
||||
}
|
||||
if *self.metadata.prestige > 0 {
|
||||
out.push_str(&indent(
|
||||
1,
|
||||
&format!(
|
||||
"├─ {}: {}\n",
|
||||
"prestige".bright_green(),
|
||||
self.metadata.prestige
|
||||
),
|
||||
));
|
||||
}
|
||||
out.push_str(&indent(
|
||||
1,
|
||||
&format!(
|
||||
"└─ {}: {}\n",
|
||||
"prestige".bright_green(),
|
||||
self.metadata.prestige
|
||||
"position".bright_green(),
|
||||
self.metadata.position.to_symbol()
|
||||
),
|
||||
));
|
||||
|
||||
|
|
@ -288,15 +294,50 @@ impl Entity {
|
|||
pub fn delta_stat(&mut self, pair: StatPair) {
|
||||
add_to_stat(&mut self.stats, pair);
|
||||
}
|
||||
|
||||
/// Replace the entity's duration.
|
||||
///
|
||||
/// The method simply overwrites the current `duration` field with the
|
||||
/// supplied value. It is primarily intended for use when an entity
|
||||
/// is instantiated from external data that already contains a duration value.
|
||||
pub fn modify_duration(&mut self, duration: EntityDuration) {
|
||||
self.duration = duration
|
||||
}
|
||||
|
||||
/// Set the way the entity's effects are applied.
|
||||
///
|
||||
/// The field `effect_nature` determines how the entity's abilities or
|
||||
/// status effects interact with the world.
|
||||
/// This method overwrites the existing value with the supplied `EffectApplication`.
|
||||
pub fn modify_effect_application(&mut self, effect: EffectApplication) {
|
||||
self.effect_nature = effect
|
||||
}
|
||||
|
||||
/// Update the bounds that govern the entity's effects.
|
||||
///
|
||||
/// `effect_bounds` controls the maximum/minimum strength, duration or
|
||||
/// other limits that can be applied to the entity's effects. This
|
||||
/// method simply replaces the current bounds with the supplied
|
||||
/// `EffectBounds`.
|
||||
pub fn modify_effect_bounds(&mut self, effect: EffectBounds) {
|
||||
self.effect_bounds = effect
|
||||
}
|
||||
}
|
||||
// TODO: Redoc
|
||||
/// Overwrite a stat in a table
|
||||
|
||||
/// Replace a statistic in `stats` with the value from `pair`.
|
||||
///
|
||||
/// This function performs a direct overwrite: the existing value is
|
||||
/// discarded and the new value from `pair` is written in its place.
|
||||
fn overwrite_stat(stats: &mut OverallStats, pair: StatPair) {
|
||||
let affected_stat = stats.get_field_mut(&pair.stat);
|
||||
*affected_stat = pair.value;
|
||||
}
|
||||
|
||||
/// Add to a stat in a table
|
||||
/// Add a delta to a statistic in `stats`.
|
||||
///
|
||||
/// The delta in `pair.value` is added to the current statistic value
|
||||
/// using `saturating_add`, so that the result never overflows the
|
||||
/// underlying integer type.
|
||||
fn add_to_stat(stats: &mut OverallStats, pair: StatPair) {
|
||||
let affected_stat = stats.get_field_mut(&pair.stat);
|
||||
let current_value = *affected_stat;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,98 @@
|
|||
//! Mostly from implementation for entities
|
||||
|
||||
use crate::entity::EffectBounds;
|
||||
|
||||
use crate::error::EpochError;
|
||||
|
||||
use crate::entity::EntityDuration;
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
/// Simple error type used by `FromStr`.
|
||||
/// clap only needs the error to implement `Display`, so a `String` is fine.
|
||||
impl FromStr for EntityDuration {
|
||||
type Err = EpochError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
// Normalise the string: trim and lowercase.
|
||||
let raw = s.trim().to_ascii_lowercase();
|
||||
|
||||
match raw.as_str() {
|
||||
"permanent" => Ok(EntityDuration::Permanent),
|
||||
"done" => Ok(EntityDuration::Done),
|
||||
|
||||
// Handle the `duration:NNN` form.
|
||||
_ if raw.starts_with("duration:") => {
|
||||
let num_part = &raw["duration:".len()..];
|
||||
match num_part.parse::<usize>() {
|
||||
Ok(v) => Ok(EntityDuration::Duration(v)),
|
||||
Err(_) => Err(EpochError::ParsingDuration(
|
||||
"Invalid duration value",
|
||||
num_part.to_string(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
// Allow a bare number (e.g. `10` → Duration(10)).
|
||||
_ if raw.chars().all(|c| c.is_ascii_digit()) => match raw.parse::<usize>() {
|
||||
Ok(v) => Ok(EntityDuration::Duration(v)),
|
||||
Err(_) => Err(EpochError::ParsingDuration("Could not parse number", raw)),
|
||||
},
|
||||
|
||||
// Anything else is an error.
|
||||
_ => Err(EpochError::ParsingDuration("Invalid EntityDuration", raw)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for EffectBounds {
|
||||
type Err = EpochError;
|
||||
|
||||
/// Parse an `EffectBounds` from a string.
|
||||
///
|
||||
/// Acceptable forms:
|
||||
/// * `min:max` - colon-separated values
|
||||
/// * `min-max` - dash-separated values
|
||||
///
|
||||
/// Errors are reported with `EpochError::ParsingDurationError`.
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
// Normalise the string: trim whitespace.
|
||||
let raw = s.trim();
|
||||
|
||||
// Helper to parse a pair of numbers from a delimiter separated string.
|
||||
fn parse_pair(raw: &str, delim: char) -> Result<(usize, usize), EpochError> {
|
||||
let parts: Vec<&str> = raw.split(delim).collect();
|
||||
if parts.len() != 2 {
|
||||
return Err(EpochError::ParsingBounds(
|
||||
"Invalid EffectBounds format",
|
||||
raw.to_string(),
|
||||
));
|
||||
}
|
||||
let min = parts[0].trim().parse::<usize>().map_err(|_| {
|
||||
EpochError::ParsingBounds("Could not parse number", raw.to_string())
|
||||
})?;
|
||||
let max = parts[1].trim().parse::<usize>().map_err(|_| {
|
||||
EpochError::ParsingBounds("Could not parse number", raw.to_string())
|
||||
})?;
|
||||
Ok((min, max))
|
||||
}
|
||||
|
||||
// 1. Try colon-separated (`min:max`).
|
||||
if raw.find(':').is_some() {
|
||||
let (min, max) = parse_pair(raw, ':')?;
|
||||
return Ok(EffectBounds { min, max });
|
||||
}
|
||||
|
||||
// 2. Try dash-separated (`min-max`).
|
||||
if raw.find('-').is_some() {
|
||||
let (min, max) = parse_pair(raw, '-')?;
|
||||
return Ok(EffectBounds { min, max });
|
||||
}
|
||||
|
||||
// 3. Anything else is an error.
|
||||
Err(EpochError::ParsingBounds(
|
||||
"Invalid EffectBounds",
|
||||
raw.to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
@ -291,6 +291,20 @@ pub enum EpochError {
|
|||
/// The UUID that uniquely identifies the table instance.
|
||||
id: Uuid,
|
||||
},
|
||||
|
||||
/// Failed to parse a duration string.
|
||||
#[error("Failed to parse duration: {0}:{1}")]
|
||||
#[diagnostic(code(EpochError::ParsingDuration))]
|
||||
#[help(
|
||||
"Verify that the duration string follows the expected syntax, `permanent` or `duration:X` or `done`."
|
||||
)]
|
||||
ParsingDuration(&'static str, String),
|
||||
|
||||
/// Failed to parse a bounds string.
|
||||
#[error("Failed to parse bounds: {0}:{1}")]
|
||||
#[diagnostic(code(EpochError::ParsingBounds))]
|
||||
#[help("Verify that the bounds string follows the expected syntax, `X-X` or `X:X`.")]
|
||||
ParsingBounds(&'static str, String),
|
||||
}
|
||||
|
||||
/// A small enum of explicit user-facing error messages.
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ pub struct NamingData {
|
|||
/// Good suffixes for town names
|
||||
pub town_suffixes: Vec<String>,
|
||||
|
||||
/// Good blocker prefixes
|
||||
pub blocker_prefixes: Vec<String>,
|
||||
/// Good blocker suffixes
|
||||
pub blocker_suffixes: Vec<String>,
|
||||
/// Character adjectives
|
||||
pub character_adjectives: Vec<String>,
|
||||
/// Name prefixes
|
||||
|
|
@ -40,7 +44,8 @@ pub struct NamingData {
|
|||
pub exotic_infixes: Vec<String>,
|
||||
/// Exotic suffixes
|
||||
pub exotic_suffixes: Vec<String>,
|
||||
|
||||
/// Mighty mystical adjectives
|
||||
pub mystical_adjectives: Vec<String>,
|
||||
/// A list of event ideas and characteristic associated to it
|
||||
pub event_ideas: Vec<EventDescription>,
|
||||
}
|
||||
|
|
@ -148,6 +153,81 @@ impl NamingData {
|
|||
})
|
||||
}
|
||||
|
||||
/// Pick a random event name
|
||||
#[allow(clippy::unwrap_used)]
|
||||
pub fn random_event_name(&self) -> String {
|
||||
if let Ok(event) = self.random_event_idea() {
|
||||
event.name.clone()
|
||||
} else {
|
||||
"The Great Bobbening".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a random **blocker** name (e.g. “Stone‑Gate”, “Witch‑Wall”).
|
||||
///
|
||||
/// The name is formed by choosing a random prefix *and* suffix from the
|
||||
/// corresponding lists. If either list is empty, a sensible default is
|
||||
/// returned.
|
||||
pub fn generate_blocker_name(&self) -> String {
|
||||
let mut rng = rand::rng();
|
||||
|
||||
let binding = "Mystic ".to_string();
|
||||
let prefix = self.blocker_prefixes.choose(&mut rng).unwrap_or(&binding);
|
||||
|
||||
let binding = "Barrier".to_string();
|
||||
let suffix = self.blocker_suffixes.choose(&mut rng).unwrap_or(&binding);
|
||||
|
||||
format!("{} {}", prefix, suffix).trim().to_string()
|
||||
}
|
||||
|
||||
/// Generate a *calamity* name.
|
||||
///
|
||||
/// A calamity is a **complex exotic** word (prefix + 2–4 infixes + optional suffix)
|
||||
/// followed by a *mystical* adjective.
|
||||
///
|
||||
/// Example output: “Umbral‑Shatterfall Cataclysmic”
|
||||
pub fn generate_calamity_name(&self) -> String {
|
||||
let mut rng = rand::rng();
|
||||
|
||||
/* ----- 1️⃣ Build the exotic base --------------------------------- */
|
||||
// Pick a prefix (or fall back to "Umbral")
|
||||
let prefix = self
|
||||
.exotic_prefixes
|
||||
.choose(&mut rng)
|
||||
.unwrap_or(&"Umbral".to_string())
|
||||
.clone();
|
||||
|
||||
// Pick 2–4 infixes (this gives the “complex” feel)
|
||||
let infix_count = rng.random_range(2..=4);
|
||||
let infixes: String = (0..infix_count)
|
||||
.map(|_| {
|
||||
self.exotic_infixes
|
||||
.choose(&mut rng)
|
||||
.expect("exotic_infixes must not be empty")
|
||||
.clone()
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Optional suffix – if you don’t have a list, this will be an empty string
|
||||
let suffix = self
|
||||
.exotic_suffixes
|
||||
.choose(&mut rng)
|
||||
.cloned()
|
||||
.unwrap_or_else(String::new);
|
||||
|
||||
// Combine into the base calamity word
|
||||
let base = format!("{}{}{}", prefix, infixes, suffix);
|
||||
|
||||
/* ----- 2️⃣ Append a mystical adjective --------------------------- */
|
||||
let adjective = self
|
||||
.mystical_adjectives
|
||||
.choose(&mut rng)
|
||||
.unwrap_or(&"Cataclysmic".to_string())
|
||||
.clone();
|
||||
|
||||
format!("{} {}", base, adjective).trim().to_string()
|
||||
}
|
||||
|
||||
/// Generates something like:
|
||||
/// “The Magnificent Sir Aurelius Blackthorn the Swift”
|
||||
/// Random adjective, prefix, base name and suffix are all optional.
|
||||
|
|
|
|||
Loading…
Reference in New Issue