diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.gitignore b/.gitignore index bf83296..bd1b155 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # ---> Godot # Godot 4+ specific ignores .godot/ +/android/ # Godot-specific ignores .import/ diff --git a/autoload/ContentRegistry.gd b/autoload/ContentRegistry.gd new file mode 100644 index 0000000..283efcc --- /dev/null +++ b/autoload/ContentRegistry.gd @@ -0,0 +1,11 @@ + +extends Node + +var units = {} +var buildings = {} + +func register_unit(data: Dictionary): + units[data["id"]] = data + +func register_building(data: Dictionary): + buildings[data["id"]] = data diff --git a/autoload/ContentRegistry.gd.uid b/autoload/ContentRegistry.gd.uid new file mode 100644 index 0000000..65a0b18 --- /dev/null +++ b/autoload/ContentRegistry.gd.uid @@ -0,0 +1 @@ +uid://chylch01h275w diff --git a/autoload/ModLoader.gd b/autoload/ModLoader.gd new file mode 100644 index 0000000..391654e --- /dev/null +++ b/autoload/ModLoader.gd @@ -0,0 +1,58 @@ + +extends Node + +var mod_paths := [] +var mod_manifests := {} +const MODS_DIR := "res://mods" + +func _ready(): + load_mods(MODS_DIR) + load_mod_content() + +func load_mods(base_path: String): + var dir := DirAccess.open(base_path) + if not dir: + push_error("No mods folder found.") + return + + for folder in dir.get_directories(): + var mod_path = base_path + "/" + folder + var manifest_path = mod_path + "/manifest.json" + 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) + mod_manifests[manifest["id"]] = manifest + print("Mod loaded: %s" % manifest["name"]) + +func load_units(units_path: String): + var dir := DirAccess.open(units_path) + if dir: + for file in dir.get_files(): + if file.get_extension() == "json": + var file_path = units_path + "/" + file + var f := FileAccess.open(file_path, FileAccess.READ) + if f: + var data = JSON.parse_string(f.get_as_text()) + if typeof(data) == TYPE_DICTIONARY: + ContentRegistry.register_unit(data) + print("Unit loaded: %s" % data["id"]) + +func load_buildings(buildings_path: String): + var dir := DirAccess.open(buildings_path) + if dir: + for file in dir.get_files(): + if file.get_extension() == "json": + var file_path = buildings_path + "/" + file + var f := FileAccess.open(file_path, FileAccess.READ) + if f: + var data = JSON.parse_string(f.get_as_text()) + if typeof(data) == TYPE_DICTIONARY: + ContentRegistry.register_building(data) + print("Building loaded: %s" % data["id"]) + +func load_mod_content(): + for mod_path in mod_paths: + load_units(mod_path + "/units") + load_buildings(mod_path + "/buildings") diff --git a/autoload/ModLoader.gd.uid b/autoload/ModLoader.gd.uid new file mode 100644 index 0000000..02221e8 --- /dev/null +++ b/autoload/ModLoader.gd.uid @@ -0,0 +1 @@ +uid://c82sxdmgrv7lk diff --git a/main/Label.tscn b/main/Label.tscn new file mode 100644 index 0000000..1f22931 --- /dev/null +++ b/main/Label.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://label"] + +[node name="Label" type="Label"] diff --git a/main/Main.gd b/main/Main.gd new file mode 100644 index 0000000..edf5980 --- /dev/null +++ b/main/Main.gd @@ -0,0 +1,9 @@ + +extends Node + +@onready var label := $Label + +func _ready(): + var unit_list = ContentRegistry.units.keys() + var building_list = ContentRegistry.buildings.keys() + label.text = "Loaded units: " + str(unit_list) + "\n" + "Loaded buildings: " + str(building_list) diff --git a/main/Main.gd.uid b/main/Main.gd.uid new file mode 100644 index 0000000..8149eba --- /dev/null +++ b/main/Main.gd.uid @@ -0,0 +1 @@ +uid://byy1qyojb5rwv diff --git a/main/Main.tscn b/main/Main.tscn new file mode 100644 index 0000000..aac620d --- /dev/null +++ b/main/Main.tscn @@ -0,0 +1,9 @@ +[gd_scene load_steps=3 format=3 uid="uid://duto8i2373vdn"] + +[ext_resource type="Script" uid="uid://byy1qyojb5rwv" path="res://main/Main.gd" id="1_qv31u"] +[ext_resource type="PackedScene" uid="uid://label" path="res://main/Label.tscn" id="2_wbnyf"] + +[node name="Main" type="Node3D"] +script = ExtResource("1_qv31u") + +[node name="Label" parent="." instance=ExtResource("2_wbnyf")] diff --git a/mods/base_content/buildings/barracks.json b/mods/base_content/buildings/barracks.json new file mode 100644 index 0000000..a9f69d8 --- /dev/null +++ b/mods/base_content/buildings/barracks.json @@ -0,0 +1,12 @@ + +{ + "id": "barracks", + "name": "Barracks", + "description": "Trains melee units.", + "build_cost": { + "wood": 100, + "stone": 50 + }, + "build_time": 30, + "produces_units": ["soldier"] +} diff --git a/mods/base_content/manifest.json b/mods/base_content/manifest.json new file mode 100644 index 0000000..91fa471 --- /dev/null +++ b/mods/base_content/manifest.json @@ -0,0 +1,10 @@ + +{ + "id": "base_content", + "name": "Core Vanilla Game", + "version": "1.0", + "description": "Factions, unités, bâtiments et cartes de base.", + "author": "TonStudio", + "dependencies": [], + "load_order": 0 +} diff --git a/mods/base_content/units/soldier.json b/mods/base_content/units/soldier.json new file mode 100644 index 0000000..4a0b9a2 --- /dev/null +++ b/mods/base_content/units/soldier.json @@ -0,0 +1,8 @@ + +{ + "id": "soldier", + "name": "Soldier", + "health": 100, + "attack": 10, + "speed": 3.0 +} diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..65bb3a4 --- /dev/null +++ b/project.godot @@ -0,0 +1,19 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +run/main_scene="uid://duto8i2373vdn" +config/features=PackedStringArray("4.4") + +[autoload] + +ModLoader="*res://autoload/ModLoader.gd" +ContentRegistry="*res://autoload/ContentRegistry.gd"