Files
tekton/tools/build_dasher_pack.gd
T
2026-06-12 18:05:04 +08:00

53 lines
1.8 KiB
GDScript

@tool
extends EditorScript
# Editor tool: combine all dasher_<name>.tres AnimationLibrary files into a
# single dasher-pack.tres for player.tscn to reference.
#
# Run AFTER convert_dasher_animations.gd.
# File > Run (Ctrl+Shift+X) on this script.
#
# Output: res://assets/characters/animations/dasher-pack.tres
#
# Then add an ext_resource to scenes/player.tscn:
# [ext_resource type="AnimationLibrary" path="res://assets/characters/animations/dasher-pack.tres" id="..."]
# And on the AnimationPlayer node:
# libraries/dasher-pack = ExtResource("...")
const ANIM_DIR := "res://assets/characters/animations"
const OUTPUT := "res://assets/characters/animations/dasher-pack.res"
func _run() -> void:
var combined := AnimationLibrary.new()
var dir := DirAccess.open(ANIM_DIR)
if not dir:
push_error("[Build] Cannot open %s" % ANIM_DIR)
return
var loaded: Array[String] = []
for fname in dir.get_files():
if not fname.begins_with("dasher_"): continue
if not fname.ends_with(".res"): continue
if fname == "dasher-pack.res": continue
var path := "%s/%s" % [ANIM_DIR, fname]
var res: Resource = load(path)
if not res is AnimationLibrary:
push_warning("[Build] %s is not an AnimationLibrary, skipping" % fname)
continue
var lib: AnimationLibrary = res
for anim_name in lib.get_animation_list():
if combined.has_animation(anim_name):
push_warning("[Build] Duplicate anim name '%s' in %s, skipping" % [anim_name, fname])
continue
combined.add_animation(anim_name, lib.get_animation(anim_name))
loaded.append("%s/%s" % [fname, anim_name])
var err := ResourceSaver.save(combined, OUTPUT)
if err != OK:
push_error("[Build] ResourceSaver.save failed: %d" % err)
return
print("[Build] %d animation(s) written to %s" % [loaded.size(), OUTPUT])
for l in loaded:
print(" - %s" % l)