refactor: clarify simulation ownership

This commit is contained in:
Rijad Zuzo
2026-07-10 11:02:11 +02:00
parent 0f7b12080e
commit ce8f71082b
29 changed files with 793 additions and 587 deletions
@@ -177,6 +177,7 @@ static func _migrate_legacy(legacy_data: Dictionary, version: int) -> Dictionary
if version == LEGACY_SCHEMA_VERSION:
var village_data: Dictionary = legacy_data.get("village", {})
var initial_food := float(village_data.get("food", 0.0))
var initial_wood := float(village_data.get("wood", 0.0))
migrated["storages"] = [
(
StorageStateRecord
@@ -185,6 +186,14 @@ static func _migrate_legacy(legacy_data: Dictionary, version: int) -> Dictionary
{String(SimulationIds.RESOURCE_FOOD): initial_food}
)
. to_dictionary()
),
(
StorageStateRecord
. create(
SimulationIds.STORAGE_VILLAGE_WOODPILE,
{String(SimulationIds.RESOURCE_WOOD): initial_wood}
)
. to_dictionary()
)
]
migrated["economic_events"] = []
+5 -3
View File
@@ -57,10 +57,12 @@ func get_total_amount() -> float:
return total
func get_available_capacity() -> float:
return maxf(float(data["capacity"]) - get_total_amount(), 0.0)
func deposit(item_id: StringName, requested_amount: float) -> float:
var accepted := minf(
maxf(requested_amount, 0.0), maxf(float(data["capacity"]) - get_total_amount(), 0.0)
)
var accepted := minf(maxf(requested_amount, 0.0), get_available_capacity())
if accepted <= 0.0:
return 0.0
data["amounts"][String(item_id)] = get_amount(item_id) + accepted