Merge 8a673a8fa8
into fda87985c7
This commit is contained in:
commit
0aa4e9d8ea
10 changed files with 138 additions and 39 deletions
|
@ -175,6 +175,26 @@ Interpreter.prototype.stepActiveThread = function() {
|
|||
}
|
||||
};
|
||||
|
||||
Interpreter.prototype.resumeThread = function() {
|
||||
this.activeThread.paused = false;
|
||||
}
|
||||
|
||||
Interpreter.prototype.pauseThread = function() {
|
||||
this.activeThread.paused = true;
|
||||
}
|
||||
|
||||
Interpreter.prototype.resumeAllThreads = function() {
|
||||
for(var index=0; index<this.threads.length; index++) {
|
||||
this.threads[index].paused = false;
|
||||
}
|
||||
}
|
||||
|
||||
Interpreter.prototype.pauseAllThreads = function() {
|
||||
for(var index=0; index<this.threads.length; index++) {
|
||||
this.threads[index].paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
Interpreter.prototype.toggleThread = function(b, targetObj) {
|
||||
var newThreads = [], wasRunning = false;
|
||||
for (var i = 0; i < this.threads.length; i++) {
|
||||
|
|
61
js/Sprite.js
61
js/Sprite.js
|
@ -75,6 +75,8 @@ var Sprite = function(data) {
|
|||
|
||||
// HTML element for the ask bubbles
|
||||
this.askInput = null;
|
||||
this.askInputForm = null;
|
||||
this.askInputHiddenText = null;
|
||||
this.askInputField = null;
|
||||
this.askInputButton = null;
|
||||
this.askInputOn = false;
|
||||
|
@ -151,24 +153,25 @@ Sprite.prototype.attach = function(scene) {
|
|||
this.updateVisible();
|
||||
this.updateTransform();
|
||||
|
||||
if (! this.isStage) {
|
||||
this.talkBubble = $('<div class="bubble-container"></div>');
|
||||
this.talkBubble.css('display', 'none');
|
||||
this.talkBubbleBox = $('<div class="bubble"></div>');
|
||||
this.talkBubbleStyler = $('<div class="bubble-say"></div>');
|
||||
this.talkBubble.append(this.talkBubbleBox);
|
||||
this.talkBubble.append(this.talkBubbleStyler);
|
||||
}
|
||||
this.talkBubble = $('<div class="bubble-container"></div>');
|
||||
this.talkBubble.css('display', 'none');
|
||||
this.talkBubbleBox = $('<div class="bubble"></div>');
|
||||
this.talkBubbleStyler = $('<div class="bubble-say"></div>');
|
||||
this.talkBubble.append(this.talkBubbleBox);
|
||||
this.talkBubble.append(this.talkBubbleStyler);
|
||||
|
||||
this.askInput = $('<div class="ask-container"></div>');
|
||||
this.askInput.css('display', 'none');
|
||||
this.askInputForm = $('<form onSubmit="Sprite.prototype.persistDoAskInput(\'' + this.objName + '\');"></form>');
|
||||
this.askInputHiddenText = $('<div class="ask-input-hidden-text"></div>');
|
||||
this.askInputField = $('<div class="ask-field"></div>');
|
||||
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);
|
||||
this.askInput.append(this.askInputForm);
|
||||
this.askInputForm.append(this.askInputHiddenText);
|
||||
this.askInputForm.append(this.askInputField);
|
||||
this.askInputForm.append(this.askInputButton);
|
||||
|
||||
runtime.scene.append(this.talkBubble);
|
||||
runtime.scene.append(this.askInput);
|
||||
|
@ -403,24 +406,36 @@ Sprite.prototype.hideBubble = function() {
|
|||
this.talkBubble.css('display', 'none');
|
||||
};
|
||||
|
||||
Sprite.prototype.showAsk = function() {
|
||||
Sprite.prototype.showAsk = function(text) {
|
||||
this.askInputOn = true;
|
||||
this.askInput.css('z-index', this.z);
|
||||
this.askInput.css('left', '15px');
|
||||
this.askInput.css('right', '15px');
|
||||
this.askInput.css('bottom', '7px');
|
||||
this.askInput.css('height', '25px');
|
||||
this.askInput.css('z-index', this.z + 1);
|
||||
|
||||
if (this.visible) {
|
||||
this.askInput.css('display', 'inline-block');
|
||||
this.askInputTextField.focus();
|
||||
this.askInput.css('display', 'inline-block');
|
||||
this.askInputTextField.focus();
|
||||
|
||||
if (! this.visible || this.isStage) {
|
||||
this.askInput.css('height', '42px');
|
||||
this.askInputHiddenText.css('display', 'inline-block');
|
||||
this.askInputHiddenText.html(text);
|
||||
}
|
||||
};
|
||||
|
||||
Sprite.prototype.hideAsk = function() {
|
||||
this.askInputOn = false;
|
||||
this.askInputTextField.val('');
|
||||
this.askInput.css('height', '25px');
|
||||
this.askInput.css('display', 'none');
|
||||
this.askInputHiddenText.css('display', 'none');
|
||||
this.askInputHiddenText.html('');
|
||||
};
|
||||
|
||||
Sprite.prototype.persistDoAskInput = function(spriteName) {
|
||||
var stage = interp.targetStage();
|
||||
stage.askAnswer = $(this.askInputTextField).val();
|
||||
var sprite = runtime.spriteNamed(spriteName);
|
||||
sprite.hideBubble();
|
||||
sprite.hideAsk();
|
||||
interp.resumeAllThreads();
|
||||
};
|
||||
|
||||
Sprite.prototype.bindDoAskButton = function() {
|
||||
|
@ -428,11 +443,7 @@ Sprite.prototype.bindDoAskButton = function() {
|
|||
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;
|
||||
self.persistDoAskInput(self.objName);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -181,8 +181,8 @@ SensingPrims.prototype.primDoAsk= function(b) {
|
|||
showBubble(b, "doAsk");
|
||||
var s = interp.targetSprite();
|
||||
if (s !== null) {
|
||||
interp.activeThread.paused = true;
|
||||
s.showAsk();
|
||||
s.showAsk(interp.arg(b, 0));
|
||||
interp.pauseAllThreads();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
22
player.css
22
player.css
|
@ -447,31 +447,41 @@ button#trigger-stop:hover {
|
|||
}
|
||||
.ask-container {
|
||||
position: absolute;
|
||||
display: inline-block;
|
||||
display: none;
|
||||
padding: 5px 0px 0px 5px;
|
||||
border-radius: 5px;
|
||||
border-radius: 7px;
|
||||
background: #fff;
|
||||
font-family: sans-serif;
|
||||
font-weight: bold;
|
||||
font-size: 14px;
|
||||
color: #000;
|
||||
left: 15px;
|
||||
right: 15px;
|
||||
bottom: 7px;
|
||||
height: 25px;
|
||||
}
|
||||
.ask-container .ask-field .ask-text-field {
|
||||
position: absolute;
|
||||
width: 405px;
|
||||
height: 16px;
|
||||
bottom: 3px;
|
||||
font-family: sans-serif;
|
||||
font-weight: light;
|
||||
font-size: 12px;
|
||||
background: #EAEAEA;
|
||||
}
|
||||
|
||||
.ask-container .ask-button {
|
||||
position: absolute;
|
||||
right: 2px;
|
||||
top: 2px;
|
||||
bottom: 3px;
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
background: url(img/ask-button.png) transparent no-repeat;
|
||||
}
|
||||
|
||||
|
||||
.ask-container .ask-input-hidden-text {
|
||||
position: absolute;
|
||||
display: none;
|
||||
font-family: sans-serif;
|
||||
font-weight: light;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,10 @@ var interpreterMock = function() {
|
|||
'targetSprite' : function() { return getArgs('targetSprite'); },
|
||||
'arg': function(block, index) { return getArgs('arg');},
|
||||
'activeThread': new threadMock(),
|
||||
'pauseThread': function() {},
|
||||
'resumeThread': function() {},
|
||||
'pauseAllThreads': function() {},
|
||||
'resumeAllThreads': function() {},
|
||||
'targetStage': function() { var rtMock = new runtimeMock(); return rtMock.stage}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@ var runtimeMock = function() {
|
|||
'sprites' : [
|
||||
new spriteMock()
|
||||
],
|
||||
'spriteNamed' : function(){ return getArgs('spriteName') || new spriteMock();},
|
||||
'stage': new stageMock()
|
||||
|
||||
}
|
||||
};
|
||||
|
|
3
test/fixtures/karma.conf.js
vendored
3
test/fixtures/karma.conf.js
vendored
|
@ -11,7 +11,8 @@ module.exports = function(config){
|
|||
'js/util/**/*.js',
|
||||
'js/**/*.js',
|
||||
'node_modules/jasmine-jquery/lib/jasmine-jquery.js',
|
||||
'node_modules/underscore/underscore.js'
|
||||
'node_modules/underscore/underscore.js',
|
||||
'player.css'
|
||||
],
|
||||
|
||||
exclude : [
|
||||
|
|
|
@ -75,12 +75,56 @@ describe('Interpreter', function() {
|
|||
expect(initInterp.opCount2).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('TargetStage', function() {
|
||||
it('should return the target.stage object', function() {
|
||||
runtime = new runtimeMock();
|
||||
expect(interp.prototype.targetStage()).toEqual(runtime.stage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('TargetStage', function() {
|
||||
it('should return the target.stage object', function() {
|
||||
runtime = new runtimeMock();
|
||||
expect(interp.prototype.targetStage()).toEqual(runtime.stage);
|
||||
describe('Pause and Resume Single Threads', function() {
|
||||
var initInterp;
|
||||
|
||||
beforeEach(function() {
|
||||
initInterp = new interp();
|
||||
});
|
||||
|
||||
it('should pause the current activeThread', function() {
|
||||
initInterp.pauseThread();
|
||||
expect(initInterp.activeThread.paused).toEqual(true);
|
||||
});
|
||||
|
||||
it('should resume the current activeThread', function() {
|
||||
initInterp.resumeThread();
|
||||
expect(initInterp.activeThread.paused).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Pause and Resume All Threads', function() {
|
||||
var initInterp;
|
||||
|
||||
beforeEach(function() {
|
||||
initInterp = new interp();
|
||||
initInterp.threads.push(new threadMock());
|
||||
initInterp.threads.push(new threadMock());
|
||||
});
|
||||
|
||||
it('should pause the current activeThread', function() {
|
||||
initInterp.pauseAllThreads();
|
||||
_.each(initInterp.threads, function(thread) {
|
||||
expect(thread.paused).toEqual(true);
|
||||
});
|
||||
expect(initInterp.threads.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should resume the current activeThread', function() {
|
||||
initInterp.resumeAllThreads();
|
||||
_.each(initInterp.threads, function(thread) {
|
||||
expect(thread.paused).toEqual(false);
|
||||
});
|
||||
expect(initInterp.threads.length).toBe(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -98,6 +98,7 @@ describe('SensingPrims', function() {
|
|||
});
|
||||
|
||||
it('should call the showBubble method on the targetedSprite', function() {
|
||||
spyOn(interp, "pauseAllThreads");
|
||||
spyOn(window, "showBubble");
|
||||
spyOn(targetSpriteMock, "showAsk");
|
||||
sensingPrims.prototype.primDoAsk(askBlock);
|
||||
|
|
|
@ -392,5 +392,13 @@ describe('Sprite', function() {
|
|||
expect(spriteProto.visible).toBe(false);
|
||||
expect(spriteProto.updateVisible).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should have a penShade variable', function() {
|
||||
expect(initSprite.penShade).toBe(50);
|
||||
});
|
||||
|
||||
it('should have a penColorCache variable', function() {
|
||||
expect(initSprite.penColorCache).toBe(0x0000FF);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Reference in a new issue