refactor: clarify simulation ownership
This commit is contained in:
@@ -16,7 +16,7 @@ func _run() -> void:
|
||||
|
||||
var pantry: StorageStateRecord = manager.get_pantry()
|
||||
pantry.withdraw(SimulationIds.RESOURCE_FOOD, 1000.0)
|
||||
manager._sync_village_food()
|
||||
manager.economy.sync_resource(SimulationIds.RESOURCE_FOOD)
|
||||
var resource := ResourceStateRecord.from_dictionary(
|
||||
{
|
||||
"schema_version": ResourceStateRecord.SCHEMA_VERSION,
|
||||
@@ -190,7 +190,7 @@ func _test_wood_work_requires_material() -> void:
|
||||
var woodpile: StorageStateRecord = manager.get_woodpile()
|
||||
woodpile.withdraw(SimulationIds.RESOURCE_WOOD, 1000.0)
|
||||
woodpile.deposit(SimulationIds.RESOURCE_WOOD, 0.5)
|
||||
manager._sync_village_wood()
|
||||
manager.economy.sync_resource(SimulationIds.RESOURCE_WOOD)
|
||||
var npc: SimNPC = manager.npcs[0]
|
||||
var safety_before: float = manager.village.safety
|
||||
|
||||
@@ -215,7 +215,8 @@ func _test_wood_work_requires_material() -> void:
|
||||
"An unpaid completion cost should create a readable blocked-task fact"
|
||||
)
|
||||
|
||||
manager.add_wood(1.5)
|
||||
woodpile.deposit(SimulationIds.RESOURCE_WOOD, 1.5)
|
||||
manager.economy.sync_resource(SimulationIds.RESOURCE_WOOD)
|
||||
_check(
|
||||
(
|
||||
is_equal_approx(woodpile.get_amount(SimulationIds.RESOURCE_WOOD), 2.0)
|
||||
|
||||
@@ -59,8 +59,21 @@ func _run() -> void:
|
||||
|
||||
var pantry := main_scene.get_node("JajceWorld/WorldObjects/StorageSites/VillagePantry") as StorageNode
|
||||
var pantry_state: StorageStateRecord = simulation_manager.get_pantry()
|
||||
pantry_state.deposit(
|
||||
SimulationIds.RESOURCE_FOOD, pantry_state.get_available_capacity() - 0.5
|
||||
)
|
||||
simulation_manager.economy.sync_resource(SimulationIds.RESOURCE_FOOD)
|
||||
bush_state.set_amount_remaining(1.0)
|
||||
player.global_position = bush.interaction_point.global_position
|
||||
player.try_interact()
|
||||
_check(
|
||||
is_equal_approx(bush_state.get_amount_remaining(), 0.5)
|
||||
and is_equal_approx(pantry_state.get_available_capacity(), 0.0),
|
||||
"Player harvesting should leave overflow at its source when storage fills"
|
||||
)
|
||||
|
||||
pantry_state.deposit(SimulationIds.RESOURCE_FOOD, 3.0)
|
||||
simulation_manager._sync_village_food()
|
||||
simulation_manager.economy.sync_resource(SimulationIds.RESOURCE_FOOD)
|
||||
var pantry_food_before := pantry_state.get_amount(SimulationIds.RESOURCE_FOOD)
|
||||
player.global_position = pantry.get_interaction_position()
|
||||
player.try_interact()
|
||||
|
||||
@@ -185,17 +185,25 @@ func _test_legacy_world_storage_migration() -> void:
|
||||
legacy_data["schema_version"] = SimulationStateRecord.LEGACY_SCHEMA_VERSION
|
||||
legacy_data.erase("storages")
|
||||
var migrated := SimulationStateRecord.from_dictionary(legacy_data)
|
||||
_check(migrated != null, "World schema v1 should migrate pantry storage")
|
||||
_check(migrated != null, "World schema v1 should migrate authored storage")
|
||||
if migrated != null:
|
||||
var migrated_storages := {}
|
||||
for storage in migrated.storages:
|
||||
migrated_storages[storage.get_storage_id()] = storage
|
||||
var pantry: StorageStateRecord = migrated_storages.get(
|
||||
SimulationIds.STORAGE_VILLAGE_PANTRY
|
||||
)
|
||||
var woodpile: StorageStateRecord = migrated_storages.get(
|
||||
SimulationIds.STORAGE_VILLAGE_WOODPILE
|
||||
)
|
||||
_check(
|
||||
(
|
||||
migrated.storages.size() == 1
|
||||
and is_equal_approx(
|
||||
migrated.storages[0].get_amount(SimulationIds.RESOURCE_FOOD),
|
||||
manager.village.food
|
||||
)
|
||||
pantry != null
|
||||
and woodpile != null
|
||||
and is_equal_approx(pantry.get_amount(SimulationIds.RESOURCE_FOOD), manager.village.food)
|
||||
and is_equal_approx(woodpile.get_amount(SimulationIds.RESOURCE_WOOD), manager.village.wood)
|
||||
),
|
||||
"World migration should preserve legacy village food in pantry"
|
||||
"World migration should preserve legacy village resources in their storage"
|
||||
)
|
||||
manager.free()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user