dino_tomato/vfs/vfs_loaders.gd

72 lines
1.8 KiB
GDScript

static func validate_loader(loader:Callable)->bool:
if loader.get_unbound_arguments_count() != 1:
push_error("Cannot add loader for %s as only one String arg can be taken.")
return false
elif loader.get_bound_arguments()[0] is not String \
or loader.get_bound_arguments()[0] is not StringName:
push_error("Cannot add loader for %s as only one String arg can be taken.")
return false
return true
static func load_bin(buffer:PackedByteArray)->PackedByteArray: return buffer
static func load_png(buffer:PackedByteArray)->Image:
var img := Image.new()
img.load_png_from_buffer(buffer)
return img
static func load_jpg(buffer:PackedByteArray)->Image:
var img := Image.new()
img.load_jpg_from_buffer(buffer)
return img
static func load_mp3(buffer:PackedByteArray)->AudioStreamMP3:
var sfx := AudioStreamMP3.new()
sfx.data = buffer
return sfx
static func load_ogg(buffer:PackedByteArray)->AudioStreamOggVorbis:
return AudioStreamOggVorbis.load_from_buffer(buffer)
static func load_txt(buffer:PackedByteArray)->String:
var txt:String = buffer.get_string_from_utf8()
return txt
static func load_wav(buffer:PackedByteArray)->AudioStreamWAV:
var sfx := AudioStreamWAV.new()
sfx.load_from_buffer(buffer)
return sfx
# can't use CONST since Callables are technically instanced dynamically
static var DEFAULT_SUPPORTED_FILES:Dictionary[String,Callable] = {
"bin": load_bin,
"txt": load_txt,
"png": load_png,
"jpg": load_jpg,
"jpeg": load_jpg,
"mp3": load_mp3,
"ogg": load_ogg,
"wav": load_wav,
}
static var DATA_FILES:Dictionary[String,Callable] = {
"bin": load_bin,
"txt": load_txt,
}
static var IMAGE_FILES:Dictionary[String,Callable] = {
"png": load_png,
"jpg": load_jpg,
"jpeg": load_jpg,
}
static var AUDIO_FILES:Dictionary[String,Callable] = {
"mp3": load_mp3,
"ogg": load_ogg,
"wav": load_wav,
}