-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add support for cross-language mixins using MixinScript
(aka MultiScript
)
#92
Merged
Conversation
This file contains 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
WIP: based on commit 15bce7f75f0dfab9863db5d4c7a51f5fc96fdb89 in Godot.
Seems to work at runtime as well!
Consistent with `visual_script` module.
Renamed `MultiScriptOwner` to `Mixin` respectively. See https://stackoverflow.com/questions/925609/mixins-vs-traits
[ci skip]
Nodes extended with `MixinScript` are not very useful unless they have ability to be edited just like any other script from other languages.
This introduces `MixinScriptEditor` with the purpose of handling script editing. The editor will delegate script editing to other editors that handle `main_script`, if it's valid.
[ci skip]
Allows to conveniently attach main script to `MixinScript`. The complexity here is that we cannot use regular mechanism of attaching scripts, because usually scripts are attached to nodes, not scripts!
Allows to manually switch to mixin script editor when main script is edited automatically.
Those are not useful anymore, and they are limited to the number of letters. There's `MixinScriptEditor` which allows to edit `MixinScript` now.
Makes everything more consistent.
Unfortunately, we cannot provide overrides for arbitrary instances. However, the real object is still available to all mixins via `owner` property.
They are identical, and the former is removed in Godot 3.x.
Since there's no way to make arbitrary instances to use base types other than `Mixin`, there's not much benefit in disntinguishing between the "main" script and "mixins". However, the first script added to `MixinScript` will be treated as the "main" one, in the sense that script editing is going to be automatically delegated to the first script. This greatly simplifies both the core and the editor.
YOLO. |
This was referenced Jun 22, 2021
This is such an amazing feature! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is a resurrection of multiscript PR in Godot, see godotengine/godot#8718. The feature got re-added in development versions of Godot in 2017, but got quickly removed again, so most users have never seen
MultiScript
in Godot.See also godotengine/godot-proposals#1346, godotengine/godot-proposals#758, godotengine/godot#23101.
The reason why it was removed is because of various limitations inherent to cross-language implementation of having multiple scripts per instance, and the usability of the feature was really lacking. I've took some time to improve upon the previous implementation in Godot and even made an editor for it, and now it's an actual language which is recognized via
ms
extension:Mixin script create dialog
Mixin script editor
The reason why I've rebranded the
MultiScript
toMixinScript
is mainly because it better reflects the logic behind the inner workings, and potentially allows to avoid ambiguity with the notion of having "multiple" scripts per node: https://stackoverflow.com/questions/925609/mixins-vs-traits.With this feature, it's possible to combine the methods, properties, signals of
GDScript
,VisualScript
,NativeScript
etc. into a single instance. Notice that I've emphasized instance becauseMixinScript
only extends run-time functionality of objects/nodes. For example, here's how editing aMixin
looks like:So, the real limitation is that all objects must inherit
Mixin
class (at least in GDScript), but at the end of the day, you can code the real object viaowner
property (owner
hasMixinScript
attached). If other mixins define new methods, those will be available inowner
as well, regardless of whether they are written inGDScript
,VisualScript
,C#
etc. This allows you to avoid depending on node hierarchy.If you're dealing with the
MixinScript
instance from outside of the class (say when you instantiate a scene), then you won't have to useowner
property; all properties and methods should be made available as if they were defined in the same script for real.To-do
Depending on whether the feature will be useful for other developers, there are still quite some work to do on the editor side to make the development experience more smooth:
Test project
https://github.com/goostengine/goost-examples/tree/8e634b4a30404a2a55fb48dfb7382b4eabbbace5/scripting/mixins