scratchfoundation / scratch-vm

Virtual Machine used to represent, run, and maintain the state of programs for Scratch 3.0
http://scratchfoundation.github.io/scratch-vm/
BSD 3-Clause "New" or "Revised" License
1.2k stars 1.49k forks source link

Menu formatting in extension documentation #2064

Open ZenithRogue opened 5 years ago

ZenithRogue commented 5 years ago

I am trying to write a Scratch 2.0 to Scratch 3.0 extension converter, but am confused by the lack of documentation surrounding the dropdown menus here.

Here is my 2.0 extension

And my 3.0 conversion

Is there something I am missing with the dropdowns? Everything else was working prior to this.

naddison36 commented 5 years ago

There are a number of different options from what I've worked out. Try replacing in your code

"text": {
    "id": "supermath_Kwzz",
    "defaultMessage": "+"
}

with

text: '+'

Or

text: formatMessage({
    id: 'supermath_Kwzz',
    default: '+',
    description: 'Sum'
})

For this to work, you will also have to import the formatMessage function by adding

const formatMessage = require('format-message');

Or use the following function like is done in the ev3 extension

_formatMenu (menu) {
        const m = [];
        for (let i = 0; i < menu.length; i++) {
            const obj = {};
            obj.text = menu[i];
            obj.value = i.toString();
            m.push(obj);
        }
        return m;
    }

The menu declaration then becomes

menus: [{
    supermath: this._formatMenu(['+', '-', '*', '/']),
}],
thisandagain commented 5 years ago

Thanks @NitroCipher! This is really neat. As a heads-up: the Scratch 3.0 extension specification is still in very active development and the way menus work may continue to change. Once our extension specification is a little more settled we will publish documentation.

/cc @cwillisf @kchadha