diff --git a/Jenkinsfile b/Jenkinsfile index a7ed200..6d40fcd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -46,11 +46,11 @@ pipeline { post { success { publishChecks conclusion: 'SUCCESS', name: 'Build Successful', summary: 'The build was successful', text: 'The build was sucessful', title: 'Build Successful' - echo '✅Site Deployed!' + echo '✅ Build Deployed!' } failure { publishChecks conclusion: 'FAILURE', name: 'Build Failed', summary: 'The build failed', text: 'The build was a failure', title: 'Build failed' - echo '❌Site Failed to Deploy' + echo '❌Build Failed to Deploy' } unstable{ publishChecks conclusion: 'ACTION_REQUIRED', name: 'Build Unstable', summary: 'Unstable build', text: 'Unstable build', title: 'Build Unstable' diff --git a/lib_efo/src/entity/implementations.rs b/lib_efo/src/entity/implementations.rs index f565fe4..cc00cf1 100644 --- a/lib_efo/src/entity/implementations.rs +++ b/lib_efo/src/entity/implementations.rs @@ -74,7 +74,7 @@ impl Displayable for Entity { } impl Entity { - // Display the entity’s statistics in a pretty table. + // Display the entity's statistics in a pretty table. /// /// The table contains both the permanent and temporary statistics of the /// entity. The table is formatted with a custom border and separator @@ -92,7 +92,7 @@ impl Entity { self.stat_to_table(items) } - /// Display the entity’s statistics in a pretty table (same format as + /// Display the entity's statistics in a pretty table (same format as /// `full_stats_to_table`). /// /// This method is provided for backward compatibility and forwards all @@ -110,7 +110,7 @@ impl Entity { self.stat_to_table(items) } - /// Display the entity’s statistics in a pretty table (same format as + /// Display the entity's statistics in a pretty table (same format as /// `full_stats_to_table`). /// /// This method is provided for backward compatibility and forwards all @@ -148,9 +148,9 @@ impl Entity { }) } - /// Pretty‑print the entity as a coloured tree. + /// Pretty-print the entity as a coloured tree. /// - /// The output is a `String` that visualises the entity’s metadata, type, + /// The output is a `String` that visualises the entity's metadata, type, /// duration, effect bounds, and any links. Colours are applied using /// `colored::Colorize`. /// @@ -211,7 +211,7 @@ impl Entity { )); } } - // ── Other top‑level fields + // ── Other top-level fields out.push_str(&indent( 0, &format!( @@ -242,12 +242,12 @@ impl Entity { /// and a random prestige value derived from the supplied `RngLevel`. /// /// # Arguments - /// * `e_type` – The type of entity to create. - /// * `rng` – The RNG level to use when generating random values. + /// * `e_type` - The type of entity to create. + /// * `rng` - The RNG level to use when generating random values. /// /// # Returns - /// * `Ok(Self)` – The newly created entity. - /// * `Err(EpochError)` – Propagated from any randomisation failure. + /// * `Ok(Self)` - The newly created entity. + /// * `Err(EpochError)` - Propagated from any randomisation failure. /// pub fn create_rng(e_type: &EntityType, rng: &RngLevel) -> Result { let mut r = rand::rng(); @@ -265,26 +265,26 @@ impl Entity { }) } - /// Change one of the entity’s statistics. + /// Change one of the entity's statistics. /// /// The stat identified by `pair` is replaced with the new value specified in /// the `StatPair`. This is a direct overwrite and does not apply any delta. /// /// # Arguments - /// * `pair` – The stat pair containing the key and new value. + /// * `pair` - The stat pair containing the key and new value. /// pub fn change_stat(&mut self, pair: StatPair) { overwrite_stat(&mut self.stats, pair); } - /// Apply a delta to all of the entity’s statistics. + /// Apply a delta to all of the entity's statistics. /// /// The delta specified by `pair` is added to each of the statistics in /// `self.stats`. Positive values increase the stat, negative values /// decrease it. /// /// # Arguments - /// * `pair` – The stat pair representing the change to apply. + /// * `pair` - The stat pair representing the change to apply. pub fn delta_stat(&mut self, pair: StatPair) { add_to_stat(&mut self.stats, pair); } diff --git a/lib_efo/src/epoch/epoch_config.rs b/lib_efo/src/epoch/epoch_config.rs index ccc45f2..47a2957 100644 --- a/lib_efo/src/epoch/epoch_config.rs +++ b/lib_efo/src/epoch/epoch_config.rs @@ -10,9 +10,12 @@ //! The world data and all event logs belong to the individual epoch //! directories and are **not** part of this file. -use crate::epoch::{ - EpochId, EpochIdentifier, EpochInfo, MAIN_NAME, SUBFOLDER_NAMING, SaveMode, - epoch_traits::ConfigWritable, +use crate::{ + entity::Entity, + epoch::{ + EpochId, EpochIdentifier, EpochInfo, MAIN_NAME, SUBFOLDER_NAMING, SaveMode, + epoch_traits::ConfigWritable, + }, }; use std::{ collections::HashMap, @@ -22,6 +25,7 @@ use std::{ use log::{info, warn}; use serde::{Deserialize, Serialize}; +use uuid::Uuid; use crate::{epoch::epoch_traits::Prettiable, error::EpochError}; @@ -362,6 +366,40 @@ impl EpochConfig { EpochInfo::show_as_table(items_to_log); Ok(()) } + + /// Find an entity by its UUID. + /// + /// This function searches the currently loaded epoch for an entity whose + /// `id` matches the supplied `Uuid`. It looks in both the `events`, `towns` + /// and `characters` collections of the epoch. + /// + /// # Safety + /// The caller must guarantee that the epoch identified by `self.epoch_id` + /// has already been loaded into memory (for example by calling + /// `try_load` first). The function performs an unchecked reference + /// conversion via `try_load_id`; invoking it when the epoch is not + /// cached results in **undefined behaviour**. + /// + /// # Arguments + /// * `id` - The `Uuid` of the entity to locate. + /// + /// # Returns + /// * `Ok(&Entity)` - Reference to the entity if it is present in the + /// current epoch. + /// * `Err(EpochError::EntityNotFoundById(id))` - No entity with the + /// supplied UUID exists in the epoch. + /// + 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; + epoch_info + .events + .iter() + .find(predicate) + .or(epoch_info.characters.iter().find(predicate)) + .or(epoch_info.towns.iter().find(predicate)) + .ok_or(EpochError::EntityNotFoundById(id)) + } } impl ConfigWritable for EpochConfig { diff --git a/lib_efo/src/error.rs b/lib_efo/src/error.rs index 60858cb..7667afe 100644 --- a/lib_efo/src/error.rs +++ b/lib_efo/src/error.rs @@ -246,6 +246,14 @@ pub enum EpochError { #[help("This is an internal error. Please file a bug report.")] EpochHashingImpossible(&'static str, u32), + /// The entity with id **`{0}`** could not be found. + #[error("Entity of type with id {0:?} not found")] + #[diagnostic(code(epoch::entity_not_found_by_id))] + #[help( + "Verify that the identifier is correct and that the entity exists in the current epoch." + )] + EntityNotFoundById(Uuid), + /// The entity could not be found #[error("Entity of type {0:?} with name {1:?} & id {2:?} not found")] #[diagnostic(code(epoch::entity_not_found))] @@ -261,7 +269,7 @@ pub enum EpochError { #[help("Ensure that the supplied range bounds satisfy `min < max`.")] UniformRngCreation(#[from] rand::distr::uniform::Error), - /// The string did not contain exactly two comma‑separated values. + /// The string did not contain exactly two comma-separated values. #[error("Invalid position format: expected \"x,y\" found {0}")] #[diagnostic(code(EpochError::InvalidPositionFormat))] #[help("Provide exactly two numbers separated by a comma.")] diff --git a/lib_efo/src/stats/implementations.rs b/lib_efo/src/stats/implementations.rs index 57ac944..2198eff 100644 --- a/lib_efo/src/stats/implementations.rs +++ b/lib_efo/src/stats/implementations.rs @@ -216,7 +216,7 @@ impl OverallStats { /// /// # Arguments /// - /// * `field` – The `ListStats` variant that selects which statistic to return. + /// * `field` - The `ListStats` variant that selects which statistic to return. /// /// # Returns /// @@ -260,7 +260,7 @@ impl OverallStats { /// /// # Arguments /// - /// * `field` – The `ListStats` variant that selects which statistic to modify. + /// * `field` - The `ListStats` variant that selects which statistic to modify. /// /// # Returns /// @@ -339,9 +339,9 @@ impl FromStr for StatPair { /// /// # Errors /// -/// * `ParsePositionError::InvalidFormat` – the string does not contain +/// * `ParsePositionError::InvalidFormat` - the string does not contain /// exactly one comma or there are not exactly two components. -/// * `ParsePositionError::ParseIntError` – one of the components cannot be +/// * `ParsePositionError::ParseIntError` - one of the components cannot be /// parsed as an `isize`. impl std::str::FromStr for Position { type Err = EpochError;