refactor(mc-turn): read encounter/lair/courier JSON via ContentRegistry (p3-28)

authored_encounter_rates(), authored_lair_siege_config(), and
severable_infra_from_data() drop their bespoke include_str! (two using
CARGO_MANIFEST_DIR concat, one a ../../../../../ relative path) and pull raw
bytes from content::get(EncounterRates/LairCombatModes/Couriers). Embedded
fallbacks centralized in mc-core. mc-turn tests green (297 + suites).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Natalie 2026-06-28 09:59:43 -04:00
parent 69f80189c6
commit af91484343
2 changed files with 6 additions and 16 deletions

View file

@ -222,9 +222,7 @@ fn severable_infra_from_data() -> Option<&'static [(&'static str, u8)]> {
use std::sync::OnceLock;
static CELL: OnceLock<Vec<(&'static str, u8)>> = OnceLock::new();
let parsed = CELL.get_or_init(|| {
const JSON: &str = include_str!(
"../../../../../public/games/age-of-dwarves/data/couriers.json"
);
let json = mc_core::content::get(mc_core::content::ContentKey::Couriers);
#[derive(serde::Deserialize)]
struct File {
severable_infra: Vec<Entry>,
@ -234,7 +232,7 @@ fn severable_infra_from_data() -> Option<&'static [(&'static str, u8)]> {
era_tier: u8,
improvement_id: String,
}
match serde_json::from_str::<File>(JSON) {
match serde_json::from_str::<File>(&json) {
Ok(parsed) => parsed
.severable_infra
.into_iter()

View file

@ -326,13 +326,8 @@ pub struct TurnProcessor {
pub fn authored_encounter_rates() -> &'static EncounterRates {
static RATES: OnceLock<EncounterRates> = OnceLock::new();
RATES.get_or_init(|| {
// 4 `..` from this crate's manifest dir reaches the repo root:
// crates/mc-turn -> crates -> simulator -> src -> repo root.
const JSON: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../../public/resources/ecology/encounter_rates.json"
));
EncounterRates::from_json(JSON).expect("authored encounter_rates.json must parse")
let json = mc_core::content::get(mc_core::content::ContentKey::EncounterRates);
EncounterRates::from_json(&json).expect("authored encounter_rates.json must parse")
})
}
@ -344,11 +339,8 @@ pub fn authored_encounter_rates() -> &'static EncounterRates {
pub fn authored_lair_siege_config() -> &'static crate::lair_siege::LairSiegeConfig {
static CFG: OnceLock<crate::lair_siege::LairSiegeConfig> = OnceLock::new();
CFG.get_or_init(|| {
const JSON: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../../public/resources/ecology/fauna/lair_combat_modes.json"
));
crate::lair_siege::LairSiegeConfig::from_lair_combat_modes_json(JSON)
let json = mc_core::content::get(mc_core::content::ContentKey::LairCombatModes);
crate::lair_siege::LairSiegeConfig::from_lair_combat_modes_json(&json)
.expect("authored lair_combat_modes.json must carry a siege.siege_pressure block")
})
}