Files
2026-09-16 22:15:52 +09:00

39 lines
1.2 KiB
GDScript
Raw Permalink 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.
# MsaMotion —— 读 .msa 文本里的根运动:移动动作每秒位移(cm/s,movSpd 100 时)。
#
# MotionDuration 0.600000
# Accumulation 0.00 -255.45 0.00
#
# 服务端 CHARACTER::GetMoveMotionSpeed = -Accumulation.y / MotionDuration
# 客户端 CActorInstance::AccumulationMovement 按同一累计量推进。这里取 xy 长度。
extends RefCounted
static var _cache := {} # path -> float
static func move_speed(path: String) -> float:
if path == "" or not path.to_lower().ends_with(".msa"):
return 0.0
if _cache.has(path):
return float(_cache[path])
var speed := 0.0
var f := FileAccess.open(path, FileAccess.READ)
if f:
var duration := 0.0
var accum := Vector2.ZERO
while not f.eof_reached():
var parts := _fields(f.get_line())
if parts.size() < 2:
continue
match String(parts[0]):
"MotionDuration":
duration = String(parts[1]).to_float()
"Accumulation":
if parts.size() >= 3:
accum = Vector2(String(parts[1]).to_float(), String(parts[2]).to_float())
if duration > 0.0:
speed = accum.length() / duration
_cache[path] = speed
return speed
static func _fields(line: String) -> PackedStringArray:
return line.strip_edges().replace("\t", " ").split(" ", false)