Created
December 5, 2024 18:04
-
-
Save MarianoGnu/f979ab687dafd9b67d0ee7f282557740 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tool | |
class_name EnemyEntity extends CharacterBody2D | |
@export_custom(PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR) var _ai_cache: Dictionary | |
@onready var behaviour_tree_player: BTPlayer = get_node_or_null("BTPlayer") | |
@onready var blackboard_plan: BlackboardPlan = \ | |
null if behaviour_tree_player == null else behaviour_tree_player.blackboard_plan | |
# more stuff | |
func _ready() -> void: | |
if is_instance_valid(blackboard_plan): | |
# Initialize forwarded properties from _ai_cache | |
for property in _ai_cache: | |
if _ai_cache[property] is NodePath: | |
blackboard_plan.set(property, get_node(_ai_cache[property])) | |
else: | |
blackboard_plan.set(property, _ai_cache[property]) | |
if Engine.is_editor_hint(): | |
return | |
# more stuff | |
func _get_property_list() -> Array[Dictionary]: | |
var ret_properties: Array[Dictionary] = [] | |
if blackboard_plan != null: | |
const PROPERTY_BLACKLIST: Array[String] = ["prefetch_nodepath_vars"] | |
var forwarding: bool = false | |
for property: Dictionary in blackboard_plan.get_property_list(): | |
if property.usage == PROPERTY_USAGE_CATEGORY: | |
if property.name == "BlackboardPlan": | |
forwarding = true | |
else: | |
forwarding = false | |
continue | |
if forwarding: | |
if property.name in PROPERTY_BLACKLIST: | |
continue | |
property.name = "ai_properties/" + property.name | |
ret_properties.append(property) | |
return ret_properties | |
func _get(property: StringName) -> Variant: | |
if not is_instance_valid(blackboard_plan): | |
return null | |
if property.begins_with("ai_properties/"): | |
return blackboard_plan.get(property.substr(14)) | |
return null | |
func _set(property: StringName, value: Variant) -> bool: | |
if not is_instance_valid(blackboard_plan): | |
return false | |
if property.begins_with("ai_properties/"): | |
blackboard_plan.set(property.substr(14), value) | |
if value is Node: | |
_ai_cache[property.substr(14)] = get_path_to(value) | |
else: | |
_ai_cache[property.substr(14)] = value | |
return true | |
return false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment