CORE/resmgr.gd
JeremyStarTM b57d00e9cd Many improvements (see commit description)
Added more things to roadmap, removed autoload singleton check, added support for Godot 4.1, all startup messages now use Logger.diag() instead of Logger.info() (making them disappear but can be shown if needed), removed autoload.gd, fixes syntax.
2023-07-07 10:58:49 +02:00

47 lines
1.3 KiB
GDScript

# 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()