summaryrefslogtreecommitdiff
path: root/objects.js
diff options
context:
space:
mode:
Diffstat (limited to 'objects.js')
-rw-r--r--objects.js89
1 files changed, 72 insertions, 17 deletions
diff --git a/objects.js b/objects.js
index 077d3f7..45dbea4 100644
--- a/objects.js
+++ b/objects.js
@@ -125,7 +125,7 @@ PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.objects = '2015-January-28';
+modules.objects = '2015-February-28';
var SpriteMorph;
var StageMorph;
@@ -613,11 +613,22 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'control',
spec: 'when %keyHat key pressed'
},
+
+ /* migrated to a newer block version:
+
receiveClick: {
type: 'hat',
category: 'control',
spec: 'when I am clicked'
},
+ */
+
+ receiveInteraction: {
+ type: 'hat',
+ category: 'control',
+ spec: 'when I am %interaction',
+ defaults: ['clicked']
+ },
receiveMessage: {
type: 'hat',
category: 'control',
@@ -1294,6 +1305,10 @@ SpriteMorph.prototype.initBlockMigrations = function () {
doStopBlock: {
selector: 'doStopThis',
inputs: [['this block']]
+ },
+ receiveClick: {
+ selector: 'receiveInteraction',
+ inputs: [['clicked']]
}
};
};
@@ -1342,8 +1357,6 @@ SpriteMorph.prototype.blockAlternatives = {
setSize: ['changeSize'],
// control:
- receiveGo: ['receiveClick'],
- receiveClick: ['receiveGo'],
doBroadcast: ['doBroadcastAndWait'],
doBroadcastAndWait: ['doBroadcast'],
doIf: ['doIfElse', 'doUntil'],
@@ -1514,15 +1527,13 @@ SpriteMorph.prototype.setName = function (string) {
SpriteMorph.prototype.drawNew = function () {
var myself = this,
- currentCenter = this.center(),
+ currentCenter,
facing, // actual costume heading based on my rotation style
isFlipped,
- isLoadingCostume = this.costume &&
- typeof this.costume.loaded === 'function',
+ isLoadingCostume,
cst,
pic, // (flipped copy of) actual costume based on my rotation style
- stageScale = this.parent instanceof StageMorph ?
- this.parent.scale : 1,
+ stageScale,
newX,
corners = [],
origin,
@@ -1536,6 +1547,11 @@ SpriteMorph.prototype.drawNew = function () {
this.wantsRedraw = true;
return;
}
+ currentCenter = this.center();
+ isLoadingCostume = this.costume &&
+ typeof this.costume.loaded === 'function';
+ stageScale = this.parent instanceof StageMorph ?
+ this.parent.scale : 1;
facing = this.rotationStyle ? this.heading : 90;
if (this.rotationStyle === 2) {
facing = 90;
@@ -1683,7 +1699,7 @@ SpriteMorph.prototype.blockForSelector = function (selector, setDefaults) {
: new ReporterBlockMorph(info.type === 'predicate');
block.color = this.blockColor[info.category];
block.category = info.category;
- block.selector = selector;
+ block.selector = migration ? migration.selector : selector;
if (contains(['reifyReporter', 'reifyPredicate'], block.selector)) {
block.isStatic = true;
}
@@ -1930,7 +1946,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(block('receiveGo'));
blocks.push(block('receiveKey'));
- blocks.push(block('receiveClick'));
+ blocks.push(block('receiveInteraction'));
blocks.push(block('receiveMessage'));
blocks.push('-');
blocks.push(block('doBroadcast'));
@@ -3326,6 +3342,7 @@ SpriteMorph.prototype.prepareToBeGrabbed = function (hand) {
SpriteMorph.prototype.justDropped = function () {
this.restoreLayers();
this.positionTalkBubble();
+ this.receiveUserInteraction('dropped');
};
// SpriteMorph drawing:
@@ -3655,9 +3672,6 @@ SpriteMorph.prototype.allHatBlocksFor = function (message) {
if (morph.selector === 'receiveOnClone') {
return message === '__clone__init__';
}
- if (morph.selector === 'receiveClick') {
- return message === '__click__';
- }
}
return false;
});
@@ -3686,13 +3700,37 @@ SpriteMorph.prototype.allHatBlocksForKey = function (key) {
});
};
+SpriteMorph.prototype.allHatBlocksForInteraction = function (interaction) {
+ return this.scripts.children.filter(function (morph) {
+ if (morph.selector) {
+ if (morph.selector === 'receiveInteraction') {
+ return morph.inputs()[0].evaluate()[0] === interaction;
+ }
+ }
+ return false;
+ });
+};
+
// SpriteMorph events
SpriteMorph.prototype.mouseClickLeft = function () {
- var stage = this.parentThatIsA(StageMorph),
- hats = this.allHatBlocksFor('__click__'),
- procs = [];
+ return this.receiveUserInteraction('clicked');
+};
+
+SpriteMorph.prototype.mouseEnter = function () {
+ return this.receiveUserInteraction('mouse-entered');
+};
+
+SpriteMorph.prototype.mouseDownLeft = function () {
+ return this.receiveUserInteraction('pressed');
+};
+SpriteMorph.prototype.receiveUserInteraction = function (interaction) {
+ var stage = this.parentThatIsA(StageMorph),
+ procs = [],
+ hats;
+ if (!stage) {return; } // currently dragged
+ hats = this.allHatBlocksForInteraction(interaction);
hats.forEach(function (block) {
procs.push(stage.threads.startProcess(block, stage.isThreadSafe));
});
@@ -4367,6 +4405,7 @@ SpriteMorph.prototype.mouseEnterDragging = function () {
};
SpriteMorph.prototype.mouseLeave = function () {
+ this.receiveUserInteraction('mouse-departed');
if (!this.enableNesting) {return; }
this.removeHighlight();
};
@@ -5224,7 +5263,7 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push(block('receiveGo'));
blocks.push(block('receiveKey'));
- blocks.push(block('receiveClick'));
+ blocks.push(block('receiveInteraction'));
blocks.push(block('receiveMessage'));
blocks.push('-');
blocks.push(block('doBroadcast'));
@@ -5819,11 +5858,27 @@ StageMorph.prototype.allHatBlocksFor
StageMorph.prototype.allHatBlocksForKey
= SpriteMorph.prototype.allHatBlocksForKey;
+StageMorph.prototype.allHatBlocksForInteraction
+ = SpriteMorph.prototype.allHatBlocksForInteraction;
+
// StageMorph events
StageMorph.prototype.mouseClickLeft
= SpriteMorph.prototype.mouseClickLeft;
+StageMorph.prototype.mouseEnter
+ = SpriteMorph.prototype.mouseEnter;
+
+StageMorph.prototype.mouseLeave = function () {
+ this.receiveUserInteraction('mouse-departed');
+};
+
+StageMorph.prototype.mouseDownLeft
+ = SpriteMorph.prototype.mouseDownLeft;
+
+StageMorph.prototype.receiveUserInteraction
+ = SpriteMorph.prototype.receiveUserInteraction;
+
// StageMorph custom blocks
StageMorph.prototype.deleteAllBlockInstances