Magikcraft / product-board-deprecated

DEPRECATED! See: https://github.com/Magikcraft/magikcraft-release-notes
https://github.com/Magikcraft/magikcraft-release-notes
0 stars 0 forks source link

MGK-006 Spell- and mini-game packages #6

Closed jwulf closed 7 years ago

jwulf commented 7 years ago

User Story

As a user I can add a module to my package.json, save it, then run spells from it directly in Minecraft with a command like /call <module_name> <exported_entrypoint> - eg: /call mct1 start.

I can also install and run mini-games from packages without writing any additional spell code to load them.

Background

At the moment you can import packages, but you still have to write a spell to use anything from the package. Developers currently cannot write packages of reusable spells that require nothing more than importing. With this feature, developers can write packages of spells and mini-games that end-users can import and cast "out of the box".

Feature Description

Spell packages

Package interface definition

This is a specification for exporting spells from a package, and a wrapper method to call those exported entry points. A package of reusable spells must export spells:

module.exports.spells = {
    _default: require('./lib/lightning.js'),
    lightning : require('./lib/lightning.js'),
    fireball: require('./lib/fireball.js')
};

Calling spells from a spell package

A prototype call spell can work like this:

function call(module, spell) {
    require(module)[spell]();
}

It is used like this: /cast call mct1 start. An alternative syntax is: /cast call mct1:start or /cast call mct1.start.

The implementation for this is:

function call(module, spell = '_default') {
    let char;
    [':', '.'].forEach(_char => {
        if (module.indexOf(_char) != -1) {
            const _args = module.split(char);
            module = _args[0];
            spell = _args[1];
        }
    });
    require(module).spells[spell]();
}

[TODO - In or out of scope?] A further consideration is passing further arguments through to the exported spell, for example:

/cast call sitapati lstrike <playername>

Inspecting a spell (or mini-game) package

Packages can be inspected for the spells they contain like this:

const magik = magikcraft.io;

function inspect(module) {
    const spells = require(_module).spells;
    magik.dixit(`Module ${module} contains the following spells:`);
    magik.dixit(Object.keys(spells));
}

Mini-game packages

This is a specification for mini-game packages.

Naming convention

They should be named magikcraft-minigame-*.

Mini-game package interface definition

A mini-game package must export:

module.exports = { spells: { _default: require('./entrypoint.js` } };

It can optionally export additional entrypoints, but the spells._default export is mandatory, and should start the game.

Loading a mini-game package

The following spell will load a mini-game package that conforms to this specification:

function game(module, spell = '_default') {
    const _module = `magikcraft-minigame-${module}`;
    require(_module).spells[spell]();
}

Out of Scope

Out of scope for the initial implementation are:

Acceptance Criteria

A module with a conforming spells export can be added to the package.json, and then /cast call <modulename>:<spell> and /cast call <modulename> <spell> execute the spell.

/cast call <modulename> <spell> <arg1> <arg2> passes the arguments through to the exported spell.

User Acceptance Test Plan

Here is the process for testing this feature:

End-User Documentation

[Docs that can be copypasta to the user docs]

jwulf commented 7 years ago

This issue was moved to Magikcraft/magikcraft-release-notes#7