You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
6.0 KiB
GDScript

2 years ago
extends AnimatedSprite3D
class_name View
2 years ago
@onready var status: Status = (%Status as Status)
2 years ago
class Trans:
2 years ago
var condition: StringName
var compareType: String
2 years ago
var conditionValue
2 years ago
var from: StringName
var to: StringName
var trigger_name: StringName
var on_end: bool
var trans_list: Array[Variant] = []
var move_sprite_frames: SpriteFrames
2 years ago
func _ready():
# 地面行走
2 years ago
trans("idle_loop", "run1", "speed_xz", ">", 1)
run("run1", "run2_loop")
trans("run1", "run3", "speed_xz", "<", 1)
trans("run2_loop", "run3", "speed_xz", "<", 1)
run("run3", "idle_loop")
trans("run3", "run1", "speed_xz", ">", 1)
2 years ago
# 跳跃
2 years ago
trigger("any", "jump1", "trigger_jump")
run("jump1", "jump2_loop")
trans("jump2_loop", "jump3", "speed_y", "<=", 0)
run("jump3", "jump4_loop")
trans("jump4_loop", "jump5", "is_on_floor", "=", true)
run("jump5", "idle_loop")
trans("jump5", "run1", "speed_xz", ">", 1)
2 years ago
#地面受击
2 years ago
trigger("any", "hit1", "trigger_hit")
trigger("any", "mhit1", "trigger_mhit")
trigger("any", "lhit1", "trigger_lhit")
run("hit1", "hit2_loop")
run("mhit1", "mhit2_loop")
run("lhit1", "lhit2_loop")
trans("hit2_loop", "hit3", "is_stagger", "=", false)
trans("mhit2_loop", "mhit3", "is_stagger", "=", false)
trans("lhit2_loop", "lhit3", "is_stagger", "=", false)
run("hit3", "idle_loop")
run("mhit3", "idle_loop")
run("lhit3", "idle_loop")
2 years ago
#空中受击
2 years ago
trigger("any", "airhit1", "trigger_air_hit_up")
trigger("any", "airhit4_loop", "trigger_air_hit_down")
run("airhit1", "airhit2_loop")
trans("airhit2_loop", "airhit3", "speed_y", "<=", 0)
run("airhit3", "airhit4_loop")
trans("airhit4_loop", "airhit5", "is_on_floor", "=", true)
run("airhit5", "ground1_loop")
trans("ground1_loop", "ground2", "is_stagger", "=", false)
run("ground2", "idle_loop")
2 years ago
#眩晕受击
2 years ago
trigger_with_condition("any", "stunhit", "trigger_stun_hit", "is_on_floor", "=", true)
run("stunhit", "ground_stun1_loop")
trans("ground_stun1_loop", "ground_stun2", "is_stun", "=", false)
run("ground_stun2", "idle_loop")
2 years ago
#空中眩晕受击
2 years ago
trans("airhit5", "airhit5_stun", "is_stun", "=", true)
run("airhit5_stun", "ground_stun1_loop")
2 years ago
#落地反弹
2 years ago
trigger("any", "rebound", "trigger_rebound")
run("rebound", "airhit2_loop")
func _process(delta) -> void:
2 years ago
if not status.is_skill_running and status.is_pause == is_playing():
2 years ago
if status.is_pause: pause()
else: play_animation(animation)
2 years ago
update_view()
2 years ago
if status.is_pause: return
2 years ago
update_flip()
2 years ago
update_trans(false)
update_material()
2 years ago
return
2 years ago
2 years ago
func init(default: SpriteFrames):
2 years ago
sprite_frames = default
move_sprite_frames = default
2 years ago
play_animation("idle_loop")
2 years ago
2 years ago
2 years ago
func reset():
sprite_frames = move_sprite_frames
if status.is_on_floor:
play_animation("idle_loop")
else:
play_animation("jump4_loop")
2 years ago
2 years ago
2 years ago
func run(from: StringName, to: StringName):
_add_trans(from, to, "", "", "", "", true)
func run_with_condition(from: StringName, to: StringName, condition, compareType, conditionValue):
_add_trans(from, to, condition, compareType, conditionValue, "", true)
2 years ago
2 years ago
func trans(from: StringName, to: StringName, condition, compareType, conditionValue):
_add_trans(from, to, condition, compareType, conditionValue, "", false)
2 years ago
2 years ago
func trigger(from: StringName, to: StringName, trigger_name: StringName):
_add_trans(from, to, "", "", "", trigger_name, false)
func trigger_with_condition(from: StringName, to: StringName, trigger_name: StringName, condition, compareType, conditionValue):
_add_trans(from, to, condition, compareType, conditionValue, trigger_name, false)
func _add_trans(from: StringName, to: StringName, condition, compareType, conditionValue, trigger_name: StringName, on_end: bool):
2 years ago
var new_trans = Trans.new()
new_trans.condition = condition
new_trans.compareType = compareType
new_trans.conditionValue = conditionValue
new_trans.from = from
new_trans.to = to
new_trans.trigger_name = trigger_name
new_trans.on_end = on_end
trans_list.append(new_trans)
2 years ago
func update_trans(on_end: bool):
for trans in trans_list:
2 years ago
if on_end != trans.on_end:
continue
if not (trans.from == "any" or trans.from == animation):
continue
if trans.condition != "":
var conditionValue = status.get(trans.condition)
match trans.compareType:
2 years ago
">": if conditionValue <= trans.conditionValue: continue
"<": if conditionValue >= trans.conditionValue: continue
">=": if conditionValue < trans.conditionValue: continue
"<=": if conditionValue > trans.conditionValue: continue
"=": if conditionValue != trans.conditionValue: continue
2 years ago
if trans.trigger_name != "":
if status.get(trans.trigger_name):
2 years ago
status.set(trans.trigger_name, false)
else: continue
2 years ago
play_animation(trans.to)
2 years ago
2 years ago
2 years ago
func update_flip():
scale.x = 1 if status.is_right else -1
2 years ago
2 years ago
2 years ago
func update_view():
position = status.basic_offset + status.shake_offset
global_position = Util.snap_vector3(global_position)
2 years ago
2 years ago
func _on_animation_finished():
2 years ago
update_trans(true)
2 years ago
func update_material():
call_deferred("_update_material")
2 years ago
func _update_material():
2 years ago
var material: ShaderMaterial = material_override as ShaderMaterial
var material2: ShaderMaterial = material_override.next_pass as ShaderMaterial
var tex: Texture2D = sprite_frames.get_frame_texture(animation, frame)
var deformation_rate: float = status.deformation_rate * (0.5 if status.is_floating else 0.4)
material2.set_shader_parameter("flash_white", status.flash_white_rate)
material.set_shader_parameter("deformation_dir", status.deformation_dir)
material2.set_shader_parameter("deformation_dir", status.deformation_dir)
material.set_shader_parameter("deformation_rate", deformation_rate)
material2.set_shader_parameter("deformation_rate", deformation_rate)
material.set_shader_parameter("tex", tex)
material2.set_shader_parameter("tex", tex)
func play_animation(animation_name: String) -> void:
if not sprite_frames.has_animation(animation_name):
2 years ago
print("无效动画:", animation_name)
return
2 years ago
if animation_name == animation:
frame = 0
frame_progress = 0
play()
2 years ago
else:
2 years ago
play(animation_name, Setting.animation_speed_scale)
2 years ago