CORE/resmgr.gd

48 lines
1.3 KiB
GDScript3
Raw Normal View History

# 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 loadres(resname:String,respath:String,replace:bool = false) -> void:
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 !resources.has(resname):
Logger.error("resmgr","Unloading \"" + resname + "\" failed: Resource is not present")
return
resources.erase(resname)
func loadbatch(batch:Dictionary) -> void:
if batch == {}:
Logger.error("resmgr","Loading a batch failed: Batch is empty")
for i in batch:
loadres(i,batch[i])
func unloadbatch(batch:Array) -> void:
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 !resources.has(resname):
return null
return resources[resname]
func _ready() -> void:
core.setready()