Commit 0d10f121 authored by Cody Ede (cme527)'s avatar Cody Ede (cme527)
Browse files

All most there

parent 923cdf01
......@@ -91,7 +91,11 @@ function Experiment(options) {
item: data.item.name});
});
// Load previous state (if it exists)
if (options.reset === "true") {
this.started = false;
......
......@@ -35,6 +35,7 @@ function FastTapMenu(options) {
this.flashTime[r] = new Array(this.cols);
}
this._itemClickHandlers = [];
this._itemPressedHandlers = [];
this.bg = new PIXI.Graphics();
this.addChild(this.bg);
......@@ -100,6 +101,8 @@ FastTapMenu.prototype.removeItemClickedCB = function(f) {
return false;
};
FastTapMenu.prototype.openMenu = function() {
if (!this.openable) {
return;
......
......@@ -35,13 +35,13 @@ var items = [{name:"Left", binding:"Shift+G", value: "G", icon:"assets/images/bo
{name:"Left Justify", binding:"", value: " ", icon:"assets/images/paragraph/Left_Justify.png"},
{name:"Center Justify", binding:"", value: " ", icon:"assets/images/paragraph/Center_Justify.png"},
{name:"Right Justify", binding:"", value: " ", icon:"assets/images/paragraph/Right_Justify.png"},
{name:"Full Justify", binding:"Shift+V", value: "V", icon:"assets/images/paragraph/Full_Justify.png"},
{name:"Full Justify", binding:"", value: "", icon:"assets/images/paragraph/Full_Justify.png"},
{name:"Bullets", binding:"", value: " ", icon:"assets/images/paragraph/Bullets.png"},
{name:"Numbered", binding:"", value: " ", icon:"assets/images/paragraph/Numbered.png"},
{name:"Less Indent", binding:"", value: " ", icon:"assets/images/paragraph/Less_Indent.png"},
{name:"More Indent", binding:"Shift+9", value: "9", icon:"assets/images/paragraph/More_Indent.png"},
{name:"Square", binding:"Shift+1", value: "1", icon:"assets/images/shapes/Square.png"},
{name:"Arrow", binding:"", value: " ", icon:"assets/images/shapes/Arrow.png"},
{name:"Arrow", binding:" Shift+V", value: "V", icon:"assets/images/shapes/Arrow.png"},
{name:"Oval", binding:"Shift+E", value: "E", icon:"assets/images/shapes/Oval.png"},
{name:"Cross", binding:"", value: " ", icon:"assets/images/shapes/Cross.png"},
{name:"Diamond", binding:"", value: " ", icon:"assets/images/shapes/Diamond.png"},
......
function KeyWatch() {
this._keyLog = [];
this._keyNeed;
}
KeyWatch.prototype.lookKey = function(f) {
this._keyNeed = f;
console.log(this._keyNeed);
}
KeyWatch.prototype.getKey = function(f){
this._keyLog.push(f);
}
module.exports = KeyWatch;
\ No newline at end of file
......@@ -24,7 +24,7 @@ function KeyboardManager() {
_sKeydown = {state: false, value: 's'};
_tKeydown = {state: false, value: 't'};
_uKeydown = {state: false, value: 'u'};
_vKeydown = {state: false, value: 'v'};
_vKeydown = {state: false, value: 'V'};
_wKeydown = {state: false, value: 'w'};
_xKeydown = {state: false, value: 'x'};
_yKeydown = {state: false, value: 'y'};
......@@ -42,15 +42,18 @@ function KeyboardManager() {
this._stateChangeHandlers = [];
this._keysPressed = [];
this._shortcutPerformedCallbacks = [];
}
KeyboardManager.prototype.tick = function() {
kd.tick();
if (kd.SPACE.isDown() && this._SPACEKeydown == false) {
this._SPACEKeydown = true;
this.notifyObservers();
} else if (!kd.SPACE.isDown() && this._SPACEKeydown == true) {
this._SPACEKeydown = false;
this.notifyObservers();
......@@ -66,6 +69,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.A.isDown() && _aKeydown.state == false && this._SHIFTKeydown == true){
_aKeydown.state = true;
this.notifyShortCutPerformed(_aKeydown);
console.log('Shift + A');
}
if (!kd.A.isDown() && _aKeydown.state == true ){
......@@ -74,6 +78,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.B.isDown() && _bKeydown.state == false && this._SHIFTKeydown == true){
_bKeydown.state = true;
this.notifyShortCutPerformed(_bKeydown);
console.log('Shift + B');
}
if (!kd.B.isDown() && _bKeydown.state == true ){
......@@ -82,14 +87,16 @@ KeyboardManager.prototype.tick = function() {
if(kd.C.isDown() && _cKeydown.state == false && this._SHIFTKeydown == true){
_cKeydown.state = true;
this.notifyShortCutPerformed(_cKeydown);
console.log('Shift + C');
}
if (!kd.C.isDown() && _cKeydown.state == true ){
_aKeydown.state = false;
_cKeydown.state = false;
}
if(kd.D.isDown() && _dKeydown.state == false && this._SHIFTKeydown == true){
_dKeydown.state = true;
this.notifyShortCutPerformed(_dKeydown);
console.log('Shift + D');
}
if (!kd.D.isDown() && _dKeydown.state == true ){
......@@ -98,6 +105,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.E.isDown() && _eKeydown.state == false && this._SHIFTKeydown == true){
_eKeydown.state = true;
this.notifyShortCutPerformed(_eKeydown);
console.log('Shift + E');
}
if (!kd.E.isDown() && _eKeydown.state == true ){
......@@ -106,6 +114,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.F.isDown() && _fKeydown.state == false && this._SHIFTKeydown == true){
_fKeydown.state = true;
this.notifyShortCutPerformed(_fKeydown);
console.log('Shift + F');
}
if (!kd.F.isDown() && _fKeydown.state == true ){
......@@ -114,6 +123,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.G.isDown() && _gKeydown.state == false && this._SHIFTKeydown == true){
_gKeydown.state = true;
this.notifyShortCutPerformed(_gKeydown);
console.log('Shift + G');
}
if (!kd.G.isDown() && _gKeydown.state == true ){
......@@ -122,6 +132,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.H.isDown() && _hKeydown.state == false && this._SHIFTKeydown == true){
_hKeydown.state = true;
this.notifyShortCutPerformed(_hKeydown);
console.log('Shift + H');
}
if (!kd.H.isDown() && _hKeydown.state == true ){
......@@ -130,6 +141,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.I.isDown() && _iKeydown.state == false && this._SHIFTKeydown == true){
_iKeydown.state = true;
this.notifyShortCutPerformed(_iKeydown);
console.log('Shift + I');
}
if (!kd.I.isDown() && _iKeydown.state == true ){
......@@ -138,6 +150,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.J.isDown() && _jKeydown.state == false && this._SHIFTKeydown == true){
_jKeydown.state = true;
this.notifyShortCutPerformed(_jKeydown);
console.log('Shift + J');
}
if (!kd.J.isDown() && _jKeydown.state == true ){
......@@ -146,6 +159,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.K.isDown() && _kKeydown.state == false && this._SHIFTKeydown == true){
_kKeydown.state = true;
this.notifyShortCutPerformed(_kKeydown);
console.log('Shift + K');
}
if (!kd.K.isDown() && _kKeydown.state == true ){
......@@ -154,6 +168,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.L.isDown() && _lKeydown.state == false && this._SHIFTKeydown == true){
_lKeydown.state = true;
this.notifyShortCutPerformed(_lKeydown);
console.log('Shift + L');
}
if (!kd.L.isDown() && _lKeydown.state == true ){
......@@ -162,6 +177,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.M.isDown() && _mKeydown.state == false && this._SHIFTKeydown == true){
_mKeydown.state = true;
this.notifyShortCutPerformed(_mKeydown);
console.log('Shift + M');
}
if (!kd.M.isDown() && _mKeydown.state == true ){
......@@ -170,6 +186,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.N.isDown() && _nKeydown.state == false && this._SHIFTKeydown == true){
_nKeydown.state = true;
this.notifyShortCutPerformed(_nKeydown);
console.log('Shift + N');
}
if (!kd.N.isDown() && _nKeydown.state == true ){
......@@ -178,6 +195,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.O.isDown() && _oKeydown.state == false && this._SHIFTKeydown == true){
_oKeydown.state = true;
this.notifyShortCutPerformed(_oKeydown);
console.log('Shift + O');
}
if (!kd.O.isDown() && _oKeydown.state == true ){
......@@ -186,14 +204,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.P.isDown() && _pKeydown.state == false && this._SHIFTKeydown == true){
_pKeydown.state = true;
console.log('Shift + P');
}
if (!kd.P.isDown() && _pKeydown.state == true ){
_pKeydown.state = false;
}
if(kd.P.isDown() && _pKeydown.state == false && this._SHIFTKeydown == true){
_pKeydown.state = true;
this.notifyShortCutPerformed(_pKeydown);
console.log('Shift + P');
}
if (!kd.P.isDown() && _pKeydown.state == true ){
......@@ -202,6 +213,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.Q.isDown() && _qKeydown.state == false && this._SHIFTKeydown == true){
_qKeydown.state = true;
this.notifyShortCutPerformed(_qKeydown);
console.log('Shift + Q');
}
if (!kd.Q.isDown() && _qKeydown.state == true ){
......@@ -210,6 +222,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.R.isDown() && _rKeydown.state == false && this._SHIFTKeydown == true){
_rKeydown.state = true;
this.notifyShortCutPerformed(_rKeydown);
console.log('Shift + R');
}
if (!kd.R.isDown() && _rKeydown.state == true ){
......@@ -218,6 +231,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.S.isDown() && _sKeydown.state == false && this._SHIFTKeydown == true){
_sKeydown.state = true;
this.notifyShortCutPerformed(_sKeydown);
console.log('Shift + S');
}
if (!kd.S.isDown() && _sKeydown.state == true ){
......@@ -226,6 +240,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.T.isDown() && _tKeydown.state == false && this._SHIFTKeydown == true){
_tKeydown.state = true;
this.notifyShortCutPerformed(_tKeydown);
console.log('Shift + T');
}
if (!kd.T.isDown() && _tKeydown.state == true ){
......@@ -234,6 +249,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.U.isDown() && _uKeydown.state == false && this._SHIFTKeydown == true){
_uKeydown.state = true;
this.notifyShortCutPerformed(_uKeydown);
console.log('Shift + U');
}
if (!kd.U.isDown() && _uKeydown.state == true ){
......@@ -242,6 +258,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.V.isDown() && _vKeydown.state == false && this._SHIFTKeydown == true){
_vKeydown.state = true;
this.notifyShortCutPerformed(_vKeydown);
console.log('Shift + V');
}
if (!kd.V.isDown() && _vKeydown.state == true ){
......@@ -250,6 +267,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.W.isDown() && _wKeydown.state == false && this._SHIFTKeydown == true){
_wKeydown.state = true;
this.notifyShortCutPerformed(_wKeydown);
console.log('Shift + W');
}
if (!kd.W.isDown() && _wKeydown.state == true ){
......@@ -258,6 +276,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.X.isDown() && _xKeydown.state == false && this._SHIFTKeydown == true){
_xKeydown.state = true;
this.notifyShortCutPerformed(_xKeydown);
console.log('Shift + X');
}
if (!kd.X.isDown() && _xKeydown.state == true ){
......@@ -266,6 +285,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.Y.isDown() && _yKeydown.state == false && this._SHIFTKeydown == true){
_yKeydown.state = true;
this.notifyShortCutPerformed(_yKeydown);
console.log('Shift + Y');
}
if (!kd.Y.isDown() && _yKeydown.state == true ){
......@@ -274,6 +294,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.Z.isDown() && _zKeydown.state == false && this._SHIFTKeydown == true){
_zKeydown.state = true;
this.notifyShortCutPerformed(_zKeydown);
console.log('Shift + Z');
}
if (!kd.Z.isDown() && _zKeydown.state == true ){
......@@ -282,6 +303,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.ONE.isDown() && _1Keydown.state == false && this._SHIFTKeydown == true){
_1Keydown.state = true;
this.notifyShortCutPerformed(_1Keydown);
console.log('Shift + 1');
}
if (!kd.ONE.isDown() && _1Keydown.state == true ){
......@@ -290,6 +312,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.TWO.isDown() && _2Keydown.state == false && this._SHIFTKeydown == true){
_2Keydown.state = true;
this.notifyShortCutPerformed(_2Keydown);
console.log('Shift + 2');
}
if (!kd.TWO.isDown() && _2Keydown.state == true ){
......@@ -298,6 +321,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.THREE.isDown() && _3Keydown.state == false && this._SHIFTKeydown == true){
_3Keydown.state = true;
this.notifyShortCutPerformed(_3Keydown);
console.log('Shift + 3');
}
if (!kd.THREE.isDown() && _3Keydown.state == true ){
......@@ -306,6 +330,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.FOUR.isDown() && _4Keydown.state == false && this._SHIFTKeydown == true){
_4Keydown.state = true;
this.notifyShortCutPerformed(_4Keydown);
console.log('Shift + 4');
}
if (!kd.FOUR.isDown() && _4Keydown.state == true ){
......@@ -314,6 +339,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.FIVE.isDown() && _5Keydown.state == false && this._SHIFTKeydown == true){
_5Keydown.state = true;
this.notifyShortCutPerformed(_5Keydown);
console.log('Shift + 5');
}
if (!kd.FIVE.isDown() && _5Keydown.state == true ){
......@@ -322,6 +348,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.SIX.isDown() && _6Keydown.state == false && this._SHIFTKeydown == true){
_6Keydown.state = true;
this.notifyShortCutPerformed(_6Keydown);
console.log('Shift + 6');
}
if (!kd.SIX.isDown() && _6Keydown.state == true ){
......@@ -330,6 +357,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.SEVEN.isDown() && _7Keydown.state == false && this._SHIFTKeydown == true){
_7Keydown.state = true;
this.notifyShortCutPerformed(_7Keydown);
console.log('Shift + 7');
}
if (!kd.SEVEN.isDown() && _7Keydown.state == true ){
......@@ -338,6 +366,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.EIGHT.isDown() && _8Keydown.state == false && this._SHIFTKeydown == true){
_8Keydown.state = true;
this.notifyShortCutPerformed(_8Keydown);
console.log('Shift + 8');
}
if (!kd.EIGHT.isDown() && _8Keydown.state == true ){
......@@ -346,6 +375,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.NINE.isDown() && _9Keydown.state == false && this._SHIFTKeydown == true){
_9Keydown.state = true;
this.notifyShortCutPerformed(_9Keydown);
console.log('Shift + 9');
}
if (!kd.NINE.isDown() && _9Keydown.state == true ){
......@@ -354,6 +384,7 @@ KeyboardManager.prototype.tick = function() {
if(kd.ZERO.isDown() && _0Keydown.state == false && this._SHIFTKeydown == true){
_0Keydown.state = true;
this.notifyShortCutPerformed(_0Keydown);
console.log('Shift + 0');
}
if (!kd.ZERO.isDown() && _0Keydown.state == true ){
......@@ -364,16 +395,36 @@ KeyboardManager.prototype.tick = function() {
};
KeyboardManager.prototype.addKeyPress = function(f) {
this._keyPressed.push(f.value);
KeyboardManager.prototype.addShortcutPerformedCB = function(callbackFunction){
this._shortcutPerformedCallbacks.push(callbackFunction);
};
KeyboardManager.prototype.removeKeyPress = function() {
for (var i = 0; i < this._keyPressed.length; i++) {
KeyboardManager.prototype.removeShortcutPerformedCB = function(callbackFunction){
for (var i = 0; i < this._shortcutPerformedCallbacks.length; i++) {
if (this._shortcutPerformedCallbacks[i] === callbackFunction) {
this._shortcutPerformedCallbacks.splice(i,1);
return true;
}
}
return false;
};
KeyboardManager.prototype.notifyShortCutPerformed = function(keyValue) {
// Go through and call all the callback functions that have previously
// been added, with the kb shortcut just performed
for (var i = 0; i < this._shortcutPerformedCallbacks.length; i++) {
this._shortcutPerformedCallbacks[i](keyValue);
}
};
}
}
KeyboardManager.prototype.notifyObservers = function() {
for (var i = 0; i < this._stateChangeHandlers.length; i++) {
this._stateChangeHandlers[i](this._SPACEKeydown);
......
......@@ -6,6 +6,7 @@ function Stimulus() {
this.width = 450;
}
Stimulus.prototype.setByItem = function(item) {
var mi = new FastTapMenuItem(item.name, item.icon, 100, 100);
mi.position.x = Math.floor(this.width / 2 - mi.width / 2);
......
......@@ -2,7 +2,8 @@ var Trial = require('./Trial.js'),
StudyLogger = require('study-logger'),
items = require('./Items.js'),
moment = require('moment'),
Strings = require('./Strings.js');
Strings = require('./Strings.js'),
KeyboardManager = require('./KeyboardManager.js');
function TrainTrial(experiment, options) {
Trial.call(this, experiment, options);
......@@ -12,6 +13,7 @@ function TrainTrial(experiment, options) {
this.stimulus = options.stimulus;
}
TrainTrial.prototype = Object.create(Trial.prototype);
kbManager = new KeyboardManager();
TrainTrial.prototype.start = function() {
this.experiment.fastTapMenu.openable = true;
......@@ -19,40 +21,62 @@ TrainTrial.prototype.start = function() {
this.experiment.instructions.Text = (Strings["side-instructions-train"]);
this.startTimestamp = +moment();
this.handleItemClick = function(data) {
// this.handleItemClick = function(data) {
this.experiment.fastTapMenu.flashAround(data.row, data.col, 0);
// this.experiment.fastTapMenu.flashAround(data.row, data.col, 0);
if (data.item.name === this.stimulus) {
StudyLogger.logEvent({type: 'event.endtrial',
trialtype: this.type,
trialid: this.trialid,
blockid: this.blockid,
stimulus: this.stimulus,
success: true,
duration: +moment() - this.startTimestamp,
clickitem: data.item.name,
clickrow: data.row,
clickcol: data.col,
clickx: data.menuX,
clicky: data.menuY});
this.experiment.fastTapMenu.removeItemClickedCB(this.handleItemClick);
this.completed = true;
}
// if (data.item.name === this.stimulus) {
// StudyLogger.logEvent({type: 'event.endtrial',
// trialtype: this.type,
// trialid: this.trialid,
// blockid: this.blockid,
// stimulus: this.stimulus,
// success: true,
// duration: +moment() - this.startTimestamp,
// clickitem: data.item.name,
// clickrow: data.row,
// clickcol: data.col,
// clickx: data.menuX,
// clicky: data.menuY});
// this.experiment.fastTapMenu.removeItemClickedCB(this.handleItemClick);
// this.completed = true;
// }
}.bind(this);
// }.bind(this);
this.experiment.fastTapMenu.addItemClickedCB(this.handleItemClick);
// this.experiment.fastTapMenu.addItemClickedCB(this.handleItemClick);
// StudyLogger.logEvent({type: 'event.starttrial',
// trialtype: this.type,
// trialid: this.trialid,
// blockid: this.blockid,
// stimulus: this.stimulus});
this.ShortCutPerformed = function(keyPress) {
console.log(keyPress);
console.log(this.stimulus)
if(this.keyPress === this.stimulus)
{
// This will advance to the next Trail Round when keyPress matches
// the stimulus
this.kbManager.removeShortcutPerformedCB(this.ShortCutPerformed);
this.completed = true;
}
}.bind(this);
this.experiment.kbManager.addShortcutPerformedCB(this.ShortCutPerformed);
StudyLogger.logEvent({type: 'event.starttrial',
trialtype: this.type,
trialid: this.trialid,
blockid: this.blockid,
stimulus: this.stimulus});
trialtype: this.type,
trailid: this.trailid,
blockid: this.blockid,
stimulus: this.stimulus});
};
TrainTrial.prototype.update = function(delta) {
};
module.exports = TrainTrial;
module.exports = TrainTrial;
\ No newline at end of file
......@@ -11,7 +11,7 @@ var STAGE_BG = 0xffffff;
var WIDTH = 1260;
var HEIGHT = 810;
var renderer = new PIXI.CanvasRenderer(WIDTH, HEIGHT,{backgroundColor 0xFFFFFF});
var renderer = new PIXI.CanvasRenderer(WIDTH, HEIGHT,{backgroundColor: 0xFFFFFF});
document.body.appendChild(renderer.view);
var interactive = true;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment