2024-01-23 09:33:57 +00:00
|
|
|
/**
|
2024-01-23 19:02:23 +00:00
|
|
|
* blackboard_plan.h
|
2024-01-23 09:33:57 +00:00
|
|
|
* =============================================================================
|
|
|
|
* Copyright 2021-2024 Serhii Snitsaruk
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
|
|
|
|
2024-01-23 19:02:23 +00:00
|
|
|
#ifndef BLACKBOARD_PLAN_H
|
|
|
|
#define BLACKBOARD_PLAN_H
|
2024-01-23 09:33:57 +00:00
|
|
|
|
|
|
|
#include "core/io/resource.h"
|
|
|
|
|
|
|
|
#include "bb_variable.h"
|
|
|
|
#include "blackboard.h"
|
|
|
|
|
2024-01-23 19:02:23 +00:00
|
|
|
class BlackboardPlan : public Resource {
|
|
|
|
GDCLASS(BlackboardPlan, Resource);
|
2024-01-23 09:33:57 +00:00
|
|
|
|
|
|
|
private:
|
2024-01-23 11:05:54 +00:00
|
|
|
HashMap<String, BBVariable> data;
|
2024-01-23 16:54:20 +00:00
|
|
|
|
2024-01-23 19:02:23 +00:00
|
|
|
// When base is not null, the plan is considered to be derived from the base plan.
|
2024-01-24 22:11:09 +00:00
|
|
|
// A derived plan can only have variables that exist in the base plan,
|
|
|
|
// and only the values can be different in those variables.
|
2024-01-23 19:02:23 +00:00
|
|
|
Ref<BlackboardPlan> base;
|
2024-01-23 09:33:57 +00:00
|
|
|
|
2024-01-23 14:31:56 +00:00
|
|
|
protected:
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2024-01-23 16:54:20 +00:00
|
|
|
bool _property_can_revert(const StringName &p_name) const;
|
|
|
|
bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
|
2024-01-23 14:31:56 +00:00
|
|
|
|
2024-01-23 09:33:57 +00:00
|
|
|
public:
|
2024-01-23 19:02:23 +00:00
|
|
|
void set_base_plan(const Ref<BlackboardPlan> &p_base);
|
|
|
|
Ref<BlackboardPlan> get_base_plan() const { return base; }
|
2024-01-23 14:31:56 +00:00
|
|
|
|
2024-01-23 09:33:57 +00:00
|
|
|
void set_value(const String &p_name, const Variant &p_value);
|
|
|
|
Variant get_value(const String &p_name) const;
|
2024-01-24 22:11:09 +00:00
|
|
|
|
2024-01-23 09:33:57 +00:00
|
|
|
void add_var(const String &p_name, const BBVariable &p_var);
|
|
|
|
void remove_var(const String &p_name);
|
|
|
|
BBVariable get_var(const String &p_name);
|
2024-01-24 22:11:09 +00:00
|
|
|
Pair<String, BBVariable> get_var_by_index(int p_index);
|
|
|
|
bool has_var(const String &p_name) { return data.has(p_name); }
|
2024-01-23 11:05:54 +00:00
|
|
|
bool is_empty() const { return data.is_empty(); }
|
2024-01-24 22:11:09 +00:00
|
|
|
int get_var_count() const { return data.size(); }
|
|
|
|
|
|
|
|
PackedStringArray list_vars() const;
|
|
|
|
String get_var_name(const BBVariable &p_var) const;
|
|
|
|
void rename_var(const String &p_name, const String &p_new_name);
|
|
|
|
void swap_vars(int idx_a, int idx_b);
|
2024-01-23 09:33:57 +00:00
|
|
|
|
2024-01-23 19:02:23 +00:00
|
|
|
void sync_with_base_plan();
|
2024-01-23 16:54:20 +00:00
|
|
|
bool is_derived() { return base.is_valid(); }
|
|
|
|
|
2024-01-23 11:05:54 +00:00
|
|
|
Ref<Blackboard> create_blackboard();
|
|
|
|
void populate_blackboard(const Ref<Blackboard> &p_blackboard, bool overwrite);
|
2024-01-23 09:33:57 +00:00
|
|
|
|
2024-01-23 19:02:23 +00:00
|
|
|
BlackboardPlan();
|
2024-01-23 09:33:57 +00:00
|
|
|
};
|
|
|
|
|
2024-01-23 19:02:23 +00:00
|
|
|
#endif // BLACKBOARD_PLAN_H
|