From 9cba437ee2f0d1153033d9b03d2514a8a53a8a22 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sat, 18 Mar 2023 18:02:07 +0100 Subject: [PATCH] Added autoloader and welcome() function --- autoload.gd | 25 +++++++++++++++++++++++++ core.gd | 8 ++++++++ coreloader.gd | 3 +++ 3 files changed, 36 insertions(+) create mode 100644 autoload.gd diff --git a/autoload.gd b/autoload.gd new file mode 100644 index 0000000..d7a6a20 --- /dev/null +++ b/autoload.gd @@ -0,0 +1,25 @@ +# autoload.gd +# CORE Autoloader +# +# This file is part of StarOpenSource CORE (SOSCORE) +# Made by the StarOpenSource Project and Contributers +# Licensed under GNU GPLv3 +extends Node + +func singleton(singleton_name:String,singleton_path:String) -> void: + var node = Control.new() + node.name = singleton_name + node.set_script(ResourceLoader.load(singleton_path)) + get_tree().root.add_child(node) + +func preset(plugin_id:String) -> bool: + var node = Control.new() + match(plugin_id): + "dialogmgr": + node.name = "DialogueManager" + node.set_script(ResourceLoader.load("res://addons/dialogue_manager/dialogue_manager.gd")) + _: + Logger.error("autoload","Failed adding preset \"" + plugin_id + "\": Invalid preset.") + return false + get_tree().root.add_child(node) + return true diff --git a/core.gd b/core.gd index 2134343..09adce7 100644 --- a/core.gd +++ b/core.gd @@ -6,10 +6,12 @@ # Licensed under GNU GPLv3 extends Node +const version = "git-develop" var locked = false var config = null var wmgr = null var smgr = null +var autoload = null func attach(type:String,component:Script) -> void: if locked: @@ -28,6 +30,9 @@ func attach(type:String,component:Script) -> void: "smgr": add_child(comp) smgr = comp + "autoload": + add_child(comp) + autoload = comp _: Logger.error("core","Failed attaching " + type + " to CORE: Invalid component") comp.free() @@ -37,3 +42,6 @@ func attach(type:String,component:Script) -> void: func lock() -> void: locked = true Logger.diag("core","CORE is now locked. No new attachments can be made.") + +func welcome() -> void: + Logger.info("core","CORE " + version + " welcomes you!It seems like everything is working :)") diff --git a/coreloader.gd b/coreloader.gd index 45fc90d..5a890e8 100644 --- a/coreloader.gd +++ b/coreloader.gd @@ -15,6 +15,7 @@ func _ready() -> void: var scr_core = ResourceLoader.load("res://CORE/core.gd") var scr_wmgr = ResourceLoader.load("res://CORE/wmgr.gd") var scr_smgr = ResourceLoader.load("res://CORE/smgr.gd") + var scr_autoload = ResourceLoader.load("res://CORE/autoload.gd") Logger.info("coreloader","Constructing CORE") var core = Control.new() core.name = "core" @@ -29,6 +30,8 @@ func _ready() -> void: core.attach("wmgr",scr_wmgr) Logger.info("coreloader","Attaching smgr to CORE") core.attach("smgr",scr_smgr) + Logger.info("coreloader","Attaching autoload to CORE") + core.attach("autoload",scr_autoload) Logger.info("coreloader","Locking CORE") core.lock() Logger.info("coreloader","Waiting for CORE to fully initialize")