feat: add versioned simulation state records

This commit is contained in:
2026-07-05 12:52:07 +02:00
parent c690937afa
commit 30cac28fc0
12 changed files with 514 additions and 1 deletions
+39
View File
@@ -0,0 +1,39 @@
class_name VillageStateRecord
extends RefCounted
const SCHEMA_VERSION := 1
var data: Dictionary
func _init(record_data: Dictionary = {}) -> void:
data = record_data.duplicate(true)
static func capture(village: SimVillage) -> VillageStateRecord:
return VillageStateRecord.new({
"schema_version": SCHEMA_VERSION,
"food": village.food,
"wood": village.wood,
"safety": village.safety,
"knowledge": village.knowledge
})
static func from_dictionary(record_data: Dictionary) -> VillageStateRecord:
if int(record_data.get("schema_version", -1)) != SCHEMA_VERSION:
return null
if not record_data.has_all(["food", "wood", "safety", "knowledge"]):
return null
return VillageStateRecord.new(record_data)
func restore(debug_logs: bool) -> SimVillage:
var village := SimVillage.new()
village.debug_logs = debug_logs
village.food = float(data["food"])
village.wood = float(data["wood"])
village.safety = float(data["safety"])
village.knowledge = float(data["knowledge"])
village.update_modifiers()
village.update_priorities()
return village
func to_dictionary() -> Dictionary:
return data.duplicate(true)