diff --git a/addons/beehave/blackboard.gd b/addons/beehave/blackboard.gd index c6bb26f5..326553ef 100644 --- a/addons/beehave/blackboard.gd +++ b/addons/beehave/blackboard.gd @@ -1,24 +1,25 @@ -extends Object -class_name Blackboard -var blackboard = {} +class_name Blackboard extends RefCounted -func set(key, value, blackboard_name = 'default'): +var blackboard: Dictionary = {} + + +func set_value(key: Variant, value: Variant, blackboard_name: String = 'default') -> void: if not blackboard.has(blackboard_name): blackboard[blackboard_name] = {} blackboard[blackboard_name][key] = value -func get(key, default_value = null, blackboard_name = 'default'): - if has(key, blackboard_name): +func get_value(key: Variant, default_value: Variant = null, blackboard_name: String = 'default') -> Variant: + if has_value(key, blackboard_name): return blackboard[blackboard_name].get(key, default_value) return default_value -func has(key, blackboard_name = 'default'): +func has_value(key: Variant, blackboard_name: String = 'default') -> bool: return blackboard.has(blackboard_name) and blackboard[blackboard_name].has(key) and blackboard[blackboard_name][key] != null -func erase(key, blackboard_name = 'default'): +func erase_value(key: Variant, blackboard_name: String = 'default') -> void: if blackboard.has(blackboard_name): blackboard[blackboard_name][key] = null diff --git a/addons/beehave/nodes/beehave_root.gd b/addons/beehave/nodes/beehave_root.gd index 954323c2..8702a6b3 100644 --- a/addons/beehave/nodes/beehave_root.gd +++ b/addons/beehave/nodes/beehave_root.gd @@ -1,7 +1,6 @@ class_name BeehaveRoot extends BeehaveTree @icon("../icons/tree.svg") -var Blackboard = load("res://addons/beehave/blackboard.gd") const SUCCESS = 0 const FAILURE = 1 const RUNNING = 2 @@ -12,7 +11,7 @@ const RUNNING = 2 var actor : Node -@onready var blackboard = Blackboard.new() +@onready var blackboard: Blackboard = Blackboard.new() func _ready(): if self.get_child_count() != 1: @@ -27,26 +26,26 @@ func _ready(): set_physics_process(enabled) func _physics_process(delta): - blackboard.set("delta", delta) + blackboard.set_value("delta", delta) var status = self.get_child(0).tick(actor, blackboard) if status != RUNNING: - blackboard.set("running_action", null) + blackboard.set_value("running_action", null) func get_running_action(): - if blackboard.has("running_action"): - return blackboard.get("running_action") + if blackboard.has_value("running_action"): + return blackboard.get_value("running_action") return null func get_last_condition(): - if blackboard.has("last_condition"): - return blackboard.get("last_condition") + if blackboard.has_value("last_condition"): + return blackboard.get_value("last_condition") return null func get_last_condition_status(): - if blackboard.has("last_condition_status"): - var status = blackboard.get("last_condition_status") + if blackboard.has_value("last_condition_status"): + var status = blackboard.get_value("last_condition_status") if status == SUCCESS: return "SUCCESS" elif status == FAILURE: diff --git a/addons/beehave/nodes/composites/selector.gd b/addons/beehave/nodes/composites/selector.gd index 56a55eed..178d3dfe 100644 --- a/addons/beehave/nodes/composites/selector.gd +++ b/addons/beehave/nodes/composites/selector.gd @@ -8,12 +8,12 @@ func tick(actor, blackboard): var response = c.tick(actor, blackboard) if c is ConditionLeaf: - blackboard.set("last_condition", c) - blackboard.set("last_condition_status", response) + blackboard.set_value("last_condition", c) + blackboard.set_value("last_condition_status", response) if response != FAILURE: if c is ActionLeaf and response == RUNNING: - blackboard.set("running_action", c) + blackboard.set_value("running_action", c) return response return FAILURE diff --git a/addons/beehave/nodes/composites/selector_star.gd b/addons/beehave/nodes/composites/selector_star.gd index d24da2d3..c82f7e34 100644 --- a/addons/beehave/nodes/composites/selector_star.gd +++ b/addons/beehave/nodes/composites/selector_star.gd @@ -17,12 +17,12 @@ func tick(actor, blackboard): var response = c.tick(actor, blackboard) if c is ConditionLeaf: - blackboard.set("last_condition", c) - blackboard.set("last_condition_status", response) + blackboard.set_value("last_condition", c) + blackboard.set_value("last_condition_status", response) if response != FAILURE: if c is ActionLeaf and response == RUNNING: - blackboard.set("running_action", c) + blackboard.set_value("running_action", c) if response == SUCCESS: last_execution_index = 0 return response diff --git a/addons/beehave/nodes/composites/sequence.gd b/addons/beehave/nodes/composites/sequence.gd index e429ea09..e9cb1520 100644 --- a/addons/beehave/nodes/composites/sequence.gd +++ b/addons/beehave/nodes/composites/sequence.gd @@ -8,12 +8,12 @@ func tick(actor, blackboard): var response = c.tick(actor, blackboard) if c is ConditionLeaf: - blackboard.set("last_condition", c) - blackboard.set("last_condition_status", response) + blackboard.set_value("last_condition", c) + blackboard.set_value("last_condition_status", response) if response != SUCCESS: if c is ActionLeaf and response == RUNNING: - blackboard.set("running_action", c) + blackboard.set_value("running_action", c) return response return SUCCESS diff --git a/addons/beehave/nodes/composites/sequence_star.gd b/addons/beehave/nodes/composites/sequence_star.gd index ff7d67d0..53e8d1a0 100644 --- a/addons/beehave/nodes/composites/sequence_star.gd +++ b/addons/beehave/nodes/composites/sequence_star.gd @@ -16,14 +16,14 @@ func tick(actor, blackboard): var response = c.tick(actor, blackboard) if c is ConditionLeaf: - blackboard.set("last_condition", c) - blackboard.set("last_condition_status", response) + blackboard.set_value("last_condition", c) + blackboard.set_value("last_condition_status", response) if response != SUCCESS: if response == FAILURE: successful_index = 0 if c is ActionLeaf and response == RUNNING: - blackboard.set("running_action", c) + blackboard.set_value("running_action", c) return response else: successful_index += 1 diff --git a/addons/beehave/nodes/decorators/inverter.gd b/addons/beehave/nodes/decorators/inverter.gd index 78bfaaf8..51a5a854 100644 --- a/addons/beehave/nodes/decorators/inverter.gd +++ b/addons/beehave/nodes/decorators/inverter.gd @@ -13,5 +13,5 @@ func tick(action, blackboard): return SUCCESS if c is Leaf and response == RUNNING: - blackboard.set("running_action", c) + blackboard.set_value("running_action", c) return RUNNING diff --git a/addons/beehave/nodes/decorators/limiter.gd b/addons/beehave/nodes/decorators/limiter.gd index 07f64b46..8c3e9f5f 100644 --- a/addons/beehave/nodes/decorators/limiter.gd +++ b/addons/beehave/nodes/decorators/limiter.gd @@ -8,13 +8,13 @@ class_name LimiterDecorator @export var max_count : float = 0 func tick(actor, blackboard): - var current_count = blackboard.get(cache_key) + var current_count = blackboard.get_value(cache_key) if current_count == null: current_count = 0 if current_count <= max_count: - blackboard.set(cache_key, current_count + 1) + blackboard.set_value(cache_key, current_count + 1) return self.get_child(0).tick(actor, blackboard) else: return FAILED diff --git a/project.godot b/project.godot index 83081195..e4acb3a0 100644 --- a/project.godot +++ b/project.godot @@ -39,7 +39,7 @@ _global_script_classes=[{ "language": &"GDScript", "path": "res://addons/beehave/nodes/beehave_tree.gd" }, { -"base": "Object", +"base": "RefCounted", "class": &"Blackboard", "language": &"GDScript", "path": "res://addons/beehave/blackboard.gd" @@ -119,6 +119,7 @@ _global_script_class_icons={ config/name="Beehave" config/features=PackedStringArray("4.0") boot_splash/image="res://splash.png" +boot_splash/fullsize=false config/icon="res://icon.png" [editor_plugins]