mirror of
https://github.com/scratchfoundation/scratch-html5.git
synced 2024-12-11 00:02:22 -05:00
Added getTimeString to the runtime and made a few other small fixes.
This commit is contained in:
parent
5482589da7
commit
311b411315
2 changed files with 22 additions and 4 deletions
|
@ -177,6 +177,22 @@ Runtime.prototype.spriteNamed = function(n) {
|
||||||
return selected_sprite;
|
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
|
// Reassigns z-indices for layer functions
|
||||||
Runtime.prototype.reassignZ = function(target, move) {
|
Runtime.prototype.reassignZ = function(target, move) {
|
||||||
var sprites = this.sprites;
|
var sprites = this.sprites;
|
||||||
|
|
|
@ -29,6 +29,8 @@ SensingPrims.prototype.addPrimsTo = function(primTable) {
|
||||||
primTable['distanceTo:'] = this.primDistanceTo;
|
primTable['distanceTo:'] = this.primDistanceTo;
|
||||||
|
|
||||||
primTable['getAttribute:of:'] = this.primGetAttribute;
|
primTable['getAttribute:of:'] = this.primGetAttribute;
|
||||||
|
|
||||||
|
primTable['timeAndDate'] = function(b){ return runtime.getTimeString(interp.arg(b, 0)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
SensingPrims.prototype.primTouching = function(b) {
|
SensingPrims.prototype.primTouching = function(b) {
|
||||||
|
@ -124,9 +126,9 @@ var stageColorHitTest = function(target, color) {
|
||||||
|
|
||||||
var stageColorByColorHitTest = function(target, myColor, otherColor) {
|
var stageColorByColorHitTest = function(target, myColor, otherColor) {
|
||||||
var threshold_acceptable = function(a, b, c, x, y, z) {
|
var threshold_acceptable = function(a, b, c, x, y, z) {
|
||||||
diff_a = Math.abs(a-x);
|
var diff_a = Math.abs(a-x);
|
||||||
diff_b = Math.abs(b-y);
|
var diff_b = Math.abs(b-y);
|
||||||
diff_c = Math.abs(c-z);
|
var diff_c = Math.abs(c-z);
|
||||||
if (diff_a + diff_b + diff_c < 100) {
|
if (diff_a + diff_b + diff_c < 100) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -154,7 +156,7 @@ var stageColorByColorHitTest = function(target, myColor, otherColor) {
|
||||||
var hitCanvas = document.createElement('canvas');
|
var hitCanvas = document.createElement('canvas');
|
||||||
hitCanvas.width = 480;
|
hitCanvas.width = 480;
|
||||||
hitCanvas.height = 360;
|
hitCanvas.height = 360;
|
||||||
hitCtx = hitCanvas.getContext('2d');
|
var hitCtx = hitCanvas.getContext('2d');
|
||||||
$.each(runtime.sprites, function(i, sprite) {
|
$.each(runtime.sprites, function(i, sprite) {
|
||||||
if (sprite != target)
|
if (sprite != target)
|
||||||
sprite.stamp(hitCtx, 100);
|
sprite.stamp(hitCtx, 100);
|
||||||
|
|
Loading…
Reference in a new issue