Repository navigation
Add support for cross-language mixins using MixinScript (aka MultiScript) - #92
Merged
Merged
Conversation
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.
Contributor
Author
|
YOLO. |
This was referenced Jun 22, 2021
|
This is such an amazing feature! |
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
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
MultiScriptin 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
msextension:Mixin script create dialog
Mixin script editor
The reason why I've rebranded the
MultiScripttoMixinScriptis 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,NativeScriptetc. into a single instance. Notice that I've emphasized instance becauseMixinScriptonly extends run-time functionality of objects/nodes. For example, here's how editing aMixinlooks like:So, the real limitation is that all objects must inherit
Mixinclass (at least in GDScript), but at the end of the day, you can code the real object viaownerproperty (ownerhasMixinScriptattached). If other mixins define new methods, those will be available inowneras 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
MixinScriptinstance from outside of the class (say when you instantiate a scene), then you won't have to useownerproperty; 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