This is done by adding a new element "customFieldTypes" to the extension info structure. Ex:
```
customFieldTypes: {
angleField: {
implementation: { fromJson: options => new AngleField(options) },
output: 'number',
outputShape: 2,
}
}
```
Field types are defined by an implementation that has to match what is expected by ScratchBlocks.Field.register and its output and shape.
src/engine/runtime.js has been updated to handle the new "customFieldTypes"-field:
- Existing (global) field types cannot be overridden
- New fields are "namespaced" to the extension in the same way as opcodes are.
Once the custom field type has been picked up by scratch-vm a "EXTENSION_FIELD_ADDED" event is emitted.
It is then up to the hosting app to call ScratchBlocks.Field.register to register the field type with ScratchBlocks. Ex:
```
vm.addListener('EXTENSION_FIELD_ADDED', fieldInfo => {
this.ScratchBlocks.Field.register(fieldInfo.name, fieldInfo.implementation);
});
```
This change makes the VM's `setLocale` method call `refreshBlocks` even
when not changing the language, though it still skips an unnecessary
call to `formatMessage.setup` in this case.
And emit it whenever we think the project has changed. Try to not emit it when a change has happened internally that shouldn't affect the serialized project.
This iteration fires the event too frequently, e.g., when switching sprites. This is meant as a simple initial implementation that can be improved.
Resolves#1601. Does not include the project JSON since that would require knowledge of a project ID, which the VM has not been responsible for so far.
For now, it is the responsibility of the consumer to determine if these assets should be saved or not. Otherwise the VM would need to be responsible for saving, which has been out of its scope.
* Beginning refactor: renaming 'device' to 'peripheral', shortening function names, reordering functions, etc.
* Continuing refactoring: renaming some functions to be more verbose in the runtime, adding JSDocs, etc.
* Changing 'device' to 'peripheral', etc.
* Changing 'session' to 'socket'.
* Fixing EV3 menus and menu arg validation, reordering functions, etc.
* Add _send, add some references to documentation, etc.
* Factored out _outputCommand and _inputCommand, renamed some enums, etc.
* Fixed _outputCommand, some other minor cleanup.
* Make _outputCommand and _inputCommand public.
* Added TODO.
* Renamed BLE UUID enums to be clearer.
* Change WeDo2 in comments to WeDo 2.0, etc.
* Changed some WeDo2Motor command names, cleaned up some JSDocs.
* Beginning a major EV3 refactor.
* WeDo2 formatting and comment changes.
* Motor refactoring in EV3: motorTurnClockwise and motorTurnCounterClockwise initial working state.
* Add reminders to possibly cast motor menu args in WeDo2.
* Continue to move motor commands in EV3 to EV3Motor class, don't create new EV3Motor on every poll cycle, etc.
* Factoring EV3 polling value commands, etc.
* Fixing EV3 motor power, position and button pressed, and some commenting, etc.
* Move EV3 motor position parsing to EV3Motor class, move directCommand and directCompoundCommand functions, some commenting, etc.
* Changed WeDo2 motor label enum name.
* Removed some EV3 motor functions that aren't needed, changed menu label enum names, moved some opcodes up to enums.
* Fixing comments and documentation.
* Some commenting.
* Adding further documentation and references to PDFs, changed reply check to be safer, etc.
* Some comment changes.
* Moving some functions around in EV3 and WeDo2 to match.
* Commenting, etc.
* Some renaming of session, etc.
* Fix stopAllMotors in EV3.
* Fixing clearing of motors in EV3.
* Some comment changes.
* Change runtime .extensions/registerExtension to .peripheralExtensions/registerPeripheralExtension.
* Renaming outputCommand/inputCommand to generateOutputCommand/generateInputCommand, etc.
* Moved motorCommandIDs to EV3Motor class, renamed directCommand to generateCommand, etc.
* Adding a reminder to rename something.
* JSDoc fix in EV3Motor class.
* Fixing microbit function name.
* Adding a todo item.
* Changing Ev3 menu formats to be backwards compatible, moving a BLE function up.
* Fixing EV3 ports again, and button pressed returning a boolean.
* Fixing menu value to be a string in EV3.