modloader prototype

This commit is contained in:
Lucas 2025-07-31 19:34:57 +02:00
parent 4adff6e9b8
commit 4218e2099d
No known key found for this signature in database
5 changed files with 66 additions and 0 deletions

View file

@ -0,0 +1,38 @@
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

View file

@ -0,0 +1 @@
uid://qkh5uvr4st7i

25
autoloads/bootstrap.gd Normal file
View file

@ -0,0 +1,25 @@
extends Node
## Should always be at the top of autoloads
func _ready() -> void:
var loader := AssetLoader.new()
# If there was a critical error, quit immediately
if loader.critical_error:
Engine.get_main_loop().quit(1)
return
loader.load_all() # TODO: Making it async
# Otherwise, continue startup
_start_game()
## This will show a native MessageBox on Windows,
## a native dialog on macOS, and GTK/QT dialog on Linux.
func _show_error_popup(context:String, message: String) -> void:
OS.alert(context+":"+message, context+":Error")
func _start_game() -> void:
print("Game starting...")
#TODO: Load main menu or world scene

View file

@ -0,0 +1 @@
uid://bbmtxflx0ivgp

View file

@ -21,6 +21,7 @@ config/windows_native_icon="res://4589AD_icon.ico"
[autoload]
Bootstrap="*res://autoloads/bootstrap.gd"
DebugTools="*res://dev/debug_tools.tscn"
[debug]