feat: make pantry crises visible in the world
This commit is contained in:
@@ -5,6 +5,7 @@ extends Node
|
||||
@export var npc_visual_scene: PackedScene
|
||||
@export var simulation_manager: Node
|
||||
@export var active_npcs_parent: Node3D
|
||||
@export var pantry_visual: Node3D
|
||||
|
||||
var active_npc_visuals := {}
|
||||
|
||||
@@ -44,11 +45,24 @@ func initialize_world_view() -> void:
|
||||
simulation_manager.relationship_changed.connect(_on_relationship_changed)
|
||||
else:
|
||||
push_error("WorldViewManager: SimulationManager has no relationship_changed signal")
|
||||
if simulation_manager.has_signal("economic_event_recorded"):
|
||||
simulation_manager.economic_event_recorded.connect(_on_economic_event_recorded)
|
||||
else:
|
||||
push_error("WorldViewManager: SimulationManager has no economic_event_recorded signal")
|
||||
if simulation_manager.has_signal("opportunity_opened"):
|
||||
simulation_manager.opportunity_opened.connect(_on_opportunity_changed)
|
||||
else:
|
||||
push_error("WorldViewManager: SimulationManager has no opportunity_opened signal")
|
||||
if simulation_manager.has_signal("opportunity_resolved"):
|
||||
simulation_manager.opportunity_resolved.connect(_on_opportunity_resolved)
|
||||
else:
|
||||
push_error("WorldViewManager: SimulationManager has no opportunity_resolved signal")
|
||||
if simulation_manager.has_signal("state_restored"):
|
||||
simulation_manager.state_restored.connect(_on_simulation_state_restored)
|
||||
else:
|
||||
push_error("WorldViewManager: SimulationManager has no state_restored signal")
|
||||
spawn_initial_npcs()
|
||||
_refresh_world_state_presentation(false)
|
||||
|
||||
|
||||
func spawn_initial_npcs() -> void:
|
||||
@@ -86,6 +100,7 @@ func spawn_npc_visual(npc: SimNPC) -> void:
|
||||
else:
|
||||
push_error("WorldViewManager: NPCVisual has no position_changed signal")
|
||||
active_npc_visuals[npc.id] = visual
|
||||
_sync_npc_opportunity_concern(npc.id, visual)
|
||||
debug_log("Spawned visual for %s at %s" % [npc.npc_name, npc.position])
|
||||
if npc.is_dead:
|
||||
visual.apply_dead_visual_state()
|
||||
@@ -200,8 +215,62 @@ func _on_relationship_changed(
|
||||
push_error("WorldViewManager: NPCVisual has no play_trust_gain_reaction method")
|
||||
|
||||
|
||||
func _on_economic_event_recorded(_event: EconomicEventRecord) -> void:
|
||||
_refresh_pantry_stock(true)
|
||||
|
||||
|
||||
func _on_opportunity_changed(_opportunity: OpportunityStateRecord) -> void:
|
||||
_refresh_world_state_presentation(true)
|
||||
|
||||
|
||||
func _on_opportunity_resolved(
|
||||
_opportunity: OpportunityStateRecord, _cause_event: EconomicEventRecord
|
||||
) -> void:
|
||||
_refresh_world_state_presentation(true)
|
||||
|
||||
|
||||
func _on_simulation_state_restored() -> void:
|
||||
for visual in active_npc_visuals.values():
|
||||
visual.queue_free()
|
||||
active_npc_visuals.clear()
|
||||
spawn_initial_npcs()
|
||||
_refresh_world_state_presentation(false)
|
||||
|
||||
|
||||
func _refresh_world_state_presentation(animate: bool) -> void:
|
||||
_refresh_pantry_stock(animate)
|
||||
_refresh_opportunity_concern()
|
||||
|
||||
|
||||
func _refresh_pantry_stock(animate: bool) -> void:
|
||||
if pantry_visual == null or not pantry_visual.has_method("set_food_amount"):
|
||||
return
|
||||
var pantry: StorageStateRecord = simulation_manager.get_pantry()
|
||||
var amount := 0.0
|
||||
if pantry != null:
|
||||
amount = pantry.get_amount(SimulationIds.RESOURCE_FOOD)
|
||||
pantry_visual.set_food_amount(amount, animate)
|
||||
|
||||
|
||||
func _refresh_opportunity_concern() -> void:
|
||||
for visual in active_npc_visuals.values():
|
||||
if visual.has_method("set_opportunity_concern_visible"):
|
||||
visual.set_opportunity_concern_visible(false)
|
||||
var opportunity: OpportunityStateRecord = simulation_manager.get_active_opportunity()
|
||||
if opportunity == null:
|
||||
return
|
||||
var interested_visual = active_npc_visuals.get(opportunity.get_interested_npc_id())
|
||||
if (
|
||||
interested_visual != null
|
||||
and interested_visual.has_method("set_opportunity_concern_visible")
|
||||
):
|
||||
interested_visual.set_opportunity_concern_visible(true)
|
||||
|
||||
|
||||
func _sync_npc_opportunity_concern(npc_id: int, visual: Node3D) -> void:
|
||||
if not visual.has_method("set_opportunity_concern_visible"):
|
||||
return
|
||||
var opportunity: OpportunityStateRecord = simulation_manager.get_active_opportunity()
|
||||
visual.set_opportunity_concern_visible(
|
||||
opportunity != null and opportunity.get_interested_npc_id() == npc_id
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user