xiandie/scene/ux/note/sync_slices.gd
2025-07-03 01:40:34 +08:00

53 lines
1.7 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.

@tool
extends HandnoteEvent2D
@export_range(0, 5) var chapter := 1
@export_tool_button("同步") var sync_nodes = _sync_nodes
@export var slices_path = "res://asset/art/ui/note/c02_slices/"
# 0 初始化隐藏1 开始显示2 划掉3 结束隐藏
@export var ignore_stages: Array[int] = [0, 3]
func _ready() -> void:
if Engine.is_editor_hint():
return
super._ready()
visible = stage == chapter
if visible:
print("[Handnote] current chapter: ", chapter)
func _sync_nodes() -> void:
if not DirAccess.dir_exists_absolute(slices_path):
printerr("目录不存在: ", slices_path)
return
var existed_events = []
_travase_existed_nodes(get_tree().edited_scene_root, existed_events)
for s in DirAccess.get_files_at(slices_path):
var evt = &"handnote_" + s.split(".")[0]
if existed_events.has(evt):
continue
print("[color=green]创建事件节点: ", evt)
var event_node = HandnoteEvent2D.new() as HandnoteEvent2D
event_node.texture = load(slices_path + s)
event_node = event_node
event_node.event = evt
event_node.hide_if_on_stage = ignore_stages.duplicate()
add_child(event_node)
event_node.name = "Event_" + evt
event_node.owner = get_tree().edited_scene_root
func _travase_existed_nodes(node, existed_events: Array):
if not node:
return
if node is HandnoteEvent2D:
existed_events.append(node.event)
print("配置已存在的事件节点: ", node.event)
if len(node.hide_if_on_stage) == 0:
print_rich("[color=green]设置 hide_if_on_stage: ", ignore_stages)
node.hide_if_on_stage = ignore_stages.duplicate()
else:
print_rich("[color=cyan]已存在 hide_if_on_stage跳过设置: ", node.hide_if_on_stage)
for c in node.get_children():
_travase_existed_nodes(c, existed_events)