feat: add organisation management and compatible naming

This commit is contained in:
Dandaedre 2026-09-20 22:00:08 +02:00
parent 36757dca57
commit cff2cd0dcf
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
17 changed files with 121 additions and 35 deletions

View File

@ -61,7 +61,7 @@ acceptance gates on 2026-09-20. Phase 3 is the next active milestone.
parent links, tags, IDs, entity references, and parseability.
- [x] Make `init --force` safe and explicit; it must not silently destroy an
existing Epoch Forge repository or unrelated files.
- [ ] Resolve naming inconsistencies (`chr`, calamity mapped to monster,
- [x] Resolve naming inconsistencies (`chr`, calamity mapped to monster,
missing organisation surface) with aliases/deprecation where compatibility
warrants it.
- [ ] Improve all command help with examples and valid-value guidance.

View File

@ -8,8 +8,8 @@ designed for people who are comfortable with Git-like concepts: inspect the
current state, advance it, compare it with history, and deliberately discard a
future timeline when needed.
The current release manages characters, towns, events, calamities, and blockers
with statistics and relationships. Organisation-agnostic custom fields,
The current release manages organisations, characters, towns, events,
calamities, and blockers with statistics and relationships. Custom fields,
pseudo-staging, complete restore/revert workflows, and a TUI are planned—not
implemented. There is no GUI or web interface.
@ -69,7 +69,7 @@ Run `efo --help`, `efo <command> --help`, or see the
|---|---|---|
| Repository | Initialise in the current directory; inspect status | Discovery from child directories; locking; migrations |
| Timeline | Advance, switch, log, tag, summarise, diff, check integrity, delete future epochs | Integrity repair; branching; atomic restore/revert |
| Entities | Add, edit, list, inspect, diff, and delete five built-in types | Organisations; custom types and custom fields; bulk operations |
| Entities | Add, edit, list, inspect, diff, and delete six built-in types | Custom types and custom fields; bulk operations |
| Generation | Generate character, town, event, calamity, blocker, and exotic names | Deterministic seed controls and template packs |
| Interfaces | CLI | TUI (possible stretch goal); GUI/web (out of scope) |

View File

@ -50,12 +50,18 @@ pub(crate) fn update_defaults(entity_args: &AddArgs, e: &mut Entity) {
EffectBounds { min: 20, max: 60 },
NAMING.generate_town_name(),
),
EntityType::Monster => (
EntityType::Calamity => (
lib_efo::entity::EntityDuration::Permanent,
lib_efo::entity::EffectApplication::WhenPresent,
EffectBounds { min: 20, max: 80 },
NAMING.generate_calamity_name(),
),
EntityType::Organization => (
lib_efo::entity::EntityDuration::Permanent,
lib_efo::entity::EffectApplication::WhenPresent,
EffectBounds { min: 0, max: 120 },
"Unnamed Organisation".to_string(),
),
EntityType::Blocker => (
lib_efo::entity::EntityDuration::Permanent,
lib_efo::entity::EffectApplication::WhenPresent,
@ -311,7 +317,8 @@ pub(crate) fn default_rng_for(e_type: &stats::EntityType) -> RngLevel {
stats::EntityType::Character => RngLevel::Med,
stats::EntityType::Player => RngLevel::High,
stats::EntityType::Town => RngLevel::Med,
stats::EntityType::Monster => RngLevel::Legendary,
stats::EntityType::Calamity => RngLevel::Legendary,
stats::EntityType::Organization => RngLevel::Med,
stats::EntityType::Blocker => RngLevel::Apocaliptic,
stats::EntityType::Event => RngLevel::Doom,
}

View File

@ -156,6 +156,7 @@ fn print_world_diff(start: &EpochInfo, end: &EpochInfo) -> Result<(), AppError>
("towns", &start.towns, &end.towns),
("events", &start.events, &end.events),
("calamities", &start.calamities, &end.calamities),
("organisations", &start.organizations, &end.organizations),
("blockers", &start.blockers, &end.blockers),
];
let mut changes = 0;
@ -406,19 +407,33 @@ fn handle_fsck(args: &cli_epoch::Fsck, main_epoch: &mut EpochConfig) -> Result<(
))?;
}
let mut entity_ids = std::collections::HashSet::new();
for entity in epoch
.characters
.iter()
.chain(&epoch.towns)
.chain(&epoch.events)
.chain(&epoch.calamities)
.chain(&epoch.blockers)
{
if entity.id.is_nil() || !entity_ids.insert(entity.id) {
Err(EpochError::TreeInvalid(
*id,
format!("entity `{}` has a missing or duplicate UUID", entity.name),
))?;
for (entities, expected_type) in [
(&epoch.characters, lib_efo::stats::EntityType::Character),
(&epoch.towns, lib_efo::stats::EntityType::Town),
(&epoch.events, lib_efo::stats::EntityType::Event),
(&epoch.calamities, lib_efo::stats::EntityType::Calamity),
(
&epoch.organizations,
lib_efo::stats::EntityType::Organization,
),
(&epoch.blockers, lib_efo::stats::EntityType::Blocker),
] {
for entity in entities {
if entity.id.is_nil() || !entity_ids.insert(entity.id) {
Err(EpochError::TreeInvalid(
*id,
format!("entity `{}` has a missing or duplicate UUID", entity.name),
))?;
}
if entity.entity_type != expected_type {
Err(EpochError::TreeInvalid(
*id,
format!(
"entity `{}` is stored in the wrong collection ({:?}, expected {:?})",
entity.name, entity.entity_type, expected_type
),
))?;
}
}
}
for tag in epoch.tags.iter() {

View File

@ -18,6 +18,8 @@ pub enum ShowCmd {
Town,
/// Show calamities.
Calamity,
/// Show organisations.
Organization,
/// Show blockers.
Blocker,
}
@ -31,13 +33,15 @@ pub fn handle_show_cmd(cmd: &ShowCmd) -> Result<(), AppError> {
("Characters", EntityType::Character),
("Towns", EntityType::Town),
("Events", EntityType::Event),
("Calamities", EntityType::Monster),
("Calamities", EntityType::Calamity),
("Organisations", EntityType::Organization),
("Blockers", EntityType::Blocker),
],
ShowCmd::Event => &[("Events", EntityType::Event)],
ShowCmd::Character => &[("Characters", EntityType::Character)],
ShowCmd::Town => &[("Towns", EntityType::Town)],
ShowCmd::Calamity => &[("Calamities", EntityType::Monster)],
ShowCmd::Calamity => &[("Calamities", EntityType::Calamity)],
ShowCmd::Organization => &[("Organisations", EntityType::Organization)],
ShowCmd::Blocker => &[("Blockers", EntityType::Blocker)],
};

View File

@ -41,6 +41,7 @@ pub(crate) fn status(cmd: &StatusCmd) -> Result<(), crate::error::AppError> {
println!(" ├─ Towns {}", epoch.towns.len());
println!(" ├─ Events {}", epoch.events.len());
println!(" ├─ Calamities {}", epoch.calamities.len());
println!(" └─ Blockers {}", epoch.blockers.len());
println!(" ├─ Organisations {}", epoch.organizations.len());
println!(" └─ Blockers {}", epoch.blockers.len());
Ok(())
}

View File

@ -73,7 +73,12 @@ enum TopLevelCmd {
Show(ShowCmd),
/// Handle characters
#[command(subcommand)]
#[command(visible_alias = "character")]
Chr(EntitySubCommands),
/// Handle organisations and factions
#[command(subcommand)]
#[command(visible_aliases = ["organization", "organisation"])]
Org(EntitySubCommands),
/// Handle events
#[command(subcommand)]
Event(EntitySubCommands),
@ -144,6 +149,10 @@ fn exec_dispatch(cli: Cli) -> Result<(), AppError> {
&cmd,
&lib_efo::stats::EntityType::Character,
),
TopLevelCmd::Org(cmd) => commands::entity_generic::handle_entity_commands(
&cmd,
&lib_efo::stats::EntityType::Organization,
),
TopLevelCmd::Event(cmd) => commands::entity_generic::handle_entity_commands(
&cmd,
&lib_efo::stats::EntityType::Event,
@ -154,7 +163,7 @@ fn exec_dispatch(cli: Cli) -> Result<(), AppError> {
),
TopLevelCmd::Calamity(cmd) => commands::entity_generic::handle_entity_commands(
&cmd,
&lib_efo::stats::EntityType::Monster,
&lib_efo::stats::EntityType::Calamity,
),
TopLevelCmd::Blocker(cmd) => commands::entity_generic::handle_entity_commands(
&cmd,

View File

@ -179,6 +179,7 @@ fn every_entity_type_supports_a_stable_id_lifecycle() {
("town", "towns", "Durn"),
("event", "events", "Storm"),
("calamity", "calamities", "The Blight"),
("org", "organizations", "Iron Council"),
("blocker", "blockers", "North Wall"),
];
let mut identifiers = Vec::new();

View File

@ -23,7 +23,8 @@ parent directories. `efo <command> --help` is the authoritative syntax.
## Entities
The built-in nouns are `chr`, `town`, `event`, `calamity`, and `blocker`:
The built-in nouns are `org`, `chr`, `town`, `event`, `calamity`, and `blocker`.
`character` aliases `chr`; `organization` and `organisation` alias `org`:
```text
efo <noun> add [NAME | --rng-name] [OPTIONS]

View File

@ -158,7 +158,7 @@ Entity {
),
reach: None,
},
entity_type: Monster,
entity_type: Calamity,
duration: Permanent,
effect_nature: Recurring,
effect_bounds: EffectBounds {

View File

@ -420,7 +420,7 @@ fn snapshot_entity_delta() {
prestige: stats::GenericStat(3),
reach: stats::Reach::Local(12),
},
entity_type: EntityType::Monster,
entity_type: EntityType::Calamity,
duration: EntityDuration::Permanent,
effect_nature: EffectApplication::Recurring,
effect_bounds: EffectBounds::from(0..33),
@ -604,7 +604,7 @@ fn test_rng() {
Entity::create_rng(&EntityType::Character, &crate::utils::RngLevel::Zero).unwrap();
Entity::create_rng(&EntityType::Player, &crate::utils::RngLevel::Low).unwrap();
Entity::create_rng(&EntityType::Town, &crate::utils::RngLevel::Med).unwrap();
Entity::create_rng(&EntityType::Monster, &crate::utils::RngLevel::High).unwrap();
Entity::create_rng(&EntityType::Calamity, &crate::utils::RngLevel::High).unwrap();
Entity::create_rng(&EntityType::Blocker, &crate::utils::RngLevel::Legendary).unwrap();
Entity::create_rng(&EntityType::Event, &crate::utils::RngLevel::Mixed).unwrap();
Entity::create_rng(&EntityType::Event, &crate::utils::RngLevel::Flawed).unwrap();

View File

@ -441,6 +441,7 @@ impl EpochConfig {
+ elt.characters.len()
+ elt.towns.len()
+ elt.calamities.len()
+ elt.organizations.len()
+ elt.blockers.len())
.to_string()
.yellow(),

View File

@ -59,6 +59,10 @@ pub struct EpochInfo {
#[table(skip)]
/// The list of characters currently present
pub characters: Vec<Entity>,
/// The list of organisations currently present.
#[serde(default)]
#[table(skip)]
pub organizations: Vec<Entity>,
#[table(skip)]
/// The list of towns currently present
pub towns: Vec<Entity>,
@ -81,6 +85,7 @@ impl Default for EpochInfo {
summary: String::new(),
events: Vec::new(),
characters: Vec::new(),
organizations: Vec::new(),
towns: Vec::new(),
calamities: Vec::new(),
blockers: Vec::new(),
@ -214,6 +219,7 @@ impl EpochInfo {
.iter()
.find(predicate)
.or(self.characters.iter().find(predicate))
.or(self.organizations.iter().find(predicate))
.or(self.towns.iter().find(predicate))
.or(self.blockers.iter().find(predicate))
.or(self.calamities.iter().find(predicate))
@ -239,6 +245,7 @@ impl EpochInfo {
.iter()
.find(predicate)
.or(self.characters.iter().find(predicate))
.or(self.organizations.iter().find(predicate))
.or(self.towns.iter().find(predicate))
.or(self.blockers.iter().find(predicate))
.or(self.calamities.iter().find(predicate))
@ -269,6 +276,7 @@ impl EpochInfo {
.iter_mut()
.find(predicate)
.or(self.characters.iter_mut().find(predicate))
.or(self.organizations.iter_mut().find(predicate))
.or(self.towns.iter_mut().find(predicate))
.or(self.blockers.iter_mut().find(predicate))
.or(self.calamities.iter_mut().find(predicate))
@ -287,7 +295,8 @@ impl EpochInfo {
EntityType::Character => &self.characters,
EntityType::Player => unimplemented!("No players for now"),
EntityType::Town => &self.towns,
EntityType::Monster => &self.calamities,
EntityType::Calamity => &self.calamities,
EntityType::Organization => &self.organizations,
EntityType::Blocker => &self.blockers,
EntityType::Event => &self.events,
}
@ -326,7 +335,8 @@ impl EpochInfo {
EntityType::Character => &mut self.characters,
EntityType::Player => unimplemented!("No players for now"),
EntityType::Town => &mut self.towns,
EntityType::Monster => &mut self.calamities,
EntityType::Calamity => &mut self.calamities,
EntityType::Organization => &mut self.organizations,
EntityType::Blocker => &mut self.blockers,
EntityType::Event => &mut self.events,
}
@ -338,6 +348,7 @@ impl EpochInfo {
self.events
.iter_mut()
.chain(self.characters.iter_mut())
.chain(self.organizations.iter_mut())
.chain(self.towns.iter_mut())
.chain(self.calamities.iter_mut())
.chain(self.blockers.iter_mut())
@ -377,6 +388,35 @@ impl EpochInfo {
impl Symbols for EpochId {
fn to_symbol(&self) -> String {
format!("[󰹻 {:<2}]", self)
format!("[{} {:<2}]", crate::output::symbol("󰹻", "epoch"), self)
}
}
#[cfg(test)]
mod compatibility_tests {
use super::*;
#[test]
fn old_snapshot_without_organizations_and_with_monster_type_still_loads() {
let mut old_entity = Entity::default();
old_entity.name = "Old Blight".to_string();
old_entity.entity_type = EntityType::Calamity;
let mut calamity = serde_json::to_value(old_entity).expect("serialize entity");
calamity["entity_type"] = serde_json::Value::String("Monster".to_string());
let value = serde_json::json!({
"epoch_id": { "id": 0 },
"rng_seed": 0,
"tags": { "inner": [] },
"summary": "",
"events": [],
"characters": [],
"towns": [],
"calamities": [calamity],
"blockers": []
});
let epoch: EpochInfo = serde_json::from_value(value).expect("load legacy snapshot");
assert!(epoch.organizations.is_empty());
assert_eq!(epoch.calamities[0].entity_type, EntityType::Calamity);
}
}

View File

@ -563,7 +563,10 @@ pub enum EntityType {
Character,
Player,
Town,
Monster,
/// A calamity. Serialized as `Monster` for repository compatibility.
#[serde(rename = "Monster")]
Calamity,
Organization,
Blocker,
#[default]
Event,

View File

@ -5,6 +5,7 @@ expression: out
:[C]
 :[P]
󱡵 :[T]
 :[M]
 :[X]
 :[O]
 :[B]
:[E]

View File

@ -26,7 +26,8 @@ impl Symbols for EntityType {
EntityType::Character => "[C]".to_string(),
EntityType::Player => "[P]".to_string(),
EntityType::Town => "[T]".to_string(),
EntityType::Monster => "[M]".to_string(),
EntityType::Calamity => "[X]".to_string(),
EntityType::Organization => "[O]".to_string(),
EntityType::Blocker => "[B]".to_string(),
EntityType::Event => "[E]".to_string(),
}
@ -36,7 +37,8 @@ impl Symbols for EntityType {
EntityType::Character => symbol("", "person").to_string(),
EntityType::Player => symbol("", "player ").to_string(),
EntityType::Town => symbol("󱡵 ", "town ").to_string(),
EntityType::Monster => symbol("", "calamity ").to_string(),
EntityType::Calamity => symbol("", "calamity ").to_string(),
EntityType::Organization => symbol("", "organisation ").to_string(),
EntityType::Blocker => symbol("", "blocker ").to_string(),
EntityType::Event => symbol("", "event").to_string(),
}

View File

@ -277,7 +277,8 @@ fn test_entity_type_to_shortest() {
stats::EntityType::Character,
stats::EntityType::Player,
stats::EntityType::Town,
stats::EntityType::Monster,
stats::EntityType::Calamity,
stats::EntityType::Organization,
stats::EntityType::Blocker,
stats::EntityType::Event,
]