Implement pen blocks
These blocks implement pen features as found in Scratch 2.0 Supporting changes include: - `Target` is now an event emitter - `RenderedTarget` now emits an event when it moves - `Target` can now store arbitrary "extra" data, called "custom state" in the code, using a `Target`'s `setCustomState` and `getCustomState` methods. This is used to store per-target pen state without requiring `Target` or `RenderedTarget` to know anything about the pen. - `Cast` can now cast to an RGB color object. - `Color` now has functions to convert between RGB and HSV, constants for for black & white, and a `mixRgb` function to lerp between two colors.
This commit is contained in:
1 parent
d33af47a87
commit
369c02b5d5
7 files changed
+382
-6
No files matched your search
@@ -15,6 +15,7 @@ var defaultBlockPackages = {
|
||||
scratch3_looks: require('../blocks/scratch3_looks'),
|
||||
scratch3_motion: require('../blocks/scratch3_motion'),
|
||||
scratch3_operators: require('../blocks/scratch3_operators'),
|
||||
scratch3_pen: require('../blocks/scratch3_pen'),
|
||||
scratch3_sound: require('../blocks/scratch3_sound'),
|
||||
scratch3_sensing: require('../blocks/scratch3_sensing'),
|
||||
scratch3_data: require('../blocks/scratch3_data'),
|
||||
|
||||
+28
-1
@@ -1,3 +1,6 @@
|
||||
var EventEmitter = require('events');
|
||||
var util = require('util');
|
||||
|
||||
var Blocks = require('./blocks');
|
||||
var Variable = require('../engine/variable');
|
||||
var List = require('../engine/list');
|
||||
@@ -14,6 +17,8 @@ var uid = require('../util/uid');
|
||||
* @constructor
|
||||
*/
|
||||
var Target = function (blocks) {
|
||||
EventEmitter.call(this);
|
||||
|
||||
if (!blocks) {
|
||||
blocks = new Blocks(this);
|
||||
}
|
||||
@@ -39,8 +44,20 @@ var Target = function (blocks) {
|
||||
* @type {Object.<string,*>}
|
||||
*/
|
||||
this.lists = {};
|
||||
/**
|
||||
* Dictionary of custom state for this target.
|
||||
* This can be used to store target-specific custom state for blocks which need it.
|
||||
* TODO: do we want to persist this in SB3 files?
|
||||
* @type {Object.<string,*>}
|
||||
*/
|
||||
this._customState = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Inherit from EventEmitter
|
||||
*/
|
||||
util.inherits(Target, EventEmitter);
|
||||
|
||||
/**
|
||||
* Called when the project receives a "green flag."
|
||||
* @abstract
|
||||
@@ -112,10 +129,20 @@ Target.prototype.lookupOrCreateList = function (name) {
|
||||
*/
|
||||
Target.prototype.postSpriteInfo = function () {};
|
||||
|
||||
Target.prototype.getCustomState = function (stateId) {
|
||||
return this._customState[stateId];
|
||||
};
|
||||
|
||||
Target.prototype.setCustomState = function (stateId, newValue) {
|
||||
this._customState[stateId] = newValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* Call to destroy a target.
|
||||
* @abstract
|
||||
*/
|
||||
Target.prototype.dispose = function () {};
|
||||
Target.prototype.dispose = function () {
|
||||
this._customState = {};
|
||||
};
|
||||
|
||||
module.exports = Target;
|
||||
Reference in new issue
Block a user