summaryrefslogtreecommitdiff
path: root/blocks.js
diff options
context:
space:
mode:
Diffstat (limited to 'blocks.js')
-rw-r--r--blocks.js119
1 files changed, 107 insertions, 12 deletions
diff --git a/blocks.js b/blocks.js
index 5cdcc1c..e9daff2 100644
--- a/blocks.js
+++ b/blocks.js
@@ -9,7 +9,7 @@
written by Jens Mönig
jens@moenig.org
- Copyright (C) 2014 by Jens Mönig
+ Copyright (C) 2015 by Jens Mönig
This file is part of Snap!.
@@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/
// Global stuff ////////////////////////////////////////////////////////
-modules.blocks = '2015-February-28';
+modules.blocks = '2015-March-23';
var SyntaxElementMorph;
@@ -340,7 +340,7 @@ SyntaxElementMorph.prototype.setScale = function (num) {
};
SyntaxElementMorph.prototype.setScale(1);
-SyntaxElementMorph.prototype.isCachingInputs = true;
+SyntaxElementMorph.prototype.isCachingInputs = false;
// SyntaxElementMorph instance creation:
@@ -382,9 +382,36 @@ SyntaxElementMorph.prototype.inputs = function () {
return part instanceof SyntaxElementMorph;
});
}
+ // this.debugCachedInputs();
return this.cachedInputs;
};
+SyntaxElementMorph.prototype.debugCachedInputs = function () {
+ // private - only used for manually debugging inputs caching
+ var realInputs, i;
+ if (!isNil(this.cachedInputs)) {
+ realInputs = this.parts().filter(function (part) {
+ return part instanceof SyntaxElementMorph;
+ });
+ }
+ if (this.cachedInputs.length !== realInputs.length) {
+ throw new Error('cached inputs size do not match: ' +
+ this.constructor.name);
+ }
+ for (i = 0; i < realInputs.length; i += 1) {
+ if (this.cachedInputs[i] !== realInputs[i]) {
+ throw new Error('cached input does not match: ' +
+ this.constructor.name +
+ ' #' +
+ i +
+ ' ' +
+ this.cachedInputs[i].constructor.name +
+ ' != ' +
+ realInputs[i].constructor.name);
+ }
+ }
+};
+
SyntaxElementMorph.prototype.allInputs = function () {
// answer arguments and nested reporters of all children
var myself = this;
@@ -994,6 +1021,8 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
null,
false,
{
+ 'any key': ['any key'],
+ 'number key': ['number key'],
'up arrow': ['up arrow'],
'down arrow': ['down arrow'],
'right arrow': ['right arrow'],
@@ -1164,6 +1193,15 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
);
part.isStatic = true;
break;
+ case '%shd':
+ part = new InputSlotMorph(
+ null,
+ false,
+ 'shadowedVariablesMenu',
+ true
+ );
+ part.isStatic = true;
+ break;
case '%lst':
part = new InputSlotMorph(
null,
@@ -1862,7 +1900,8 @@ SyntaxElementMorph.prototype.endLayout = function () {
%att - chameleon colored rectangular drop-down for attributes
%fun - chameleon colored rectangular drop-down for math functions
%typ - chameleon colored rectangular drop-down for data types
- %var - chameleon colored rectangular drop-down for variable names
+ %var - chameleon colored rectangular drop-down for variable names
+ %shd - Chameleon colored rectuangular drop-down for shadowed var names
%lst - chameleon colored rectangular drop-down for list names
%b - chameleon colored hexagonal slot (for predicates)
%l - list icon
@@ -1916,6 +1955,7 @@ BlockMorph.uber = SyntaxElementMorph.prototype;
// BlockMorph preferences settings:
+BlockMorph.prototype.isCachingInputs = true;
BlockMorph.prototype.zebraContrast = 40; // alternating color brightness
// BlockMorph sound feedback:
@@ -2988,6 +3028,12 @@ BlockMorph.prototype.alternateBlockColor = function () {
this.fixChildrensBlockColor(true); // has issues if not forced
};
+BlockMorph.prototype.ghost = function () {
+ this.setColor(
+ SpriteMorph.prototype.blockColor[this.category].lighter(35)
+ );
+};
+
BlockMorph.prototype.fixLabelColor = function () {
if (this.zebraContrast > 0 && this.category) {
var clr = SpriteMorph.prototype.blockColor[this.category];
@@ -3036,6 +3082,9 @@ BlockMorph.prototype.fullCopy = function () {
ans.setSpec(this.instantiationSpec);
}
ans.allChildren().filter(function (block) {
+ if (block instanceof SyntaxElementMorph) {
+ block.cachedInputs = null;
+ }
return !isNil(block.comment);
}).forEach(function (block) {
var cmnt = block.comment.fullCopy();
@@ -3065,6 +3114,10 @@ BlockMorph.prototype.mouseClickLeft = function () {
}
};
+BlockMorph.prototype.reactToTemplateCopy = function () {
+ this.forceNormalColoring();
+};
+
// BlockMorph thumbnail
BlockMorph.prototype.thumbnail = function (scale, clipWidth, noShadow) {
@@ -4614,6 +4667,7 @@ RingMorph.uber = ReporterBlockMorph.prototype;
// RingMorph preferences settings:
+RingMorph.prototype.isCachingInputs = false;
// RingMorph.prototype.edge = 2;
// RingMorph.prototype.rounding = 9;
// RingMorph.prototype.alpha = 0.8;
@@ -6860,6 +6914,21 @@ InputSlotMorph.prototype.getVarNamesDict = function () {
return {};
};
+InputSlotMorph.prototype.shadowedVariablesMenu = function () {
+ var block = this.parentThatIsA(BlockMorph),
+ rcvr,
+ dict = {};
+
+ if (!block) {return dict; }
+ rcvr = block.receiver();
+ if (rcvr) {
+ rcvr.inheritedVariableNames(true).forEach(function (name) {
+ dict[name] = name;
+ });
+ }
+ return dict;
+};
+
InputSlotMorph.prototype.setChoices = function (dict, readonly) {
// externally specify choices and read-only status,
// used for custom blocks
@@ -7778,6 +7847,8 @@ SymbolMorph.prototype.names = [
'pointRight',
'gears',
'file',
+ 'mutedSounds',
+ 'unmutedSounds',
'fullScreen',
'normalScreen',
'smallStage',
@@ -7902,6 +7973,10 @@ SymbolMorph.prototype.symbolCanvasColored = function (aColor) {
return this.drawSymbolGears(canvas, aColor);
case 'file':
return this.drawSymbolFile(canvas, aColor);
+ case 'mutedSounds':
+ return this.drawSymbolMutedSounds(canvas, aColor);
+ case 'unmutedSounds':
+ return this.drawSymbolUnmutedSounds(canvas, aColor);
case 'fullScreen':
return this.drawSymbolFullScreen(canvas, aColor);
case 'normalScreen':
@@ -8104,6 +8179,34 @@ SymbolMorph.prototype.drawSymbolFile = function (canvas, color) {
return canvas;
};
+SymbolMorph.prototype.drawSymbolMutedSounds = function (canvas, color) {
+ // answer a canvas showing a muted sounds toggling symbol
+ var ctx = canvas.getContext('2d'),
+ w = canvas.width,
+ h = canvas.height,
+ w2 = w / 2,
+ h2 = h / 2;
+
+ ctx.fillStyle = color.darker(40).toString();
+ ctx.fillRect(0, 0, w, h);
+
+ return canvas;
+};
+
+SymbolMorph.prototype.drawSymbolUnmutedSounds = function (canvas, color) {
+ // answer a canvas showing a UNmuted sounds toggling symbol
+ var ctx = canvas.getContext('2d'),
+ w = canvas.width,
+ h = canvas.height,
+ w2 = w / 2,
+ h2 = h / 2;
+
+ ctx.fillStyle = color.darker(60).toString();
+ ctx.fillRect(0, 0, w, h);
+
+ return canvas;
+};
+
SymbolMorph.prototype.drawSymbolFullScreen = function (canvas, color) {
// answer a canvas showing two arrows pointing diagonally outwards
var ctx = canvas.getContext('2d'),
@@ -9197,10 +9300,6 @@ MultiArgMorph.prototype = new ArgMorph();
MultiArgMorph.prototype.constructor = MultiArgMorph;
MultiArgMorph.uber = ArgMorph.prototype;
-// MultiArgMorph preferences settings
-
-MultiArgMorph.prototype.isCachingInputs = false;
-
// MultiArgMorph instance creation:
function MultiArgMorph(
@@ -9631,10 +9730,6 @@ ArgLabelMorph.prototype = new ArgMorph();
ArgLabelMorph.prototype.constructor = ArgLabelMorph;
ArgLabelMorph.uber = ArgMorph.prototype;
-// ArgLabelMorph preferences settings
-
-ArgLabelMorph.prototype.isCachingInputs = false;
-
// MultiArgMorph instance creation:
function ArgLabelMorph(argMorph, labelTxt) {