updates to finish doAsk
This commit is contained in:
parent
6f54f52f3c
commit
e59b279be1
19 changed files with 341 additions and 62 deletions
|
@ -40,6 +40,7 @@ var Thread = function(block, target) {
|
|||
this.tmp = null; // used for thread operations like Timer
|
||||
this.tmpObj = []; // used for Sprite operations like glide
|
||||
this.firstTime = true;
|
||||
this.paused = false;
|
||||
};
|
||||
|
||||
var Interpreter = function() {
|
||||
|
@ -126,6 +127,13 @@ Interpreter.prototype.stepThreads = function() {
|
|||
}
|
||||
};
|
||||
|
||||
Interpreter.prototype.pauseActiveThread = function() {
|
||||
var self = this;
|
||||
var timeoutId = setTimeout(function () {
|
||||
(self.activeThread.paused) ? self.pauseActiveThread() : clearTimeout(timeoutId);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
Interpreter.prototype.stepActiveThread = function() {
|
||||
// Run the active thread until it yields.
|
||||
if (typeof(this.activeThread) == 'undefined') {
|
||||
|
@ -135,6 +143,8 @@ Interpreter.prototype.stepActiveThread = function() {
|
|||
if (b == null) return;
|
||||
this.yield = false;
|
||||
while (true) {
|
||||
if (this.activeThread.paused) return;
|
||||
|
||||
++this.opCount;
|
||||
// Advance the "program counter" to the next block before running the primitive.
|
||||
// Control flow primitives (e.g. if) may change activeThread.nextBlock.
|
||||
|
@ -247,6 +257,10 @@ Interpreter.prototype.targetSprite = function() {
|
|||
return this.activeThread.target;
|
||||
};
|
||||
|
||||
Interpreter.prototype.targetStage = function() {
|
||||
return runtime.stage;
|
||||
};
|
||||
|
||||
// Timer
|
||||
Interpreter.prototype.startTimer = function(secs) {
|
||||
var waitMSecs = 1000 * secs;
|
||||
|
|
|
@ -29,14 +29,19 @@ var Reporter = function(data) {
|
|||
this.y = data.y;
|
||||
this.z = io.getCount();
|
||||
|
||||
//Set the label after hydrating the cmd and param variables
|
||||
this.label = this.determineReporterLabel();
|
||||
|
||||
this.el = null; // jQuery Element for the outer box
|
||||
this.valueEl = null; // jQ element containing the reporter value
|
||||
this.slider = null; // slider jQ element
|
||||
};
|
||||
|
||||
Reporter.prototype.determineReporterLabel = function() {
|
||||
if (this.target === 'Stage') {
|
||||
if (this.target === 'Stage' && this.cmd === "getVar:") {
|
||||
return this.param;
|
||||
} else if (this.target === 'Stage' && this.param === null) {
|
||||
return this.cmd;
|
||||
} else {
|
||||
return this.target + ': ' + this.param;
|
||||
}
|
||||
|
@ -46,7 +51,7 @@ Reporter.prototype.attach = function(scene) {
|
|||
switch (this.mode) {
|
||||
case 1: // Normal
|
||||
case 3: // Slider
|
||||
this.el = $('<div class="reporter-normal">' + this.determineReporterLabel() + '</div>');
|
||||
this.el = $('<div class="reporter-normal">' + this.label + '</div>');
|
||||
this.valueEl = $('<div class="reporter-inset">null</div>');
|
||||
this.el.append(this.valueEl);
|
||||
if (this.mode == 3) {
|
||||
|
@ -84,6 +89,9 @@ Reporter.prototype.update = function() {
|
|||
var newValue = '';
|
||||
var target = runtime.spriteNamed(this.target);
|
||||
switch (this.cmd) {
|
||||
case 'answer':
|
||||
newValue = target.askAnswer;
|
||||
break;
|
||||
case 'getVar:':
|
||||
newValue = target.variables[this.param];
|
||||
break;
|
||||
|
|
23
js/Sprite.js
23
js/Sprite.js
|
@ -80,7 +80,6 @@ var Sprite = function(data) {
|
|||
this.askInputOn = false;
|
||||
|
||||
// Internal variables used for rendering meshes.
|
||||
this.askAnswer = null; //this is a private variable
|
||||
this.textures = [];
|
||||
this.materials = [];
|
||||
this.geometries = [];
|
||||
|
@ -161,9 +160,10 @@ Sprite.prototype.attach = function(scene) {
|
|||
this.askInput = $('<div class="ask-container"></div>');
|
||||
this.askInput.css('display', 'none');
|
||||
this.askInputField = $('<div class="ask-field"></div>');
|
||||
this.askInputTextField = $('<input class="ask-text-field"></input>');
|
||||
this.askInputTextField = $('<input type="text" class="ask-text-field"></input>');
|
||||
this.askInputField.append(this.askInputTextField);
|
||||
this.askInputButton = $('<div class="ask-button"></div>');
|
||||
this.bindDoAskButton();
|
||||
this.askInput.append(this.askInputField);
|
||||
this.askInput.append(this.askInputButton);
|
||||
|
||||
|
@ -368,8 +368,8 @@ Sprite.prototype.showBubble = function(text, type) {
|
|||
this.talkBubble.css('left', xy[0] + 'px');
|
||||
this.talkBubble.css('top', xy[1] + 'px');
|
||||
|
||||
this.talkBubble.removeClass('say-think-border');
|
||||
this.talkBubble.removeClass('ask-border');
|
||||
this.talkBubbleBox.removeClass('say-think-border');
|
||||
this.talkBubbleBox.removeClass('ask-border');
|
||||
|
||||
this.talkBubbleStyler.removeClass('bubble-say');
|
||||
this.talkBubbleStyler.removeClass('bubble-think');
|
||||
|
@ -412,9 +412,24 @@ Sprite.prototype.showAsk = function() {
|
|||
|
||||
Sprite.prototype.hideAsk = function() {
|
||||
this.askInputOn = false;
|
||||
this.askInputTextField.val('');
|
||||
this.askInput.css('display', 'none');
|
||||
};
|
||||
|
||||
Sprite.prototype.bindDoAskButton = function() {
|
||||
var self = this;
|
||||
this.askInputButton.on("keypress click", function(e){
|
||||
var eType = e.type;
|
||||
if (eType === 'click' || (eType === 'keypress' && e.which === 13)) {
|
||||
var stage = interp.targetStage();
|
||||
stage.askAnswer = $(self.askInputTextField).val();
|
||||
self.hideBubble();
|
||||
self.hideAsk();
|
||||
interp.activeThread.paused = false;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Sprite.prototype.setXY = function(x, y) {
|
||||
this.scratchX = x;
|
||||
this.scratchY = y;
|
||||
|
|
|
@ -34,6 +34,7 @@ var Stage = function(data) {
|
|||
this.lineCanvas.height = 360;
|
||||
this.lineCache = this.lineCanvas.getContext('2d');
|
||||
this.isStage = true;
|
||||
this.askAnswer = ""; //this is a private variable and should be blank
|
||||
|
||||
Sprite.call(this, data);
|
||||
};
|
||||
|
|
|
@ -43,9 +43,6 @@ LooksPrims.prototype.addPrimsTo = function(primTable) {
|
|||
primTable['setGraphicEffect:to:'] = this.primSetEffect;
|
||||
primTable['filterReset'] = this.primClearEffects;
|
||||
|
||||
primTable['doAsk'] = this.primDoAsk;
|
||||
primTable['answer'] = this.primAnswer;
|
||||
|
||||
primTable['say:'] = function(b) { showBubble(b, 'say'); };
|
||||
primTable['say:duration:elapsed:from:'] = function(b) { showBubbleAndWait(b, 'say'); };
|
||||
primTable['think:'] = function(b) { showBubble(b, 'think'); };
|
||||
|
@ -173,25 +170,14 @@ LooksPrims.prototype.primClearEffects = function(b) {
|
|||
s.updateFilters();
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primDoAsk= function(b) {
|
||||
showBubble(b, "doAsk");
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.showAsk();
|
||||
};
|
||||
|
||||
LooksPrims.prototype.primAnswer = function() {
|
||||
var s = interp.targetSprite();
|
||||
return ((s != null) ? s.answer : undefined);
|
||||
};
|
||||
|
||||
var showBubble = function(b, type) {
|
||||
var s = interp.targetSprite();
|
||||
if (s != null) s.showBubble(interp.arg(b, 0), type);
|
||||
if (s !== null) s.showBubble(interp.arg(b, 0), type);
|
||||
};
|
||||
|
||||
var showBubbleAndWait = function(b, type) {
|
||||
var s = interp.targetSprite();
|
||||
if (s == null) return;
|
||||
if (s === null) return;
|
||||
if (interp.activeThread.firstTime) {
|
||||
var text = interp.arg(b, 0);
|
||||
var secs = interp.numarg(b, 1);
|
||||
|
|
|
@ -22,6 +22,9 @@ SensingPrims.prototype.addPrimsTo = function(primTable) {
|
|||
primTable['touchingColor:'] = this.primTouchingColor;
|
||||
primTable['color:sees:'] = this.primColorTouchingColor;
|
||||
|
||||
primTable['doAsk'] = this.primDoAsk;
|
||||
primTable['answer'] = this.primAnswer;
|
||||
|
||||
primTable['keyPressed:'] = this.primKeyPressed;
|
||||
primTable['mousePressed'] = function(b) { return runtime.mouseDown; };
|
||||
primTable['mouseX'] = function(b) { return runtime.mousePos[0]; };
|
||||
|
@ -174,6 +177,21 @@ var stageColorByColorHitTest = function(target, myColor, otherColor) {
|
|||
return false;
|
||||
};
|
||||
|
||||
SensingPrims.prototype.primDoAsk= function(b) {
|
||||
showBubble(b, "doAsk");
|
||||
var s = interp.targetSprite();
|
||||
if (s !== null) {
|
||||
interp.activeThread.paused = true;
|
||||
s.showAsk();
|
||||
}
|
||||
};
|
||||
|
||||
SensingPrims.prototype.primAnswer = function(b) {
|
||||
var s = interp.targetStage();
|
||||
return (s !== null ? s.askAnswer : undefined);
|
||||
};
|
||||
|
||||
|
||||
SensingPrims.prototype.primKeyPressed = function(b) {
|
||||
var key = interp.arg(b, 0);
|
||||
var ch = key.charCodeAt(0);
|
||||
|
|
Reference in a new issue