2023-07-21 09:50:06 +00:00
|
|
|
/**
|
|
|
|
* blackboard.h
|
|
|
|
* =============================================================================
|
2024-03-03 22:38:52 +00:00
|
|
|
* Copyright 2021-2024 Serhii Snitsaruk
|
2023-07-21 09:50:06 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style
|
|
|
|
* license that can be found in the LICENSE file or at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
2022-09-08 13:56:51 +00:00
|
|
|
|
|
|
|
#ifndef BLACKBOARD_H
|
|
|
|
#define BLACKBOARD_H
|
|
|
|
|
2024-01-23 11:05:54 +00:00
|
|
|
#include "bb_variable.h"
|
2024-08-15 20:15:53 +00:00
|
|
|
#include "core/typedefs.h"
|
2024-01-23 11:05:54 +00:00
|
|
|
|
2024-01-06 20:04:34 +00:00
|
|
|
#ifdef LIMBOAI_MODULE
|
2022-12-15 07:26:52 +00:00
|
|
|
#include "core/object/object.h"
|
|
|
|
#include "core/object/ref_counted.h"
|
|
|
|
#include "core/variant/variant.h"
|
|
|
|
#include "scene/main/node.h"
|
2024-01-06 20:04:34 +00:00
|
|
|
#endif // LIMBOAI_MODULE
|
|
|
|
|
|
|
|
#ifdef LIMBOAI_GDEXTENSION
|
|
|
|
#include <godot_cpp/classes/node.hpp>
|
|
|
|
#include <godot_cpp/classes/ref.hpp>
|
|
|
|
#include <godot_cpp/classes/ref_counted.hpp>
|
|
|
|
#include <godot_cpp/core/object.hpp>
|
2024-01-25 16:59:38 +00:00
|
|
|
#include <godot_cpp/templates/hash_map.hpp>
|
2024-01-06 20:04:34 +00:00
|
|
|
using namespace godot;
|
|
|
|
#endif // LIMBOAI_GDEXTENSION
|
2022-12-15 07:26:52 +00:00
|
|
|
|
|
|
|
class Blackboard : public RefCounted {
|
|
|
|
GDCLASS(Blackboard, RefCounted);
|
2022-09-08 13:56:51 +00:00
|
|
|
|
|
|
|
private:
|
2024-03-03 22:38:52 +00:00
|
|
|
HashMap<StringName, BBVariable> data;
|
2022-09-08 13:56:51 +00:00
|
|
|
Ref<Blackboard> parent;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2024-01-25 13:27:14 +00:00
|
|
|
void set_parent(const Ref<Blackboard> &p_blackboard) { parent = p_blackboard; }
|
|
|
|
Ref<Blackboard> get_parent() const { return parent; }
|
2022-09-08 13:56:51 +00:00
|
|
|
|
2022-11-23 17:02:46 +00:00
|
|
|
Ref<Blackboard> top() const;
|
|
|
|
|
2024-06-01 08:53:56 +00:00
|
|
|
Variant get_var(const StringName &p_name, const Variant &p_default = Variant(), bool p_complain = true) const;
|
2024-03-03 22:38:52 +00:00
|
|
|
void set_var(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool has_var(const StringName &p_name) const;
|
2024-08-15 20:15:53 +00:00
|
|
|
_FORCE_INLINE_ bool has_local_var(const StringName &p_name) const { return data.has(p_name); }
|
2024-03-03 22:38:52 +00:00
|
|
|
void erase_var(const StringName &p_name);
|
2024-05-31 07:56:45 +00:00
|
|
|
void clear() { data.clear(); }
|
|
|
|
TypedArray<StringName> list_vars() const;
|
|
|
|
|
|
|
|
Dictionary get_vars_as_dict() const;
|
|
|
|
void populate_from_dict(const Dictionary &p_dictionary);
|
2024-01-23 11:05:54 +00:00
|
|
|
|
2024-04-09 09:34:22 +00:00
|
|
|
void bind_var_to_property(const StringName &p_name, Object *p_object, const StringName &p_property, bool p_create = false);
|
2024-03-03 22:38:52 +00:00
|
|
|
void unbind_var(const StringName &p_name);
|
2024-01-27 15:38:58 +00:00
|
|
|
|
2024-03-11 23:30:38 +00:00
|
|
|
void assign_var(const StringName &p_name, const BBVariable &p_var);
|
2022-12-16 11:13:03 +00:00
|
|
|
|
2024-04-09 09:34:22 +00:00
|
|
|
void link_var(const StringName &p_name, const Ref<Blackboard> &p_target_blackboard, const StringName &p_target_var, bool p_create = false);
|
2022-09-08 13:56:51 +00:00
|
|
|
};
|
|
|
|
|
2024-01-23 11:05:54 +00:00
|
|
|
#endif // BLACKBOARD_H
|