Formatting and indentation fixes
This commit is contained in:
parent
73fdd4b7eb
commit
1a72b01b31
22 changed files with 690 additions and 691 deletions
|
@ -15,7 +15,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var LooksPrims = function() {}
|
||||
var LooksPrims = function() {};
|
||||
|
||||
LooksPrims.prototype.addPrimsTo = function(primTable) {
|
||||
primTable["show"] = this.primShow;
|
||||
|
@ -42,28 +42,28 @@ LooksPrims.prototype.addPrimsTo = function(primTable) {
|
|||
primTable["changeGraphicEffect:by:"] = this.primChangeEffect;
|
||||
primTable["setGraphicEffect:to:"] = this.primSetEffect;
|
||||
primTable["filterReset"] = this.primClearEffects;
|
||||
|
||||
|
||||
primTable["say:"] = function(b) { showBubble(b, 'say'); };
|
||||
primTable["say:duration:elapsed:from:"] = function(b) { showBubbleAndWait(b, 'say'); };
|
||||
primTable["think:"] = function(b) { showBubble(b, 'think'); };
|
||||
primTable["think:duration:elapsed:from:"] = function(b) { showBubbleAndWait(b, 'think'); };
|
||||
}
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primShow = function(b) {
|
||||
interp.targetSprite().setVisible(true);
|
||||
interp.redraw();
|
||||
}
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primHide = function(b) {
|
||||
interp.targetSprite().setVisible(false);
|
||||
interp.targetSprite().setVisible(false);
|
||||
interp.redraw();
|
||||
}
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primNextCostume = function(b) {
|
||||
interp.targetSprite().showCostume(interp.targetSprite().currentCostumeIndex + 1);
|
||||
interp.redraw();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primShowCostume = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s == null) return;
|
||||
|
@ -88,8 +88,8 @@ LooksPrims.prototype.primShowCostume = function(b) {
|
|||
}
|
||||
}
|
||||
if (s.visible) interp.redraw();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primStartScene = function(b) {
|
||||
var s = runtime.stage;
|
||||
var arg = interp.arg(b, 0);
|
||||
|
@ -113,55 +113,55 @@ LooksPrims.prototype.primStartScene = function(b) {
|
|||
}
|
||||
}
|
||||
if (s.visible) interp.redraw();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primCostumeNum = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
return (s == null) ? 1 : s.currentCostumeIndex + 1;
|
||||
}
|
||||
|
||||
return s == null ? 1 : s.currentCostumeIndex + 1;
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primChangeSize = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s == null) return;
|
||||
s.setSize(s.getSize() + interp.arg(b, 0));
|
||||
if (s.visible) interp.redraw();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primSetSize = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s == null) return;
|
||||
s.setSize(interp.arg(b, 0));
|
||||
if (s.visible) interp.redraw();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primSize = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s == null) return 100;
|
||||
return s.getSize();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primGoFront = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
runtime.reassignZ(s, null);
|
||||
if(s.visible) interp.redraw();
|
||||
}
|
||||
|
||||
if (s.visible) interp.redraw();
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primGoBack = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
runtime.reassignZ(s, interp.arg(b, 0));
|
||||
if(s.visible) interp.redraw();
|
||||
}
|
||||
|
||||
LooksPrims.prototype.primChangeEffect = function(b) {}
|
||||
if (s.visible) interp.redraw();
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primSetEffect = function(b) {}
|
||||
LooksPrims.prototype.primChangeEffect = function(b) {};
|
||||
|
||||
LooksPrims.prototype.primClearEffects = function(b) {}
|
||||
LooksPrims.prototype.primSetEffect = function(b) {};
|
||||
|
||||
LooksPrims.prototype.primClearEffects = function(b) {};
|
||||
|
||||
var showBubble = function(b, type) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.showBubble(interp.arg(b, 0), type);
|
||||
}
|
||||
};
|
||||
|
||||
var showBubbleAndWait = function(b, type) {
|
||||
var s = interp.targetSprite();
|
||||
|
@ -175,4 +175,4 @@ var showBubbleAndWait = function(b, type) {
|
|||
} else {
|
||||
if (interp.checkTimer()) s.hideBubble();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var MotionAndPenPrims = function() {}
|
||||
var MotionAndPenPrims = function() {};
|
||||
|
||||
MotionAndPenPrims.prototype.addPrimsTo = function(primTable) {
|
||||
primTable['forward:'] = this.primMove;
|
||||
|
@ -26,19 +26,19 @@ MotionAndPenPrims.prototype.addPrimsTo = function(primTable) {
|
|||
primTable["gotoX:y:"] = this.primGoTo;
|
||||
primTable["gotoSpriteOrMouse:"] = this.primGoToSpriteOrMouse;
|
||||
primTable["glideSecs:toX:y:elapsed:from:"] = this.primGlide;
|
||||
|
||||
|
||||
primTable["changeXposBy:"] = this.primChangeX;
|
||||
primTable["xpos:"] = this.primSetX;
|
||||
primTable["changeYposBy:"] = this.primChangeY;
|
||||
primTable["ypos:"] = this.primSetY;
|
||||
|
||||
|
||||
primTable["bounceOffEdge"] = this.primBounceOffEdge;
|
||||
primTable["setRotationStyle"] = this.primSetRotationStyle;
|
||||
|
||||
|
||||
primTable["xpos"] = this.primXPosition;
|
||||
primTable["ypos"] = this.primYPosition;
|
||||
primTable["heading"] = this.primDirection;
|
||||
|
||||
|
||||
primTable["clearPenTrails"] = this.primClear;
|
||||
primTable["putPenDown"] = this.primPenDown;
|
||||
primTable["putPenUp"] = this.primPenUp;
|
||||
|
@ -49,63 +49,62 @@ MotionAndPenPrims.prototype.addPrimsTo = function(primTable) {
|
|||
primTable["changePenShadeBy:"] = this.primChangePenShade;
|
||||
primTable["penSize:"] = this.primSetPenSize;
|
||||
primTable["changePenSizeBy:"] = this.primChangePenSize;
|
||||
|
||||
|
||||
primTable["stampCostume"] = this.primStamp;
|
||||
primTable["stampTransparent"] = this.primStampTransparent;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primMove = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
var radians = ((Math.PI * (90 - s.direction)) / 180);
|
||||
var radians = (90 - s.direction) * Math.PI / 180;
|
||||
var d = interp.arg(b, 0);
|
||||
|
||||
moveSpriteTo(s, s.scratchX + (d * Math.cos(radians)),
|
||||
s.scratchY + (d * Math.sin(radians)));
|
||||
if(s.visible) interp.redraw();
|
||||
}
|
||||
moveSpriteTo(s, s.scratchX + d * Math.cos(radians), s.scratchY + d * Math.sin(radians));
|
||||
if (s.visible) interp.redraw();
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primTurnLeft = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
var d = s.direction - interp.arg(b, 0);
|
||||
s.setDirection(d);
|
||||
if(s.visible) interp.redraw();
|
||||
}
|
||||
if (s.visible) interp.redraw();
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primTurnRight = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
var d = s.direction + interp.arg(b, 0);
|
||||
s.setDirection(d);
|
||||
if(s.visible) interp.redraw();
|
||||
}
|
||||
if (s.visible) interp.redraw();
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primSetDirection = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
s.setDirection(interp.arg(b, 0));
|
||||
if(s.visible) interp.redraw();
|
||||
}
|
||||
if (s.visible) interp.redraw();
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primPointTowards = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
var p = mouseOrSpritePosition(interp.arg(b, 0));
|
||||
if ((s == null) || (p == null)) return;
|
||||
if (s == null || p == null) return;
|
||||
var dx = p.x - s.scratchX;
|
||||
var dy = p.y - s.scratchY;
|
||||
var angle = 90 - ((Math.atan2(dy, dx) * 180) / Math.PI);
|
||||
var angle = 90 - Math.atan2(dy, dx) * 180 / Math.PI;
|
||||
s.setDirection(angle);
|
||||
if (s.visible) interp.redraw();
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primGoTo = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) moveSpriteTo(s, interp.arg(b, 0), interp.arg(b, 1));
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primGoToSpriteOrMouse = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
var p = mouseOrSpritePosition(interp.arg(b, 0));
|
||||
if ((s == null) || (p == null)) return;
|
||||
if (s == null || p == null) return;
|
||||
moveSpriteTo(s, p.x, p.y);
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primGlide = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
|
@ -119,44 +118,43 @@ MotionAndPenPrims.prototype.primGlide = function(b) {
|
|||
return;
|
||||
}
|
||||
// record state: [0]start msecs, [1]duration, [2]startX, [3]startY, [4]endX, [5]endY
|
||||
interp.activeThread.tmpObj =
|
||||
[interp.currentMSecs, 1000 * secs, s.scratchX, s.scratchY, destX, destY];
|
||||
interp.activeThread.tmpObj = [interp.currentMSecs, 1000 * secs, s.scratchX, s.scratchY, destX, destY];
|
||||
interp.startTimer(secs);
|
||||
} else {
|
||||
var state = interp.activeThread.tmpObj;
|
||||
if (!interp.checkTimer()) {
|
||||
// in progress: move to intermediate position along path
|
||||
var frac = (interp.currentMSecs - state[0]) / state[1];
|
||||
var newX = state[2] + (frac * (state[4] - state[2]));
|
||||
var newY = state[3] + (frac * (state[5] - state[3]));
|
||||
var newX = state[2] + frac * (state[4] - state[2]);
|
||||
var newY = state[3] + frac * (state[5] - state[3]);
|
||||
moveSpriteTo(s, newX, newY);
|
||||
} else {
|
||||
// finished: move to final position and clear state
|
||||
moveSpriteTo(s, state[4], state[5]);
|
||||
interp.activeThread.tmpObj = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primChangeX = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) moveSpriteTo(s, s.scratchX + interp.arg(b, 0), s.scratchY);
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primSetX = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) moveSpriteTo(s, interp.arg(b, 0), s.scratchY);
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primChangeY = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) moveSpriteTo(s, s.scratchX, s.scratchY + interp.arg(b, 0));
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primSetY = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) moveSpriteTo(s, s.scratchX, interp.arg(b, 0));
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primBounceOffEdge = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
|
@ -164,7 +162,7 @@ MotionAndPenPrims.prototype.primBounceOffEdge = function(b) {
|
|||
if (!turnAwayFromEdge(s)) return;
|
||||
ensureOnStageOnBounce(s);
|
||||
if (s.visible) interp.redraw();
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primSetRotationStyle = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
|
@ -175,95 +173,94 @@ MotionAndPenPrims.prototype.primSetRotationStyle = function(b) {
|
|||
else if (request == 'left-right') rotationStyle = 'leftRight';
|
||||
else if (request == 'none') rotationStyle = 'none';
|
||||
s.setRotationStyle(rotationStyle);
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primXPosition = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
return (s != null) ? s.scratchX : 0;
|
||||
}
|
||||
return s != null ? s.scratchX : 0;
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primYPosition = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
return (s != null) ? s.scratchY : 0;
|
||||
}
|
||||
return s != null ? s.scratchY : 0;
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primDirection = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
return (s != null) ? s.direction : 0;
|
||||
}
|
||||
return s != null ? s.direction : 0;
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primClear = function(b) {
|
||||
runtime.stage.clearPenStrokes();
|
||||
interp.redraw();
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primPenDown = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.penIsDown = true;
|
||||
stroke(s, s.scratchX, s.scratchY, s.scratchX + 0.2, s.scratchY + 0.2);
|
||||
interp.redraw();
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primPenUp = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.penIsDown = false;
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primSetPenColor = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.setPenColor(interp.arg(b, 0));
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primSetPenHue = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.setPenHue(interp.arg(b, 0));
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primChangePenHue = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.setPenHue(s.penHue + interp.arg(b, 0));
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primSetPenShade = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.setPenShade(interp.arg(b, 0));
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primChangePenShade = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.setPenShade(s.penShade + interp.arg(b, 0));
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primSetPenSize = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
var w = Math.max(0, Math.min(interp.arg(b, 0), 100));
|
||||
if (s != null) s.penWidth = w;
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primChangePenSize = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
var w = Math.max(0, Math.min(s.penWidth + interp.arg(b, 0), 100));
|
||||
if (s != null) s.penWidth = w;
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primStamp = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
s.stamp(runtime.stage.lineCache, 100);
|
||||
}
|
||||
};
|
||||
|
||||
MotionAndPenPrims.prototype.primStampTransparent = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
var transparency = Math.max(0, Math.min(interp.arg(b, 0), 100));
|
||||
var alpha = 100 - transparency;
|
||||
s.stamp(runtime.stage.lineCache, alpha);
|
||||
}
|
||||
};
|
||||
|
||||
// Helpers
|
||||
var stroke = function(s, oldX, oldY, newX, newY) {
|
||||
runtime.stage.stroke([oldX, oldY],
|
||||
[newX, newY], s.penWidth, s.penColorCache);
|
||||
runtime.stage.stroke([oldX, oldY], [newX, newY], s.penWidth, s.penColorCache);
|
||||
interp.redraw();
|
||||
}
|
||||
};
|
||||
|
||||
var mouseOrSpritePosition = function(arg) {
|
||||
if (arg == "_mouse_") {
|
||||
|
@ -275,7 +272,7 @@ var mouseOrSpritePosition = function(arg) {
|
|||
return new Point(s.scratchX, s.scratchY);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
var moveSpriteTo = function(s, newX, newY) {
|
||||
var oldX = s.scratchX;
|
||||
|
@ -283,8 +280,8 @@ var moveSpriteTo = function(s, newX, newY) {
|
|||
s.setXY(newX, newY);
|
||||
s.keepOnStage();
|
||||
if (s.penIsDown) stroke(s, oldX, oldY, s.scratchX, s.scratchY);
|
||||
if ((s.penIsDown) || (s.visible)) interp.redraw();
|
||||
}
|
||||
if (s.penIsDown || s.visible) interp.redraw();
|
||||
};
|
||||
|
||||
var turnAwayFromEdge = function(s) {
|
||||
// turn away from the nearest edge if it's close enough; otherwise do nothing
|
||||
|
@ -298,23 +295,23 @@ var turnAwayFromEdge = function(s) {
|
|||
var d4 = Math.max(0, 360 - r.bottom);
|
||||
// find the nearest edge
|
||||
var e = 0, minDist = 100000;
|
||||
if (d1 < minDist) { minDist = d1; e = 1 }
|
||||
if (d2 < minDist) { minDist = d2; e = 2 }
|
||||
if (d3 < minDist) { minDist = d3; e = 3 }
|
||||
if (d4 < minDist) { minDist = d4; e = 4 }
|
||||
if (d1 < minDist) { minDist = d1; e = 1; }
|
||||
if (d2 < minDist) { minDist = d2; e = 2; }
|
||||
if (d3 < minDist) { minDist = d3; e = 3; }
|
||||
if (d4 < minDist) { minDist = d4; e = 4; }
|
||||
if (minDist > 0) return false; // not touching to any edge
|
||||
// point away from nearest edge
|
||||
var radians = ((90 - s.direction) * Math.PI) / 180;
|
||||
var radians = (90 - s.direction) * Math.PI / 180;
|
||||
var dx = Math.cos(radians);
|
||||
var dy = -Math.sin(radians);
|
||||
if (e == 1) { dx = Math.max(0.2, Math.abs(dx)) }
|
||||
if (e == 2) { dy = Math.max(0.2, Math.abs(dy)) }
|
||||
if (e == 3) { dx = 0 - Math.max(0.2, Math.abs(dx)) }
|
||||
if (e == 4) { dy = 0 - Math.max(0.2, Math.abs(dy)) }
|
||||
var newDir = ((180 * Math.atan2(dy, dx)) / Math.PI) + 90;
|
||||
if (e == 1) { dx = Math.max(0.2, Math.abs(dx)); }
|
||||
if (e == 2) { dy = Math.max(0.2, Math.abs(dy)); }
|
||||
if (e == 3) { dx = 0 - Math.max(0.2, Math.abs(dx)); }
|
||||
if (e == 4) { dy = 0 - Math.max(0.2, Math.abs(dy)); }
|
||||
var newDir = Math.atan2(dy, dx) * 180 / Math.PI + 90;
|
||||
s.direction = newDir;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
var ensureOnStageOnBounce = function(s) {
|
||||
var r = s.getRect();
|
||||
|
@ -326,4 +323,4 @@ var ensureOnStageOnBounce = function(s) {
|
|||
if (r.bottom > 360) {
|
||||
moveSpriteTo(s, s.scratchX, s.scratchY + (r.bottom - 360));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -26,57 +26,57 @@ var Primitives = function() {}
|
|||
|
||||
Primitives.prototype.addPrimsTo = function(primTable) {
|
||||
// Math primitives
|
||||
primTable["+"] = function(b) { return interp.arg(b, 0) + interp.arg(b, 1) };
|
||||
primTable["-"] = function(b) { return interp.arg(b, 0) - interp.arg(b, 1) };
|
||||
primTable["*"] = function(b) { return interp.arg(b, 0) * interp.arg(b, 1) };
|
||||
primTable["/"] = function(b) { return interp.arg(b, 0) / interp.arg(b, 1) };
|
||||
primTable["%"] = function(b) { return interp.arg(b, 0) % interp.arg(b, 1) };
|
||||
primTable["+"] = function(b) { return interp.arg(b, 0) + interp.arg(b, 1); };
|
||||
primTable["-"] = function(b) { return interp.arg(b, 0) - interp.arg(b, 1); };
|
||||
primTable["*"] = function(b) { return interp.arg(b, 0) * interp.arg(b, 1); };
|
||||
primTable["/"] = function(b) { return interp.arg(b, 0) / interp.arg(b, 1); };
|
||||
primTable["%"] = function(b) { return interp.arg(b, 0) % interp.arg(b, 1); };
|
||||
primTable["randomFrom:to:"] = this.primRandom;
|
||||
primTable["<"] = function(b) { return (interp.arg(b, 0) < interp.arg(b, 1)) };
|
||||
primTable["="] = function(b) { return (interp.arg(b, 0) == interp.arg(b, 1)) };
|
||||
primTable[">"] = function(b) { return (interp.arg(b, 0) > interp.arg(b, 1)) };
|
||||
primTable["&"] = function(b) { return interp.arg(b, 0) && interp.arg(b, 1) };
|
||||
primTable["|"] = function(b) { return interp.arg(b, 0) || interp.arg(b, 1) };
|
||||
primTable["<"] = function(b) { return (interp.arg(b, 0) < interp.arg(b, 1)); };
|
||||
primTable["="] = function(b) { return (interp.arg(b, 0) == interp.arg(b, 1)); };
|
||||
primTable[">"] = function(b) { return (interp.arg(b, 0) > interp.arg(b, 1)); };
|
||||
primTable["&"] = function(b) { return interp.arg(b, 0) && interp.arg(b, 1); };
|
||||
primTable["|"] = function(b) { return interp.arg(b, 0) || interp.arg(b, 1); };
|
||||
primTable["not"] = function(b) { return !interp.arg(b, 0) };
|
||||
primTable["abs"] = function(b) { return Math.abs(interp.arg(b, 0)) };
|
||||
primTable["sqrt"] = function(b) { return Math.sqrt(interp.arg(b, 0)) };
|
||||
|
||||
primTable["\\\\"] = this.primModulo;
|
||||
primTable["rounded"] = function(b) { return Math.round(interp.arg(b, 0)) };
|
||||
primTable["rounded"] = function(b) { return Math.round(interp.arg(b, 0)); };
|
||||
primTable["computeFunction:of:"] = this.primMathFunction;
|
||||
|
||||
|
||||
// String primitives
|
||||
primTable["concatenate:with:"] = function(b) { return "" + interp.arg(b, 0) + interp.arg(b, 1) };
|
||||
primTable["concatenate:with:"] = function(b) { return "" + interp.arg(b, 0) + interp.arg(b, 1); };
|
||||
primTable["letter:of:"] = this.primLetterOf;
|
||||
primTable["stringLength:"] = function(b) { return interp.arg(b, 0).length };
|
||||
|
||||
primTable["stringLength:"] = function(b) { return interp.arg(b, 0).length; };
|
||||
|
||||
new VarListPrims().addPrimsTo(primTable);
|
||||
new MotionAndPenPrims().addPrimsTo(primTable);
|
||||
new LooksPrims().addPrimsTo(primTable);
|
||||
new SensingPrims().addPrimsTo(primTable);
|
||||
new SoundPrims().addPrimsTo(primTable);
|
||||
}
|
||||
|
||||
|
||||
Primitives.prototype.primRandom = function(b) {
|
||||
var n1 = interp.arg(b, 0);
|
||||
var n2 = interp.arg(b, 1);
|
||||
var low = (n1 <= n2) ? n1 : n2;
|
||||
var hi = (n1 <= n2) ? n2 : n1;
|
||||
if(low == hi) return low;
|
||||
var low = n1 <= n2 ? n1 : n2;
|
||||
var hi = n1 <= n2 ? n2 : n1;
|
||||
if (low == hi) return low;
|
||||
// if both low and hi are ints, truncate the result to an int
|
||||
if ((Math.floor(low) == low) && (Math.floor(hi) == hi)) {
|
||||
return low + Math.floor(Math.random() * ((hi + 1) - low));
|
||||
if (Math.floor(low) == low && Math.floor(hi) == hi) {
|
||||
return low + Math.floor(Math.random() * (hi + 1 - low));
|
||||
}
|
||||
return (Math.random() * (hi - low)) + low;
|
||||
return Math.random() * (hi - low) + low;
|
||||
}
|
||||
|
||||
|
||||
Primitives.prototype.primLetterOf = function(b) {
|
||||
var s = interp.arg(b, 1);
|
||||
var i = interp.arg(b, 0) - 1;
|
||||
if ((i < 0) || (i >= s.length)) return "";
|
||||
if (i < 0 || i >= s.length) return "";
|
||||
return s.charAt(i);
|
||||
}
|
||||
|
||||
|
||||
Primitives.prototype.primModulo = function(b) {
|
||||
var modulus = interp.arg(b, 1);
|
||||
var n = interp.arg(b, 0) % modulus;
|
||||
|
@ -90,14 +90,14 @@ Primitives.prototype.primMathFunction = function(b) {
|
|||
switch(op) {
|
||||
case "abs": return Math.abs(n);
|
||||
case "sqrt": return Math.sqrt(n);
|
||||
case "sin": return Math.sin((Math.PI * n) / 180);
|
||||
case "cos": return Math.cos((Math.PI * n) / 180);
|
||||
case "tan": return Math.tan((Math.PI * n) / 180);
|
||||
case "asin": return (Math.asin(n) * 180) / Math.PI;
|
||||
case "acos": return (Math.acos(n) * 180) / Math.PI;
|
||||
case "atan": return (Math.atan(n) * 180) / Math.PI;
|
||||
case "sin": return Math.sin(n * Math.PI / 180);
|
||||
case "cos": return Math.cos(n * Math.PI / 180);
|
||||
case "tan": return Math.tan(n * Math.PI / 180);
|
||||
case "asin": return Math.asin(n) * 180 / Math.PI;
|
||||
case "acos": return Math.acos(n) * 180 / Math.PI;
|
||||
case "atan": return Math.atan(n) * 180 / Math.PI;
|
||||
case "ln": return Math.log(n);
|
||||
case "log": return Math.log(n) / Math.LN10;
|
||||
case "log": return Math.log(n) / Math.LN10;
|
||||
case "e ^": return Math.exp(n);
|
||||
case "10 ^": return Math.exp(n * Math.LN10);
|
||||
}
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var SensingPrims = function() {}
|
||||
var SensingPrims = function() {};
|
||||
|
||||
SensingPrims.prototype.addPrimsTo = function(primTable) {
|
||||
primTable['touching:'] = this.primTouching;
|
||||
primTable['touchingColor:'] = this.primTouchingColor;
|
||||
primTable['color:sees:'] = this.primColorTouchingColor;
|
||||
|
||||
|
||||
primTable['keyPressed:'] = this.primKeyPressed;
|
||||
primTable['mousePressed'] = function(b) { return runtime.mouseDown; };
|
||||
primTable['mouseX'] = function(b) { return runtime.mousePos[0]; };
|
||||
|
@ -32,27 +32,27 @@ SensingPrims.prototype.addPrimsTo = function(primTable) {
|
|||
|
||||
primTable['timeAndDate'] = function(b){ return runtime.getTimeString(interp.arg(b, 0)); };
|
||||
primTable['timestamp'] = this.primTimestamp;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
SensingPrims.prototype.primTouching = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s == null || !s.visible) return false;
|
||||
|
||||
|
||||
var arg = interp.arg(b, 0);
|
||||
if (arg == '_edge_') {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
|
||||
if (arg == '_mouse_') {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
|
||||
var s2 = runtime.spriteNamed(arg);
|
||||
if (s2 == null || !s2.visible) return false;
|
||||
|
||||
|
||||
return spriteHitTest(s, s2);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
SensingPrims.prototype.primTouchingColor = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s == null || !s.visible) return false;
|
||||
|
@ -60,8 +60,8 @@ SensingPrims.prototype.primTouchingColor = function(b) {
|
|||
var color = interp.arg(b, 0);
|
||||
|
||||
return stageColorHitTest(s, color);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
SensingPrims.prototype.primColorTouchingColor = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s == null || !s.visible) return false;
|
||||
|
@ -70,8 +70,8 @@ SensingPrims.prototype.primColorTouchingColor = function(b) {
|
|||
var stageColor = interp.arg(b, 1);
|
||||
|
||||
return stageColorByColorHitTest(s, myColor, stageColor);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var spriteHitTest = function(a, b) {
|
||||
var hitCanvas = document.createElement('canvas');
|
||||
hitCanvas.width = 480;
|
||||
|
@ -91,8 +91,8 @@ var spriteHitTest = function(a, b) {
|
|||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var stageColorHitTest = function(target, color) {
|
||||
var r, g, b;
|
||||
r = (color >> 16);
|
||||
|
@ -123,8 +123,8 @@ var stageColorHitTest = function(target, color) {
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var stageColorByColorHitTest = function(target, myColor, otherColor) {
|
||||
var threshold_acceptable = function(a, b, c, x, y, z) {
|
||||
var diff_a = Math.abs(a-x);
|
||||
|
@ -134,7 +134,7 @@ var stageColorByColorHitTest = function(target, myColor, otherColor) {
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
var targetCanvas = document.createElement('canvas');
|
||||
targetCanvas.width = 480;
|
||||
targetCanvas.height = 360;
|
||||
|
@ -159,21 +159,21 @@ var stageColorByColorHitTest = function(target, myColor, otherColor) {
|
|||
hitCanvas.height = 360;
|
||||
var hitCtx = hitCanvas.getContext('2d');
|
||||
$.each(runtime.sprites, function(i, sprite) {
|
||||
if (sprite != target)
|
||||
if (sprite != target) {
|
||||
sprite.stamp(hitCtx, 100);
|
||||
}
|
||||
});
|
||||
|
||||
var hitData = hitCtx.getImageData(0, 0, hitCanvas.width, hitCanvas.height).data;
|
||||
var pxCount = targetData.length;
|
||||
for (var i = 0; i < pxCount; i += 4) {
|
||||
if (threshold_acceptable(targetData[i], targetData[i+1], targetData[i+2], mr, mg, mb)
|
||||
&& threshold_acceptable(hitData[i], hitData[i+1], hitData[i+2], or, og, ob)) {
|
||||
if (threshold_acceptable(targetData[i], targetData[i+1], targetData[i+2], mr, mg, mb) && threshold_acceptable(hitData[i], hitData[i+1], hitData[i+2], or, og, ob)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
SensingPrims.prototype.primKeyPressed = function(b) {
|
||||
var key = interp.arg(b, 0);
|
||||
var ch = key.charCodeAt(0);
|
||||
|
@ -184,8 +184,8 @@ SensingPrims.prototype.primKeyPressed = function(b) {
|
|||
if (key == "down arrow") ch = 40;
|
||||
if (key == "space") ch = 32;
|
||||
return (typeof(runtime.keysDown[ch]) != 'undefined');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
SensingPrims.prototype.primDistanceTo = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
var p = mouseOrSpritePosition(interp.arg(b, 0));
|
||||
|
@ -193,8 +193,8 @@ SensingPrims.prototype.primDistanceTo = function(b) {
|
|||
var dx = p.x - s.scratchX;
|
||||
var dy = p.y - s.scratchY;
|
||||
return Math.sqrt((dx * dx) + (dy * dy));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
SensingPrims.prototype.primGetAttribute = function(b) {
|
||||
var attr = interp.arg(b, 0);
|
||||
var targetSprite = runtime.spriteNamed(interp.arg(b, 1));
|
||||
|
@ -207,7 +207,7 @@ SensingPrims.prototype.primGetAttribute = function(b) {
|
|||
if (attr == 'size') return targetSprite.getSize();
|
||||
if (attr == 'volume') return targetSprite.volume;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
SensingPrims.prototype.primTimeDate = function(b) {
|
||||
var dt = interp.arg(b, 0);
|
||||
|
@ -220,13 +220,16 @@ SensingPrims.prototype.primTimeDate = function(b) {
|
|||
if (dt == 'minute') return now.getMinutes();
|
||||
if (dt == 'second') return now.getSeconds();
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
SensingPrims.prototype.primTimestamp = function(b) {
|
||||
var now = new Date(), epoch = new Date(2000,0,1), dst = now.getTimezoneOffset() - epoch.getTimezoneOffset(), msSince = now.getTime() - epoch.getTime();
|
||||
msSince += (now.getTimezoneOffset() - dst) * 60000;
|
||||
return msSince / 86400000;
|
||||
}
|
||||
var now = new Date();
|
||||
var epoch = new Date(2000, 0, 1);
|
||||
var dst = now.getTimezoneOffset() - epoch.getTimezoneOffset();
|
||||
var msSince = now.getTime() - epoch.getTime();
|
||||
msSince += (now.getTimezoneOffset() - dst) * 60000;
|
||||
return msSince / 86400000;
|
||||
};
|
||||
|
||||
// Helpers
|
||||
SensingPrims.prototype.mouseOrSpritePosition = function(arg) {
|
||||
|
@ -239,4 +242,4 @@ SensingPrims.prototype.mouseOrSpritePosition = function(arg) {
|
|||
return new Point(s.scratchX, s.scratchY);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var SoundPrims = function() {}
|
||||
var SoundPrims = function() {};
|
||||
|
||||
SoundPrims.prototype.addPrimsTo = function(primTable) {
|
||||
primTable['playSound:'] = this.primPlaySound;
|
||||
|
@ -34,7 +34,7 @@ SoundPrims.prototype.addPrimsTo = function(primTable) {
|
|||
primTable['changeTempoBy:'] = function(b) { runtime.stage.data.tempoBPM = runtime.stage.data.tempoBPM + interp.arg(b, 0); };
|
||||
primTable['setTempoTo:'] = function(b) { runtime.stage.data.tempoBPM = interp.arg(b, 0); };
|
||||
primTable['tempo'] = function(b) { return runtime.stage.data.tempoBPM; };
|
||||
}
|
||||
};
|
||||
|
||||
var playSound = function(snd) {
|
||||
if (snd.source) {
|
||||
|
@ -42,11 +42,11 @@ var playSound = function(snd) {
|
|||
snd.source.noteOff(0);
|
||||
snd.source = null;
|
||||
}
|
||||
|
||||
|
||||
snd.source = runtime.audioContext.createBufferSource();
|
||||
snd.source.buffer = snd.buffer;
|
||||
snd.source.connect(runtime.audioGain);
|
||||
|
||||
|
||||
// Track the sound's completion state
|
||||
snd.source.done = false;
|
||||
snd.source.finished = function() {
|
||||
|
@ -64,7 +64,7 @@ var playSound = function(snd) {
|
|||
runtime.audioPlaying.push(snd);
|
||||
snd.source.noteOn(0);
|
||||
return snd.source;
|
||||
}
|
||||
};
|
||||
|
||||
var playDrum = function(drum, secs, client) {
|
||||
var player = SoundBank.getDrumPlayer(drum, secs);
|
||||
|
@ -81,9 +81,9 @@ var playDrum = function(drum, secs, client) {
|
|||
runtime.notesPlaying.splice(i, 1);
|
||||
}
|
||||
}
|
||||
window.setTimeout(source.finished, secs * 1000);
|
||||
window.setTimeout(source.finished, secs * 1000);
|
||||
return player;
|
||||
}
|
||||
};
|
||||
|
||||
var playNote = function(instrument, midiKey, secs, client) {
|
||||
var player = SoundBank.getNotePlayer(instrument, midiKey);
|
||||
|
@ -99,9 +99,9 @@ var playNote = function(instrument, midiKey, secs, client) {
|
|||
runtime.notesPlaying.splice(i, 1);
|
||||
}
|
||||
}
|
||||
window.setTimeout(source.finished, secs * 1000);
|
||||
window.setTimeout(source.finished, secs * 1000);
|
||||
return player;
|
||||
}
|
||||
};
|
||||
|
||||
var stopAllSounds = function() {
|
||||
var oldPlaying = runtime.audioPlaying;
|
||||
|
@ -121,14 +121,14 @@ var stopAllSounds = function() {
|
|||
oldPlaying[s].finished();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SoundPrims.prototype.primPlaySound = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s == null) return;
|
||||
var snd = s.soundNamed(interp.arg(b, 0));
|
||||
if (snd != null) playSound(snd);
|
||||
}
|
||||
};
|
||||
|
||||
SoundPrims.prototype.primPlaySoundUntilDone = function(b) {
|
||||
var activeThread = interp.activeThread;
|
||||
|
@ -145,11 +145,11 @@ SoundPrims.prototype.primPlaySoundUntilDone = function(b) {
|
|||
} else {
|
||||
interp.yield = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var beatsToSeconds = function(beats) {
|
||||
return (beats * 60) / runtime.stage.data.tempoBPM;
|
||||
}
|
||||
return beats * 60 / runtime.stage.data.tempoBPM;
|
||||
};
|
||||
|
||||
SoundPrims.prototype.primPlayNote = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
|
@ -162,7 +162,7 @@ SoundPrims.prototype.primPlayNote = function(b) {
|
|||
} else {
|
||||
interp.checkTimer();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SoundPrims.prototype.primPlayDrum = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
|
@ -175,7 +175,7 @@ SoundPrims.prototype.primPlayDrum = function(b) {
|
|||
} else {
|
||||
interp.checkTimer();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SoundPrims.prototype.primPlayRest = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
|
@ -186,28 +186,28 @@ SoundPrims.prototype.primPlayRest = function(b) {
|
|||
} else {
|
||||
interp.checkTimer();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SoundPrims.prototype.primSetInstrument = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.instrument = interp.arg(b, 0);
|
||||
}
|
||||
};
|
||||
|
||||
SoundPrims.prototype.primStopAllSounds = function(b) {
|
||||
stopAllSounds();
|
||||
}
|
||||
};
|
||||
|
||||
SoundPrims.prototype.primChangeVolume = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.volume += interp.arg(b, 0);
|
||||
}
|
||||
};
|
||||
|
||||
SoundPrims.prototype.primSetVolume = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.volume = interp.arg(b, 0);
|
||||
}
|
||||
};
|
||||
|
||||
SoundPrims.prototype.primVolume = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
return (s != null) ? s.volume : 0;
|
||||
}
|
||||
return s != null ? s.volume : 0;
|
||||
};
|
||||
|
|
|
@ -34,7 +34,7 @@ VarListPrims.prototype.addPrimsTo = function(primTable) {
|
|||
primTable['lineCountOfList:'] = this.primListLength;
|
||||
primTable['getLine:ofList:'] = this.primListGetLine;
|
||||
primTable['list:contains:'] = this.primListContains;
|
||||
}
|
||||
};
|
||||
|
||||
// Variable primitive implementations
|
||||
|
||||
|
@ -42,21 +42,23 @@ VarListPrims.prototype.primReadVar = function(b) {
|
|||
var s = interp.targetSprite();
|
||||
if (s == null) return;
|
||||
var targetVar = interp.arg(b, 0);
|
||||
if (targetVar in s.variables)
|
||||
if (targetVar in s.variables) {
|
||||
return s.variables[targetVar];
|
||||
else if (targetVar in runtime.stage.variables)
|
||||
} else if (targetVar in runtime.stage.variables) {
|
||||
return runtime.stage.variables[targetVar];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primSetVar = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
if (s == null) return;
|
||||
var targetVar = interp.arg(b, 0);
|
||||
if (targetVar in s.variables)
|
||||
if (targetVar in s.variables) {
|
||||
s.variables[targetVar] = interp.arg(b, 1);
|
||||
else if (targetVar in runtime.stage.variables)
|
||||
} else if (targetVar in runtime.stage.variables) {
|
||||
runtime.stage.variables[targetVar] = interp.arg(b, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primChangeVar = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
|
@ -69,7 +71,7 @@ VarListPrims.prototype.primChangeVar = function(b) {
|
|||
runtime.stage.variables[targetVar] = parseFloat(runtime.stage.variables[targetVar]);
|
||||
runtime.stage.variables[targetVar] += interp.arg(b, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primHideVar = function(b) {
|
||||
var targetVar = interp.arg(b, 0);
|
||||
|
@ -79,7 +81,7 @@ VarListPrims.prototype.primHideVar = function(b) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primShowVar = function(b) {
|
||||
var targetVar = interp.arg(b, 0);
|
||||
|
@ -89,11 +91,11 @@ VarListPrims.prototype.primShowVar = function(b) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// List primitive implementations
|
||||
|
||||
// Take a list name and target sprite and return the JS list itself
|
||||
// Take a list name and target sprite and return the JS list itself
|
||||
var findList = function(targetSprite, listName) {
|
||||
if (targetSprite == null) targetSprite = runtime.stage;
|
||||
if (listName in targetSprite.lists) {
|
||||
|
@ -102,20 +104,20 @@ var findList = function(targetSprite, listName) {
|
|||
return runtime.stage.lists[listName].contents;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primReadList = function(b) {
|
||||
var list = findList(interp.targetSprite(), interp.arg(b, 0));
|
||||
if (list) {
|
||||
var allOne = list.map(function(val){return val.length}).reduce(function(old,val){return old+val},0)===list.length;
|
||||
return list.join(allOne?'':' ');
|
||||
var allOne = list.map(function(val) { return val.length; }).reduce(function(old,val) { return old + val; }, 0) === list.length;
|
||||
return list.join(allOne ? '' : ' ');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primListAppend = function(b) {
|
||||
var list = findList(interp.targetSprite(), interp.arg(b, 1));
|
||||
if (list) list.push(interp.arg(b, 0));
|
||||
}
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primListDeleteLine = function(b) {
|
||||
var list = findList(interp.targetSprite(), interp.arg(b, 1));
|
||||
|
@ -124,41 +126,42 @@ VarListPrims.prototype.primListDeleteLine = function(b) {
|
|||
if (line == 'all' || list.length == 0) list.length = 0;
|
||||
else if (line == 'last') list.splice(list.length - 1, 1);
|
||||
else if (parseInt(line) - 1 in list) list.splice(parseInt(line) - 1, 1);
|
||||
}
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primListInsertAt = function(b) {
|
||||
var list = findList(interp.targetSprite(), interp.arg(b, 2));
|
||||
if (!list) return;
|
||||
var newItem = interp.arg(b, 0);
|
||||
|
||||
|
||||
var position = interp.arg(b, 1);
|
||||
if (position == 'last') position = list.length;
|
||||
else if (position == 'random') position = Math.round(Math.random() * list.length);
|
||||
else position = parseInt(position) - 1;
|
||||
if (position > list.length) return;
|
||||
|
||||
|
||||
list.splice(position, 0, newItem);
|
||||
}
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primListSetLine = function(b) {
|
||||
var list = findList(interp.targetSprite(), interp.arg(b, 1));
|
||||
if (!list) return;
|
||||
var newItem = interp.arg(b, 2);
|
||||
var position = interp.arg(b, 0);
|
||||
|
||||
|
||||
if (position == 'last') position = list.length - 1;
|
||||
else if (position == 'random') position = Math.floor(Math.random() * list.length);
|
||||
else position = parseInt(position) - 1;
|
||||
|
||||
if (position > list.length - 1) return;
|
||||
|
||||
list[position] = newItem;
|
||||
}
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primListLength = function(b) {
|
||||
var list = findList(interp.targetSprite(), interp.arg(b, 0));
|
||||
if (!list) return 0;
|
||||
return list.length;
|
||||
}
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primListGetLine = function(b) {
|
||||
var list = findList(interp.targetSprite(), interp.arg(b, 1));
|
||||
|
@ -169,7 +172,7 @@ VarListPrims.prototype.primListGetLine = function(b) {
|
|||
else if (line == 'last') line = list.length;
|
||||
else if (list.length < line) return 0;
|
||||
return list[line - 1];
|
||||
}
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primListContains = function(b) {
|
||||
var list = findList(interp.targetSprite(), interp.arg(b, 0));
|
||||
|
@ -177,4 +180,4 @@ VarListPrims.prototype.primListContains = function(b) {
|
|||
var searchItem = interp.arg(b, 1);
|
||||
if (parseFloat(searchItem) == searchItem) searchItem = parseFloat(searchItem);
|
||||
return $.inArray(searchItem, list) > -1;
|
||||
}
|
||||
};
|
||||
|
|
Reference in a new issue