Skip to content
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

Implement GDScript mod loading #2861

Open
hhyyrylainen opened this issue Nov 26, 2021 · 5 comments
Open

Implement GDScript mod loading #2861

hhyyrylainen opened this issue Nov 26, 2021 · 5 comments

Comments

@hhyyrylainen
Copy link
Member

From some investigation it seems that gdscript mods can't start executing by themselves, we need to add a new property in the ModInfo to specify that a scene should be loaded and attached to the root node from a mod. This should allow gdscript made code mods to load.

After this works an example mod should be made: Revolutionary-Games/ThriveMods#5
and instructions updated: https://wiki.revolutionarygamesstudio.com/index.php?title=Modding

@I-Have-No-Idea-What-IAmDoing
Copy link
Contributor

Could gdscript mods start execution the same as c# mod by calling a initialize function?

@hhyyrylainen
Copy link
Member Author

How do you instantiate a gdscript class, then? I don't know how that would work, that's why I suggested the approach of attaching a basically an "autoload" from the mod to the Scene tree, then the ready method in the gdscript file for that scene can run.

@I-Have-No-Idea-What-IAmDoing
Copy link
Contributor

to create the script you have load it using the ResourceLoader as a 'GDScript' and then use the '.new()' function to create a new instance of the script and then you can call the intilize function using the '.call()' function

docs you can view:

this is the way i did it in my personal modloader, though only GdScript worked:

            // Entry Script Loading
            if (currentMod.EntryScriptPath != null && ResourceLoader.Exists(currentMod.EntryScriptPath))
            {
                var entryScript = ResourceLoader.Load(currentMod.EntryScriptPath) as Script;

                Object entryScriptInstance = new Object();

                if (entryScript?.CanInstance() == true)
                {
                    // Need to create an instance of the resource create a object of the class
                    switch (Path.GetExtension(ProjectSettings.GlobalizePath(currentMod.EntryScriptPath)))
                    {
                        case ".gd":
                            var gdEntryScript = entryScript as GDScript;
                            entryScriptInstance = (Object)gdEntryScript?.New();
                            break;
                        case ".csx":
                        case ".cs":
                            var cSharpEntryScript = entryScript as CSharpScript;
                            entryScriptInstance = (Object)cSharpEntryScript?.New();
                            break;
                        case ".c":
                        case ".cpp":
                        case ".cc":
                        case ".cxx":
                            var nativeScriptEntryScript = entryScript as NativeScript;
                            entryScriptInstance = (Object)nativeScriptEntryScript?.New();
                            break;
                    }

                    // Calls the intialization method, passing in the ModInfo, so that mods can get their own config
                    entryScriptInstance?.Call(currentMod.EntryFunctionName, currentMod);
                }
            }

@hhyyrylainen
Copy link
Member Author

That's a pretty interesting approach.
Is there a concrete benefit of having it be like that versus just needing a Node where the ready loads the mod? I think many mods that contain code will want to attach at least one Node to the scene tree so that would save one step from the mod author.

@I-Have-No-Idea-What-IAmDoing
Copy link
Contributor

probably not beside making everything work the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backburner
Development

No branches or pull requests

2 participants