From 11426744dfaa50a327a5bdbfd8c5e9f6e61205bd Mon Sep 17 00:00:00 2001 From: autocommit Date: Thu, 16 Apr 2026 23:14:46 -0700 Subject: [PATCH] =?UTF-8?q?refactor(autoloads):=20=E2=99=BB=EF=B8=8F=20Opt?= =?UTF-8?q?imize=20ecology=20data=20loading=20performance=20by=20decouplin?= =?UTF-8?q?g=20redundancy=20and=20improving=20resource=20loading=20sequenc?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- src/game/engine/src/autoloads/data_loader.gd | 1 + .../src/autoloads/data_loader_ecology.gd | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/game/engine/src/autoloads/data_loader.gd b/src/game/engine/src/autoloads/data_loader.gd index c64e3ffb..1b92f8a5 100644 --- a/src/game/engine/src/autoloads/data_loader.gd +++ b/src/game/engine/src/autoloads/data_loader.gd @@ -440,6 +440,7 @@ func get_social_policies() -> Dictionary: # -- Ecology: delegated to _ecology (data_loader_ecology.gd) -- func get_biome(id: String) -> Variant: return _ecology.get_biome(id) +func get_biome_collectibles(id: String) -> Array: return _ecology.get_biome_collectibles(id) func get_all_biomes() -> Array: return _ecology.get_all_biomes() func get_flora_profile(biome_id: String) -> Variant: return _ecology.get_flora_profile(biome_id) func get_substrate(id: String) -> Variant: return _ecology.get_substrate(id) diff --git a/src/game/engine/src/autoloads/data_loader_ecology.gd b/src/game/engine/src/autoloads/data_loader_ecology.gd index b1370d2a..c65deada 100644 --- a/src/game/engine/src/autoloads/data_loader_ecology.gd +++ b/src/game/engine/src/autoloads/data_loader_ecology.gd @@ -18,8 +18,9 @@ const AirFaunaScript = preload("res://engine/src/models/world/air_fauna.gd") ## Back-reference to _raw on the parent DataLoader (set by DataLoader after construction). var _raw: Dictionary = {} -var _biomes: Dictionary = {} # id -> BiomeModel -var _flora_profiles: Dictionary = {} # biome_id -> FloraProfile +var _biomes: Dictionary = {} # id -> BiomeModel +var _biome_collectibles: Dictionary = {} # id -> Array of collectible entry Dictionaries +var _flora_profiles: Dictionary = {} # biome_id -> FloraProfile var _substrates: Dictionary = {} # id -> SubstrateType var _marine_fauna: Variant = null # MarineFaunaModel var _land_fauna: Variant = null # LandFaunaModel @@ -28,6 +29,7 @@ var _air_fauna: Variant = null # AirFaunaModel func clear() -> void: _biomes.clear() + _biome_collectibles.clear() _flora_profiles.clear() _substrates.clear() _marine_fauna = null @@ -58,6 +60,11 @@ func get_all_biomes() -> Array: return _biomes.values() +func get_biome_collectibles(id: String) -> Array: + ## Returns the raw collectibles Array for a biome, or empty if none. + return _biome_collectibles.get(id, []) + + func get_flora_profile(biome_id: String) -> Variant: ## Returns a FloraProfile for the given biome or null if not found. return _flora_profiles.get(biome_id) @@ -174,6 +181,7 @@ func register_collection_biome(biome_data: Dictionary) -> void: if _biomes.has(biome_id): return # game-pack biome takes precedence over collection _biomes[biome_id] = BiomeModelScript.from_dict(biome_data) + _store_collectibles(biome_id, biome_data) # Build flora profile if this biome has vegetation var climax: Dictionary = biome_data.get("flora_climax", {}) if climax.get("canopy", 0.0) > 0.0 or climax.get("undergrowth", 0.0) > 0.0: @@ -208,15 +216,25 @@ func _deserialize_biomes() -> void: if entry is Dictionary: if not entry.has("id"): entry["id"] = key - _biomes[entry.get("id", key)] = BiomeModelScript.from_dict(entry) + var bid: String = entry.get("id", key) + _biomes[bid] = BiomeModelScript.from_dict(entry) + _store_collectibles(bid, entry) elif biomes_data is Array: for entry: Variant in biomes_data: if entry is Dictionary and entry.has("id"): - _biomes[entry["id"]] = BiomeModelScript.from_dict(entry) + var bid: String = entry["id"] + _biomes[bid] = BiomeModelScript.from_dict(entry) + _store_collectibles(bid, entry) if _biomes.size() > 0: print("DataLoader: Deserialized %d biome models" % _biomes.size()) +func _store_collectibles(biome_id: String, entry: Dictionary) -> void: + var raw: Array = entry.get("collectibles", []) + if not raw.is_empty(): + _biome_collectibles[biome_id] = raw + + func _deserialize_flora_profiles() -> void: var raw_flora: Dictionary = _raw.get("world_flora", {}) for biome_id: String in _biomes: