-
Couldn't load subscription status.
- Fork 44
feat: ✨ adds refresh_scene and extend_scene
#378
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c3c8e06
feat: :sparkles: adds `refresh_scene` and `extend_scene`
KANAjetzt 75fc50b
fix: :pencil2: updated comments
KANAjetzt e1e416d
refactor: :fire: removed deprecations
KANAjetzt 9e0456b
docs: :pencil2: added success comment after scene extensions applied
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
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,43 @@ | ||
| class_name _ModLoaderSceneExtension | ||
| extends RefCounted | ||
|
|
||
| # This Class provides methods for working with scene extensions. | ||
| # Currently all of the included methods are internal and should only be used by the mod loader itself. | ||
|
|
||
| const LOG_NAME := "ModLoader:SceneExtension" | ||
|
|
||
|
|
||
| # Iterates over the list of scenes to refresh them from storage. | ||
| # Used to apply script extensions to preloaded scenes. | ||
| static func refresh_scenes() -> void: | ||
| for scene_path in ModLoaderStore.scenes_to_refresh: | ||
| # Refresh cached scenes from storage | ||
| var _scene_from_file: PackedScene = ResourceLoader.load(scene_path, "", ResourceLoader.CACHE_MODE_REPLACE) | ||
| ModLoaderLog.debug("Refreshed scene at path: %s" % scene_path, LOG_NAME) | ||
|
|
||
|
|
||
| # Iterates over the list of scenes to modify and applies the specified edits to each scene. | ||
| static func handle_scene_extensions() -> void: | ||
| for scene_path in ModLoaderStore.scenes_to_modify.keys(): | ||
| for edit_callable in ModLoaderStore.scenes_to_modify[scene_path]: | ||
| var cached_scene: PackedScene = load(scene_path) | ||
| var cached_scene_instance: Node = cached_scene.instantiate() | ||
| var edited_scene: Node = edit_callable.call(cached_scene_instance) | ||
| _save_scene(edited_scene, scene_path) | ||
|
|
||
|
|
||
| # Saves a modified scene to resource cache. | ||
| # Further attempts to load this scene by path will instead return this resource. | ||
| # | ||
| # Parameters: | ||
| # - modified_scene (Node): The modified scene instance to be saved. | ||
| # - scene_path (String): The path to the scene file that will be replaced. | ||
| # | ||
| # Returns: void | ||
| static func _save_scene(modified_scene: Node, scene_path: String) -> void: | ||
| var packed_scene := PackedScene.new() | ||
| var _pack_error := packed_scene.pack(modified_scene) | ||
| ModLoaderLog.debug("packing scene -> %s" % packed_scene, LOG_NAME) | ||
| packed_scene.take_over_path(scene_path) | ||
| ModLoaderLog.debug("save_scene - taking over path - new path -> %s" % packed_scene.resource_path, LOG_NAME) | ||
| ModLoaderStore.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
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.