Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename to "mod_main.gd" and "manifest.json" #26

Merged
merged 1 commit into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ yourmod.zip
├───.import
└───mods-unpacked
└───Author-ModName
├───ModMain.gd
└───_meta.json
├───mod_main.gd
└───manifest.json
```

#### Notes on .import
Expand All @@ -30,10 +30,10 @@ You can copy your custom assets from your project's .import directory. They can

Mods you create must have the following 2 files:

- **ModMain.gd** - The init file for your mod.
- **_meta.json** - Meta data for your mod (see below).
- **mod_main.gd** - The init file for your mod.
- **manifest.json** - Meta data for your mod (see below).

#### Example _meta.json
#### Example manifest.json

```json
{
Expand Down Expand Up @@ -85,8 +85,8 @@ yourmod.zip
├───.import
└───mods-unpacked
└───Author-ModName
├───ModMain.gd
├───_meta.json
├───mod_main.gd
├───manifest.json
└───extensions
└───Any files that extend vanilla code can go here, eg:
├───main.gd
Expand Down
24 changes: 12 additions & 12 deletions loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ const MOD_LOG_PATH = "user://mods.log"
const UNPACKED_DIR = "res://mods-unpacked/"

# These 2 files are always required by mods.
# ModMain.gd = The main init file for the mod
# _meta.json = Meta data for the mod, including its dependancies
const REQUIRED_MOD_FILES = ["ModMain.gd", "_meta.json"]
# mod_main.gd = The main init file for the mod
# manifest.json = Meta data for the mod, including its dependancies
const REQUIRED_MOD_FILES = ["mod_main.gd", "manifest.json"]

# Required keys in a mod's _meta.json file
# Required keys in a mod's manifest.json file
const REQUIRED_META_TAGS = [
"id",
"name",
Expand Down Expand Up @@ -101,7 +101,7 @@ func _init():

# Loop over all loaded mods via their entry in mod_data. Verify that they
# have all the required files (REQUIRED_MOD_FILES), load their meta data
# (from their _meta.json file), and verify that the meta JSON has all
# (from their manifest.json file), and verify that the meta JSON has all
# required properties (REQUIRED_META_TAGS)
for mod_id in mod_data:
var mod = mod_data[mod_id]
Expand Down Expand Up @@ -310,8 +310,8 @@ func _init_mod_data(mod_folder_path):

for required_filename in REQUIRED_MOD_FILES:
# Eg:
# "modmain.gd": local_mod_path + "/ModMain.gd",
# "_meta.json": local_mod_path + "/_meta.json"
# "mod_main.gd": local_mod_path + "/mod_main.gd",
# "manifest.json": local_mod_path + "/manifest.json"
mod_data[mod_id].required_files_path[required_filename] = local_mod_path + "/" + required_filename


Expand All @@ -332,21 +332,21 @@ func _check_mod_files(mod_id):
mod_log(str("ERROR - ", mod_id, " cannot be loaded due to missing required files"), LOG_NAME)


# Load meta data into mod_data, from a mod's _meta.json file
# Load meta data into mod_data, from a mod's manifest.json file
func _load_meta_data(mod_id):
mod_log(str("Loading meta_data for -> ", mod_id), LOG_NAME)
var mod = mod_data[mod_id]

# Load meta data file
var meta_path = mod.required_files_path["_meta.json"]
var meta_path = mod.required_files_path["manifest.json"]
var meta_data = _get_json_as_dict(meta_path)

dev_log(str(mod_id, " loaded meta data -> ", meta_data), LOG_NAME)

# Check if the meta data has all required fields
var missing_fields = _check_meta_file(meta_data)
if(missing_fields.size() > 0):
mod_log(str("ERROR - ", mod_id, " ", missing_fields, " are required in _meta.json."), LOG_NAME)
mod_log(str("ERROR - ", mod_id, " ", missing_fields, " are required in manifest.json."), LOG_NAME)
# Flag mod - so it's not loaded later
mod.is_loadable = false
# Continue with the next mod
Expand All @@ -369,7 +369,7 @@ func _check_meta_file(meta_data):


# Run dependency checks on a mod, checking any dependencies it lists in its
# meta_data (ie. its _meta.json file). If a mod depends on another mod that
# meta_data (ie. its manifest.json file). If a mod depends on another mod that
# hasn't been loaded, the dependent mod won't be loaded.
func _check_dependencies(mod_id:String, deps:Array):
dev_log(str("Checking dependencies - mod_id: ", mod_id, " dependencies: ", deps), LOG_NAME)
Expand Down Expand Up @@ -434,7 +434,7 @@ func _compare_Importance(a, b):
# Instance every mod and add it as a node to the Mod Loader.
# Runs mods in the order stored in mod_load_order.
func _init_mod(mod):
var mod_main_path = mod.required_files_path["ModMain.gd"]
var mod_main_path = mod.required_files_path["mod_main.gd"]
dev_log(str("Loading script from -> ", mod_main_path), LOG_NAME)
var mod_main_script = ResourceLoader.load(mod_main_path)
dev_log(str("Loaded script -> ", mod_main_script), LOG_NAME)
Expand Down