refactor(player-api,api-wasm): read score/resources JSON via ContentRegistry (p3-28)
projection.rs score_weights() and api-wasm resources.rs catalog() drop their own include_str! and pull raw bytes from content::get(ScoreWeights/Resources). Closes the last production include_str! content sites. mc-player-api (142) and mc-score tests green; magic-civ-physics (api-wasm) checks clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
af91484343
commit
a401701810
2 changed files with 10 additions and 10 deletions
|
|
@ -1,8 +1,9 @@
|
|||
//! Resource catalog WASM bridge — exposes per-tile resource metadata
|
||||
//! including the 3-axis visibility schema landed in p2-54.
|
||||
//!
|
||||
//! The catalog is baked at compile time from `public/resources/resources.json`
|
||||
//! and parsed once via `OnceLock` on first access.
|
||||
//! The catalog is read from the host-fed `mc_core::content` registry (embedded
|
||||
//! `public/resources/resources.json` fallback) and parsed once via `OnceLock`
|
||||
//! on first access.
|
||||
|
||||
use mc_core::grid::GridState;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -44,8 +45,8 @@ static CATALOG: OnceLock<HashMap<String, CatalogEntry>> = OnceLock::new();
|
|||
|
||||
fn catalog() -> &'static HashMap<String, CatalogEntry> {
|
||||
CATALOG.get_or_init(|| {
|
||||
const JSON: &str = include_str!("../../../../public/resources/resources.json");
|
||||
let bundle: ResourcesJson = serde_json::from_str(JSON).unwrap_or(ResourcesJson {
|
||||
let json = mc_core::content::get(mc_core::content::ContentKey::Resources);
|
||||
let bundle: ResourcesJson = serde_json::from_str(&json).unwrap_or(ResourcesJson {
|
||||
bonus: vec![],
|
||||
luxury: vec![],
|
||||
strategic: vec![],
|
||||
|
|
|
|||
|
|
@ -938,16 +938,15 @@ fn classify_relation(rel: &mc_trade::relation::RelationState) -> String {
|
|||
|
||||
/// Canonical score weights, loaded once from
|
||||
/// `public/games/age-of-dwarves/data/score.json` (Rail-2 — no hardcoded weights).
|
||||
/// Compiled in via `include_str!` because the projector runs on every `view()`
|
||||
/// and per-call I/O is unacceptable.
|
||||
/// The raw JSON comes from the host-fed [`mc_core::content`] registry (embedded
|
||||
/// `include_str!` fallback, no per-call I/O) and is cached for the process — the
|
||||
/// projector runs on every `view()` so per-call I/O would be unacceptable.
|
||||
fn score_weights() -> &'static mc_score::ScoreWeights {
|
||||
use std::sync::OnceLock;
|
||||
static WEIGHTS: OnceLock<mc_score::ScoreWeights> = OnceLock::new();
|
||||
WEIGHTS.get_or_init(|| {
|
||||
const JSON: &str = include_str!(
|
||||
"../../../../../public/games/age-of-dwarves/data/score.json"
|
||||
);
|
||||
mc_score::ScoreWeights::from_json(JSON).expect("score.json must parse")
|
||||
let json = mc_core::content::get(mc_core::content::ContentKey::ScoreWeights);
|
||||
mc_score::ScoreWeights::from_json(&json).expect("score.json must parse")
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue