Skip to content

Commit db1adf9

Browse files
Update manifest key validation to match Thunderstore requirements (#27)
* docs: update example manifest.json * update manifest key validation to match Thunderstore requirements * docs: generic manifest.json
1 parent f3341e7 commit db1adf9

File tree

2 files changed

+50
-23
lines changed

2 files changed

+50
-23
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,23 @@ Mods you create must have the following 2 files:
3737

3838
```json
3939
{
40-
"id": "AuthorName-ModName",
41-
"name": "Mod Name",
42-
"version": "1.0.0",
43-
"compatible_game_version": ["0.6.1.6"],
44-
"authors": ["AuthorName"],
45-
"description": "Mod description goes here",
46-
"website_url": "",
47-
"dependencies": [
40+
"name": "ModName",
41+
"version": "1.0.0",
42+
"description": "Mod description goes here",
43+
"website_url": "https://github.com/example/repo",
44+
"dependencies": [
4845
"Add IDs of other mods here, if your mod needs them to work"
49-
],
50-
"incompatibilities": [
51-
"Add IDs of other mods here, if your mod conflicts with them"
52-
]
46+
],
47+
"extra": {
48+
"godot": {
49+
"id": "AuthorName-ModName",
50+
"incompatibilities": [
51+
"Add IDs of other mods here, if your mod conflicts with them"
52+
],
53+
"authors": ["AuthorName"],
54+
"compatible_game_version": ["0.6.1.6"],
55+
}
56+
}
5357
}
5458
```
5559

loader/mod_loader.gd

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,19 @@ const REQUIRED_MOD_FILES = ["mod_main.gd", "manifest.json"]
5252
const REQUIRED_META_TAGS = [
5353
"id",
5454
"name",
55-
"version",
56-
"compatible_game_version",
57-
"authors",
55+
"version_number",
56+
"website_url",
5857
"description",
58+
"dependencies",
59+
"extra",
60+
]
61+
62+
# Required keys in manifest's `json.extra.godot`
63+
const REQUIRED_MANIFEST_KEYS_EXTRA = [
64+
"id",
65+
"incompatibilities",
66+
"authors",
67+
"compatible_game_version",
5968
]
6069

6170
# Set to true to require using "--enable-mods" to enable them
@@ -338,19 +347,20 @@ func _check_mod_files(mod_id):
338347

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

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

348-
dev_log(str(mod_id, " loaded meta data -> ", meta_data), LOG_NAME)
357+
dev_log(str(mod_id, " loaded manifest data -> ", meta_data), LOG_NAME)
349358

350-
# Check if the meta data has all required fields
359+
# Check if the manifest data has all required fields
351360
var missing_fields = _check_meta_file(meta_data)
352361
if(missing_fields.size() > 0):
353-
mod_log(str("ERROR - ", mod_id, " ", missing_fields, " are required in manifest.json."), LOG_NAME)
362+
for missing_field in missing_fields:
363+
mod_log(str("ERROR - ", mod_id, " - Missing a required field in manifest.json: '", missing_field, "'"), LOG_NAME)
354364
# Flag mod - so it's not loaded later
355365
mod.is_loadable = false
356366
# Continue with the next mod
@@ -360,14 +370,27 @@ func _load_meta_data(mod_id):
360370
mod.meta_data = meta_data
361371

362372

363-
# Make sure the meta file has all required fields
373+
# Ensure manifest.json has all required keys
364374
func _check_meta_file(meta_data):
365-
var missing_fields = REQUIRED_META_TAGS
375+
var missing_keys_root = REQUIRED_MANIFEST_KEYS_ROOT.duplicate()
376+
var missing_keys_extra = REQUIRED_MANIFEST_KEYS_EXTRA.duplicate()
366377

367378
for key in meta_data:
368-
if(REQUIRED_META_TAGS.has(key)):
379+
if(REQUIRED_MANIFEST_KEYS_ROOT.has(key)):
369380
# remove the entry from missing fields if it is there
370-
missing_fields.erase(key)
381+
missing_keys_root.erase(key)
382+
383+
if meta_data.has("extra") && meta_data.extra.has("godot"):
384+
for godot_key in meta_data:
385+
if(REQUIRED_MANIFEST_KEYS_EXTRA.has(godot_key)):
386+
missing_keys_extra.erase(godot_key)
387+
388+
# Combine both arrays, and reformat the "extra" keys
389+
var missing_fields = missing_keys_root
390+
if missing_keys_extra.size() > 0:
391+
for godot_key in missing_keys_extra:
392+
var formatted_key = str("extra.godot.", godot_key)
393+
missing_fields.push_back(formatted_key)
371394

372395
return missing_fields
373396

0 commit comments

Comments
 (0)