summaryrefslogtreecommitdiff
path: root/threads.js
diff options
context:
space:
mode:
Diffstat (limited to 'threads.js')
-rw-r--r--threads.js66
1 files changed, 50 insertions, 16 deletions
diff --git a/threads.js b/threads.js
index d4a6732..77632d0 100644
--- a/threads.js
+++ b/threads.js
@@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/
// Global stuff ////////////////////////////////////////////////////////
-modules.threads = '2014-January-10';
+modules.threads = '2014-Feb-10';
var ThreadManager;
var Process;
@@ -111,7 +111,7 @@ function snapEquals(a, b) {
y = b;
}
- // handle text comparision text-insensitive.
+ // handle text comparision case-insensitive.
if (isString(x) && isString(y)) {
return x.toLowerCase() === y.toLowerCase();
}
@@ -1643,15 +1643,15 @@ Process.prototype.doGlide = function (secs, endX, endY) {
if (!this.context.startTime) {
this.context.startTime = Date.now();
this.context.startValue = new Point(
- this.homeContext.receiver.xPosition(),
- this.homeContext.receiver.yPosition()
+ this.blockReceiver().xPosition(),
+ this.blockReceiver().yPosition()
);
}
if ((Date.now() - this.context.startTime) >= (secs * 1000)) {
- this.homeContext.receiver.gotoXY(endX, endY);
+ this.blockReceiver().gotoXY(endX, endY);
return null;
}
- this.homeContext.receiver.glide(
+ this.blockReceiver().glide(
secs * 1000,
endX,
endY,
@@ -1666,10 +1666,10 @@ Process.prototype.doGlide = function (secs, endX, endY) {
Process.prototype.doSayFor = function (data, secs) {
if (!this.context.startTime) {
this.context.startTime = Date.now();
- this.homeContext.receiver.bubble(data);
+ this.blockReceiver().bubble(data);
}
if ((Date.now() - this.context.startTime) >= (secs * 1000)) {
- this.homeContext.receiver.stopTalking();
+ this.blockReceiver().stopTalking();
return null;
}
this.pushContext('doYield');
@@ -1679,16 +1679,21 @@ Process.prototype.doSayFor = function (data, secs) {
Process.prototype.doThinkFor = function (data, secs) {
if (!this.context.startTime) {
this.context.startTime = Date.now();
- this.homeContext.receiver.doThink(data);
+ this.blockReceiver().doThink(data);
}
if ((Date.now() - this.context.startTime) >= (secs * 1000)) {
- this.homeContext.receiver.stopTalking();
+ this.blockReceiver().stopTalking();
return null;
}
this.pushContext('doYield');
this.pushContext();
};
+Process.prototype.blockReceiver = function () {
+ return this.context ? this.context.receiver || this.homeContext.receiver
+ : this.homeContext.receiver;
+};
+
// Process sound primitives (interpolated)
Process.prototype.doPlaySoundUntilDone = function (name) {
@@ -1723,7 +1728,7 @@ Process.prototype.doStopAllSounds = function () {
Process.prototype.doAsk = function (data) {
var stage = this.homeContext.receiver.parentThatIsA(StageMorph),
- isStage = this.homeContext.receiver instanceof StageMorph,
+ isStage = this.blockReceiver() instanceof StageMorph,
activePrompter;
if (!this.prompter) {
@@ -1733,7 +1738,7 @@ Process.prototype.doAsk = function (data) {
);
if (!activePrompter) {
if (!isStage) {
- this.homeContext.receiver.bubble(data, false, true);
+ this.blockReceiver().bubble(data, false, true);
}
this.prompter = new StagePrompterMorph(isStage ? data : null);
if (stage.scale < 1) {
@@ -1753,7 +1758,7 @@ Process.prototype.doAsk = function (data) {
stage.lastAnswer = this.prompter.inputField.getValue();
this.prompter.destroy();
this.prompter = null;
- if (!isStage) {this.homeContext.receiver.stopTalking(); }
+ if (!isStage) {this.blockReceiver().stopTalking(); }
return null;
}
}
@@ -2288,7 +2293,7 @@ Process.prototype.createClone = function (name) {
// Process sensing primitives
Process.prototype.reportTouchingObject = function (name) {
- var thisObj = this.homeContext.receiver;
+ var thisObj = this.blockReceiver();
if (thisObj) {
return this.objectTouchingObject(thisObj, name);
@@ -2384,7 +2389,7 @@ Process.prototype.reportColorIsTouchingColor = function (color1, color2) {
};
Process.prototype.reportDistanceTo = function (name) {
- var thisObj = this.homeContext.receiver,
+ var thisObj = this.blockReceiver(),
thatObj,
stage,
rc,
@@ -2407,7 +2412,7 @@ Process.prototype.reportDistanceTo = function (name) {
};
Process.prototype.reportAttributeOf = function (attribute, name) {
- var thisObj = this.homeContext.receiver,
+ var thisObj = this.blockReceiver(),
thatObj,
stage;
@@ -2531,6 +2536,35 @@ Process.prototype.reportTimer = function () {
return 0;
};
+// Process Dates and times in Snap
+// Map block options to built-in functions
+var dateMap = {
+ 'year' : 'getFullYear',
+ 'month' : 'getMonth',
+ 'date': 'getDate',
+ 'day of week' : 'getDay',
+ 'hour' : 'getHours',
+ 'minute' : 'getMinutes',
+ 'second' : 'getSeconds',
+ 'time in milliseconds' : 'getTime'
+};
+
+Process.prototype.reportDate = function (datefn) {
+ var inputFn = this.inputOption(datefn),
+ currDate = new Date(),
+ func = dateMap[inputFn],
+ result = currDate[func]();
+
+ if (!dateMap[inputFn]) { return ''; }
+
+ // Show months as 1-12 and days as 1-7
+ if (inputFn === 'month' || inputFn === 'day of week') {
+ result += 1;
+ }
+
+ return result;
+};
+
// Process code mapping
/*