dino_tomato/asset_pack.gd

35 lines
1.0 KiB
GDScript

class_name AssetPack extends Object
const ASSET_DIR := "./assets.zip"
static func load_sfx()->Dictionary[StringName, AudioStream]:
var dict := load_user_assets(
VFileAccess.IMPORTS.AUDIO_FILES, ["ogg","mp3","wav"])
var ugh:Dictionary[StringName,AudioStream]
ugh.assign(dict)
return ugh
static func load_gfx()->Dictionary[StringName, Texture2D]:
var images:Dictionary = load_user_assets(
VFileAccess.IMPORTS.IMAGE_FILES, ["png","jpg","jpeg"])
var output:Dictionary[StringName, Texture2D] = {}
for id:StringName in images.keys():
output[id] = ImageTexture.create_from_image(images[id])
return output
static func load_user_assets(
formats_supported:Dictionary[String,Callable],
formats:Array[String]
)->Dictionary:
var vfs := VFileAccess.CREATE.create_readonly_zip_access(ASSET_DIR, false, formats_supported)
var load_asset := vfs.load_any_supported.bind(formats)
var output:Dictionary = {
&"rest": load_asset.call("rest"),
&"longrest": load_asset.call("longrest"),
&"run": load_asset.call("run")
}
vfs.close()
return output