refactor(mc-comms): read comms.json via mc-core ContentRegistry (p3-28)

Both phase3_cfg() and heartbeat_interval_for_tier() dropped their own fragile
../../../../../ include_str! and now pull raw bytes from content::get(Comms).
Embedded fallback unchanged (now centralized in mc-core). 11 tests green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Natalie 2026-06-28 09:50:53 -04:00
parent 787f08f073
commit 1c256e7db4
2 changed files with 7 additions and 10 deletions

View file

@ -74,19 +74,18 @@ pub struct Phase3Cfg {
pub beacon_tap: BeaconTapCfg, pub beacon_tap: BeaconTapCfg,
} }
/// Load Phase 3 config from the bundled `comms.json`. The JSON is /// Load Phase 3 config from `comms.json`. The raw JSON comes from the host-fed
/// compiled in via `include_str!`, parsed once, and cached. /// [`mc_core::content`] registry (embedded `include_str!` fallback when no host
/// override), parsed once, and cached.
#[must_use] #[must_use]
pub fn phase3_cfg() -> &'static Phase3Cfg { pub fn phase3_cfg() -> &'static Phase3Cfg {
static CELL: OnceLock<Phase3Cfg> = OnceLock::new(); static CELL: OnceLock<Phase3Cfg> = OnceLock::new();
CELL.get_or_init(|| { CELL.get_or_init(|| {
const JSON: &str = include_str!( let json = mc_core::content::get(mc_core::content::ContentKey::Comms);
"../../../../../public/games/age-of-dwarves/data/comms.json"
);
// Tolerate field shape: parse the whole file as a generic Value, // Tolerate field shape: parse the whole file as a generic Value,
// then pluck the two blocks we care about. Missing blocks fall // then pluck the two blocks we care about. Missing blocks fall
// back to defaults. // back to defaults.
let value: serde_json::Value = serde_json::from_str(JSON) let value: serde_json::Value = serde_json::from_str(&json)
.expect("comms.json must parse as valid JSON"); .expect("comms.json must parse as valid JSON");
let capital_blackout = value let capital_blackout = value
.get("capital_blackout") .get("capital_blackout")

View file

@ -134,10 +134,8 @@ pub fn heartbeat_interval_for_tier(tier: u8) -> Option<u32> {
use std::sync::OnceLock; use std::sync::OnceLock;
static CELL: OnceLock<Vec<(u8, Option<u32>)>> = OnceLock::new(); static CELL: OnceLock<Vec<(u8, Option<u32>)>> = OnceLock::new();
let table = CELL.get_or_init(|| { let table = CELL.get_or_init(|| {
const JSON: &str = include_str!( let json = mc_core::content::get(mc_core::content::ContentKey::Comms);
"../../../../../public/games/age-of-dwarves/data/comms.json" let value: serde_json::Value = serde_json::from_str(&json)
);
let value: serde_json::Value = serde_json::from_str(JSON)
.expect("comms.json must parse as valid JSON"); .expect("comms.json must parse as valid JSON");
let mut out: Vec<(u8, Option<u32>)> = Vec::new(); let mut out: Vec<(u8, Option<u32>)> = Vec::new();
if let Some(arr) = value.get("comm_tier_table").and_then(|v| v.as_array()) { if let Some(arr) = value.get("comm_tier_table").and_then(|v| v.as_array()) {