diff --git a/libs/bt/include/psemek/bt/condition.hpp b/libs/bt/include/psemek/bt/condition.hpp index 8e01d211..f1003e6f 100644 --- a/libs/bt/include/psemek/bt/condition.hpp +++ b/libs/bt/include/psemek/bt/condition.hpp @@ -5,11 +5,11 @@ namespace psemek::bt { - template - struct condition; + template + struct condition_node; - template - struct condition> + template + struct condition_node, ConditionFn> : node> { using tree_type = tree; @@ -17,12 +17,23 @@ namespace psemek::bt using typename node_type::finished; using typename node_type::status; + condition_node(ConditionFn && condition_fn) + : condition_fn_(std::move(condition_fn)) + {} + status update(Time, Args ... args) override { - return finished{check(args...)}; + return finished{condition_fn_(args...)}; } - virtual bool check(Args ... args) = 0; + private: + ConditionFn condition_fn_; }; + template + node_ptr condition(ConditionFn && condition_fn) + { + return std::make_unique>(std::move(condition_fn)); + } + }