From 31facca4326616ee72c665d8e146ed5a5d26cf11 Mon Sep 17 00:00:00 2001 From: Natalie Date: Sat, 18 Apr 2026 21:56:13 -0700 Subject: [PATCH] =?UTF-8?q?fix(@projects/@magic-civilization):=20?= =?UTF-8?q?=F0=9F=90=9B=20adjust=20difficulty=20loading=20timing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- .../games/age-of-dwarves/data/difficulty.json | 2 +- src/game/engine/scenes/tests/auto_play.gd | 15 +++---- src/game/engine/src/autoloads/game_state.gd | 43 +++++++++---------- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/public/games/age-of-dwarves/data/difficulty.json b/public/games/age-of-dwarves/data/difficulty.json index 87c37d25..fb53a098 100644 --- a/public/games/age-of-dwarves/data/difficulty.json +++ b/public/games/age-of-dwarves/data/difficulty.json @@ -1,5 +1,5 @@ { - "ai_difficulty": [ + "difficulty": [ { "level": 1, "id": "easy", diff --git a/src/game/engine/scenes/tests/auto_play.gd b/src/game/engine/scenes/tests/auto_play.gd index ad1fc00c..640dbad8 100644 --- a/src/game/engine/scenes/tests/auto_play.gd +++ b/src/game/engine/scenes/tests/auto_play.gd @@ -524,11 +524,8 @@ func _process(_delta: float) -> void: if not diff_env.is_empty(): GameState.game_settings["difficulty"] = diff_env print("AutoPlay: AI_DIFFICULTY=%s applied" % diff_env) - GameState.apply_ai_difficulty() - # Per-player difficulty overrides for asymmetric matchups (p0-24). - # AI_DIFFICULTY_P0= and AI_DIFFICULTY_P1= each override - # that player's production/research multipliers independently. - _apply_per_player_difficulty_overrides() + # apply_ai_difficulty() + per-player overrides are deferred to + # wait_loading (after DataLoader.load_theme runs in loading_screen). _state = "wait_loading" _frame = 0 if _frame > 120: @@ -549,6 +546,10 @@ func _process(_delta: float) -> void: # real clan assignments the Python per-clan aggregator # (tools/autoplay-report.py) reads. _write_meta() + # Apply difficulty modifiers NOW — DataLoader.load_theme ran + # during loading_screen so get_data("difficulty") is populated. + GameState.apply_ai_difficulty() + _apply_per_player_difficulty_overrides() _state = "fix_start" _frame = 0 if _frame > 600: @@ -799,10 +800,6 @@ func _apply_per_player_difficulty_overrides() -> void: # DataLoader.get_data("difficulty") returns {"easy": {full entry}, "normal": {...}, ...} # already keyed by id — no wrapping "ai_difficulty" array at this level. var diff_data: Dictionary = DataLoader.get_data("difficulty") - print("AutoPlay: per_player_override entry: diff_data.size=%d P0='%s' P1='%s'" % [ - diff_data.size(), - EnvConfig.get_var("AI_DIFFICULTY_P0", "__unset__"), - EnvConfig.get_var("AI_DIFFICULTY_P1", "__unset__")]) if diff_data == null or diff_data.is_empty(): return # Use a fixed upper bound — this runs before loading_screen.gd populates diff --git a/src/game/engine/src/autoloads/game_state.gd b/src/game/engine/src/autoloads/game_state.gd index 58b55ab5..0da5cd3d 100644 --- a/src/game/engine/src/autoloads/game_state.gd +++ b/src/game/engine/src/autoloads/game_state.gd @@ -228,28 +228,27 @@ func apply_ai_difficulty() -> void: var diff_data: Dictionary = DataLoader.get_data("difficulty") as Dictionary if diff_data == null or diff_data.is_empty(): return - var levels: Array = diff_data.get("ai_difficulty", []) as Array - for entry: Dictionary in levels: - if entry.get("id", "") == diff_id: - var mods: Dictionary = entry.get("ai_modifiers", {}) as Dictionary - ai_difficulty_modifier = float(mods.get("production_mult", 1.0)) - ai_research_modifier = float(mods.get("research_mult", 1.0)) - ai_starting_gold_bonus = int(mods.get("starting_gold_bonus", 0)) - ai_extra_starting_units = int(mods.get("extra_starting_units", 0)) - ai_extra_unit_id = str(mods.get("extra_unit_id", "warrior")) - print( - ( - "GameState: difficulty=%s prod=%.2f research=%.2f gold_bonus=%d extra_units=%d" - % [ - diff_id, - ai_difficulty_modifier, - ai_research_modifier, - ai_starting_gold_bonus, - ai_extra_starting_units - ] - ) - ) - return + var entry: Dictionary = diff_data.get(diff_id, {}) as Dictionary + if entry.is_empty(): + return + var mods: Dictionary = entry.get("ai_modifiers", {}) as Dictionary + if mods.is_empty(): + return + ai_difficulty_modifier = float(mods.get("production_mult", 1.0)) + ai_research_modifier = float(mods.get("research_mult", 1.0)) + ai_starting_gold_bonus = int(mods.get("starting_gold_bonus", 0)) + ai_extra_starting_units = int(mods.get("extra_starting_units", 0)) + ai_extra_unit_id = str(mods.get("extra_unit_id", "warrior")) + print( + "GameState: difficulty=%s prod=%.2f research=%.2f gold_bonus=%d extra_units=%d" + % [ + diff_id, + ai_difficulty_modifier, + ai_research_modifier, + ai_starting_gold_bonus, + ai_extra_starting_units + ] + ) func get_max_event_tier() -> int: