# resmgr.gd # Resource Manager # # This file is part of StarOpenSource CORE (SOSCORE) # Made by the StarOpenSource Project and Contributers # Licensed under GNU GPLv3 extends Node @onready var core = get_node(NodePath("/root/core")) var resources = {} func initialize() -> void: if core.protection_mode: return core.setready() func loadres(resname:String,respath:String,replace:bool = false) -> void: if core.protection_mode: return if resources.has(resname): if replace: resources.erase(resname) else: Logger.error("resmgr","Loading \"" + resname + "\" failed: Resource is loaded already") return resources.merge({resname:ResourceLoader.load(respath)}) func unloadres(resname:String) -> void: if core.protection_mode: return if !resources.has(resname): Logger.error("resmgr","Unloading \"" + resname + "\" failed: Resource is not present") return resources.erase(resname) func loadbatch(batch:Dictionary,replace:bool = false) -> void: if core.protection_mode: return if batch == {}: Logger.error("resmgr","Loading a batch failed: Batch is empty") for i in batch: loadres(i,batch[i],replace) func unloadbatch(batch:Array) -> void: if core.protection_mode: return if batch == []: Logger.error("resmgr","Unloading a batch failed: Batch is empty") for i in batch: unloadres(i) # No set return type here as it can return literally everything. func getres(resname:String): if core.protection_mode: return null if !resources.has(resname): return null return resources[resname]