91 lines
2.2 KiB
GDScript3
91 lines
2.2 KiB
GDScript3
|
class_name Base
|
||
|
extends Node
|
||
|
## A base addon
|
||
|
##
|
||
|
## A base addon for shared functionality between all other addons
|
||
|
|
||
|
var _logger
|
||
|
var _data
|
||
|
var _persister
|
||
|
var _triggerer
|
||
|
var _information = {
|
||
|
"log_category": "???",
|
||
|
"accent": "#000000",
|
||
|
"icon": "res://components/Cursor/mouse-pointer-2.svg"
|
||
|
}
|
||
|
|
||
|
var CORE_NODES = {
|
||
|
"Logger": {
|
||
|
"property": "_logger"
|
||
|
},
|
||
|
"Data": {
|
||
|
"property": "_data"
|
||
|
},
|
||
|
"Triggerer": {
|
||
|
"property": "_triggerer",
|
||
|
},
|
||
|
"Persister": {
|
||
|
"property": "_persister",
|
||
|
"connections": {"data_persisted": "_on_data_persisted"}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
func _ready():
|
||
|
for node in CORE_NODES:
|
||
|
# Prevent circular references
|
||
|
if name == node:
|
||
|
break
|
||
|
|
||
|
# Connect up core nodes
|
||
|
var node_value = CORE_NODES[node]
|
||
|
|
||
|
if get_tree().root.has_node(node):
|
||
|
set(node_value.property, get_tree().root.get_node(node))
|
||
|
var property = get(node_value.property)
|
||
|
|
||
|
if node_value.has("connections"):
|
||
|
var connections = node_value.connections
|
||
|
|
||
|
for connection in connections:
|
||
|
var connection_callback = connections[connection]
|
||
|
|
||
|
property.get(connection).connect(get(connection_callback))
|
||
|
|
||
|
if _data and _data.components.has(name):
|
||
|
_information = _data.components[name].information
|
||
|
|
||
|
if _information.has("triggers"):
|
||
|
for trigger in _information.triggers:
|
||
|
_triggerer.listen(trigger, Callable(self, _information.triggers[trigger]))
|
||
|
|
||
|
if has_method("_prespawned"):
|
||
|
call("_prespawned")
|
||
|
|
||
|
_info("%s is active" % [name])
|
||
|
|
||
|
if has_method("_spawned"):
|
||
|
call("_spawned")
|
||
|
|
||
|
_info("%s is ready" % [name])
|
||
|
|
||
|
|
||
|
func _on_data_persisted(key: String, value, category: PersisterEnums.Scope):
|
||
|
pass
|
||
|
|
||
|
|
||
|
func _debug(message: String):
|
||
|
if _logger: _logger.debug(message, { "category": _information.log_category, "image": _information.icon, "color": _information.accent })
|
||
|
|
||
|
|
||
|
func _info(message: String):
|
||
|
if _logger: _logger.info(message, { "category": _information.log_category, "image": _information.icon, "color": _information.accent })
|
||
|
|
||
|
|
||
|
func _warn(message: String):
|
||
|
if _logger: _logger.warn(message, { "category": _information.log_category, "image": _information.icon, "color": _information.accent })
|
||
|
|
||
|
|
||
|
func _error(message: String):
|
||
|
if _logger: _logger.error(message, { "category": _information.log_category, "image": _information.icon, "color": _information.accent })
|