From 1c256e7db4efa6183132971a785ac4a3961dcdad Mon Sep 17 00:00:00 2001 From: Natalie Date: Sun, 28 Jun 2026 09:50:53 -0400 Subject: [PATCH] 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 --- src/simulator/crates/mc-comms/src/config.rs | 11 +++++------ src/simulator/crates/mc-comms/src/heartbeat.rs | 6 ++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/simulator/crates/mc-comms/src/config.rs b/src/simulator/crates/mc-comms/src/config.rs index 89315714..f1cd2dbe 100644 --- a/src/simulator/crates/mc-comms/src/config.rs +++ b/src/simulator/crates/mc-comms/src/config.rs @@ -74,19 +74,18 @@ pub struct Phase3Cfg { pub beacon_tap: BeaconTapCfg, } -/// Load Phase 3 config from the bundled `comms.json`. The JSON is -/// compiled in via `include_str!`, parsed once, and cached. +/// Load Phase 3 config from `comms.json`. The raw JSON comes from the host-fed +/// [`mc_core::content`] registry (embedded `include_str!` fallback when no host +/// override), parsed once, and cached. #[must_use] pub fn phase3_cfg() -> &'static Phase3Cfg { static CELL: OnceLock = OnceLock::new(); CELL.get_or_init(|| { - const JSON: &str = include_str!( - "../../../../../public/games/age-of-dwarves/data/comms.json" - ); + let json = mc_core::content::get(mc_core::content::ContentKey::Comms); // Tolerate field shape: parse the whole file as a generic Value, // then pluck the two blocks we care about. Missing blocks fall // 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"); let capital_blackout = value .get("capital_blackout") diff --git a/src/simulator/crates/mc-comms/src/heartbeat.rs b/src/simulator/crates/mc-comms/src/heartbeat.rs index 840787b4..9a36e74c 100644 --- a/src/simulator/crates/mc-comms/src/heartbeat.rs +++ b/src/simulator/crates/mc-comms/src/heartbeat.rs @@ -134,10 +134,8 @@ pub fn heartbeat_interval_for_tier(tier: u8) -> Option { use std::sync::OnceLock; static CELL: OnceLock)>> = OnceLock::new(); let table = CELL.get_or_init(|| { - const JSON: &str = include_str!( - "../../../../../public/games/age-of-dwarves/data/comms.json" - ); - let value: serde_json::Value = serde_json::from_str(JSON) + let json = mc_core::content::get(mc_core::content::ContentKey::Comms); + let value: serde_json::Value = serde_json::from_str(&json) .expect("comms.json must parse as valid JSON"); let mut out: Vec<(u8, Option)> = Vec::new(); if let Some(arr) = value.get("comm_tier_table").and_then(|v| v.as_array()) {