-
-
Notifications
You must be signed in to change notification settings - Fork 18
Added a few new features for FSMs #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
1e25875
da7b238
1d8aed6
c34e4d3
7667244
472d72e
08279f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@tool | ||
@icon("res://addons/behaviour_toolkit/icons/BTLeafPrint.svg") | ||
class_name FSMStatePrintOnEnter extends FSMState | ||
|
||
@export var custom_text: String | ||
|
||
|
||
# Executes after the state is entered. | ||
func _on_enter(_actor: Node, _blackboard: Blackboard) -> void: | ||
if custom_text != "": | ||
print(custom_text) | ||
else: | ||
print("Hello World!") |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed before, having an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sketched this out locally, and ended up implementing a new property (with some dependency juggling with ## Evaluates true, if the transition conditions are met.
func is_valid(_actor: Node, _blackboard: Blackboard) -> bool:
if always_transition:
return true
return false This would keep everything else in place, because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated this to show what I mean. If you'd like the implementation to change a bit it'll be easier now that it's in |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@tool | ||
@icon("res://addons/behaviour_toolkit/icons/FSMAlwaysTransition.svg") | ||
class_name FSMAlwaysTransition extends FSMTransition | ||
## A transition between two [FSMState]s in a [FiniteStateMachine]. | ||
## | ||
## This is a convenience class that always transitions. To implement your | ||
## logic you can override the [code]_on_transition[/code] method when | ||
## extending the node's script.[br] | ||
|
||
|
||
# Evaluates true, if the transition conditions are met. | ||
func is_valid(_actor: Node, _blackboard: Blackboard) -> bool: | ||
return true | ||
|
||
|
||
func _get_configuration_warnings() -> PackedStringArray: | ||
var warnings: Array = [] | ||
|
||
warnings.append_array(super._get_configuration_warnings()) | ||
|
||
if use_event or event != "": | ||
warnings.append("FSMAlwaysTransition does not use events.") | ||
|
||
return warnings |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
@tool | ||
@icon("res://addons/behaviour_toolkit/icons/FSMSplitTransition.svg") | ||
class_name FSMSplitTransition extends FSMTransition | ||
|
||
## The state to transition to. | ||
@export var next_state_true: FSMState: | ||
set(value): | ||
next_state_true = value | ||
update_configuration_warnings() | ||
|
||
@export var next_state_false: FSMState: | ||
set(value): | ||
next_state_false = value | ||
update_configuration_warnings() | ||
|
||
# Internal flag that determines which state gets transitioned to | ||
var _transition_flag: bool | ||
|
||
|
||
# Executed when the transition is taken. | ||
func _on_transition(_delta: float, _actor: Node, _blackboard: Blackboard) -> void: | ||
pass | ||
|
||
|
||
# Always returns true, because this transition always triggers one way or another. | ||
# Because `get_next_state()` doesn't have access to the actor or blackboard, a flag is | ||
# set internally here which sets up the next transition. | ||
func is_valid(actor: Node, blackboard: Blackboard) -> bool: | ||
set_transition_flag(actor, blackboard) | ||
return true | ||
|
||
|
||
func set_transition_flag(_actor: Node, _blackboard: Blackboard) -> void: | ||
pass | ||
|
||
|
||
## Returns which state to transition to, based on internal transition flag set in `set_transition_flag()`. | ||
func get_next_state() -> FSMState: | ||
return next_state_true if _transition_flag else next_state_false | ||
|
||
|
||
# Add custom configuration warnings | ||
# Note: Can be deleted if you don't want to define your own warnings. | ||
func _get_configuration_warnings() -> PackedStringArray: | ||
var warnings: Array = [] | ||
|
||
var parent: Node = get_parent() | ||
if not parent is FSMState: | ||
warnings.append("FSMSplitTransition should be a child of FSMState.") | ||
|
||
if next_state: | ||
warnings.append("FSMSplitTransition has next state; unset and set true and false states.") | ||
|
||
if not next_state_true: | ||
warnings.append("FSMSplitTransition has no next state for true.") | ||
|
||
if not next_state_false: | ||
warnings.append("FSMSplitTransition has no next state for false.") | ||
|
||
if use_event and event == "": | ||
warnings.append("FSMSplitTransition has no event set.") | ||
|
||
return warnings |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://do4ajfcbotwd6" | ||
path="res://.godot/imported/FSMAlwaysTransition.svg-d277d25a1a214bba18ffa87b756a2e31.ctex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://addons/behaviour_toolkit/icons/FSMAlwaysTransition.svg" | ||
dest_files=["res://.godot/imported/FSMAlwaysTransition.svg-d277d25a1a214bba18ffa87b756a2e31.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/high_quality=false | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=0 | ||
compress/channel_pack=0 | ||
mipmaps/generate=false | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=1 | ||
svg/scale=1.0 | ||
editor/scale_with_editor_scale=false | ||
editor/convert_colors_with_editor_theme=false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://c4vs4uicrouno" | ||
path="res://.godot/imported/FSMSplitTransition.svg-e6773317add235944b13c8c864f570b3.ctex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://addons/behaviour_toolkit/icons/FSMSplitTransition.svg" | ||
dest_files=["res://.godot/imported/FSMSplitTransition.svg-e6773317add235944b13c8c864f570b3.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/high_quality=false | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=0 | ||
compress/channel_pack=0 | ||
mipmaps/generate=false | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=1 | ||
svg/scale=1.0 | ||
editor/scale_with_editor_scale=false | ||
editor/convert_colors_with_editor_theme=false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A own print state node is overkill - however this feature should totally be part of a debugging toolset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved it into examples and removed
class_name
.