Skip to content

Conversation

@KANAjetzt
Copy link
Member

@KANAjetzt KANAjetzt commented Dec 7, 2024

With the introduction of zippeeking®™, the mod loading flow has changed.

This refactor aims to fully leverage zippeeking®™ and streamline the mod loading process along the way.

Change Overview

  • Moved check_autoload_positions() to ./internal/godot.gd
  • Added get_mod_paths_from_all_sources() to _ModLoaderPath
  • Added is_zip(path: String) to _ModLoaderPath
  • Added get_mod_dir_name_in_zip() to _ModLoaderFile
  • Removed unused methods:
    • _reload_mods()
    • _reset_mods()
    • _disable_mods()
    • _disable_mod()
  • Removed DEBUG_ENABLE_STORING_FILEPATHS and its associated logic
  • Removed file structure comparison from mod loading
  • Added constants for required and optional file names in ModData
  • Moved get_zip_paths_in() from _ModLoaderFile to _ModLoaderPath
  • Moved manifest loading out of ModData
  • Moved validate_game_version_compatibility() from ModData to ModManifest
  • Refactored ModManifest to always return a new instance instead of null
    • Made all validation functions non-static so they can access validation_messages_error and validation_messages_warning
    • Validation issues are now collected in validation_messages_error and validation_messages_warning and logged at the end, with no more early returns
  • Updated the manifest validation test to initialize an empty ModManifest

Dev Notes

  • All this file structure comparing is no longer needed we can just check the structure in the zip before we load it in. I move this to ModData._init()
    • We check for required files in the zip and unpacked dir in ModData._init() if the structure is incorrect this checks will fail.
    • Maybe we can add an additional check if the mods-unpacked dir exists, but I keep it as is for now should be enough.(?)

# Get the current directories inside UNPACKED_DIR
# This array is used to determine which directory is new
var current_mod_dirs := _ModLoaderPath.get_dir_paths_in_dir(_ModLoaderPath.get_unpacked_mods_dir_path())
# Create a backup to reference when the next mod is loaded
var current_mod_dirs_backup := current_mod_dirs.duplicate()
# Remove all directory paths that existed before, leaving only the one added last
for previous_mod_dir in ModLoaderStore.previous_mod_dirs:
current_mod_dirs.erase(previous_mod_dir)
# If the mod zip is not structured correctly, it may not be in the UNPACKED_DIR.
if current_mod_dirs.is_empty():
ModLoaderLog.fatal(
"The mod zip at path \"%s\" does not have the correct file structure. For more information, please visit \"%s\"."
% [mod_zip_global_path, URL_MOD_STRUCTURE_DOCS],
LOG_NAME
)
continue
# Update previous_mod_dirs in ModLoaderStore to use for the next mod
ModLoaderStore.previous_mod_dirs = current_mod_dirs_backup

  • 🔦I think I currently don't add mod_data to the store if the manifest or mod structure is invalid. I'm pretty sure we still want that data so it can be properly displayed in a mod menu.

    • Changed things so we have ModData even if the manifest can't be parsed.
  • Check if _exit_tree() cache saving got lost

    • got lost and is back
  • Check if _on_new_hooks_created() got lost

    • got lost and is back

@KANAjetzt KANAjetzt added refactor / cleanup Improves readability or maintainability 4.x labels Dec 7, 2024
@KANAjetzt KANAjetzt self-assigned this Dec 11, 2024
@KANAjetzt KANAjetzt added this to the 4.x - 7.0.0 milestone Dec 11, 2024
@KANAjetzt KANAjetzt marked this pull request as ready for review December 11, 2024 09:42
@KANAjetzt KANAjetzt requested a review from Qubus0 December 11, 2024 09:42
@KANAjetzt KANAjetzt force-pushed the refactor_mod_loader branch 2 times, most recently from 0fdb773 to 8bdf229 Compare December 27, 2024 08:47
Copy link
Collaborator

@Qubus0 Qubus0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really nice job, way cleaner. thank you 😄

@KANAjetzt KANAjetzt added this pull request to the merge queue Jan 7, 2025
Merged via the queue into GodotModding:4.x with commit 9c9a5fd Jan 7, 2025
2 checks passed
@KANAjetzt KANAjetzt deleted the refactor_mod_loader branch January 28, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.x refactor / cleanup Improves readability or maintainability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants