feat: unify authored activity commands

This commit is contained in:
Rijad Zuzo
2026-08-13 00:08:30 +02:00
parent e5aecee0de
commit b3b98c6456
36 changed files with 3013 additions and 96 deletions
+64 -17
View File
@@ -22,26 +22,43 @@ signal narrative_event_requested(
var village: SimVillage
var storage_states: Dictionary = {}
var debug_logs := false
var content_catalog: ContentCatalog
var storage_routing := StorageRoutingPolicy.new()
var _storage_id_by_item_id: Dictionary = {}
func configure(village_state: SimVillage, should_debug: bool) -> void:
func configure(
village_state: SimVillage, should_debug: bool, configured_catalog: ContentCatalog = null
) -> void:
village = village_state
debug_logs = should_debug
content_catalog = (
configured_catalog if configured_catalog != null else ContentCatalog.create_core()
)
storage_routing = StorageRoutingPolicy.new(content_catalog)
_storage_id_by_item_id.clear()
func initialize_storage() -> void:
if village == null:
return
if not storage_states.has(SimulationIds.STORAGE_VILLAGE_PANTRY):
storage_states[SimulationIds.STORAGE_VILLAGE_PANTRY] = StorageStateRecord.create(
SimulationIds.STORAGE_VILLAGE_PANTRY,
{String(SimulationIds.RESOURCE_FOOD): village.food}
)
if not storage_states.has(SimulationIds.STORAGE_VILLAGE_WOODPILE):
storage_states[SimulationIds.STORAGE_VILLAGE_WOODPILE] = StorageStateRecord.create(
SimulationIds.STORAGE_VILLAGE_WOODPILE,
{String(SimulationIds.RESOURCE_WOOD): village.wood}
)
if content_catalog != null and content_catalog.is_valid():
for definition in content_catalog.get_storages():
if storage_states.has(definition.storage_id):
continue
var initial_amounts := {}
if definition.storage_id == SimulationIds.STORAGE_VILLAGE_PANTRY:
initial_amounts[String(SimulationIds.RESOURCE_FOOD)] = village.food
elif definition.storage_id == SimulationIds.STORAGE_VILLAGE_WOODPILE:
initial_amounts[String(SimulationIds.RESOURCE_WOOD)] = village.wood
var initial_total := 0.0
for amount in initial_amounts.values():
initial_total += float(amount)
storage_states[definition.storage_id] = StorageStateRecord.create(
definition.storage_id, initial_amounts, maxf(definition.capacity, initial_total)
)
_ensure_legacy_village_storage()
_rebuild_storage_route_cache()
sync_all()
@@ -67,12 +84,42 @@ func get_woodpile() -> StorageStateRecord:
func get_storage_for_resource(resource_id: StringName) -> StorageStateRecord:
match resource_id:
SimulationIds.RESOURCE_FOOD:
return get_pantry()
SimulationIds.RESOURCE_WOOD:
return get_woodpile()
return null
var storage_id := StringName(_storage_id_by_item_id.get(resource_id, &""))
return get_storage(storage_id) if not storage_id.is_empty() else null
func _ensure_legacy_village_storage() -> void:
if not storage_states.has(SimulationIds.STORAGE_VILLAGE_PANTRY):
storage_states[SimulationIds.STORAGE_VILLAGE_PANTRY] = StorageStateRecord.create(
SimulationIds.STORAGE_VILLAGE_PANTRY,
{String(SimulationIds.RESOURCE_FOOD): village.food},
maxf(StorageStateRecord.DEFAULT_CAPACITY, village.food)
)
if not storage_states.has(SimulationIds.STORAGE_VILLAGE_WOODPILE):
storage_states[SimulationIds.STORAGE_VILLAGE_WOODPILE] = StorageStateRecord.create(
SimulationIds.STORAGE_VILLAGE_WOODPILE,
{String(SimulationIds.RESOURCE_WOOD): village.wood},
maxf(StorageStateRecord.DEFAULT_CAPACITY, village.wood)
)
func _rebuild_storage_route_cache() -> void:
_storage_id_by_item_id.clear()
if storage_states.has(SimulationIds.STORAGE_VILLAGE_PANTRY):
_storage_id_by_item_id[SimulationIds.RESOURCE_FOOD] = (SimulationIds.STORAGE_VILLAGE_PANTRY)
if storage_states.has(SimulationIds.STORAGE_VILLAGE_WOODPILE):
_storage_id_by_item_id[SimulationIds.RESOURCE_WOOD] = (
SimulationIds.STORAGE_VILLAGE_WOODPILE
)
if content_catalog == null or not content_catalog.is_valid():
return
var available_ids: Array[StringName] = []
for storage_key in storage_states:
available_ids.append(StringName(storage_key))
for item in content_catalog.get_items():
var definition := storage_routing.resolve_definition(item.item_id, available_ids)
if definition != null:
_storage_id_by_item_id[item.item_id] = definition.storage_id
func sync_all() -> void: