Added autoloader and welcome() function

This commit is contained in:
JeremyStar™ 2023-03-18 18:02:07 +01:00
parent c988261688
commit 9cba437ee2
3 changed files with 36 additions and 0 deletions

25
autoload.gd Normal file
View file

@ -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

View file

@ -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!<nl>It seems like everything is working :)")

View file

@ -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")