From 311b411315a4f703a2623902cab21dbe885a1469 Mon Sep 17 00:00:00 2001 From: "Shane M. Clements" Date: Wed, 30 Oct 2013 11:40:53 -0600 Subject: [PATCH] Added getTimeString to the runtime and made a few other small fixes. --- js/Runtime.js | 16 ++++++++++++++++ js/primitives/SensingPrims.js | 10 ++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/js/Runtime.js b/js/Runtime.js index 00b7a38..0b8defb 100644 --- a/js/Runtime.js +++ b/js/Runtime.js @@ -176,6 +176,22 @@ Runtime.prototype.spriteNamed = function(n) { }); return selected_sprite; } + +Runtime.prototype.getTimeString = function(which) { + // Return local time properties. + var now = new Date(); + switch (which) { + case 'hour': return now.getHours(); + case 'minute': return now.getMinutes(); + case 'second': return now.getSeconds(); + case 'year': return now.getFullYear(); // four digit year (e.g. 2012) + case 'month': return now.getMonth() + 1; // 1-12 + case 'date': return now.getDate(); // 1-31 + case 'day of week': return now.getDay() + 1; // 1-7, where 1 is Sunday + } + return ''; // shouldn't happen +} + // Reassigns z-indices for layer functions Runtime.prototype.reassignZ = function(target, move) { diff --git a/js/primitives/SensingPrims.js b/js/primitives/SensingPrims.js index 0529081..49ec242 100644 --- a/js/primitives/SensingPrims.js +++ b/js/primitives/SensingPrims.js @@ -29,6 +29,8 @@ SensingPrims.prototype.addPrimsTo = function(primTable) { primTable['distanceTo:'] = this.primDistanceTo; primTable['getAttribute:of:'] = this.primGetAttribute; + + primTable['timeAndDate'] = function(b){ return runtime.getTimeString(interp.arg(b, 0)); }; } SensingPrims.prototype.primTouching = function(b) { @@ -124,9 +126,9 @@ var stageColorHitTest = function(target, color) { var stageColorByColorHitTest = function(target, myColor, otherColor) { var threshold_acceptable = function(a, b, c, x, y, z) { - diff_a = Math.abs(a-x); - diff_b = Math.abs(b-y); - diff_c = Math.abs(c-z); + var diff_a = Math.abs(a-x); + var diff_b = Math.abs(b-y); + var diff_c = Math.abs(c-z); if (diff_a + diff_b + diff_c < 100) { return true; } @@ -154,7 +156,7 @@ var stageColorByColorHitTest = function(target, myColor, otherColor) { var hitCanvas = document.createElement('canvas'); hitCanvas.width = 480; hitCanvas.height = 360; - hitCtx = hitCanvas.getContext('2d'); + var hitCtx = hitCanvas.getContext('2d'); $.each(runtime.sprites, function(i, sprite) { if (sprite != target) sprite.stamp(hitCtx, 100);