From 7263d3ab72ac11c73267b50e36967d32f17ab74e Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 13 Dec 2025 20:21:47 +0100 Subject: [PATCH] Adds boc/user doc --- .ignore | 1 + .run_status.toml | 6 ++--- badges/coverage.svg | 2 +- bin_efo/src/commands/entity_generic.rs | 15 ++++++++--- bin_efo/src/main.rs | 33 +++++++++++++++++------ lib_efo/src/epoch/epoch_config.rs | 4 +++ lib_efo/src/epoch/epoch_info.rs | 8 ++++++ lib_efo/src/error.rs | 9 +++++++ lib_efo/src/stats/implementations/test.rs | 2 -- 9 files changed, 62 insertions(+), 18 deletions(-) diff --git a/.ignore b/.ignore index bd01d04..73f8d72 100644 --- a/.ignore +++ b/.ignore @@ -1 +1,2 @@ snapshots +*.svg diff --git a/.run_status.toml b/.run_status.toml index 553a8af..12ed86c 100644 --- a/.run_status.toml +++ b/.run_status.toml @@ -1,8 +1,8 @@ [last_run_clean] run_status = "Success" lines_parsed = 83 -coverage = 51.17 +coverage = 50.17 [last_run_clean.run_duration] -secs = 24 -nanos = 975426411 +secs = 25 +nanos = 72743368 diff --git a/badges/coverage.svg b/badges/coverage.svg index 8819e8f..d697e70 100644 --- a/badges/coverage.svg +++ b/badges/coverage.svg @@ -1 +1 @@ -test-coverage: 51%test-coverage51% \ No newline at end of file +test-coverage: 50%test-coverage50% \ No newline at end of file diff --git a/bin_efo/src/commands/entity_generic.rs b/bin_efo/src/commands/entity_generic.rs index 6f4dcfe..53654f0 100644 --- a/bin_efo/src/commands/entity_generic.rs +++ b/bin_efo/src/commands/entity_generic.rs @@ -193,6 +193,13 @@ fn handle_create_entity( main_epoch: &mut EpochConfig, ) -> Result<(), EpochError> { let epoch_info = main_epoch.try_load_current_as_mut()?; + + if find_entity(entity_args, e_type, epoch_info).is_ok() { + Err(EpochError::EntityAlreadyExist( + entity_args.identifier.clone(), + ))?; + }; + let vec_entities: &mut Vec = vec_entities_mut(e_type, epoch_info); let mut entity = Entity::create_rng(e_type, &entity_args.rng)?; @@ -409,8 +416,8 @@ fn vec_entities<'a>( EntityType::Character => &epoch_info.characters, EntityType::Player => todo!(), EntityType::Town => &epoch_info.towns, - EntityType::Monster => todo!(), - EntityType::Blocker => todo!(), + EntityType::Monster => &epoch_info.calamities, + EntityType::Blocker => &epoch_info.blockers, EntityType::Event => &epoch_info.events, } } @@ -437,8 +444,8 @@ fn vec_entities_mut<'a>( EntityType::Character => &mut epoch_info.characters, EntityType::Player => todo!(), EntityType::Town => &mut epoch_info.towns, - EntityType::Monster => todo!(), - EntityType::Blocker => todo!(), + EntityType::Monster => &mut epoch_info.calamities, + EntityType::Blocker => &mut epoch_info.blockers, EntityType::Event => &mut epoch_info.events, } } diff --git a/bin_efo/src/main.rs b/bin_efo/src/main.rs index 652a527..90958c4 100644 --- a/bin_efo/src/main.rs +++ b/bin_efo/src/main.rs @@ -7,7 +7,6 @@ //! //! * [`epoch`](crate::commands::epoch) - switch / advance time //! * [`event`](crate::commands::entity_generic) - add / remove events -//! * [`org`](crate::commands::entity_generic) - add / remove organisations //! * [`chr`](crate::commands::entity_generic) - add / remove characters //! * [`town`](crate::commands::entity_generic) - add / remove towns //! * [`blocker`](crate::commands::entity_generic) - add / remove blockers @@ -26,7 +25,7 @@ use std::fmt::Debug; -use clap::{ArgAction, Parser, Subcommand}; +use clap::{Parser, Subcommand}; use crate::{ commands::{ @@ -47,10 +46,9 @@ mod success; #[command(name = "efo")] #[command(about = "Epoch Forge - manage organisations over time")] struct Cli { - /// The level of verbosity - #[arg(short, long, action = ArgAction::Count, global = true)] - verbose: u8, - + // /// The level of verbosity + // #[arg(short, long, action = ArgAction::Count, global = true)] + // verbose: u8, #[command(subcommand)] /// The top level command to be executed command: TopLevelCmd, @@ -78,8 +76,15 @@ enum TopLevelCmd { Event(EntitySubCommands), // #[command(subcommand)] // Org(commands::org::OrgCmd), - // #[command(subcommand)] - // Town(commands::town::TownCmd), + /// Handle Towns + #[command(subcommand)] + Town(EntitySubCommands), + /// Handle Calamities + #[command(subcommand)] + Calamity(EntitySubCommands), + /// Handle Blocker + #[command(subcommand)] + Blocker(EntitySubCommands), // Link(commands::link::LinkCmd), /// Generate random structures and display them #[command(subcommand)] @@ -130,5 +135,17 @@ fn exec_dispatch(cli: Cli) -> Result<(), AppError> { &cmd, &lib_efo::stats::EntityType::Event, ), + TopLevelCmd::Town(cmd) => commands::entity_generic::handle_entity_commands( + &cmd, + &lib_efo::stats::EntityType::Town, + ), + TopLevelCmd::Calamity(cmd) => commands::entity_generic::handle_entity_commands( + &cmd, + &lib_efo::stats::EntityType::Monster, + ), + TopLevelCmd::Blocker(cmd) => commands::entity_generic::handle_entity_commands( + &cmd, + &lib_efo::stats::EntityType::Blocker, + ), } } diff --git a/lib_efo/src/epoch/epoch_config.rs b/lib_efo/src/epoch/epoch_config.rs index 5836979..c83d0b3 100644 --- a/lib_efo/src/epoch/epoch_config.rs +++ b/lib_efo/src/epoch/epoch_config.rs @@ -391,6 +391,8 @@ impl EpochConfig { /// * `Err(EpochError::EntityNotFoundById(id))` - No entity with the /// supplied UUID exists in the epoch. /// + #[allow(dead_code)] + // TODO: Add to a generic show unsafe fn find_entity(&self, id: Uuid) -> Result<&Entity, EpochError> { let epoch_info = unsafe { self.try_load_id(self.epoch_id) }?; let predicate = |entity: &&Entity| entity.id == id; @@ -400,6 +402,8 @@ impl EpochConfig { .find(predicate) .or(epoch_info.characters.iter().find(predicate)) .or(epoch_info.towns.iter().find(predicate)) + .or(epoch_info.blockers.iter().find(predicate)) + .or(epoch_info.calamities.iter().find(predicate)) .ok_or(EpochError::EntityNotFoundById(id)) } } diff --git a/lib_efo/src/epoch/epoch_info.rs b/lib_efo/src/epoch/epoch_info.rs index bd37874..918015c 100644 --- a/lib_efo/src/epoch/epoch_info.rs +++ b/lib_efo/src/epoch/epoch_info.rs @@ -63,6 +63,12 @@ pub struct EpochInfo { #[table(skip)] /// The list of towns currently present pub towns: Vec, + #[table(skip)] + /// The list of calamities currently present + pub calamities: Vec, + #[table(skip)] + /// The list of blockers currently present + pub blockers: Vec, } impl Prettiable for EpochInfo {} @@ -77,6 +83,8 @@ impl Default for EpochInfo { events: Vec::new(), characters: Vec::new(), towns: Vec::new(), + calamities: Vec::new(), + blockers: Vec::new(), } } } diff --git a/lib_efo/src/error.rs b/lib_efo/src/error.rs index fa0e869..c503ed4 100644 --- a/lib_efo/src/error.rs +++ b/lib_efo/src/error.rs @@ -311,6 +311,15 @@ pub enum EpochError { #[diagnostic(code(EntityIdentifierError::InvalidIdentifier))] #[help("Verify that the UUID after `@` is a valid id.")] EmptyIdentifier, + + /// The entity already exists. + #[error("Failed to create entity: {0:?} already exists")] + #[diagnostic(code(EntityError::EntityAlreadyExist))] + #[help( + "Ensure that the entity name or ID is unique before creating a new one. \ + You may need to delete or rename the existing entity." + )] + EntityAlreadyExist(Option), } /// A small enum of explicit user-facing error messages. diff --git a/lib_efo/src/stats/implementations/test.rs b/lib_efo/src/stats/implementations/test.rs index c331dda..8fab056 100644 --- a/lib_efo/src/stats/implementations/test.rs +++ b/lib_efo/src/stats/implementations/test.rs @@ -1,9 +1,7 @@ #![allow(clippy::unwrap_used)] -use insta::assert_debug_snapshot; use insta::assert_snapshot; use super::*; -use crate::entity::Entity; use crate::stats::GameStat; use crate::stats::GenericStat; use crate::stats::StatPair;