Example project
# Conflicts: # .gitignore
This commit is contained in:
parent
1513fd00dd
commit
7f4fe92271
14 changed files with 145 additions and 0 deletions
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Normalize EOL for all files that Git considers text files.
|
||||
* text=auto eol=lf
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
# ---> Godot
|
||||
# Godot 4+ specific ignores
|
||||
.godot/
|
||||
/android/
|
||||
|
||||
# Godot-specific ignores
|
||||
.import/
|
||||
|
|
11
autoload/ContentRegistry.gd
Normal file
11
autoload/ContentRegistry.gd
Normal file
|
@ -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
|
1
autoload/ContentRegistry.gd.uid
Normal file
1
autoload/ContentRegistry.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://chylch01h275w
|
58
autoload/ModLoader.gd
Normal file
58
autoload/ModLoader.gd
Normal file
|
@ -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")
|
1
autoload/ModLoader.gd.uid
Normal file
1
autoload/ModLoader.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://c82sxdmgrv7lk
|
3
main/Label.tscn
Normal file
3
main/Label.tscn
Normal file
|
@ -0,0 +1,3 @@
|
|||
[gd_scene format=3 uid="uid://label"]
|
||||
|
||||
[node name="Label" type="Label"]
|
9
main/Main.gd
Normal file
9
main/Main.gd
Normal file
|
@ -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)
|
1
main/Main.gd.uid
Normal file
1
main/Main.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://byy1qyojb5rwv
|
9
main/Main.tscn
Normal file
9
main/Main.tscn
Normal file
|
@ -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")]
|
12
mods/base_content/buildings/barracks.json
Normal file
12
mods/base_content/buildings/barracks.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
{
|
||||
"id": "barracks",
|
||||
"name": "Barracks",
|
||||
"description": "Trains melee units.",
|
||||
"build_cost": {
|
||||
"wood": 100,
|
||||
"stone": 50
|
||||
},
|
||||
"build_time": 30,
|
||||
"produces_units": ["soldier"]
|
||||
}
|
10
mods/base_content/manifest.json
Normal file
10
mods/base_content/manifest.json
Normal file
|
@ -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
|
||||
}
|
8
mods/base_content/units/soldier.json
Normal file
8
mods/base_content/units/soldier.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
{
|
||||
"id": "soldier",
|
||||
"name": "Soldier",
|
||||
"health": 100,
|
||||
"attack": 10,
|
||||
"speed": 3.0
|
||||
}
|
19
project.godot
Normal file
19
project.godot
Normal file
|
@ -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"
|
Loading…
Reference in a new issue