xiandie/scene/little_game/八音盒.gd
2025-05-22 04:16:27 +08:00

62 lines
1.8 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends CanvasLayer
signal exit(success: bool)
@onready var animated_sprite = $AnimatedSprite2D as AnimatedSprite2D
@onready var box = $Box as Sprite2D
# 小蝉人偶,?
var xiaochan_plugged := false:
set(value):
xiaochan_plugged = value
ArchiveManager.set_global_entry("c02_musicbox_xiaochan_plugged", value)
func _ready() -> void:
if Engine.is_editor_hint():
return
xiaochan_plugged = ArchiveManager.get_global_value("c02_musicbox_xiaochan_plugged", false)
# %"小蝉人偶".visible = xiaochan_plugged
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("interact"):
# 尝试使用道具
_try_use_prop()
func _try_use_prop() -> void:
var hud = SceneManager.get_prop_hud() as PropHud
var inspector = SceneManager.get_inspector() as PropInspector
var key = SceneManager.get_current_prop(false)
if key == "prop_木头人偶" and not xiaochan_plugged:
SceneManager.disable_prop_item(key)
xiaochan_plugged = true
box.visible = false
animated_sprite.visible = true
animated_sprite.play("暗格抽屉动画")
await animated_sprite.animation_finished
await get_tree().create_timer(1.0).timeout
box.visible = true
animated_sprite.visible = false
# 先全部加载进去,再逐个展示,防止退出游戏时遗漏
hud.inventory.enable_item("prop_木头人偶")
hud.inventory.enable_item("prop_撕下的照片上")
hud.inventory.enable_item("prop_无头小猫玩具")
hud.inventory.enable_item("prop_弹珠")
SceneManager.enable_prop_item("prop_弹珠")
await inspector.quit_and_hidden
SceneManager.enable_prop_item("prop_无头小猫玩具")
await inspector.quit_and_hidden
SceneManager.enable_prop_item("prop_撕下的照片上")
await inspector.quit_and_hidden
SceneManager.enable_prop_item("prop_木头人偶")
return
# hud 无效shaking
hud.on_toggle_invalid_prop()