39 lines
1.1 KiB
GDScript3
39 lines
1.1 KiB
GDScript3
|
extends Object
|
||
|
class_name AssetLoader
|
||
|
|
||
|
const DEFAULT_ASSETS_PATH = "res://mods"
|
||
|
|
||
|
## Path to the mods folder : [param res://mods] by default
|
||
|
## [br]
|
||
|
## (is not a const but should be treated as such, so the uppercase)
|
||
|
var ASSETS_PATH
|
||
|
|
||
|
var critical_error := false
|
||
|
|
||
|
|
||
|
func _init() -> void:
|
||
|
ASSETS_PATH = ProjectSettings.get_setting("game/mods/mod_path", DEFAULT_ASSETS_PATH)
|
||
|
var dir := DirAccess.open(ASSETS_PATH)
|
||
|
if not dir:
|
||
|
push_error("AssetLoader: Mods folder not found at '%s'" % ASSETS_PATH)
|
||
|
_show_error_popup("Mods folder not found at '%s'" % ASSETS_PATH)
|
||
|
critical_error = true
|
||
|
return
|
||
|
var mod_folders := dir.get_directories()
|
||
|
|
||
|
if mod_folders.is_empty():
|
||
|
push_error("AssetLoader: Mods folder '%s' is empty — no mods to load." % ASSETS_PATH)
|
||
|
_show_error_popup("Mods folder '%s' is empty — no mods to load." % ASSETS_PATH)
|
||
|
critical_error = true
|
||
|
return
|
||
|
|
||
|
|
||
|
## This will show a native MessageBox on Windows,
|
||
|
## a native dialog on macOS, and GTK/QT dialog on Linux.
|
||
|
func _show_error_popup(message: String) -> void:
|
||
|
OS.alert("AssetLoader:"+message, "AssetLoader:Error")
|
||
|
|
||
|
|
||
|
func load_all():
|
||
|
pass
|