Skip to content

Update manifest key validation to match Thunderstore requirements #27

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

Merged
merged 4 commits 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
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,23 @@ Mods you create must have the following 2 files:

```json
{
"id": "AuthorName-ModName",
"name": "Mod Name",
"version": "1.0.0",
"compatible_game_version": ["0.6.1.6"],
"authors": ["AuthorName"],
"description": "Mod description goes here",
"website_url": "",
"dependencies": [
"name": "ModName",
"version": "1.0.0",
"description": "Mod description goes here",
"website_url": "https://github.com/example/repo",
"dependencies": [
"Add IDs of other mods here, if your mod needs them to work"
],
"incompatibilities": [
"Add IDs of other mods here, if your mod conflicts with them"
]
],
"extra": {
"godot": {
"id": "AuthorName-ModName",
"incompatibilities": [
"Add IDs of other mods here, if your mod conflicts with them"
],
"authors": ["AuthorName"],
"compatible_game_version": ["0.6.1.6"],
}
}
}
```

Expand Down
45 changes: 34 additions & 11 deletions loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,19 @@ const REQUIRED_MOD_FILES = ["mod_main.gd", "manifest.json"]
const REQUIRED_META_TAGS = [
"id",
"name",
"version",
"compatible_game_version",
"authors",
"version_number",
"website_url",
"description",
"dependencies",
"extra",
]

# Required keys in manifest's `json.extra.godot`
const REQUIRED_MANIFEST_KEYS_EXTRA = [
"id",
"incompatibilities",
"authors",
"compatible_game_version",
]

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

# 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)
mod_log(str("Loading meta_data (manifest.json) for -> ", mod_id), LOG_NAME)
var mod = mod_data[mod_id]

# Load meta data file
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)
dev_log(str(mod_id, " loaded manifest data -> ", meta_data), LOG_NAME)

# Check if the meta data has all required fields
# Check if the manifest 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 manifest.json."), LOG_NAME)
for missing_field in missing_fields:
mod_log(str("ERROR - ", mod_id, " - Missing a required field in manifest.json: '", missing_field, "'"), LOG_NAME)
# Flag mod - so it's not loaded later
mod.is_loadable = false
# Continue with the next mod
Expand All @@ -360,14 +370,27 @@ func _load_meta_data(mod_id):
mod.meta_data = meta_data


# Make sure the meta file has all required fields
# Ensure manifest.json has all required keys
func _check_meta_file(meta_data):
var missing_fields = REQUIRED_META_TAGS
var missing_keys_root = REQUIRED_MANIFEST_KEYS_ROOT.duplicate()
var missing_keys_extra = REQUIRED_MANIFEST_KEYS_EXTRA.duplicate()

for key in meta_data:
if(REQUIRED_META_TAGS.has(key)):
if(REQUIRED_MANIFEST_KEYS_ROOT.has(key)):
# remove the entry from missing fields if it is there
missing_fields.erase(key)
missing_keys_root.erase(key)

if meta_data.has("extra") && meta_data.extra.has("godot"):
for godot_key in meta_data:
if(REQUIRED_MANIFEST_KEYS_EXTRA.has(godot_key)):
missing_keys_extra.erase(godot_key)

# Combine both arrays, and reformat the "extra" keys
var missing_fields = missing_keys_root
if missing_keys_extra.size() > 0:
for godot_key in missing_keys_extra:
var formatted_key = str("extra.godot.", godot_key)
missing_fields.push_back(formatted_key)

return missing_fields

Expand Down