feat(@projects/@magic-civilization): 🏗️ p3-26 B3 (3/4) — FFI + harness boot the improvement defs
Runtime wiring so improvements actually build + yield in a real headless game:
- GdPlayerApi::set_improvement_defs_json — loads the improvement defs (JSON array of
{id, build_turns, yields}) onto GameState. Mirrors set_ecology_species_json.
- player_api_main._apply_improvement_defs — stamps DataLoader.get_all_improvements() via the
FFI at boot (after load_state_json), emitting improvement_defs_api_loaded.
With this, the full B3 chain is live: BuildImprovement → pending (build_turns) → build-tick
completes → city_improvements → process_improvement_yields folds food/production in. gdext
compiles; dylib rebuild in progress.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f4e9d02115
commit
5d12b4bbee
2 changed files with 30 additions and 0 deletions
|
|
@ -239,6 +239,24 @@ func _hydrate_player_api(num_players: int) -> void:
|
||||||
# AFTER `load_state_json`. Without this the ecology phase is a no-op (barren world).
|
# AFTER `load_state_json`. Without this the ecology phase is a no-op (barren world).
|
||||||
_apply_ecology_species()
|
_apply_ecology_species()
|
||||||
|
|
||||||
|
# p3-26 B3: stamp improvement definitions so the headless turn can build (build-tick)
|
||||||
|
# and yield (process_improvement_yields) tile improvements. Same `#[serde(skip)]`
|
||||||
|
# re-stamp pattern — load AFTER `load_state_json`. Without this improvements never
|
||||||
|
# build or yield in headless play.
|
||||||
|
_apply_improvement_defs()
|
||||||
|
|
||||||
|
|
||||||
|
## p3-26 B3: stamp improvement definitions (DataLoader's improvements: id, build_turns,
|
||||||
|
## yields:{food,production}) onto `GdPlayerApi` via `set_improvement_defs_json`. Consumed by
|
||||||
|
## the headless improvement build-tick + `process_improvement_yields`.
|
||||||
|
func _apply_improvement_defs() -> void:
|
||||||
|
var defs: Array = DataLoader.get_all_improvements()
|
||||||
|
if defs.is_empty():
|
||||||
|
_emit_protocol_error("improvement defs empty — headless improvements will not build/yield")
|
||||||
|
return
|
||||||
|
var n: int = int(_api.set_improvement_defs_json(JSON.stringify(defs)))
|
||||||
|
_emit_event("improvement_defs_api_loaded", {"count": n})
|
||||||
|
|
||||||
|
|
||||||
## p3-26 gap 2: stamp the natural-event category configs (DataLoader's merged
|
## p3-26 gap 2: stamp the natural-event category configs (DataLoader's merged
|
||||||
## `{category: {base_frequency, severity_weights, tiers, …}}`) onto `GdPlayerApi` via
|
## `{category: {base_frequency, severity_weights, tiers, …}}`) onto `GdPlayerApi` via
|
||||||
|
|
|
||||||
|
|
@ -179,6 +179,18 @@ impl GdPlayerApi {
|
||||||
.load_ecology_species_json(json.to_string().as_str()) as i64
|
.load_ecology_species_json(json.to_string().as_str()) as i64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// p3-26 B3: load improvement definitions (a JSON array of improvement
|
||||||
|
/// objects `[{id, build_turns, yields:{food,production}}, …]` from
|
||||||
|
/// `public/resources/improvements/*.json`) so the headless turn can build
|
||||||
|
/// (build-tick) and yield (process_improvement_yields) tile improvements.
|
||||||
|
/// Returns the count loaded, or 0 on parse failure. Call AFTER
|
||||||
|
/// `load_state_json` (the field is `#[serde(skip)]`).
|
||||||
|
#[func]
|
||||||
|
pub fn set_improvement_defs_json(&mut self, json: GString) -> i64 {
|
||||||
|
self.state
|
||||||
|
.load_improvement_defs_json(json.to_string().as_str()) as i64
|
||||||
|
}
|
||||||
|
|
||||||
/// Stamp the runtime `UnitsCatalog` (id → `UnitStats`) onto the held
|
/// Stamp the runtime `UnitsCatalog` (id → `UnitStats`) onto the held
|
||||||
/// `GameState`. Distinct from `set_units_catalog_json` (which loads the
|
/// `GameState`. Distinct from `set_units_catalog_json` (which loads the
|
||||||
/// tactical `ai_unit_catalog`): this is the same `mc_units::UnitsCatalog`
|
/// tactical `ai_unit_catalog`): this is the same `mc_units::UnitsCatalog`
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue