summaryrefslogtreecommitdiff
path: root/objects.js
diff options
context:
space:
mode:
Diffstat (limited to 'objects.js')
-rw-r--r--objects.js144
1 files changed, 99 insertions, 45 deletions
diff --git a/objects.js b/objects.js
index a15aec4..e5f310b 100644
--- a/objects.js
+++ b/objects.js
@@ -125,7 +125,7 @@ PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.objects = '2014-July-30';
+modules.objects = '2014-December-04';
var SpriteMorph;
var StageMorph;
@@ -1178,6 +1178,13 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'lists',
spec: 'map %repRing over %l'
},
+ doForEach: {
+ dev: true,
+ type: 'command',
+ category: 'lists',
+ spec: 'for %upvar in %l %cs',
+ defaults: [localize('each item')]
+ },
// Code mapping - experimental
doMapCodeOrHeader: { // experimental
@@ -1701,6 +1708,20 @@ SpriteMorph.prototype.blockTemplates = function (category) {
return menu;
}
+ function addVar(pair) {
+ if (pair) {
+ if (myself.variables.silentFind(pair[0])) {
+ myself.inform('that name is already in use');
+ } else {
+ myself.addVariable(pair[0], pair[1]);
+ myself.toggleVariableWatcher(pair[0], pair[1]);
+ myself.blocksCache[cat] = null;
+ myself.paletteCache[cat] = null;
+ myself.parentThatIsA(IDE_Morph).refreshPalette();
+ }
+ }
+ }
+
if (cat === 'motion') {
blocks.push(block('forward'));
@@ -1998,15 +2019,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
function () {
new VariableDialogMorph(
null,
- function (pair) {
- if (pair && !myself.variables.silentFind(pair[0])) {
- myself.addVariable(pair[0], pair[1]);
- myself.toggleVariableWatcher(pair[0], pair[1]);
- myself.blocksCache[cat] = null;
- myself.paletteCache[cat] = null;
- myself.parentThatIsA(IDE_Morph).refreshPalette();
- }
- },
+ addVar,
myself
).prompt(
'Variable name',
@@ -2088,6 +2101,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(txt);
blocks.push('-');
blocks.push(block('reportMap'));
+ blocks.push('-');
+ blocks.push(block('doForEach'));
}
/////////////////////////////////
@@ -2195,8 +2210,8 @@ SpriteMorph.prototype.freshPalette = function (category) {
var defs = SpriteMorph.prototype.blocks,
hiddens = StageMorph.prototype.hiddenPrimitives;
return Object.keys(hiddens).some(function (any) {
- return defs[any].category === category ||
- contains((more[category] || []), any);
+ return !isNil(defs[any]) && (defs[any].category === category
+ || contains((more[category] || []), any));
});
}
@@ -2235,7 +2250,7 @@ SpriteMorph.prototype.freshPalette = function (category) {
var hiddens = StageMorph.prototype.hiddenPrimitives,
defs = SpriteMorph.prototype.blocks;
Object.keys(hiddens).forEach(function (sel) {
- if (defs[sel].category === category) {
+ if (defs[sel] && (defs[sel].category === category)) {
delete StageMorph.prototype.hiddenPrimitives[sel];
}
});
@@ -3263,8 +3278,11 @@ SpriteMorph.prototype.setCenter = function (aPoint, justMe) {
SpriteMorph.prototype.nestingBounds = function () {
// same as fullBounds(), except that it uses "parts" instead of children
- var result;
- result = this.bounds;
+ // and special cases the costume-less "arrow" shape's bounding box
+ var result = this.bounds;
+ if (!this.costume && this.penBounds) {
+ result = this.penBounds.translateBy(this.position());
+ }
this.parts.forEach(function (part) {
if (part.isVisible) {
result = result.merge(part.nestingBounds());
@@ -3488,6 +3506,7 @@ SpriteMorph.prototype.allMessageNames = function () {
};
SpriteMorph.prototype.allHatBlocksFor = function (message) {
+ if (typeof message === 'number') {message = message.toString(); }
return this.scripts.children.filter(function (morph) {
var event;
if (morph.selector) {
@@ -4415,17 +4434,33 @@ StageMorph.prototype.drawOn = function (aCanvas, aRect) {
hs = h / this.scale;
context.save();
context.scale(this.scale, this.scale);
- context.drawImage(
- this.penTrails(),
- src.left() / this.scale,
- src.top() / this.scale,
- ws,
- hs,
- area.left() / this.scale,
- area.top() / this.scale,
- ws,
- hs
- );
+ try {
+ context.drawImage(
+ this.penTrails(),
+ src.left() / this.scale,
+ src.top() / this.scale,
+ ws,
+ hs,
+ area.left() / this.scale,
+ area.top() / this.scale,
+ ws,
+ hs
+ );
+ } catch (err) { // sometimes triggered only by Firefox
+ // console.log(err);
+ context.restore();
+ context.drawImage(
+ this.penTrails(),
+ 0,
+ 0,
+ this.dimensions.x,
+ this.dimensions.y,
+ this.left(),
+ this.top(),
+ this.dimensions.x * this.scale,
+ this.dimensions.y * this.scale
+ );
+ }
context.restore();
}
};
@@ -4708,6 +4743,7 @@ StageMorph.prototype.fireKeyEvent = function (key) {
var evt = key.toLowerCase(),
hats = [],
procs = [],
+ ide = this.parentThatIsA(IDE_Morph),
myself = this;
this.keysPressed[evt] = true;
@@ -4715,19 +4751,24 @@ StageMorph.prototype.fireKeyEvent = function (key) {
return this.fireGreenFlagEvent();
}
if (evt === 'ctrl f') {
- return this.parentThatIsA(IDE_Morph).currentSprite.searchBlocks();
+ if (!ide.isAppMode) {ide.currentSprite.searchBlocks(); }
+ return;
}
if (evt === 'ctrl n') {
- return this.parentThatIsA(IDE_Morph).createNewProject();
+ if (!ide.isAppMode) {ide.createNewProject(); }
+ return;
}
if (evt === 'ctrl o') {
- return this.parentThatIsA(IDE_Morph).openProjectsBrowser();
+ if (!ide.isAppMode) {ide.openProjectsBrowser(); }
+ return;
}
if (evt === 'ctrl s') {
- return this.parentThatIsA(IDE_Morph).save();
+ if (!ide.isAppMode) {ide.save(); }
+ return;
}
if (evt === 'ctrl shift s') {
- return this.parentThatIsA(IDE_Morph).saveProjectsBrowser();
+ if (!ide.isAppMode) {return ide.saveProjectsBrowser(); }
+ return;
}
if (evt === 'esc') {
return this.fireStopAllEvent();
@@ -4869,6 +4910,20 @@ StageMorph.prototype.blockTemplates = function (category) {
);
}
+ function addVar(pair) {
+ if (pair) {
+ if (myself.variables.silentFind(pair[0])) {
+ myself.inform('that name is already in use');
+ } else {
+ myself.addVariable(pair[0], pair[1]);
+ myself.toggleVariableWatcher(pair[0], pair[1]);
+ myself.blocksCache[cat] = null;
+ myself.paletteCache[cat] = null;
+ myself.parentThatIsA(IDE_Morph).refreshPalette();
+ }
+ }
+ }
+
if (cat === 'motion') {
txt = new TextMorph(localize(
@@ -5115,15 +5170,7 @@ StageMorph.prototype.blockTemplates = function (category) {
function () {
new VariableDialogMorph(
null,
- function (pair) {
- if (pair && !myself.variables.silentFind(pair[0])) {
- myself.addVariable(pair[0], pair[1]);
- myself.toggleVariableWatcher(pair[0], pair[1]);
- myself.blocksCache[cat] = null;
- myself.paletteCache[cat] = null;
- myself.parentThatIsA(IDE_Morph).refreshPalette();
- }
- },
+ addVar,
myself
).prompt(
'Variable name',
@@ -5199,6 +5246,8 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push(txt);
blocks.push('-');
blocks.push(block('reportMap'));
+ blocks.push('-');
+ blocks.push(block('doForEach'));
}
/////////////////////////////////
@@ -5337,7 +5386,7 @@ StageMorph.prototype.thumbnail = function (extentPoint, excludedSprite) {
this.dimensions.y * this.scale
);
this.children.forEach(function (morph) {
- if (morph !== excludedSprite) {
+ if (morph.isVisible && (morph !== excludedSprite)) {
fb = morph.fullBounds();
fimg = morph.fullImage();
if (fimg.width && fimg.height) {
@@ -6446,10 +6495,14 @@ CellMorph.prototype.drawNew = function () {
}
this.contentsMorph.setColor(new Color(255, 255, 255));
} else if (typeof this.contents === 'boolean') {
- this.contentsMorph = SpriteMorph.prototype.booleanMorph.call(
+ img = SpriteMorph.prototype.booleanMorph.call(
null,
this.contents
- );
+ ).fullImage();
+ this.contentsMorph = new Morph();
+ this.contentsMorph.silentSetWidth(img.width);
+ this.contentsMorph.silentSetHeight(img.height);
+ this.contentsMorph.image = img;
} else if (this.contents instanceof HTMLCanvasElement) {
this.contentsMorph = new Morph();
this.contentsMorph.silentSetWidth(this.contents.width);
@@ -6774,7 +6827,8 @@ WatcherMorph.prototype.update = function () {
if (this.target && this.getter) {
this.updateLabel();
if (this.target instanceof VariableFrame) {
- newValue = this.target.vars[this.getter];
+ newValue = this.target.vars[this.getter] ?
+ this.target.vars[this.getter].value : undefined;
} else {
newValue = this.target[this.getter]();
}
@@ -6859,7 +6913,7 @@ WatcherMorph.prototype.fixLayout = function () {
this.sliderMorph.button.pressColor.b += 100;
this.sliderMorph.setHeight(fontSize);
this.sliderMorph.action = function (num) {
- myself.target.vars[myself.getter] = Math.round(num);
+ myself.target.vars[myself.getter].value = Math.round(num);
};
this.add(this.sliderMorph);
}