godot-plateformer/addons/reedscene/prop/ReedTransition.gd

37 lines
855 B
GDScript3
Raw Normal View History

@tool
@icon("res://addons/reedscene/prop/icon/prop_trans_icon.svg")
extends Node
class_name ReedTransition
@export var from_state_id: int = -1
@export var effects: Array[ReedPropEffect] = []
## runtime only
@export var runtime_only: bool = true
##Transtion能否被触发
func can_trigger(from: ReedPropState, ctx: Dictionary) -> bool:
if from == null:
return false
if from_state_id != -1 and from.state_id != from_state_id:
return false
if runtime_only and ctx.get("is_load", false):
return false
return true
##执行Transition的逻辑
func execute(from: ReedPropState, to: ReedPropState, ctx: Dictionary) -> bool:
# Effect 不需要知道 from/to但 Transition 需要用 to 拿目标对象
var owner : Node= to._owner
var prop_comp : Node= to._owner_prop_comp
for e in effects:
e.apply(owner, prop_comp, ctx)
return true