119 lines
3.3 KiB
GDScript
119 lines
3.3 KiB
GDScript
# @tool
|
|
class_name AnimationRoot extends AnimationPlayer
|
|
|
|
# 在继承 AnimationRoot 的各场景内的脚本中,可以直接调用 DialogueResource
|
|
var dialogue_c01 := preload("res://asset/dialogue/c01.dialogue") as DialogueResource
|
|
var dialogue_c02 := preload("res://asset/dialogue/c02.dialogue") as DialogueResource
|
|
var dialogue_c03 := preload("res://asset/dialogue/c03.dialogue") as DialogueResource
|
|
var dialogue_c04 := preload("res://asset/dialogue/c04.dialogue") as DialogueResource
|
|
var dialogue_c05 := preload("res://asset/dialogue/c05.dialogue") as DialogueResource
|
|
var dialogue_c06 := preload("res://asset/dialogue/c06.dialogue") as DialogueResource
|
|
|
|
@export var data = {
|
|
# 首次进入场景时触发
|
|
"oneshot_animation_played": false
|
|
}
|
|
var oneshot_animation := ""
|
|
var ground_archive: GroundArchive
|
|
var ground: Ground2D
|
|
|
|
|
|
# 继承覆盖该方法
|
|
func _default_data() -> Dictionary:
|
|
print("read default data from root")
|
|
return {}
|
|
|
|
|
|
func _ready() -> void:
|
|
ground = get_node("..")
|
|
if not ground:
|
|
printerr("ground not found")
|
|
return
|
|
if ground.restarting:
|
|
print("restarting: skip animation root _ready()")
|
|
return
|
|
data.merge(_default_data(), true)
|
|
if Engine.is_editor_hint():
|
|
# notify_property_list_changed()
|
|
# 更新 oneshot_animation 的可选项
|
|
animation_libraries_updated.connect(notify_property_list_changed)
|
|
return
|
|
ground_archive = ArchiveManager.archive.ground_archive() as GroundArchive
|
|
var archive_data = ground_archive.get_data(name)
|
|
# merge data
|
|
for key in archive_data.keys():
|
|
if data.has(key):
|
|
data[key] = archive_data[key]
|
|
# 等待 DeployLayer 先加载完成
|
|
if not ground.is_node_ready():
|
|
ground.ready.connect(_on_ground_ready)
|
|
else:
|
|
_on_ground_ready()
|
|
ready.connect(_on_ready)
|
|
|
|
|
|
func _on_ground_ready() -> void:
|
|
pass
|
|
|
|
|
|
func _on_ready() -> void:
|
|
if Engine.is_editor_hint():
|
|
return
|
|
# 仅在首次进入场景时触发
|
|
if oneshot_animation:
|
|
if not data["oneshot_animation_played"]:
|
|
play(oneshot_animation)
|
|
animation_finished.connect(_oneshot_animation_finished, CONNECT_ONE_SHOT)
|
|
else:
|
|
if GlobalConfig.DEBUG:
|
|
print("oneshot_animation_played:", oneshot_animation)
|
|
|
|
|
|
func _oneshot_animation_finished(animation_name) -> void:
|
|
if GlobalConfig.DEBUG:
|
|
print("oneshot_animation_finished:", animation_name)
|
|
set_data("oneshot_animation_played", true)
|
|
|
|
|
|
func set_data(property: StringName, value: Variant) -> bool:
|
|
if data.has(property):
|
|
ground_archive.set_pair(name, property, value)
|
|
data[property] = value
|
|
return true
|
|
return false
|
|
|
|
|
|
func set_global_entry(property: StringName, value: Variant) -> void:
|
|
ArchiveManager.archive.set_global_entry(property, value)
|
|
|
|
|
|
func get_global_value(property: StringName, default_value = null) -> Variant:
|
|
var val = ArchiveManager.archive.get_global_value(property)
|
|
if val == null:
|
|
return default_value
|
|
return val
|
|
|
|
|
|
func _get(property: StringName) -> Variant:
|
|
if property == "oneshot_animation":
|
|
return oneshot_animation
|
|
return null
|
|
|
|
|
|
func _set(property: StringName, value: Variant) -> bool:
|
|
if property == "oneshot_animation":
|
|
oneshot_animation = value
|
|
return true
|
|
return false
|
|
|
|
|
|
func _get_property_list() -> Array[Dictionary]:
|
|
return [
|
|
{
|
|
"name": "oneshot_animation",
|
|
"type": TYPE_STRING,
|
|
"hint": PROPERTY_HINT_ENUM_SUGGESTION,
|
|
"hint_string": ",".join(get_animation_list()),
|
|
}
|
|
]
|