2023-05-29 20:46:47 +02:00
|
|
|
# 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)
|
|
|
|
|
2023-07-07 10:58:49 +02:00
|
|
|
# No set return type here as it can return literally everything.
|
2023-05-29 20:46:47 +02:00
|
|
|
func getres(resname:String):
|
|
|
|
if !resources.has(resname):
|
|
|
|
return null
|
|
|
|
return resources[resname]
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
core.setready()
|