From 79b8330b7d241b8a4a778a4d81ed399ce5d5b294 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 8 Dec 2025 01:29:33 +0100 Subject: [PATCH] Corrected some bad things about naming and started diff --- Cargo.toml | 2 +- bin_efo/src/commands/show.rs | 2 +- lib_efo/naming.json | 105 ++++++++++++++++++++++++++ lib_efo/src/entity.rs | 4 +- lib_efo/src/entity/implementations.rs | 56 +++++++++++++- lib_efo/src/epoch/epoch_traits.rs | 5 +- lib_efo/src/stats.rs | 7 +- lib_efo/src/stats/implementations.rs | 18 ++--- naming.json | 31 +------- 9 files changed, 183 insertions(+), 47 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 12f5a22..de75af9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,4 @@ serde_json = "1.0.145" miette = { version = "7.6.0", features = ["fancy"] } env_logger = "0.11.8" log = "0.4.28" -derive_more = { version = "2.0.1", features = ["display"] } +derive_more = { version = "2.0.1", features = ["display", "add"] } diff --git a/bin_efo/src/commands/show.rs b/bin_efo/src/commands/show.rs index e55ef46..5058021 100644 --- a/bin_efo/src/commands/show.rs +++ b/bin_efo/src/commands/show.rs @@ -1,7 +1,7 @@ //! The show commands //! Used to display structures with various degree of verbosity -use clap::{Args, Subcommand}; +use clap::Subcommand; use lib_efo::{Displayable, entity::Entity, naming::NAMING}; use crate::error::AppError; diff --git a/lib_efo/naming.json b/lib_efo/naming.json index 2bc4de8..240812d 100644 --- a/lib_efo/naming.json +++ b/lib_efo/naming.json @@ -421,6 +421,111 @@ "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", diff --git a/lib_efo/src/entity.rs b/lib_efo/src/entity.rs index 6b46781..8e34625 100644 --- a/lib_efo/src/entity.rs +++ b/lib_efo/src/entity.rs @@ -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 derive_more::{Add, Sub}; use serde::{Deserialize, Serialize}; use crate::stats::{EntityType, MetaStats, OverallStats}; @@ -70,12 +71,13 @@ pub struct Entity { /// been calculated to keep stats within a sane range. /// /// `min` and `max` are inclusive. -#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[derive(Debug, Serialize, Deserialize, Clone, Default, Add, Sub)] #[allow(missing_docs)] pub struct EffectBounds { pub min: usize, pub max: usize, } + /// How the entity's effect is applied over time. #[derive(Debug, Serialize, Deserialize, Clone, Default)] pub enum EffectApplication { diff --git a/lib_efo/src/entity/implementations.rs b/lib_efo/src/entity/implementations.rs index 84efe83..efaf362 100644 --- a/lib_efo/src/entity/implementations.rs +++ b/lib_efo/src/entity/implementations.rs @@ -4,7 +4,8 @@ use colored::*; // [3] - colored-rs examples use crate::Displayable; use crate::entity::Entity; -use crate::stats::Symbols; +use crate::epoch::epoch_traits::Diffable; +use crate::stats::{MetaStats, Symbols}; // ---------- Implementation ---------- impl Displayable for Entity { @@ -126,3 +127,56 @@ impl Entity { out } } + +/// Compare a field on `self` with the same field on `other`. +/// If they are equal → `None`, otherwise → the value from `other`. +macro_rules! diff_fields { + // Two arguments: the two objects you want to compare + ($self:ident, $other:ident, $( $field:ident ),* $(,)?) => { + $( + let $field = if $self.$field == $other.$field { + None + } else { + $other.$field.clone() + }; + )* + }; +} +impl Diffable for Entity { + fn delta(&self, other: &Self) -> Self { + let name = if self.name == other.name { + self.name.clone() + } else { + format!("{}->{}", self.name, other.name) + }; + Self { + name, + stats: self.stats.clone() - other.stats.clone(), + temp_stats: self.temp_stats.clone() - other.temp_stats.clone(), + metadata: self.metadata.delta(&other.metadata), + entity_type: self.entity_type.clone(), + duration: self.duration.clone(), + effect_nature: self.effect_nature.clone(), + effect_bounds: self.effect_bounds.clone() - other.effect_bounds.clone(), + } + } +} + +impl Diffable for MetaStats { + fn delta(&self, other: &Self) -> Self { + diff_fields!(self, other, capital, governor); + Self { + position: self.position.clone() - other.position.clone(), + capital, + governor, + faction: self.faction.clone() - other.faction.clone(), + links: self + .links + .clone() + .into_iter() + .filter(|t1| other.links.iter().any(|t2| t1 == t2)) + .collect(), + prestige: self.prestige - other.prestige, + } + } +} diff --git a/lib_efo/src/epoch/epoch_traits.rs b/lib_efo/src/epoch/epoch_traits.rs index 55a25bf..94b2346 100644 --- a/lib_efo/src/epoch/epoch_traits.rs +++ b/lib_efo/src/epoch/epoch_traits.rs @@ -12,7 +12,10 @@ use std::{fmt::Display, fs::File, io::Write}; use crate::{epoch::SaveMode, error::EpochError}; /// Elements that can be compared with another instance to produce a diff. -pub trait Diffable {} +pub trait Diffable { + /// Compare self with another struct of the same type and return a new instance containing the difference + fn delta(&self, other: &Self) -> Self; +} /// Elements that can be applied to the current world state. pub trait Applyable {} diff --git a/lib_efo/src/stats.rs b/lib_efo/src/stats.rs index 124c159..90d731c 100644 --- a/lib_efo/src/stats.rs +++ b/lib_efo/src/stats.rs @@ -16,7 +16,9 @@ use crate::thin_newtype; use cli_table::Color; use cli_table::Table; use colored::Colorize; +use derive_more::Add; use derive_more::Display; +use derive_more::Sub; use serde::{Deserialize, Serialize}; mod implementations; @@ -26,8 +28,7 @@ mod implementations; /// by comment blocks that describe each thematic section. #[derive(Debug, Clone, Default, Serialize, Deserialize)] // Derive more -#[derive(Table)] -// #[derive(Add, Sub)] +#[derive(Table, Add, Sub)] pub struct OverallStats { // ──────────────────────── Demographics ──────────────────────── /// Total economic health of the entity. @@ -324,7 +325,7 @@ pub struct StatPair { } /// Structure used to indicate position, possess nice helper methods to use as is in the program -#[derive(Debug, Default, Serialize, Deserialize, Clone)] +#[derive(Debug, Default, Serialize, Deserialize, Clone, Add, Sub)] pub struct Position(isize, isize); impl Position { diff --git a/lib_efo/src/stats/implementations.rs b/lib_efo/src/stats/implementations.rs index 7e183ea..c8881d4 100644 --- a/lib_efo/src/stats/implementations.rs +++ b/lib_efo/src/stats/implementations.rs @@ -3,19 +3,11 @@ use colored::Colorize; use std::str::FromStr; -use crate::entity::EffectApplication; -use crate::entity::EffectBounds; -use crate::entity::EntityDuration; +use crate::entity::{EffectApplication, EffectBounds, EntityDuration}; use crate::error::EpochError; -use crate::stats; -use crate::stats::EntityType; -use crate::stats::GameStat; -use crate::stats::GenericStat; -use crate::stats::ListStats; -use crate::stats::OverallStats; -use crate::stats::Position; -use crate::stats::StatPair; -use crate::stats::Symbols; +use crate::stats::{ + self, EntityType, GameStat, GenericStat, ListStats, OverallStats, Position, StatPair, Symbols, +}; /// Creates a thin, deref-able wrapper around an inner type. #[macro_export] @@ -36,6 +28,8 @@ macro_rules! thin_newtype { Serialize, Deserialize, Display, + Add, + Sub, )] pub struct $name(pub $inner); diff --git a/naming.json b/naming.json index d4d2fe8..bf05957 100644 --- a/naming.json +++ b/naming.json @@ -421,7 +421,6 @@ "Seer", "Master" ], - "exotic_prefixes": [ "Ar", "Bel", @@ -505,28 +504,6 @@ "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", @@ -912,7 +889,7 @@ }, { "name": "city_corruption_scandal", - "description": "A high‑ranking magistrate is discovered embezzling city funds, sparking public outrage and a demand for accountability.", + "description": "A high-ranking magistrate is discovered embezzling city funds, sparking public outrage and a demand for accountability.", "stats": [ { "stat": "Food", @@ -1490,7 +1467,7 @@ }, { "name": "resource_piracy", - "description": "Sea‑borne raiders seize a shipment of precious stones destined for the city, flooding the market with counterfeit goods.", + "description": "Sea-borne raiders seize a shipment of precious stones destined for the city, flooding the market with counterfeit goods.", "stats": [ { "stat": "Trade", @@ -2304,7 +2281,7 @@ }, { "name": "plague_of_scorpion", - "description": "A deadly disease spreads through the populace, turning citizens into venom‑infused monsters.", + "description": "A deadly disease spreads through the populace, turning citizens into venom-infused monsters.", "stats": [ { "stat": "Health", @@ -2463,4 +2440,4 @@ } } ] -} +} \ No newline at end of file