-
Notifications
You must be signed in to change notification settings - Fork 44
refactor: ♻️ Move main mod API funcs to ModLoaderMod, from ModLoader
#208
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
KANAjetzt
merged 6 commits into
GodotModding:development
from
ithinkandicode:modloadermod-refactor
Apr 9, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f616c7a
refactor: Move main mod funcs to ModLoaderMod
ithinkandicode 97d7050
Merge branch 'development' into modloadermod-refactor
KANAjetzt 935b731
refactor: :recycle: Moved `reload_mods()` to *mod.gd*
KANAjetzt 0b357cc
refactor: :fire: Removed `uninstall_script_extension()` deprecation
KANAjetzt 7322e62
fix: :bug: fixed missing `ModLoaderStore` reference
KANAjetzt 28498d8
style: :label: Added missing return type
KANAjetzt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| class_name ModLoaderMod | ||
| extends Object | ||
|
|
||
| # Helper functions to build mods | ||
|
|
||
| const LOG_NAME := "ModLoader:Mod" | ||
|
|
||
|
|
||
| # Add a script that extends a vanilla script. `child_script_path` should point | ||
| # to your mod's extender script, eg "MOD/extensions/singletons/utils.gd". | ||
| # Inside that extender script, it should include "extends {target}", where | ||
| # {target} is the vanilla path, eg: `extends "res://singletons/utils.gd"`. | ||
| # Note that your extender script doesn't have to follow the same directory path | ||
| # as the vanilla file, but it's good practice to do so. | ||
| static func install_script_extension(child_script_path:String) -> void: | ||
|
|
||
| # If this is called during initialization, add it with the other | ||
| # extensions to be installed taking inheritance chain into account | ||
| if ModLoaderStore.is_initializing: | ||
| ModLoaderStore.script_extensions.push_back(child_script_path) | ||
|
|
||
| # If not, apply the extension directly | ||
| else: | ||
| ModLoader._apply_extension(child_script_path) | ||
|
|
||
|
|
||
| static func uninstall_script_extension(extension_script_path: String) -> void: | ||
|
|
||
| # Currently this is the only thing we do, but it is better to expose | ||
| # this function like this for further changes | ||
| ModLoader._remove_extension(extension_script_path) | ||
|
|
||
|
|
||
| # This function should be called only when actually necessary | ||
| # as it can break the game and require a restart for mods | ||
| # that do not fully use the systems put in place by the mod loader, | ||
| # so anything that just uses add_node, move_node ecc... | ||
| # To not have your mod break on reload please use provided functions | ||
| # like ModLoader::save_scene, ModLoader::append_node_in_scene and | ||
| # all the functions that will be added in the next versions | ||
| # Used to reload already present mods and load new ones | ||
| func reload_mods() -> void: | ||
|
|
||
| # Currently this is the only thing we do, but it is better to expose | ||
| # this function like this for further changes | ||
| ModLoader._reload_mods() | ||
|
|
||
|
|
||
| # Register an array of classes to the global scope, since Godot only does that in the editor. | ||
| # Format: { "base": "ParentClass", "class": "ClassName", "language": "GDScript", "path": "res://path/class_name.gd" } | ||
| # You can find these easily in the project.godot file under "_global_script_classes" | ||
| # (but you should only include classes belonging to your mod) | ||
| static func register_global_classes_from_array(new_global_classes: Array) -> void: | ||
| ModLoaderUtils.register_global_classes_from_array(new_global_classes) | ||
| var _savecustom_error: int = ProjectSettings.save_custom(ModLoaderUtils.get_override_path()) | ||
|
|
||
|
|
||
| # Add a translation file, eg "mytranslation.en.translation". The translation | ||
| # file should have been created in Godot already: When you import a CSV, such | ||
| # a file will be created for you. | ||
| static func add_translation_from_resource(resource_path: String) -> void: | ||
| if not File.new().file_exists(resource_path): | ||
| ModLoaderUtils.log_fatal("Tried to load a translation resource from a file that doesn't exist. The invalid path was: %s" % [resource_path], LOG_NAME) | ||
| return | ||
|
|
||
| var translation_object: Translation = load(resource_path) | ||
| TranslationServer.add_translation(translation_object) | ||
| ModLoaderUtils.log_info("Added Translation from Resource -> %s" % resource_path, LOG_NAME) | ||
|
|
||
|
|
||
| static func append_node_in_scene(modified_scene: Node, node_name: String = "", node_parent = null, instance_path: String = "", is_visible: bool = true) -> void: | ||
| var new_node: Node | ||
| if not instance_path == "": | ||
| new_node = load(instance_path).instance() | ||
| else: | ||
| new_node = Node.instance() | ||
| if not node_name == "": | ||
| new_node.name = node_name | ||
| if is_visible == false: | ||
| new_node.visible = false | ||
| if not node_parent == null: | ||
| var tmp_node: Node = modified_scene.get_node(node_parent) | ||
| tmp_node.add_child(new_node) | ||
| new_node.set_owner(modified_scene) | ||
| else: | ||
| modified_scene.add_child(new_node) | ||
| new_node.set_owner(modified_scene) | ||
|
|
||
|
|
||
| static func save_scene(modified_scene: Node, scene_path: String) -> void: | ||
| var packed_scene := PackedScene.new() | ||
| var _pack_error := packed_scene.pack(modified_scene) | ||
| ModLoaderUtils.log_debug("packing scene -> %s" % packed_scene, LOG_NAME) | ||
| packed_scene.take_over_path(scene_path) | ||
| ModLoaderUtils.log_debug("save_scene - taking over path - new path -> %s" % packed_scene.resource_path, LOG_NAME) | ||
| ModLoader._saved_objects.append(packed_scene) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.