Permalink
Browse files

Initial HTML5 integration into TestHarness

  • Loading branch information...
1 parent cebf789 commit e10897d66d1bdaf3a18c988590518e6d275a3e6d John Conomikes committed Sep 22, 2011
@@ -1,8 +1,10 @@
-var GameControllerClient = require('./client/GameControllerClient').GameControllerClient,
- CLFlashGameEngine = require('./client/CLFlashGameEngine').CLFlashGameEngine;
+var GameControllerClient = require('./client/GameControllerClient').GameControllerClient;
+var CLFlashGameEngine = require('./client/CLFlashGameEngine').CLFlashGameEngine;
+var CLHTML5GameEngine = require('./client/CLHTML5GameEngine').CLHTML5GameEngine;
var gc = new GameControllerClient('api');
gc.registerEngineConstructor('CLFlashGameEngine', CLFlashGameEngine);
+gc.registerEngineConstructor('CLHTML5GameEngine', CLHTML5GameEngine);
var instructionsURL;
@@ -4,42 +4,48 @@
"stages": [
"test-1",
"test-2",
- "test-3"
+ "test-3",
+ "html5-test"
]
},
"cond2": {
"stages": [
"test-1",
"test-2",
- "test-3"
+ "test-3",
+ "html5-test"
]
},
"cond3": {
"stages": [
"test-1",
"test-2",
- "test-3"
+ "test-3",
+ "html5-test"
]
},
"cond4": {
"stages": [
"test-1",
"test-2",
- "test-3"
+ "test-3",
+ "html5-test"
]
},
"cond5": {
"stages": [
"test-1",
"test-2",
- "test-3"
+ "test-3",
+ "html5-test"
]
},
"cond6": {
"stages": [
"test-1",
"test-2",
- "test-3"
+ "test-3",
+ "html5-test"
]
}
},
@@ -59,6 +65,11 @@
"displayName": "Week 1: Dec to Pct, Level 3",
"engine": "racecar",
"cli_fluency_task": "test3"
+ },
+ "html5-test": {
+ "displayName": "HTML5",
+ "engine": "racecar_html5",
+ "cli_fluency_task": "test1"
}
},
@@ -71,6 +82,10 @@
"type": "CLFlashGameEngine",
"cli_task_id": "ft1_racecar"
},
+ "racecar_html5": {
+ "type": "CLHTML5GameEngine",
+ "cli_task_id": "ft1_racecar"
+ },
"fire": {
"type": "CLFlashGameEngine",
"cli_task_id": "ft2_fire"
@@ -94,6 +94,17 @@ table.display
clear: both;
}
+#cocos_test_app {
+ border: 1px solid #000;
+ width: 900px;
+ height: 600px;
+ margin: 0 auto;
+ -webkit-box-shadow: 0 3px 10px rgba(0, 0, 0, 0.75);
+ -moz-box-shadow: 0 3px 10px rgba(0, 0, 0, 0.75);
+ -o-box-shadow: 0 3px 10px rgba(0, 0, 0, 0.75);
+ box-shadow: 0 2px 2px rgba(0, 0, 0, 0.75);
+}
+
#status-message
{
display: none;
@@ -191,6 +191,10 @@ function makeEngine(engineConfig)
engineConfig.swfPath = '/fluency/games/' + engineConfig.cli_task_id;
engineConfig.dataPath = '/fluency/data/' + engineConfig.cli_task_id;
}
+ else if (engineConfig.type == 'CLHTML5GameEngine') {
+ engineConfig.scriptPath = '/fluency/games/' + engineConfig.cli_task_id + '_html5';
+ engineConfig.dataPath = '/fluency/data/' + engineConfig.cli_task_id;
+ }
engineConfig.toJSON = function ()
{
@@ -0,0 +1,61 @@
+var uuid = require('../node_modules/node-uuid/uuid');
+
+/*
+ Class: CLHTML5GameEngine
+
+ A client game engine that instantiates an HTML5 Cocos-based Carnegie Learning fluency task game engine. The config JSON should contain the following keys:
+
+ * dataPath - The base URL to input data.
+ * scriptPath - The base URL to the directory containing HTML5 javascript.
+
+ When the <run> method is called, the questionSet (or its parent stage) should define the following property:
+
+ * input - The name of the input file XML file relative to dataPath.
+*/
+exports.CLHTML5GameEngine = function CLHTML5GameEngine(json)
+{
+ this.scriptPath = json.scriptPath;
+ this.dataPath = json.dataPath;
+ var self = this;
+ this.run = function (questionSet, div, callback)
+ {
+ var props = questionSet.allGameProperties();
+ registerDoneCallback(callback);
+
+ var app_div = $('<div>');
+ app_div.attr('id', 'cocos_test_app');
+ app_div.attr('data', self.dataPath + '/' + props.input);
+ app_div.attr('gameID', uuid() + '::' + 'CLFlashGameEngine' + '::' + questionSet.parent.id + '::' + questionSet.id);
+
+ $(div).empty().append(app_div);
+
+ var head = document.getElementsByTagName('head')[0];
+ var script = document.createElement('script');
+ script.type = 'text/javascript';
+ script.src = self.scriptPath + '/' + 'cocos_test.js';
+ head.appendChild(script);
+ //data="'+ self.dataPath + '/' + props.input +'"
+ //gameid="' uuid() + '::' + 'CLFlashGameEngine' + '::' + questionSet.parent.id + '::' + questionSet.id + '"
+ };
+};
+
+var currentDoneCallback,
+ currentDoneCallbackTimeout;
+
+function registerDoneCallback(callback)
+{
+ currentDoneCallback = callback;
+}
+
+window.CLHTML5GameEngineDoneCallback = function CLHTML5GameEngineDoneCallback(xml)
+{
+ // When a game is aborted, a finish callback and an abort callback happen in quick succession. This can lead to duplicate data on the server. To work around this issue, we delay calling the real callback, only letting the last one through.
+ if (currentDoneCallbackTimeout)
+ {
+ clearTimeout(currentDoneCallbackTimeout);
+ }
+ currentDoneCallbackTimeout = setTimeout(function ()
+ {
+ currentDoneCallback(xml);
+ }, 100);
+};
View
@@ -68,12 +68,18 @@ var FluencyApp = KeyboardLayer.extend({
dash.set('position', new geo.Point(800, 0));
this.set('dash', dash);
+ // Get "command line" arguments from the div tag
+ var app_div = $("#cocos_test_app")
+ var xml_path = app_div.attr("data");
+ var game_id = app_div.attr("gameid");
+ this.set('gameID', game_id);
+
// Uncomment to run locally
//this.runLocally();
//return;
- // Set up remote resources
- __remote_resources__["resources/testset.xml"] = {meta: {mimetype: "application/xml"}, data: "set002.xml"};
+ // Set up remote resources, default value allows for running 'locally'
+ __remote_resources__["resources/testset.xml"] = {meta: {mimetype: "application/xml"}, data: xml_path ? xml_path : "set002.xml"};
// Preload remote resources
var p = cocos.Preloader.create();
@@ -241,7 +247,16 @@ var FluencyApp = KeyboardLayer.extend({
z += RC.intermissionSpacing;
// Gets the intermission value
var node = subset.firstElementChild;
- var interContent = this.parseContent(node);
+ var interContent;
+
+ var hurix = XML.safeGetAttr(node, 'VALUE');
+ if(hurix) {
+ interContent = LabelBG.create(LabelBG.helper(hurix,'#000','#fff'));
+ }
+ else {
+ interContent = this.parseContent(node);
+ }
+
var inter = Intermission.create(interContent, z);
events.addListener(inter, 'changeSelector', this.get('player').startIntermission.bind(this.get('player')));
events.addListener(inter, 'changeSelector', this.get('dash').pauseTimer.bind(this.get('dash')));
@@ -275,6 +290,9 @@ var FluencyApp = KeyboardLayer.extend({
// Answer is the same in all formats, so get it first
ans = XML.safeComboGet(node, 'Answer', 'VALUE');
+ if(!ans) {
+ ans = XML.safeComboGet(node, 'ANSWER', 'VALUE');
+ }
// Legacy check
var hurix = node.getElementsByTagName('DELIMETERS_TEXT');

0 comments on commit e10897d

Please sign in to comment.