diff --git a/SConstruct b/SConstruct index 0722eec5..b80d32a8 100644 --- a/SConstruct +++ b/SConstruct @@ -2,6 +2,14 @@ import os import sys +def recursive_glob(rootdir, pattern): + matches = [] + for root, dirnames, filenames in os.walk(rootdir): + for filename in filenames: + if filename.endswith(pattern): + matches.append(os.path.join(root, filename)) + return matches + env = SConscript("godot-cpp/SConstruct") # Add those directory manually, so we can skip the godot_cpp directory when including headers in C++ files @@ -21,10 +29,8 @@ env.Append(CPPPATH=[env.Dir(d) for d in source_path]) # tweak this if you want to use different folders, or more folders, to store your source code in. env.Append(CPPPATH=["extension/src/"]) -sources = [ - Glob("extension/src/*.cpp"), - Glob("extension/src/nodes/*.cpp") -] + +sources = recursive_glob('extension/src', '.cpp') if env["platform"] == "macos": library = env.SharedLibrary( diff --git a/addons/beehave/libs/windows/beehave.windows.editor.x86_64.dll b/addons/beehave/libs/windows/beehave.windows.editor.x86_64.dll index b7b3b4a7..11f8c916 100644 Binary files a/addons/beehave/libs/windows/beehave.windows.editor.x86_64.dll and b/addons/beehave/libs/windows/beehave.windows.editor.x86_64.dll differ diff --git a/addons/beehave/libs/windows/~beehave.windows.editor.x86_64.dll b/addons/beehave/libs/windows/~beehave.windows.editor.x86_64.dll new file mode 100644 index 00000000..11f8c916 Binary files /dev/null and b/addons/beehave/libs/windows/~beehave.windows.editor.x86_64.dll differ diff --git a/addons/gdUnit4/GdUnitRunner.cfg b/addons/gdUnit4/GdUnitRunner.cfg index 59dd7687..31365dab 100644 --- a/addons/gdUnit4/GdUnitRunner.cfg +++ b/addons/gdUnit4/GdUnitRunner.cfg @@ -1 +1 @@ -{"included":{"res://test/":[]},"server_port":31002,"skipped":{},"version":"1.0"} \ No newline at end of file +{"included":{"res://test/beehave_tree_test.gd":[]},"server_port":31002,"skipped":{},"version":"1.0"} \ No newline at end of file diff --git a/extension/src/nodes/decorators/succeeder.cpp b/docs/.gdignore similarity index 100% rename from extension/src/nodes/decorators/succeeder.cpp rename to docs/.gdignore diff --git a/examples/actions/SetModulateColor.gd b/examples/actions/SetModulateColor.gd index 311de366..89371685 100644 --- a/examples/actions/SetModulateColor.gd +++ b/examples/actions/SetModulateColor.gd @@ -1,4 +1,4 @@ -extends ActionLeaf +extends BeehaveAction @export var modulate_color:Color = Color.WHITE @export var interpolation_time:float = 3.0 @@ -6,17 +6,17 @@ extends ActionLeaf var current_color var tween -func tick(actor: Node, _blackboard: Blackboard) -> int: +func tick(context: BeehaveContext) -> int: - if current_color != modulate_color and actor.modulate != modulate_color: + if current_color != modulate_color and context.get_actor().modulate != modulate_color: if tween != null: tween.stop() current_color = modulate_color tween = create_tween()\ .set_ease(Tween.EASE_IN_OUT)\ .set_trans(Tween.TRANS_CUBIC) - tween.tween_property(actor, "modulate", current_color, interpolation_time)\ - .finished.connect(_finished.bind(actor)) + tween.tween_property(context.get_actor(), "modulate", current_color, interpolation_time)\ + .finished.connect(_finished.bind(context.get_actor())) if current_color != null: return RUNNING diff --git a/examples/conditions/HasNegativePosition.gd b/examples/conditions/HasNegativePosition.gd index 3eb580e8..f6ad4cf1 100644 --- a/examples/conditions/HasNegativePosition.gd +++ b/examples/conditions/HasNegativePosition.gd @@ -1,7 +1,7 @@ extends ConditionLeaf -func tick(actor: Node, _blackboard: Blackboard) -> int: +func tick(context: BeehaveContext) -> int: if actor.position.x < 0.0 and actor.position.y < 0.0: return SUCCESS else: diff --git a/examples/conditions/HasPositivePosition.gd b/examples/conditions/HasPositivePosition.gd index a9ce844a..2a6421e5 100644 --- a/examples/conditions/HasPositivePosition.gd +++ b/examples/conditions/HasPositivePosition.gd @@ -1,7 +1,7 @@ class_name HasPositivePosition extends ConditionLeaf -func tick(actor: Node, _blackboard: Blackboard) -> int: +func tick(context: BeehaveContext) -> int: if actor.position.x > 0.0 and actor.position.y > 0.0: return SUCCESS else: diff --git a/examples/random_tree_example/RandomAction.gd b/examples/random_tree_example/RandomAction.gd index 9d8049f5..088b2992 100644 --- a/examples/random_tree_example/RandomAction.gd +++ b/examples/random_tree_example/RandomAction.gd @@ -4,7 +4,7 @@ ## [member weights]. Changes its status every [member reset_duration_msec] ## milliseconds. @tool -class_name RandomAction extends ActionLeaf +class_name RandomAction extends BeehaveAction ## How often this action changes its return status, in milliseconds. @@ -31,7 +31,7 @@ func _get_random_action(): return weights.size() - 1 -func tick(actor: Node, blackboard: Blackboard) -> int: +func tick(context: BeehaveContext) -> int: var step = Time.get_ticks_msec() / reset_duration_msec if step != last_step: action = _get_random_action() diff --git a/extension/src/nodes/decorators/succeeder.h b/extension/.gdignore similarity index 100% rename from extension/src/nodes/decorators/succeeder.h rename to extension/.gdignore diff --git a/extension/src/nodes/beehave_tree.cpp b/extension/src/nodes/beehave_tree.cpp index 39c9d298..8c37b83f 100644 --- a/extension/src/nodes/beehave_tree.cpp +++ b/extension/src/nodes/beehave_tree.cpp @@ -28,6 +28,7 @@ /**************************************************************************/ #include "beehave_tree.h" +#include "beehave_blackboard.h" #include using namespace godot; @@ -54,6 +55,25 @@ void BeehaveTree::_bind_methods() { } void BeehaveTree::_ready() { + if (!actor) { + actor = get_parent(); + } + if (!blackboard) { + _internal_blackboard = memnew(BeehaveBlackboard); + blackboard = _internal_blackboard; + } + set_physics_process(enabled && process_thread == ProcessThread::PHYSICS); + set_process(enabled && process_thread == ProcessThread::IDLE); + + // Randomize at what frames tick() will happen to avoid stutters + _last_tick = rand() % tick_rate; +} + +void BeehaveTree::_exit_tree() { + if (_internal_blackboard) { + memfree(_internal_blackboard); + _internal_blackboard = nullptr; + } } void BeehaveTree::_process(double delta) { @@ -69,9 +89,11 @@ void BeehaveTree::_physics_process(double delta) { } void BeehaveTree::enable() { + enabled = true; } void BeehaveTree::disable() { + enabled = false; } void BeehaveTree::process_internally(double delta) { diff --git a/extension/src/nodes/beehave_tree.h b/extension/src/nodes/beehave_tree.h index b6096044..07fd90b2 100644 --- a/extension/src/nodes/beehave_tree.h +++ b/extension/src/nodes/beehave_tree.h @@ -51,6 +51,7 @@ class BeehaveTree : public Node { bool enabled; Node *actor; BeehaveBlackboard *blackboard; + BeehaveBlackboard *_internal_blackboard = nullptr; Ref context; BeehaveTreeNode::TickStatus tick_status; ProcessThread process_thread = ProcessThread::PHYSICS; @@ -69,6 +70,7 @@ class BeehaveTree : public Node { void _ready(); void _process(double delta); void _physics_process(double delta); + void _exit_tree(); void enable(); void disable(); BeehaveTreeNode::TickStatus tick(); diff --git a/extension/src/nodes/beehave_tree_node.cpp b/extension/src/nodes/beehave_tree_node.cpp index 42060cf2..e9ecfc37 100644 --- a/extension/src/nodes/beehave_tree_node.cpp +++ b/extension/src/nodes/beehave_tree_node.cpp @@ -43,7 +43,8 @@ BeehaveTreeNode::TickStatus BeehaveTreeNode::tick(Ref context) { } void BeehaveTreeNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("tick"), &BeehaveTreeNode::tick); + + BIND_VIRTUAL_METHOD(BeehaveTreeNode, tick); BIND_ENUM_CONSTANT(SUCCESS); BIND_ENUM_CONSTANT(FAILURE); diff --git a/extension/src/nodes/beehave_tree_node.h b/extension/src/nodes/beehave_tree_node.h index d2ebd050..cd1cb9ae 100644 --- a/extension/src/nodes/beehave_tree_node.h +++ b/extension/src/nodes/beehave_tree_node.h @@ -51,7 +51,7 @@ class BeehaveTreeNode : public Node { BeehaveTreeNode(); ~BeehaveTreeNode(); - TickStatus tick(Ref context); + virtual TickStatus tick(Ref context); }; } //namespace godot diff --git a/extension/src/nodes/decorators/beehave_decorator.cpp b/extension/src/nodes/decorators/beehave_decorator.cpp new file mode 100644 index 00000000..07b677ee --- /dev/null +++ b/extension/src/nodes/decorators/beehave_decorator.cpp @@ -0,0 +1,44 @@ +/**************************************************************************/ +/* beehave_decorator.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "beehave_decorator.h" + +using namespace godot; + +BeehaveDecorator::BeehaveDecorator() { + +} + +BeehaveDecorator::~BeehaveDecorator() { + +} + +void BeehaveDecorator::_bind_methods() { + +} \ No newline at end of file diff --git a/extension/src/nodes/decorators/beehave_decorator.h b/extension/src/nodes/decorators/beehave_decorator.h new file mode 100644 index 00000000..e23b58f5 --- /dev/null +++ b/extension/src/nodes/decorators/beehave_decorator.h @@ -0,0 +1,52 @@ +/**************************************************************************/ +/* beehave_decorator.h */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef BEEHAVE_DECORATOR_H +#define BEEHAVE_DECORATOR_H + +#include "nodes/beehave_tree_node.h" + +namespace godot { + +class BeehaveDecorator : public BeehaveTreeNode { + GDCLASS(BeehaveDecorator, BeehaveTreeNode); + +protected: + BeehaveTreeNode *running_child; + + static void _bind_methods(); + +public: + BeehaveDecorator(); + ~BeehaveDecorator(); +}; + +} + +#endif//BEEHAVE_DECORATOR_H \ No newline at end of file diff --git a/extension/src/nodes/decorators/beehave_succeeder.cpp b/extension/src/nodes/decorators/beehave_succeeder.cpp new file mode 100644 index 00000000..f3fb0ac6 --- /dev/null +++ b/extension/src/nodes/decorators/beehave_succeeder.cpp @@ -0,0 +1,44 @@ +/**************************************************************************/ +/* beehave_succeeder.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "beehave_succeeder.h" + +using namespace godot; + +BeehaveSucceeder::BeehaveSucceeder() { + +} + +BeehaveSucceeder::~BeehaveSucceeder() { + +} + +void BeehaveSucceeder::_bind_methods() { + +} \ No newline at end of file diff --git a/extension/src/nodes/decorators/beehave_succeeder.h b/extension/src/nodes/decorators/beehave_succeeder.h new file mode 100644 index 00000000..236c8b62 --- /dev/null +++ b/extension/src/nodes/decorators/beehave_succeeder.h @@ -0,0 +1,49 @@ +/**************************************************************************/ +/* beehave_succeeder.h */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef BEEHAVE_SUCCEEDER +#define BEEHAVE_SUCCEEDER + +#include "nodes/decorators/beehave_decorator.h" + +namespace godot { + +class BeehaveSucceeder : public BeehaveDecorator { + GDCLASS(BeehaveSucceeder, BeehaveDecorator); + +protected: + static void _bind_methods(); + +public: + BeehaveSucceeder(); + ~BeehaveSucceeder(); +}; +} + +#endif //BEEHAVE_SUCCEEDER \ No newline at end of file diff --git a/extension/src/nodes/leaves/action.h b/extension/src/nodes/leaves/action.h deleted file mode 100644 index e69de29b..00000000 diff --git a/extension/src/nodes/leaves/beehave_action.cpp b/extension/src/nodes/leaves/beehave_action.cpp new file mode 100644 index 00000000..8edabf19 --- /dev/null +++ b/extension/src/nodes/leaves/beehave_action.cpp @@ -0,0 +1,43 @@ +/**************************************************************************/ +/* beehave_acti.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "beehave_action.h" + +using namespace godot; + +void BeehaveAction::_bind_methods() { + +} + +BeehaveAction::BeehaveAction() { + +} +BeehaveAction::~BeehaveAction() { + +} \ No newline at end of file diff --git a/extension/src/nodes/leaves/beehave_action.h b/extension/src/nodes/leaves/beehave_action.h new file mode 100644 index 00000000..107df303 --- /dev/null +++ b/extension/src/nodes/leaves/beehave_action.h @@ -0,0 +1,48 @@ +/**************************************************************************/ +/* beehave_action.h */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef BEEHAVE_ACTION +#define BEEHAVE_ACTION + +#include "nodes/leaves/beehave_leaf.h" + +namespace godot { + class BeehaveAction : public BeehaveLeaf { + GDCLASS(BeehaveAction, BeehaveLeaf); + + protected: + static void _bind_methods(); + + public: + BeehaveAction(); + ~BeehaveAction(); + }; +} + +#endif //BEEHAVE_ACTION \ No newline at end of file diff --git a/extension/src/nodes/leaves/action.cpp b/extension/src/nodes/leaves/beehave_condition.cpp similarity index 100% rename from extension/src/nodes/leaves/action.cpp rename to extension/src/nodes/leaves/beehave_condition.cpp diff --git a/extension/src/nodes/leaves/beehave_condition.h b/extension/src/nodes/leaves/beehave_condition.h new file mode 100644 index 00000000..614dfbf0 --- /dev/null +++ b/extension/src/nodes/leaves/beehave_condition.h @@ -0,0 +1,28 @@ +/**************************************************************************/ +/* beehave_condition.h */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ \ No newline at end of file diff --git a/extension/src/nodes/leaves/beehave_leaf.cpp b/extension/src/nodes/leaves/beehave_leaf.cpp new file mode 100644 index 00000000..88ffa0af --- /dev/null +++ b/extension/src/nodes/leaves/beehave_leaf.cpp @@ -0,0 +1,43 @@ +/**************************************************************************/ +/* beehave_leaf.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "beehave_leaf.h" + +using namespace godot; + +void BeehaveLeaf::_bind_methods() { +} + +BeehaveLeaf::BeehaveLeaf() { + +} + +BeehaveLeaf ::~BeehaveLeaf() { + +} \ No newline at end of file diff --git a/extension/src/nodes/leaves/beehave_leaf.h b/extension/src/nodes/leaves/beehave_leaf.h new file mode 100644 index 00000000..14f89eff --- /dev/null +++ b/extension/src/nodes/leaves/beehave_leaf.h @@ -0,0 +1,49 @@ +/**************************************************************************/ +/* beehave_leaf.h */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef BEEHAVE_LEAF +#define BEEHAVE_LEAF + +#include "nodes/beehave_tree_node.h" + +namespace godot { + +class BeehaveLeaf : public BeehaveTreeNode { + GDCLASS(BeehaveLeaf, BeehaveTreeNode); + + protected: + static void _bind_methods(); + + public: + BeehaveLeaf(); + ~BeehaveLeaf(); +}; +} + +#endif //BEEHAVE_LEAF \ No newline at end of file diff --git a/extension/src/nodes/leaves/condition.cpp b/extension/src/nodes/leaves/condition.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/extension/src/nodes/leaves/condition.h b/extension/src/nodes/leaves/condition.h deleted file mode 100644 index e69de29b..00000000 diff --git a/extension/src/nodes/leaves/leaf.cpp b/extension/src/nodes/leaves/leaf.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/extension/src/nodes/leaves/leaf.h b/extension/src/nodes/leaves/leaf.h deleted file mode 100644 index e69de29b..00000000 diff --git a/extension/src/register_types.cpp b/extension/src/register_types.cpp index 3ad7a105..e4580608 100644 --- a/extension/src/register_types.cpp +++ b/extension/src/register_types.cpp @@ -8,6 +8,10 @@ #include "nodes/beehave_blackboard.h" #include "nodes/beehave_tree.h" #include "nodes/beehave_tree_node.h" +#include "nodes/leaves/beehave_leaf.h" +#include "nodes/leaves/beehave_action.h" +#include "nodes/decorators/beehave_decorator.h" +#include "nodes/decorators/beehave_succeeder.h" using namespace godot; @@ -19,6 +23,10 @@ void initialize_beehave_types(ModuleInitializationLevel p_level) { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); } void uninitialize_beehave_types(ModuleInitializationLevel p_level) { diff --git a/test/actions/clear_count_action.gd b/test/actions/clear_count_action.gd index 2436f323..5e4df324 100644 --- a/test/actions/clear_count_action.gd +++ b/test/actions/clear_count_action.gd @@ -1,8 +1,8 @@ -class_name ClearCountAction extends ActionLeaf +class_name ClearCountAction extends BeehaveAction @export var key = "custom_value" -func tick(_actor: Node, blackboard: Blackboard) -> int: +func tick(_context: BeehaveContext) -> int: if blackboard.has_value(key): blackboard.erase_value(key) return SUCCESS diff --git a/test/actions/count_up_action.gd b/test/actions/count_up_action.gd index e83ae0e5..0e2f9d04 100644 --- a/test/actions/count_up_action.gd +++ b/test/actions/count_up_action.gd @@ -1,17 +1,17 @@ -class_name CountUpAction extends ActionLeaf +class_name CountUpAction extends BeehaveAction @export var key = "custom_value" var count = 0 var status = SUCCESS -func tick(_actor: Node, blackboard: Blackboard) -> int: +func tick(context: BeehaveContext) -> int: count += 1 - blackboard.set_value(key, count) + context.get_blackboard().set_value(key, count) return status -func interrupt(_actor: Node, blackboard: Blackboard) -> void: +func interrupt(context: BeehaveContext) -> void: count = 0 - blackboard.set_value(key, count) + context.get_blackboard().set_value(key, count) status = FAILURE diff --git a/test/actions/mock_action.gd b/test/actions/mock_action.gd index 5909446c..eae70631 100644 --- a/test/actions/mock_action.gd +++ b/test/actions/mock_action.gd @@ -1,5 +1,5 @@ class_name MockAction -extends ActionLeaf +extends BeehaveAction @export_enum("Success", "Failure") var final_result: int = 0 @export var running_frame_count: int = 0 @@ -11,12 +11,12 @@ signal interrupted(actor, blackboard) var tick_count: int = 0 -func before_run(actor: Node, blackboard: Blackboard) -> void: +func before_run(context: BeehaveContext) -> void: tick_count = 0 - started_running.emit(actor, blackboard) + started_running.emit(context.get_actor(), context.get_blackboard()) -func tick(_actor: Node, _blackboard: Blackboard) -> int: +func tick(_context: BeehaveContext) -> int: if tick_count < running_frame_count: tick_count += 1 return RUNNING @@ -24,10 +24,10 @@ func tick(_actor: Node, _blackboard: Blackboard) -> int: return final_result -func interrupt(actor: Node, blackboard: Blackboard) -> void: - interrupted.emit(actor, blackboard) +func interrupt(context: BeehaveContext) -> void: + interrupted.emit(context.get_actor(), context.get_blackboard()) -func after_run(actor: Node, blackboard: Blackboard) -> void: +func after_run(context: BeehaveContext) -> void: tick_count = 0 - stopped_running.emit(actor, blackboard) + stopped_running.emit(context.get_actor(), context.get_blackboard()) diff --git a/test/beehave_tree_test.gd b/test/beehave_tree_test.gd index 47dff768..bcbc2ce6 100644 --- a/test/beehave_tree_test.gd +++ b/test/beehave_tree_test.gd @@ -86,11 +86,11 @@ func test_interrupt_running_action() -> void: assert_that(scene.count_up_action.status).is_equal(BeehaveTreeNode.FAILURE) -func test_blackboard_not_initialized() -> void: - var tree = create_tree() - tree.actor = auto_free(Node2D.new()) - var always_succeed = auto_free(AlwaysSucceedDecorator.new()) as AlwaysSucceedDecorator - always_succeed.add_child(auto_free(ActionLeaf.new())) - tree.add_child(always_succeed) - var result = tree.tick() - assert_that(result).is_equal(BeehaveTreeNode.SUCCESS) +#func test_blackboard_not_initialized() -> void: +# var tree = create_tree() +# tree.actor = auto_free(Node2D.new()) +# var always_succeed = auto_free(AlwaysSucceedDecorator.new()) as AlwaysSucceedDecorator +# always_succeed.add_child(auto_free(BeehaveAction.new())) +# tree.add_child(always_succeed) +# var result = tree.tick() +# assert_that(result).is_equal(BeehaveTreeNode.SUCCESS) diff --git a/test/before_after_run_test.gd b/test/before_after_run_test.gd index cc2be17e..ea12665b 100644 --- a/test/before_after_run_test.gd +++ b/test/before_after_run_test.gd @@ -7,7 +7,7 @@ extends GdUnitTestSuite const __mock_action = "res://test/actions/mock_action.gd" var tree: BeehaveTree -var action: ActionLeaf +var action: BeehaveAction func before_test() -> void: diff --git a/test/blackboard_test.gd b/test/blackboard_test.gd index 22506003..b650c845 100644 --- a/test/blackboard_test.gd +++ b/test/blackboard_test.gd @@ -1,5 +1,5 @@ # GdUnit generated TestSuite -class_name BlackboardTest +class_name BeehaveBlackboardTest extends GdUnitTestSuite @warning_ignore("unused_parameter") @warning_ignore("return_value_discarded") diff --git a/test/conditions/value_reached_condition.gd b/test/conditions/value_reached_condition.gd index 30aeeb57..de515eae 100644 --- a/test/conditions/value_reached_condition.gd +++ b/test/conditions/value_reached_condition.gd @@ -3,7 +3,7 @@ class_name ValueReachedCondition extends ConditionLeaf @export var limit = 2 @export var key = "custom_value" -func tick(_actor: Node, blackboard: Blackboard) -> int: +func tick(_context: BeehaveContext) -> int: if blackboard.get_value(key, 0) >= limit: return SUCCESS else: diff --git a/test/nodes/composites/selector_random_test.gd b/test/nodes/composites/selector_random_test.gd index 7b46e64f..54471618 100644 --- a/test/nodes/composites/selector_random_test.gd +++ b/test/nodes/composites/selector_random_test.gd @@ -7,25 +7,23 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/composites/selector_random.gd" const __count_up_action = "res://test/actions/count_up_action.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" const RANDOM_SEED = 123 var tree: BeehaveTree var selector: SelectorRandomComposite -var action1: ActionLeaf -var action2: ActionLeaf +var action1: BeehaveAction +var action2: BeehaveAction var actor: Node -var blackboard: Blackboard +var blackboard: BeehaveBlackboard func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) selector = auto_free(load(__source).new()) action1 = auto_free(load(__count_up_action).new()) action2 = auto_free(load(__count_up_action).new()) actor = auto_free(Node2D.new()) - blackboard = auto_free(load(__blackboard).new()) + blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(selector) selector.add_child(action1) diff --git a/test/nodes/composites/selector_reactive_test.gd b/test/nodes/composites/selector_reactive_test.gd index e589c006..20afd7e6 100644 --- a/test/nodes/composites/selector_reactive_test.gd +++ b/test/nodes/composites/selector_reactive_test.gd @@ -8,22 +8,20 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/composites/selector_reactive.gd" const __count_up_action = "res://test/actions/count_up_action.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" var tree: BeehaveTree var selector: SelectorReactiveComposite -var action1: ActionLeaf -var action2: ActionLeaf +var action1: BeehaveAction +var action2: BeehaveAction func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) action1 = auto_free(load(__count_up_action).new()) action2 = auto_free(load(__count_up_action).new()) selector = auto_free(load(__source).new()) var actor = auto_free(Node2D.new()) - var blackboard = auto_free(load(__blackboard).new()) + var blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(selector) selector.add_child(action1) diff --git a/test/nodes/composites/selector_test.gd b/test/nodes/composites/selector_test.gd index cac015d8..ee811d21 100644 --- a/test/nodes/composites/selector_test.gd +++ b/test/nodes/composites/selector_test.gd @@ -7,25 +7,23 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/composites/selector.gd" const __count_up_action = "res://test/actions/count_up_action.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" const __selector_reactive = "res://addons/beehave/nodes/composites/selector_reactive.gd" var tree: BeehaveTree var selector: SelectorComposite -var action1: ActionLeaf -var action2: ActionLeaf +var action1: BeehaveAction +var action2: BeehaveAction var actor: Node -var blackboard: Blackboard +var blackboard: BeehaveBlackboard func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) selector = auto_free(load(__source).new()) action1 = auto_free(load(__count_up_action).new()) action2 = auto_free(load(__count_up_action).new()) actor = auto_free(Node2D.new()) - blackboard = auto_free(load(__blackboard).new()) + blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(selector) selector.add_child(action1) diff --git a/test/nodes/composites/sequence_random_test.gd b/test/nodes/composites/sequence_random_test.gd index bc8eee8d..b722bfea 100644 --- a/test/nodes/composites/sequence_random_test.gd +++ b/test/nodes/composites/sequence_random_test.gd @@ -8,18 +8,16 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/composites/sequence_random.gd" const __count_up_action = "res://test/actions/count_up_action.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" const RANDOM_SEED = 123 var tree: BeehaveTree var sequence: SequenceRandomComposite -var action1: ActionLeaf -var action2: ActionLeaf +var action1: BeehaveAction +var action2: BeehaveAction func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) action1 = auto_free(load(__count_up_action).new()) action1.name = 'Action 1' action2 = auto_free(load(__count_up_action).new()) @@ -27,7 +25,7 @@ func before_test() -> void: sequence = auto_free(load(__source).new()) sequence.random_seed = RANDOM_SEED var actor = auto_free(Node2D.new()) - var blackboard = auto_free(load(__blackboard).new()) + var blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(sequence) sequence.add_child(action1) diff --git a/test/nodes/composites/sequence_reactive_test.gd b/test/nodes/composites/sequence_reactive_test.gd index 7f9596ca..c3814d5c 100644 --- a/test/nodes/composites/sequence_reactive_test.gd +++ b/test/nodes/composites/sequence_reactive_test.gd @@ -8,24 +8,22 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/composites/sequence_reactive.gd" const __count_up_action = "res://test/actions/count_up_action.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" var tree: BeehaveTree -var action1: ActionLeaf -var action2: ActionLeaf +var action1: BeehaveAction +var action2: BeehaveAction var actor: Node var sequence: SequenceReactiveComposite -var blackboard: Blackboard +var blackboard: BeehaveBlackboard func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) action1 = auto_free(load(__count_up_action).new()) action2 = auto_free(load(__count_up_action).new()) sequence = auto_free(load(__source).new()) actor = auto_free(Node2D.new()) - blackboard = auto_free(load(__blackboard).new()) + blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(sequence) sequence.add_child(action1) diff --git a/test/nodes/composites/sequence_star_test.gd b/test/nodes/composites/sequence_star_test.gd index 88bf3cb7..a3013643 100644 --- a/test/nodes/composites/sequence_star_test.gd +++ b/test/nodes/composites/sequence_star_test.gd @@ -8,24 +8,22 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/composites/sequence_star.gd" const __count_up_action = "res://test/actions/count_up_action.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" var tree: BeehaveTree -var action1: ActionLeaf -var action2: ActionLeaf +var action1: BeehaveAction +var action2: BeehaveAction var actor: Node -var blackboard: Blackboard +var blackboard: BeehaveBlackboard var sequence: SequenceStarComposite func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) action1 = auto_free(load(__count_up_action).new()) action2 = auto_free(load(__count_up_action).new()) sequence = auto_free(load(__source).new()) actor = auto_free(Node2D.new()) - blackboard = auto_free(load(__blackboard).new()) + blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(sequence) sequence.add_child(action1) diff --git a/test/nodes/composites/sequence_test.gd b/test/nodes/composites/sequence_test.gd index a588945c..2a420486 100644 --- a/test/nodes/composites/sequence_test.gd +++ b/test/nodes/composites/sequence_test.gd @@ -7,24 +7,22 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/composites/sequence.gd" const __count_up_action = "res://test/actions/count_up_action.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" var tree: BeehaveTree var sequence: SequenceComposite -var action1: ActionLeaf -var action2: ActionLeaf +var action1: BeehaveAction +var action2: BeehaveAction var actor: Node -var blackboard: Blackboard +var blackboard: BeehaveBlackboard func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) sequence = auto_free(load(__source).new()) action1 = auto_free(load(__count_up_action).new()) action2 = auto_free(load(__count_up_action).new()) actor = auto_free(Node2D.new()) - blackboard = auto_free(load(__blackboard).new()) + blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(sequence) sequence.add_child(action1) diff --git a/test/nodes/decorators/cooldown_test.gd b/test/nodes/decorators/cooldown_test.gd index 6e27b86a..00449a75 100644 --- a/test/nodes/decorators/cooldown_test.gd +++ b/test/nodes/decorators/cooldown_test.gd @@ -7,21 +7,19 @@ extends GdUnitTestSuite # TestSuite generated from const __source = 'res://addons/beehave/nodes/decorators/cooldown.gd' const __action = "res://test/actions/count_up_action.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" var tree: BeehaveTree -var action: ActionLeaf +var action: BeehaveAction var cooldown: CooldownDecorator var runner:GdUnitSceneRunner func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) action = auto_free(load(__action).new()) cooldown = auto_free(load(__source).new()) var actor = auto_free(Node2D.new()) - var blackboard = auto_free(load(__blackboard).new()) + var blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(cooldown) cooldown.add_child(action) diff --git a/test/nodes/decorators/delayer_test.gd b/test/nodes/decorators/delayer_test.gd index cda77147..91d4fd8f 100644 --- a/test/nodes/decorators/delayer_test.gd +++ b/test/nodes/decorators/delayer_test.gd @@ -7,21 +7,19 @@ extends GdUnitTestSuite # TestSuite generated from const __source = 'res://addons/beehave/nodes/decorators/delayer.gd' const __action = "res://test/actions/count_up_action.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" var tree: BeehaveTree -var action: ActionLeaf +var action: BeehaveAction var delayer: DelayDecorator var runner:GdUnitSceneRunner func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) action = auto_free(load(__action).new()) delayer = auto_free(load(__source).new()) var actor = auto_free(Node2D.new()) - var blackboard = auto_free(load(__blackboard).new()) + var blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(delayer) delayer.add_child(action) diff --git a/test/nodes/decorators/failer_test.gd b/test/nodes/decorators/failer_test.gd index 4076a00a..3168b21e 100644 --- a/test/nodes/decorators/failer_test.gd +++ b/test/nodes/decorators/failer_test.gd @@ -7,21 +7,19 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/decorators/failer.gd" const __action = "res://test/actions/count_up_action.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" var tree: BeehaveTree -var action: ActionLeaf +var action: BeehaveAction var failer: AlwaysFailDecorator func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) action = auto_free(load(__action).new()) failer = auto_free(load(__source).new()) var actor = auto_free(Node2D.new()) - var blackboard = auto_free(load(__blackboard).new()) + var blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(failer) failer.add_child(action) diff --git a/test/nodes/decorators/inverter_test.gd b/test/nodes/decorators/inverter_test.gd index 94ad495c..4aa00b75 100644 --- a/test/nodes/decorators/inverter_test.gd +++ b/test/nodes/decorators/inverter_test.gd @@ -8,21 +8,19 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/decorators/inverter.gd" const __action = "res://test/actions/count_up_action.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" var tree: BeehaveTree -var action: ActionLeaf +var action: BeehaveAction var inverter: InverterDecorator func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) action = auto_free(load(__action).new()) inverter = auto_free(load(__source).new()) var actor = auto_free(Node2D.new()) - var blackboard = auto_free(load(__blackboard).new()) + var blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(inverter) inverter.add_child(action) diff --git a/test/nodes/decorators/limiter_test.gd b/test/nodes/decorators/limiter_test.gd index b2a1ee8b..3b43cd4e 100644 --- a/test/nodes/decorators/limiter_test.gd +++ b/test/nodes/decorators/limiter_test.gd @@ -7,21 +7,19 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/decorators/limiter.gd" const __action = "res://test/actions/count_up_action.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" var tree: BeehaveTree -var action: ActionLeaf +var action: BeehaveAction var limiter: LimiterDecorator func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) action = auto_free(load(__action).new()) limiter = auto_free(load(__source).new()) var actor = auto_free(Node2D.new()) - var blackboard = auto_free(load(__blackboard).new()) + var blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(limiter) limiter.add_child(action) diff --git a/test/nodes/decorators/repeater_test.gd b/test/nodes/decorators/repeater_test.gd index 5e5340fa..f62f0d6a 100644 --- a/test/nodes/decorators/repeater_test.gd +++ b/test/nodes/decorators/repeater_test.gd @@ -8,8 +8,6 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/decorators/repeater.gd" const __action = "res://test/actions/mock_action.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" var tree: BeehaveTree var action: MockAction @@ -17,7 +15,7 @@ var repeater: RepeaterDecorator func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) action = auto_free(load(__action).new()) repeater = auto_free(load(__source).new()) @@ -27,7 +25,7 @@ func before_test() -> void: action.stopped_running.connect(_on_action_ended) var actor = auto_free(Node2D.new()) - var blackboard = auto_free(load(__blackboard).new()) + var blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(repeater) repeater.add_child(action) diff --git a/test/nodes/decorators/succeeder_test.gd b/test/nodes/decorators/succeeder_test.gd index d00c5262..6fe3dd6e 100644 --- a/test/nodes/decorators/succeeder_test.gd +++ b/test/nodes/decorators/succeeder_test.gd @@ -7,21 +7,19 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/decorators/succeeder.gd" const __action = "res://test/actions/count_up_action.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" var tree: BeehaveTree -var action: ActionLeaf +var action: BeehaveAction var succeeder: AlwaysSucceedDecorator func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) action = auto_free(load(__action).new()) succeeder = auto_free(load(__source).new()) var actor = auto_free(Node2D.new()) - var blackboard = auto_free(load(__blackboard).new()) + var blackboard = auto_free(BeehaveBlackboard.new()) tree.add_child(succeeder) succeeder.add_child(action) diff --git a/test/nodes/decorators/time_limiter_test.gd b/test/nodes/decorators/time_limiter_test.gd index be6e3a8d..cdf7ad59 100644 --- a/test/nodes/decorators/time_limiter_test.gd +++ b/test/nodes/decorators/time_limiter_test.gd @@ -7,21 +7,19 @@ extends GdUnitTestSuite # TestSuite generated from const __source = "res://addons/beehave/nodes/decorators/time_limiter.gd" const __action = "res://test/actions/count_up_action.gd" -const __tree = "res://addons/beehave/nodes/beehave_tree.gd" -const __blackboard = "res://addons/beehave/blackboard.gd" var tree: BeehaveTree -var action: ActionLeaf +var action: BeehaveAction var time_limiter: TimeLimiterDecorator var actor: Node2D -var blackboard: Blackboard +var blackboard: BeehaveBlackboard var runner:GdUnitSceneRunner func before_test() -> void: - tree = auto_free(load(__tree).new()) + tree = auto_free(BeehaveTree.new()) actor = auto_free(Node2D.new()) - blackboard = auto_free(load(__blackboard).new()) + blackboard = auto_free(BeehaveBlackboard.new()) tree.actor = actor tree.blackboard = blackboard diff --git a/test/nodes/leaves/actions/blackboard_erase_test.gd b/test/nodes/leaves/actions/blackboard_erase_test.gd index fea56a0e..acdefdef 100644 --- a/test/nodes/leaves/actions/blackboard_erase_test.gd +++ b/test/nodes/leaves/actions/blackboard_erase_test.gd @@ -1,5 +1,5 @@ # GdUnit generated TestSuite -class_name BlackboardEraseActionTest +class_name BeehaveBlackboardEraseActionTest extends GdUnitTestSuite @warning_ignore("unused_parameter") @warning_ignore("return_value_discarded") @@ -10,9 +10,9 @@ const __blackboard = "res://addons/beehave/blackboard.gd" const KEY: String = "test_key" -var blackboard_erase: BlackboardEraseAction +var blackboard_erase: BeehaveBlackboardEraseAction var actor: Node -var blackboard: Blackboard +var blackboard: BeehaveBlackboard var runner: GdUnitSceneRunner diff --git a/test/nodes/leaves/actions/blackboard_set_test.gd b/test/nodes/leaves/actions/blackboard_set_test.gd index 8e20b071..0bf5ca26 100644 --- a/test/nodes/leaves/actions/blackboard_set_test.gd +++ b/test/nodes/leaves/actions/blackboard_set_test.gd @@ -1,5 +1,5 @@ # GdUnit generated TestSuite -class_name BlackboardSetActionTest +class_name BeehaveBlackboardSetActionTest extends GdUnitTestSuite @warning_ignore('unused_parameter') @warning_ignore('return_value_discarded') @@ -12,9 +12,9 @@ const __blackboard = "res://addons/beehave/blackboard.gd" const KEY: String = "test_key" const KEY2: String = "other_key" -var blackboard_set: BlackboardSetAction +var blackboard_set: BeehaveBlackboardSetAction var actor: Node -var blackboard: Blackboard +var blackboard: BeehaveBlackboard func before_test() -> void: diff --git a/test/nodes/leaves/conditions/blackboard_compare_test.gd b/test/nodes/leaves/conditions/blackboard_compare_test.gd index 53c5df90..db8c4366 100644 --- a/test/nodes/leaves/conditions/blackboard_compare_test.gd +++ b/test/nodes/leaves/conditions/blackboard_compare_test.gd @@ -1,5 +1,5 @@ # GdUnit generated TestSuite -class_name BlackboardCompareConditionTest +class_name BeehaveBlackboardCompareConditionTest extends GdUnitTestSuite @warning_ignore("unused_parameter") @warning_ignore("return_value_discarded") @@ -9,9 +9,9 @@ const __source = "res://addons/beehave/nodes/leaves/blackboard_compare.gd" const __blackboard = "res://addons/beehave/blackboard.gd" -var blackboard_compare: BlackboardCompareCondition +var blackboard_compare: BeehaveBlackboardCompareCondition var actor: Node -var blackboard: Blackboard +var blackboard: BeehaveBlackboard var runner: GdUnitSceneRunner @@ -54,7 +54,7 @@ func test_comparison_operators() -> void: for pair in data[operands]: blackboard_compare = auto_free(load(__source).new()) - var operator: BlackboardCompareCondition.Operators = pair[0] + var operator: BeehaveBlackboardCompareCondition.Operators = pair[0] var expected_status: int = pair[1] blackboard_compare.left_operand = operands[0] @@ -70,7 +70,7 @@ func test_blackboard_access() -> void: blackboard.set_value("direction", Vector3.FORWARD) blackboard_compare.left_operand = "get_value(\"direction\").length()" - blackboard_compare.operator = BlackboardCompareCondition.Operators.EQUAL + blackboard_compare.operator = BeehaveBlackboardCompareCondition.Operators.EQUAL blackboard_compare.right_operand = "1" runner = scene_runner(blackboard_compare) @@ -79,7 +79,7 @@ func test_blackboard_access() -> void: func test_invalid_left_operand_expression() -> void: blackboard_compare.left_operand = "this is invalid!!!" - blackboard_compare.operator = BlackboardCompareCondition.Operators.EQUAL + blackboard_compare.operator = BeehaveBlackboardCompareCondition.Operators.EQUAL blackboard_compare.right_operand = "1" runner = scene_runner(blackboard_compare) @@ -88,7 +88,7 @@ func test_invalid_left_operand_expression() -> void: func test_invalid_right_operand_expression() -> void: blackboard_compare.left_operand = "1" - blackboard_compare.operator = BlackboardCompareCondition.Operators.EQUAL + blackboard_compare.operator = BeehaveBlackboardCompareCondition.Operators.EQUAL blackboard_compare.right_operand = "this is invalid!!!" runner = scene_runner(blackboard_compare) diff --git a/test/nodes/leaves/conditions/blackboard_has_test.gd b/test/nodes/leaves/conditions/blackboard_has_test.gd index f49f31d5..54d0a386 100644 --- a/test/nodes/leaves/conditions/blackboard_has_test.gd +++ b/test/nodes/leaves/conditions/blackboard_has_test.gd @@ -1,5 +1,5 @@ # GdUnit generated TestSuite -class_name BlackboardHasConditionTest +class_name BeehaveBlackboardHasConditionTest extends GdUnitTestSuite @warning_ignore('unused_parameter') @warning_ignore('return_value_discarded') @@ -11,9 +11,9 @@ const __blackboard = "res://addons/beehave/blackboard.gd" const KEY: String = "test_key" -var blackboard_has: BlackboardHasCondition +var blackboard_has: BeehaveBlackboardHasCondition var actor: Node -var blackboard: Blackboard +var blackboard: BeehaveBlackboard var runner: GdUnitSceneRunner diff --git a/test/randomized_composites/weighted_sampling/selector_random/selector_random_weights.gd b/test/randomized_composites/weighted_sampling/selector_random/selector_random_weights.gd index 9a63be0d..df5044f9 100644 --- a/test/randomized_composites/weighted_sampling/selector_random/selector_random_weights.gd +++ b/test/randomized_composites/weighted_sampling/selector_random/selector_random_weights.gd @@ -2,7 +2,7 @@ extends Node2D @onready var selector: SelectorRandomComposite = %SelectorRandom -@onready var blackboard: Blackboard = $Blackboard +@onready var blackboard: BeehaveBlackboard = $Blackboard @onready var label: Label = $Label # key: Node name | value: counter key diff --git a/test/unit_test_scene.gd b/test/unit_test_scene.gd index 72f00aba..5045ba4a 100644 --- a/test/unit_test_scene.gd +++ b/test/unit_test_scene.gd @@ -1,7 +1,7 @@ class_name UnitTestScene extends Node2D @onready var beehave_tree:BeehaveTree = %BeehaveTree -@onready var blackboard:BeehaveBlackboard = %Blackboard +@onready var blackboard:BeehaveBlackboard = %BeehaveBlackboard @onready var test_node = $Node2D @onready var count_up_action = %CountUpAction @onready var shared_action_1 = %SharedCountUpAction1 diff --git a/test/unit_test_scene.tscn b/test/unit_test_scene.tscn index 010cc27f..1743134e 100644 --- a/test/unit_test_scene.tscn +++ b/test/unit_test_scene.tscn @@ -1,105 +1,14 @@ -[gd_scene load_steps=8 format=3 uid="uid://diw3kjj050wdy"] +[gd_scene load_steps=2 format=3 uid="uid://bjyg8sehtnp6u"] -[ext_resource type="Script" path="res://addons/beehave/blackboard.gd" id="1_27ukk"] -[ext_resource type="Script" path="res://test/unit_test_scene.gd" id="1_embiv"] -[ext_resource type="Script" path="res://addons/beehave/nodes/beehave_tree.gd" id="2_phgmn"] -[ext_resource type="Script" path="res://addons/beehave/nodes/composites/sequence.gd" id="4_px6t4"] -[ext_resource type="Script" path="res://test/conditions/value_reached_condition.gd" id="5_rc0ra"] -[ext_resource type="Script" path="res://addons/beehave/nodes/decorators/inverter.gd" id="5_thhls"] -[ext_resource type="Script" path="res://test/actions/count_up_action.gd" id="6_brhwp"] +[ext_resource type="Script" path="res://test/unit_test_scene.gd" id="1_1kcjy"] [node name="UnitTestScene" type="Node2D"] -script = ExtResource("1_embiv") +script = ExtResource("1_1kcjy") -[node name="Blackboard" type="Node" parent="."] +[node name="BeehaveTree" type="BeehaveTree" parent="."] unique_name_in_owner = true -script = ExtResource("1_27ukk") -[node name="Node2D" type="Node2D" parent="."] - -[node name="BeehaveTree" type="Node" parent="Node2D" node_paths=PackedStringArray("blackboard")] -unique_name_in_owner = true -script = ExtResource("2_phgmn") -blackboard = NodePath("@Node@22048") - -[node name="SequenceComposite" type="Node" parent="Node2D/BeehaveTree"] -script = ExtResource("4_px6t4") - -[node name="ValueNotReached" type="Node" parent="Node2D/BeehaveTree/SequenceComposite"] -script = ExtResource("5_thhls") - -[node name="ValueReachedCondition" type="Node" parent="Node2D/BeehaveTree/SequenceComposite/ValueNotReached"] -script = ExtResource("5_rc0ra") - -[node name="CountUpAction" type="Node" parent="Node2D/BeehaveTree/SequenceComposite"] -unique_name_in_owner = true -script = ExtResource("6_brhwp") - -[node name="AnotherNode" type="Node2D" parent="."] - -[node name="BeehaveTree" type="Node" parent="AnotherNode" node_paths=PackedStringArray("blackboard")] -script = ExtResource("2_phgmn") -actor_node_path = NodePath("..") -blackboard = NodePath("../../Blackboard") - -[node name="SequenceComposite" type="Node" parent="AnotherNode/BeehaveTree"] -script = ExtResource("4_px6t4") - -[node name="ValueNotReached" type="Node" parent="AnotherNode/BeehaveTree/SequenceComposite"] -script = ExtResource("5_thhls") - -[node name="ValueReachedCondition" type="Node" parent="AnotherNode/BeehaveTree/SequenceComposite/ValueNotReached"] -script = ExtResource("5_rc0ra") -limit = 4 - -[node name="SharedCountUpAction1" type="Node" parent="AnotherNode/BeehaveTree/SequenceComposite"] +[node name="BeehaveBlackboard" type="BeehaveBlackboard" parent="."] unique_name_in_owner = true -script = ExtResource("6_brhwp") - -[node name="ThirdNode" type="Node2D" parent="."] - -[node name="BeehaveTree" type="Node" parent="ThirdNode" node_paths=PackedStringArray("blackboard")] -script = ExtResource("2_phgmn") -actor_node_path = NodePath("..") -blackboard = NodePath("../../Blackboard") - -[node name="SequenceComposite" type="Node" parent="ThirdNode/BeehaveTree"] -script = ExtResource("4_px6t4") - -[node name="ValueNotReached" type="Node" parent="ThirdNode/BeehaveTree/SequenceComposite"] -script = ExtResource("5_thhls") - -[node name="ValueReachedCondition" type="Node" parent="ThirdNode/BeehaveTree/SequenceComposite/ValueNotReached"] -script = ExtResource("5_rc0ra") -limit = 4 - -[node name="SharedCountUpAction2" type="Node" parent="ThirdNode/BeehaveTree/SequenceComposite"] -unique_name_in_owner = true -script = ExtResource("6_brhwp") - -[node name="EmptyTree" type="Node2D" parent="."] - -[node name="BeehaveTree" type="Node" parent="EmptyTree" node_paths=PackedStringArray("blackboard")] -script = ExtResource("2_phgmn") -blackboard = NodePath("@Node@22045") - -[node name="OnlyOneActionTree" type="Node2D" parent="."] - -[node name="BeehaveTree" type="Node" parent="OnlyOneActionTree" node_paths=PackedStringArray("blackboard")] -script = ExtResource("2_phgmn") -enabled = false -actor_node_path = NodePath("..") -blackboard = NodePath("@Node@22046") - -[node name="CountUpAction" type="Node" parent="OnlyOneActionTree/BeehaveTree"] -script = ExtResource("6_brhwp") - -[node name="DeactivatedTree" type="Node2D" parent="."] - -[node name="BeehaveTree" type="Node" parent="DeactivatedTree" node_paths=PackedStringArray("blackboard")] -script = ExtResource("2_phgmn") -actor_node_path = NodePath("..") -blackboard = NodePath("@Node@22047") -[node name="CountUpAction" type="Node" parent="DeactivatedTree/BeehaveTree"] -script = ExtResource("6_brhwp") +[node name="TestNode" type="Node2D" parent="."]