Skip to content

Commit

Permalink
Allow transition to be taken using code or signal.
Browse files Browse the repository at this point in the history
  • Loading branch information
mixemer authored and derkork committed Dec 7, 2024
1 parent 9d6d07e commit 48a8158
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addons/godot_state_charts/state_chart_state.gd
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func _find_chart(parent:Node) -> StateChart:

## Runs a transition either immediately or delayed depending on the
## transition settings.
func _run_transition(transition:Transition):
func _run_transition(transition:Transition, immediately:bool = false):
var initial_delay := transition.evaluate_delay()
if initial_delay > 0:
if not immediately and initial_delay > 0:
_queue_transition(transition, initial_delay)
else:
_chart._run_transition(transition, self)
Expand Down
9 changes: 9 additions & 0 deletions addons/godot_state_charts/transition.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ var has_event:bool:
get:
return event != null and event.length() > 0

## Takes this transition immediately or with a delay if defined
## Note: if there is a delay on this transition and immediately param is true, it forces the transition to be taken without the delay
func take(immediately:bool = true) -> void:
var parent_state:Node = get_parent()
if parent_state == null or not (parent_state is StateChartState):
push_error("Transitions must be children of states.")
return
parent_state._run_transition(self, immediately)

## Evaluates the guard expression and returns true if the transition should be taken.
## If no guard expression is specified, this function will always return true.
func evaluate_guard() -> bool:
Expand Down

0 comments on commit 48a8158

Please sign in to comment.