Some slop and prestige
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-15 03:41:20 +01:00
parent b4f979a98a
commit 43fccdd4c6
10 changed files with 95 additions and 45 deletions

View File

@ -68,7 +68,7 @@
#![warn(unused_attributes)]
use clap::{Args, Subcommand};
use lib_efo::stats::{PositionIdentifier, Symbols};
use lib_efo::stats::{GenericStat, PositionIdentifier, Symbols};
use lib_efo::{
Displayable,
entity::{EffectApplication, EffectBounds, Entity, EntityDuration, EntityIdentifier},
@ -233,6 +233,14 @@ pub struct CommonArgs {
/// The entity doens't have a capital.
#[arg(long, action = clap::ArgAction::SetTrue, default_value_t = false, group="capital_group")]
pub no_capital: bool,
/// Change the prestige
#[arg(long, group = "capital_group")]
pub prestige: Option<GenericStat>,
/// Change the prestige by a delta
#[arg(long, group = "capital_group")]
pub add_prestige: Option<GenericStat>,
// /// Add a link to another location
// /// This is currently unused and important for early testing
// #[arg(long, short = 'l')]

View File

@ -124,6 +124,12 @@ pub fn update_common_values(
if let Some(description) = &entity_args.description {
entity.modify_description(description.clone());
}
if let Some(prestige) = &entity_args.prestige {
entity.modify_prestige(*prestige)
}
if let Some(prestige) = &entity_args.add_prestige {
entity.modify_prestige_by_delta(*prestige)
}
}
/// Try to update all advanced values

View File

@ -1,4 +1,5 @@
//! Implementation of all needed traits for the Entity struct
use std::ops::Add;
mod from_impl;
use std::cmp::{max, min};
@ -45,7 +46,7 @@ impl Displayable for Entity {
.metadata
.governor
.as_ref()
.map(|g| format!("{}", g.to_symbol()).red())
.map(|g| format!("Governor: {}", g.to_symbol()).blue())
.unwrap_or_default();
let prestige = if *self.metadata.prestige > 0 {
@ -155,7 +156,6 @@ impl Entity {
let mut out = String::new();
// ── Top line: <entity_type> <name>
out.push_str(&format!(
"[{} {} 󰻾[{}]]\n",
self.entity_type.to_symbol().blue().bold(),
@ -175,7 +175,17 @@ impl Entity {
),
));
}
out.push_str(&indent(0, &format!("├─ {}\n", "metadata".green())));
if let Some(faction) = self.metadata.faction {
out.push_str(&indent(
1,
&format!(
"├─ {} : {}{}\n",
"faction".bright_green(),
"".yellow(),
faction.to_string().yellow(),
),
));
}
if let Some(governor) = self.metadata.governor {
out.push_str(&indent(
1,
@ -190,9 +200,10 @@ impl Entity {
out.push_str(&indent(
1,
&format!(
"├─ {}: {}\n",
"├─ {}: {}{}\n",
"prestige".bright_green(),
self.metadata.prestige
self.metadata.prestige.to_string().yellow(),
"".yellow()
),
));
}
@ -290,11 +301,11 @@ impl Entity {
/// Mutate a statistic in a “fuzzy” way.
///
/// This method behaves like `change_stat_strict` for ordinary stats, but
/// for *meta‑stats* it applies a random modification instead of an
/// for *meta-stats* it applies a random modification instead of an
/// outright overwrite.
///
/// # Parameters
/// * `pair` – a `StatPair` that contains the target statistic and the
/// * `pair` - a `StatPair` that contains the target statistic and the
/// value that should be used for the fuzzy change.
pub fn change_stat_fuzzy(&mut self, pair: StatPair, delta: bool) {
let stats_demo = [
@ -342,10 +353,10 @@ impl Entity {
/// Mutates a statistic in a “fuzzy” manner.
///
/// For ordinary statistics this behaves like `change_stat_strict` and
/// simply assigns the supplied value. For *meta‑stats* the function
/// chooses a random subset of the associated sub‑statistics and
/// simply assigns the supplied value. For *meta-stats* the function
/// chooses a random subset of the associated sub-statistics and
/// distributes the requested change evenly among them. The selection
/// is performed using a thread‑local RNG.
/// is performed using a thread-local RNG.
fn change_random_stats_by(
&mut self,
stats_demo: &[ListStats],
@ -436,7 +447,7 @@ impl Entity {
self.effect_bounds = effect
}
/// Sets the entity’s position using a world‑space `Position`.
/// Sets the entity's position using a world-space `Position`.
///
/// This method updates the internal metadata to the specified
/// world coordinates.
@ -444,7 +455,7 @@ impl Entity {
self.metadata.position = pos;
}
/// Sets the entity’s faction identifier.
/// Sets the entity's faction identifier.
///
/// This method updates the internal metadata to reflect the provided
/// `faction`. A `None` value indicates that the entity is not
@ -453,16 +464,16 @@ impl Entity {
self.metadata.faction = faction;
}
/// Sets the entity’s reach description.
/// Sets the entity's reach description.
///
/// The `reach` string typically contains information such as the
/// distance or area the entity can affect. This method replaces
/// the current reach value stored in the entity’s metadata.
/// the current reach value stored in the entity's metadata.
pub fn modify_reach(&mut self, reach: stats::Reach) {
self.metadata.reach = reach;
}
/// Sets the entity’s position using a grid‑space `PositionGrid`.
/// Sets the entity's position using a grid-space `PositionGrid`.
///
/// The supplied grid coordinates are converted to world space
/// before being stored.
@ -470,10 +481,22 @@ impl Entity {
self.metadata.position = pos.to_position();
}
/// Sets the entity’s description as a String.
/// Changes the entity's description text.
pub fn modify_description(&mut self, descritption: String) {
self.description = descritption;
}
/// Sets the entity's prestige stat to an absolute value.
///
/// The prestige value is stored directly in the entity's metadata
/// and overwrites any previous value.
pub fn modify_prestige(&mut self, prestige: GenericStat) {
self.metadata.prestige = prestige;
}
/// Adjusts the entity's prestige stat by adding a delta.
pub fn modify_prestige_by_delta(&mut self, prestige: GenericStat) {
self.metadata.prestige = self.metadata.prestige.add(prestige);
}
/// Add a governor to the entity if the id exists
pub fn change_governor(&mut self, governor: stats::CharacterId) {
@ -495,7 +518,7 @@ impl Entity {
self.metadata.capital.take()
}
/// Returns a **read‑only reference** to the entity’s current position.
/// Returns a **read-only reference** to the entity's current position.
pub fn position(&self) -> &Position {
&self.metadata.position
}

View File

@ -201,7 +201,7 @@ mod test {
let parsed: EpochIdentifier = "7".parse().unwrap();
assert!(matches!(parsed, EpochIdentifier::Id(_)));
// non‑empty string → Tag
// non-empty string → Tag
let parsed: EpochIdentifier = "winter-b".parse().unwrap();
assert!(matches!(parsed, EpochIdentifier::Tag(_)));

View File

@ -210,11 +210,11 @@ mod tests {
// fn test_config_writable_save_with_context_donot_erase() {
// let (item, _path) = dummy_with_tempfile(20);
// // First write – must succeed
// // First write - must succeed
// item.save_with_context("DoNotErase test 1", &SaveMode::DoNotErase)
// .unwrap();
// // Second write – should fail with `ConfigCreation` because the file
// // Second write - should fail with `ConfigCreation` because the file
// // already exists.
// let err = item
// .save_with_context("DoNotErase test 2", &SaveMode::DoNotErase)

View File

@ -426,14 +426,14 @@ pub struct StatPair {
pub value: GenericStat,
}
/// A two‑dimensional point on the world map.
/// A two-dimensional point on the world map.
///
/// The struct is a thin wrapper around a pair of `isize` values
/// representing the X and Y coordinates.
#[derive(Debug, Default, Serialize, Deserialize, Clone, Add, Sub, Mul)]
pub struct Position(isize, isize);
/// A grid‑aligned position used for chunk look‑ups.
/// A grid-aligned position used for chunk look-ups.
///
/// A `PositionGrid` stores the coordinates of a chunk in the world
/// grid. Each component is the index of the chunk in the X and Y
@ -453,7 +453,7 @@ const CHUNK_SIZE: isize = 200;
impl Position {
/// Calculates the Euclidean distance between two points.
///
/// The distance is computed in the 2‑D Euclidean space.
/// The distance is computed in the 2-D Euclidean space.
pub fn distance(&self, other: &Self) -> isize {
((self.0 - other.0).pow(2) + (self.1 * other.1).pow(2)).isqrt()
}
@ -661,7 +661,7 @@ pub enum PositionIdentifier {
/// Exact position specified as `X,Y`.
Exact(Position),
/// Grid‑aligned position specified as `~X,Y` or `gX,Y`.
/// Grid-aligned position specified as `~X,Y` or `gX,Y`.
Grid(PositionGrid),
/// Reference to an epoch by UUID, written as `@{uuid}`.
@ -671,17 +671,17 @@ pub enum PositionIdentifier {
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
/// The reach of the entity
pub enum Reach {
/// The entity can affect **any** target – no positional or faction
/// The entity can affect **any** target - no positional or faction
/// restrictions. Use this when the effect is truly global.
Global,
/// The entity has a *limited* area of effect. The `usize` usually
/// represents the radius around the entity’s position that the effect covers.
/// represents the radius around the entity's position that the effect covers.
Local(usize),
/// The entity can only affect members of a particular faction.
Faction(FactionId),
// /// The entity only affect a specific entity
// Entity(EntityIdentifier),
/// No reach – the entity should not be applied globally.
/// No reach - the entity should not be applied globally.
#[default]
None,
}

View File

@ -438,14 +438,14 @@ impl FromStr for FactionId {
/// Thin wrapper that derefs to the inner type.
///
/// By default the wrapper derives a common set of traits (`Debug`, `Clone`, `Copy`,
/// …). You can optionally provide an extra list of derives – e.g. `Add`,
/// `Sub`, `FromStr`, or any custom derive – by writing:
/// …). You can optionally provide an extra list of derives - e.g. `Add`,
/// `Sub`, `FromStr`, or any custom derive - by writing:
/// ```
/// # use lib_efo::thin_newtype;
/// use derive_more::{Add, Sub};
/// thin_newtype!(MyInt, i32, derives: [Add, Sub]);
/// ```
/// (you’ll need the corresponding crates – e.g. `derive_more` for `Add`, `Sub`).
/// (you'll need the corresponding crates - e.g. `derive_more` for `Add`, `Sub`).
#[macro_export]
macro_rules! thin_newtype {
/* ---- no custom derives ------------------------------------------------- */

View File

@ -2,7 +2,7 @@
use crate::{
error::EpochError,
stats::{self, ListStats, Position, PositionGrid, PositionIdentifier, StatPair},
stats::{self, GenericStat, ListStats, Position, PositionGrid, PositionIdentifier, StatPair},
};
use std::str::FromStr;
@ -82,9 +82,9 @@ impl std::str::FromStr for Position {
///
/// # Errors
///
/// * `EpochError::InvalidPositionFormat` – the string does not contain
/// * `EpochError::InvalidPositionFormat` - the string does not contain
/// exactly one comma or there are not exactly two components.
/// * `EpochError::ParsePositionError` – one of the components cannot be
/// * `EpochError::ParsePositionError` - one of the components cannot be
/// parsed as an `isize`. (These errors come from the underlying `Position`
/// implementation.)
impl std::str::FromStr for PositionGrid {
@ -188,3 +188,16 @@ impl std::str::FromStr for stats::Reach {
})
}
}
impl FromStr for GenericStat {
type Err = EpochError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
s.parse::<isize>()
.map_err(|_| EpochError::ParsingArgument {
argument_parsed: s.to_owned(),
while_parsing: "GenericStat",
})
.map(Self)
}
}

View File

@ -82,7 +82,7 @@ fn stat_pair_ill_formed_errors_are_detected() {
let err = StatPair::from_str("cri:abc").unwrap_err();
assert!(matches!(err, EpochError::IllFormedStatQualifier(_)));
// 6️⃣ Unknown stat – this is caught by the `ListStats::parse()` call,
// 6️⃣ Unknown stat - this is caught by the `ListStats::parse()` call,
// which already returns `IllFormedStatQualifier`
let err = StatPair::from_str("unknown:5").unwrap_err();
assert!(matches!(err, EpochError::UnknownStatAcronim(_)));
@ -104,7 +104,7 @@ fn position_invalid_format_errors_are_detected() {
let err = Position::from_str("5,").unwrap_err();
assert!(matches!(err, EpochError::ParsePositionError(_)));
// 4️⃣ Non‑integer components
// 4️⃣ Non-integer components
let err = Position::from_str("x,5").unwrap_err();
assert!(matches!(err, EpochError::ParsePositionError(_)));
@ -276,11 +276,11 @@ fn test_entity_type_to_shortest() {
}
// ---------------------------------------------------------------------------
// EntityType – already tested by your existing example
// EntityType - already tested by your existing example
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// EffectApplication – one line per variant
// EffectApplication - one line per variant
// ---------------------------------------------------------------------------
#[test]
fn test_effect_application_to_symbol() {
@ -298,7 +298,7 @@ fn test_effect_application_to_symbol() {
}
// ---------------------------------------------------------------------------
// Position – two variants, tested for both `to_symbol` and `to_shortest`
// Position - two variants, tested for both `to_symbol` and `to_shortest`
// ---------------------------------------------------------------------------
#[test]
fn test_position_to_symbol() {
@ -311,7 +311,7 @@ fn test_position_to_symbol() {
}
// ---------------------------------------------------------------------------
// EntityDuration – one line per variant
// EntityDuration - one line per variant
// ---------------------------------------------------------------------------
#[test]
fn test_entity_duration_to_symbol() {

View File

@ -31,9 +31,9 @@ pub enum RngLevel {
Mixed,
/// All non specified are either high or low
Flawed,
/// All non‑specified values are apocalyptic
/// All non-specified values are apocalyptic
Apocaliptic,
/// All non‑specified values are doomed
/// All non-specified values are doomed
Doom,
}
@ -63,10 +63,10 @@ impl RngLevel {
/// and return the rendered string.
///
/// # Parameters
/// * `$items` – A table builder that implements the `Table` trait
/// * `$items` - A table builder that implements the `Table` trait
/// (e.g. `Vec<Vec<...>>.into_table()`, `items.into_table()`, …).
/// * `$name` – The name that should be stored in `EpochError::TableStringConversionError`.
/// * `$id` – The id that should be stored in `EpochError::TableStringConversionError`.
/// * `$name` - The name that should be stored in `EpochError::TableStringConversionError`.
/// * `$id` - The id that should be stored in `EpochError::TableStringConversionError`.
#[macro_export]
macro_rules! items_table {
($items:expr, $name:expr, $id:expr) => {{