47 lines
1.2 KiB
GDScript3
47 lines
1.2 KiB
GDScript3
|
# 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)
|
||
|
|
||
|
func getres(resname:String):
|
||
|
if !resources.has(resname):
|
||
|
return null
|
||
|
return resources[resname]
|
||
|
|
||
|
func _ready() -> void:
|
||
|
core.setready()
|