one component to rule them all

This commit is contained in:
2023-10-05 22:41:54 +02:00
parent dffda5cce3
commit 2787adb648
3 changed files with 33 additions and 0 deletions

View File

@@ -12,4 +12,5 @@ var texture: Texture = null
func _init(p_item: ESCItem) -> void:
global_id = p_item.global_id
texture = p_item._get_inventory_texture()
p_item.register_components()

View File

@@ -68,6 +68,8 @@ func _ready():
##outline.offset = Vector2(1,1)
collision.add_child(outline)
outline.hide()
register_components()
func _process(_delta) -> void:
if(is_interactive == false):
@@ -93,3 +95,19 @@ func _input(event):
elif (event.is_action_released("ui_show_hints")):
if(!active):
highlight(false)
func has_component(key: String)->bool:
return components.has(key)
func get_component(key: String):
if(has_component(key)):
return components[key]
return null
func register_components():
for child in get_children():
if(child is ESCItemComponent):
child = child as ESCItemComponent
components[child.get_component_type()] = child
child.register(custom_data)

View File

@@ -0,0 +1,14 @@
extends Node
class_name ESCItemComponent
var _custom_data: Dictionary
func get_global_id():
return self.get_parent().global_id
func get_component_type():
pass
func register(custom_data: Dictionary):
pass