feat: add simulation garden demo controls
This commit is contained in:
@@ -65,6 +65,11 @@ func _update_presentation() -> void:
|
||||
label.text = text
|
||||
|
||||
|
||||
func set_debug_label_enabled(is_enabled: bool) -> void:
|
||||
debug_label_enabled = is_enabled
|
||||
_update_presentation()
|
||||
|
||||
|
||||
static func get_by_id(search_id: StringName):
|
||||
for node in _all:
|
||||
if node.site_id == search_id:
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
extends Node
|
||||
|
||||
@export var ui: CanvasLayer
|
||||
@export var active_npcs_parent: Node
|
||||
@export var debug_overlay_visible := true
|
||||
|
||||
var _refresh_accumulator := 0.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_apply_debug_overlay_visibility()
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_refresh_accumulator += delta
|
||||
if _refresh_accumulator < 0.5:
|
||||
return
|
||||
_refresh_accumulator = 0.0
|
||||
_apply_debug_overlay_visibility()
|
||||
|
||||
|
||||
func _unhandled_key_input(event: InputEvent) -> void:
|
||||
if not event is InputEventKey or not event.pressed or event.echo:
|
||||
return
|
||||
if event.keycode == KEY_F10:
|
||||
toggle_debug_overlay()
|
||||
get_viewport().set_input_as_handled()
|
||||
elif event.keycode == KEY_F12:
|
||||
reset_demo_scene()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func toggle_debug_overlay() -> void:
|
||||
debug_overlay_visible = not debug_overlay_visible
|
||||
_apply_debug_overlay_visibility()
|
||||
print(
|
||||
"[DemoController] %s"
|
||||
% ("Debug overlay visible" if debug_overlay_visible else "Cinematic overlay hidden")
|
||||
)
|
||||
|
||||
|
||||
func reset_demo_scene() -> void:
|
||||
print("[DemoController] Resetting simulation garden demo")
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
|
||||
func _apply_debug_overlay_visibility() -> void:
|
||||
if ui != null and ui.has_method("set_debug_overlay_visible"):
|
||||
ui.set_debug_overlay_visible(debug_overlay_visible)
|
||||
|
||||
for node in ResourceNode.get_all():
|
||||
if node.has_method("set_debug_label_enabled"):
|
||||
node.set_debug_label_enabled(debug_overlay_visible)
|
||||
|
||||
for node in StorageNode.get_all():
|
||||
if node.has_method("set_debug_label_enabled"):
|
||||
node.set_debug_label_enabled(debug_overlay_visible)
|
||||
|
||||
for node in ActivitySite.get_all():
|
||||
if node.has_method("set_debug_label_enabled"):
|
||||
node.set_debug_label_enabled(debug_overlay_visible)
|
||||
|
||||
if active_npcs_parent == null:
|
||||
return
|
||||
for child in active_npcs_parent.get_children():
|
||||
if child.has_method("set_debug_overlay_visible"):
|
||||
child.set_debug_overlay_visible(debug_overlay_visible)
|
||||
@@ -19,6 +19,7 @@ static var _all: Array[ResourceNode] = []
|
||||
@export var comfort_distance := 18.0
|
||||
@export var discovery_priority := 0.0
|
||||
@export var hide_visual_when_depleted: bool = false
|
||||
@export var debug_label_enabled := true
|
||||
|
||||
@onready var interaction_point: Marker3D = $InteractionPoint
|
||||
|
||||
@@ -121,6 +122,9 @@ func _update_presentation() -> void:
|
||||
if not has_node("DebugLabel"):
|
||||
return
|
||||
var label := $DebugLabel as Label3D
|
||||
label.visible = debug_label_enabled
|
||||
if not debug_label_enabled:
|
||||
return
|
||||
var text := "%s\n%s %.1f" % [node_id, resource_id, get_amount_remaining()]
|
||||
if state != null:
|
||||
text += "\nrisk:%.2f comfort:%.0f" % [state.get_safety_risk(), state.get_comfort_distance()]
|
||||
@@ -133,6 +137,11 @@ func _update_presentation() -> void:
|
||||
label.text = text
|
||||
|
||||
|
||||
func set_debug_label_enabled(is_enabled: bool) -> void:
|
||||
debug_label_enabled = is_enabled
|
||||
_update_presentation()
|
||||
|
||||
|
||||
static func get_by_id(search_id: StringName) -> ResourceNode:
|
||||
for node in _all:
|
||||
if node.node_id == search_id:
|
||||
|
||||
@@ -91,6 +91,11 @@ func _update_presentation() -> void:
|
||||
label.text = text
|
||||
|
||||
|
||||
func set_debug_label_enabled(is_enabled: bool) -> void:
|
||||
debug_label_enabled = is_enabled
|
||||
_update_presentation()
|
||||
|
||||
|
||||
static func get_by_id(search_id: StringName):
|
||||
for node in _all:
|
||||
if node.storage_id == search_id:
|
||||
|
||||
+11
-1
@@ -9,6 +9,7 @@ const DEBUG_LOGS := false
|
||||
|
||||
var selected_npc_index := 0
|
||||
var inspector_refresh_accumulator := 0.0
|
||||
var debug_overlay_visible := true
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -88,6 +89,8 @@ func _on_state_restored() -> void:
|
||||
|
||||
|
||||
func _refresh_npc_inspector() -> void:
|
||||
if not debug_overlay_visible:
|
||||
return
|
||||
if simulation_manager == null or simulation_manager.npcs.is_empty():
|
||||
npc_inspector_label.text = "No villagers available"
|
||||
return
|
||||
@@ -122,7 +125,7 @@ func _refresh_npc_inspector() -> void:
|
||||
+ "Hunger: %.0f Energy: %.0f\n"
|
||||
+ "Carrying food: %.0f\n\n"
|
||||
+ "Why\n%s%s\n\n"
|
||||
+ "[Tab] Next villager"
|
||||
+ "[Tab] Next villager [F10] Cinematic/debug [F12] Demo reset"
|
||||
) % [
|
||||
npc.npc_name,
|
||||
profession_name,
|
||||
@@ -146,3 +149,10 @@ func _get_action_name(action_id: StringName) -> String:
|
||||
if definition != null:
|
||||
return definition.display_name
|
||||
return String(action_id).capitalize()
|
||||
|
||||
|
||||
func set_debug_overlay_visible(is_visible: bool) -> void:
|
||||
debug_overlay_visible = is_visible
|
||||
visible = is_visible
|
||||
if is_visible:
|
||||
_refresh_npc_inspector()
|
||||
|
||||
Reference in New Issue
Block a user