diff --git a/assetloader/assetloader.gd b/assetloader/assetloader.gd index 3e090ce..e249fe4 100644 --- a/assetloader/assetloader.gd +++ b/assetloader/assetloader.gd @@ -1,26 +1,44 @@ extends Object class_name AssetLoader +#region declaration +# === CONST === + const DEFAULT_ASSETS_PATH = "res://mods" +## If you want to change the mod extension. Keep in mind that it's still a json under the hood +const MOD_INFOS_EXTENSION = "modinfo" + ## 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 === +var dir:DirAccess +var mod_folders:PackedStringArray var critical_error := false +var mod_paths : PackedStringArray +var mod_manifests : Dictionary[String] + +# === SIGNALS === +signal loading_finished + +#endregion + func _init() -> void: + print_verbose("------ MOD LOADING STARTED ------") ASSETS_PATH = ProjectSettings.get_setting("game/mods/mod_path", DEFAULT_ASSETS_PATH) - var dir := DirAccess.open(ASSETS_PATH) + dir = DirAccess.open(ASSETS_PATH) if not dir: push_error("AssetLoader: Mods folder not found at '%s'" % ASSETS_PATH) + push_error("AssetLoader:",DirAccess.get_open_error()) _show_error_popup("Mods folder not found at '%s'" % ASSETS_PATH) critical_error = true return - var mod_folders := dir.get_directories() - + 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) @@ -35,4 +53,25 @@ func _show_error_popup(message: String) -> void: func load_all(): - pass + load_mods() + #load_mods_content() + + +func load_mods(): + for mod in mod_folders: + var mod_name = mod + var mod_path = ASSETS_PATH + "/" + mod_name + var manifest_path = mod_path + "/" + mod_name + "." + MOD_INFOS_EXTENSION + if FileAccess.file_exists(manifest_path): + var manifest_file := FileAccess.open(manifest_path, FileAccess.READ) + var manifest: Dictionary = JSON.parse_string(manifest_file.get_as_text()) + if typeof(manifest) == TYPE_DICTIONARY: # always true ? + mod_paths.append(mod_path) + if manifest["id"]: + mod_manifests[manifest["id"]] = manifest + print_verbose("Mod loaded: %s" % manifest["name"]) + else: + mod_manifests[mod_name] = manifest + print_verbose("Mod loaded: %s" % manifest["name"]) + + print(dir.get_files()) diff --git a/autoloads/bootstrap.gd b/autoloads/bootstrap.gd index 0fd0c70..bcfc9d2 100644 --- a/autoloads/bootstrap.gd +++ b/autoloads/bootstrap.gd @@ -4,13 +4,11 @@ extends Node func _ready() -> void: var loader := AssetLoader.new() - # If there was a critical error, quit immediately + # No point to load the game if no asset are loaded if loader.critical_error: Engine.get_main_loop().quit(1) return loader.load_all() # TODO: Making it async - - # Otherwise, continue startup _start_game() diff --git a/dev/debugtool_mouse_overlay.gd b/dev/debugtool_mouse_overlay.gd index 74e4ea3..c8709ba 100644 --- a/dev/debugtool_mouse_overlay.gd +++ b/dev/debugtool_mouse_overlay.gd @@ -16,7 +16,7 @@ func _process(_delta): #update_cursor(shape) -func update_cursor(image: Resource, shape: Input.CursorShape = 0, hotspot: Vector2 = Vector2(0, 0)): +func update_cursor(image: Resource, _shape:= 0 as Input.CursorShape, hotspot: Vector2 = Vector2(0, 0)): # Get the custom cursor data from the main script if image != null: texture_rect.texture = image diff --git a/editor/script_templates/Object/clean_code_template.gd b/editor/script_templates/Object/clean_code_template.gd new file mode 100644 index 0000000..f99b187 --- /dev/null +++ b/editor/script_templates/Object/clean_code_template.gd @@ -0,0 +1,23 @@ +# meta-name: Clean Code Template +# meta-description: Use this format to structure your code into clear sections +# meta-default: true +# meta-space-indent: 4 +extends _BASE_ + +#region declaration +# === CONST === # Constants and immutables, in UPPERCASE + +# === STATIC === # Static variables/functions + +#endregion + +# === Init === # Initialization logic, if needed + +func _init() -> void: + pass + +# === PUBLIC FUNCTIONS === + +# === PRIVATE FUNCTIONS === # use _underscore() to make the difference between private and public functions + +# ==================== diff --git a/editor/script_templates/Object/clean_code_template.gd.uid b/editor/script_templates/Object/clean_code_template.gd.uid new file mode 100644 index 0000000..4ca77b8 --- /dev/null +++ b/editor/script_templates/Object/clean_code_template.gd.uid @@ -0,0 +1 @@ +uid://d524ti2uyikh diff --git a/mods/base_content/base_content.json b/mods/base_content/base_content.json new file mode 100644 index 0000000..fb66eff --- /dev/null +++ b/mods/base_content/base_content.json @@ -0,0 +1,9 @@ +{ + "id": "base_content", + "name": "Core Game Elements", + "version": 1.0, + "desc": "Factions, unités, bâtiments et cartes de base.", + "author": "TonStudio", + "dependencies": [], + "tags": ["units","vehicles","buildings","textures","maps","quests"] +} diff --git a/mods/base_content/base_content.modinfo b/mods/base_content/base_content.modinfo new file mode 100644 index 0000000..fb66eff --- /dev/null +++ b/mods/base_content/base_content.modinfo @@ -0,0 +1,9 @@ +{ + "id": "base_content", + "name": "Core Game Elements", + "version": 1.0, + "desc": "Factions, unités, bâtiments et cartes de base.", + "author": "TonStudio", + "dependencies": [], + "tags": ["units","vehicles","buildings","textures","maps","quests"] +} diff --git a/project.godot b/project.godot index 79d8ff9..a89c530 100644 --- a/project.godot +++ b/project.godot @@ -38,6 +38,11 @@ window/size/window_height_override=720 mouse_cursor/custom_image="uid://dp4ed16rb1754" mouse_cursor/custom_image_hotspot=Vector2(14, 2) +[editor] + +script/search_in_file_extensions=PackedStringArray("gd", "gdshader", "json", "modinfo") +script/templates_search_path="res://editor/script_templates" + [editor_plugins] enabled=PackedStringArray("res://addons/SimpleFormatOnSave/plugin.cfg", "res://addons/Todo_Manager/plugin.cfg")