Permalink
Browse files

No longer using these structures

  • Loading branch information...
1 parent 51b7198 commit 6ad3c5458496f6899bd0c847e6c5cfd4ed55ea01 John Conomikes committed Aug 31, 2011
Showing with 0 additions and 161 deletions.
  1. +0 −74 src/html5/src/Preloader.js
  2. +0 −87 src/html5/src/QuestionList.js
View
@@ -1,74 +0,0 @@
-var cocos = require('cocos2d');
-var util = require('util');
-var events = require('events');
-
-// Basic remote resource/image preloader
-// TODO: Trigger completion progress events
-var Preloader = BObject.extend({
- loadQueue: null, // Queue of objects to load
- toLoad: null, // Total number of objects to load
- totalLoaded: null, // Objects loaded so far
- failBit: null, // True if any object fails to load
- init: function() {
- Preloader.superclass.init.call(this);
-
- this.set('loadQueue', []);
- this.loadCallback = this.loadCallback.bind(this)
- this.failCallback = this.failCallback.bind(this)
- this.set('failbit', false);
- },
- // Queues an image in the preloader
- // path is where the image will be loaded and url is the address on the server where the image resides
- queueLoad: function(type, path, url) {
- opts = new Object();
- opts['path'] = path;
- opts['url'] = url;
-
- queue = this.get('loadQueue');
- if(type == "RemoteImage") {
- queue.push(cocos.RemoteImage.create(opts));
- }
- else if(type == "RemoteResource") {
- queue.push(cocos.RemoteResource.create(opts));
- }
-
- console.log("Queued load of resource( " + path + " ) at url: " + url);
-
- this.set('toLoad', this.get('toLoad') + 1);
- this.set('loadQueue', queue);
- },
- // Starts loading all queued images
- startLoad: function() {
- var queue = this.get('loadQueue');
- for (var i = 0; i < queue.length; i++) {
- events.addListener(queue[i], 'load', this.loadCallback);
- events.addListener(queue[i], 'fail', this.failCallback);
- console.log("Starting load of resource( " + queue[i].get('path') + " ) at url: " + queue[i].get('url'));
- queue[i].load();
- }
- },
- // Called on every load completion
- // TODO: Trigger completion progress events
- loadCallback: function(evt) {
- this.set('totalLoaded', this.get('totalLoaded') + 1);
-
- //console.log(this.get('totalLoaded') + " / " this.get('toLoad'));
- //events.trigger(this, 'progress', this.get('totalLoaded') * 1.0 / this.get('toLoad'));
-
- if(this.get('totalLoaded') >= this.get('toLoad') && !this.get('failbit')) {
- console.log("Preloading completed");
- events.trigger(this, 'complete');
- }
- },
-
- // Called when a remote resource 404's
- failCallback: function(evt) {
- if(this.get('failbit') == false) {
- this.set('failbit', true);
- console.log("A remote resource has 404'ed");
- events.trigger(this, 'runLocal');
- }
- }
-});
-
-exports.Preloader = Preloader;
@@ -1,87 +0,0 @@
-var events = require('events');
-
-// Contains the list of questions to be presented
-var QuestionList = BObject.extend({
- questions:null, //List of questions
- current:null, //Curent question index
- intermissions:null, //List of intermissions
- nextIntermission:null, //Question index of next intermission
- init: function() {
- QuestionList.superclass.init.call(this);
-
- this.set('questions', []);
- this.set('current', -1);
- this.set('intermissions', []);
- this.set('nextIntermission', -2);
-
- this.nextQuestion = this.nextQuestion.bind(this)
- },
- // Adds a question to the list
- addQuestion: function(q) {
- var list = this.get('questions');
- list[list.length] = q;
- this.set('questions', list);
- },
- // Adds an intermission set at the current end of the question list
- // Returns true on first intermission, signaling that the value passed it should be applyed to the Player
- addIntermission: function(s) {
- if(this.get('nextIntermission') == -2) {
- this.set('nextIntermission', -1);
- return true;
- }
- else if(this.get('nextIntermission') == -1) {
- this.set('nextIntermission', this.get('questions').length);
- }
-
- var list = this.get('intermissions');
- list[list.length] = {selector: s, onQuestion: this.get('questions').length};
- this.set('intermissions', list);
-
- return false;
- },
- //Stores the currently displayed question
- storeQuestion: function(question) {
- this.get('questions')[this.get('current')] = question;
- },
- // Advances to the next question
- nextQuestion: function() {
- console.log("Advancing to next question");
-
- var questions = this.get('questions');
- var c = this.get('current');
-
- // Check to see if there is an intermission ahead
- if(c + 1 == this.get('nextIntermission')) {
- console.log(" New subset detected, triggering intermission");
- var inter = this.get('intermissions')
- events.trigger(this, 'intermission', inter[0].selector);
-
- // Remove the intermission that was just triggered and set up the next one, if there is one
- inter.shift();
- if(inter.length > 0) {
- this.set('nextIntermission', inter[0].onQuestion);
- }
- else {
- this.set('nextIntermission', -3);
- }
- this.set('intermissions', inter);
- }
-
- // Proceed to next question
- else if(c < questions.length - 1) {
- c += 1;
- this.set('current', c);
-
- events.trigger(this, 'QuestionReady', questions[c]);
- console.log(" Showing question # " + (c + 1));
- }
- // Otherwise signal the end of the game
- else {
- console.log(" No more questions remaining");
-
- events.trigger(this, 'noQuestionsRemaining');
- }
- },
-});
-
-exports.QuestionList = QuestionList

0 comments on commit 6ad3c54

Please sign in to comment.