GnaspGames / Smelt

A CLI tool for Minecraft map makers
http://smelt.gnasp.com
MIT License
19 stars 4 forks source link

Support work for issue #12 - required changes to how plugins work #49

Closed GnaspGames closed 8 years ago

GnaspGames commented 8 years ago

Support work for issue #12 - required changes to how plugins work so that additional data can be sent to plugins in the future.

Example of a plugin now:

var Test = {};

Test.Install = function(smelt)
{
    smelt.addSupportModule("bang-commands-setup.mcc");
}

Test.Execute = function(smelt)
{
     // Arguments available on smelt.args
    var input = smelt.args.join(" ");

    // Add new command blocks using smelt.addCommandBlock()
    smelt.addCommandBlock("say Hello World", { type:"impulse", auto:true, conditional:false });
    smelt.addCommandBlock("say " + input, { type:"chain", auto:true, conditional:false });

    // Read variables previously set using smelt.getVariable()
    var testInputVar = smelt.getVariable("$testInputVar");
    if(testInputVar)
    {
        smelt.addCommandBlock("say testInputVar = " + testInputVar);
    }

    // Set variables to be used later using smelt.setVariable()
    smelt.setVariable("$testOutputVar", input);

     // Read the current smelt config using smelt.settings
    // For example: smelt.settings.Output.ShowDebugInfo shows that the user
    // wants additional debug info.
    if(smelt.settings.Output.ShowDebugInfo)
    {
        console.log("Setting $testOutputVar to:" + input);
    }
}
module.exports = Test; 

Each plugin should implement an Execute() function and an Install() function. Execute() takes the place of the old approach.

By passing a single smelt object into these methods, it means that new properties and methods can be added more easily in the future. Affording backwards compatibility for the existing approach.

The new Install() function will be used to register any support modules that the map maker should install into their world. By separating this out, we can add a call to this function by itself in other situations, such as when the plugin is installed, or if the command is implement to just give us the support module for a plugin.

Building on top of this; I intend to add properties to the smelt object passed to plugins so that contextual data is available, such as what the previous command block was, the coordinates relative to the corner of the module, or relative to the next command block.

mrjvs commented 8 years ago

I Did not know how plugins worked before. But this way you can easily transfer data from smelt to the plugin. It's looks easy to work with and responsive (if that is the right term).

GnaspGames commented 8 years ago

smelt object now has: getVariable(), setVariable() and settings property. See edited first post.