fix: enforce storage and tooling invariants

This commit is contained in:
Rijad Zuzo
2026-07-30 13:00:59 +02:00
parent e3aa3440a2
commit e284d3774d
9 changed files with 283 additions and 30 deletions
+24 -2
View File
@@ -288,6 +288,26 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
storage_ids[storage_id] = true
storage_records_by_id[storage_id] = storage_record
record.storages.append(storage_record)
var pantry := (
storage_records_by_id.get(SimulationIds.STORAGE_VILLAGE_PANTRY) as StorageStateRecord
)
if (
pantry != null
and not is_equal_approx(
float(record.village.data["food"]), pantry.get_amount(SimulationIds.RESOURCE_FOOD)
)
):
return null
var woodpile := (
storage_records_by_id.get(SimulationIds.STORAGE_VILLAGE_WOODPILE) as StorageStateRecord
)
if (
woodpile != null
and not is_equal_approx(
float(record.village.data["wood"]), woodpile.get_amount(SimulationIds.RESOURCE_WOOD)
)
):
return null
var event_ids := {}
var event_records_by_id := {}
@@ -689,7 +709,8 @@ static func _migrate_legacy(legacy_data: Dictionary, version: int) -> Dictionary
StorageStateRecord
. create(
SimulationIds.STORAGE_VILLAGE_PANTRY,
{String(SimulationIds.RESOURCE_FOOD): initial_food}
{String(SimulationIds.RESOURCE_FOOD): initial_food},
maxf(StorageStateRecord.DEFAULT_CAPACITY, initial_food)
)
. to_dictionary()
),
@@ -697,7 +718,8 @@ static func _migrate_legacy(legacy_data: Dictionary, version: int) -> Dictionary
StorageStateRecord
. create(
SimulationIds.STORAGE_VILLAGE_WOODPILE,
{String(SimulationIds.RESOURCE_WOOD): initial_wood}
{String(SimulationIds.RESOURCE_WOOD): initial_wood},
maxf(StorageStateRecord.DEFAULT_CAPACITY, initial_wood)
)
. to_dictionary()
)