Skip to content

Commit

Permalink
auto-reformatted whitespace with webstorm of the demo project files. …
Browse files Browse the repository at this point in the history
…excluded external libraries
  • Loading branch information
Brendon Muschamp committed Mar 21, 2014
1 parent 581427c commit a631881
Show file tree
Hide file tree
Showing 40 changed files with 2,898 additions and 2,888 deletions.
65 changes: 32 additions & 33 deletions js/BubbleDots/BubbleDotsApp.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
/**
File:
RealtimeMultiplayerGame.js
Created By:
Mario Gonzalez
Project:
RealtimeMultiplayerNodeJS
Abstract:
This is the core module for RealtimeMultiplayerGame contains the namespace, and extend method
File:
RealtimeMultiplayerGame.js
Created By:
Mario Gonzalez
Project:
RealtimeMultiplayerNodeJS
Abstract:
This is the core module for RealtimeMultiplayerGame contains the namespace, and extend method
Basic Usage:
This class is not instantiated
Version:
1.0
*/
Basic Usage:
This class is not instantiated
Version:
1.0
*/
BubbleDots = (typeof BubbleDots === 'undefined') ? {} : BubbleDots;
/**
* Allows a package to create a namespace within RealtimeMultiplayerGame
* From Javascript Patterns book
* @param ns_string
*/
BubbleDots.namespace = function(ns_string)
{
var parts = ns_string.split('.'),
parent = BubbleDots,
i = 0;
BubbleDots.namespace = function (ns_string) {
var parts = ns_string.split('.'),
parent = BubbleDots,
i = 0;

// strip redundant leading global
if (parts[0] === "BubbleDots") {
parts = parts.slice(1);
}
// strip redundant leading global
if (parts[0] === "BubbleDots") {
parts = parts.slice(1);
}

var len = parts.length,
aPackage = null;
for (i = 0; i < len; i += 1) {
var singlePart = parts[i];
// create a property if it doesn't exist
if (typeof parent[singlePart] === "undefined") {
parent[singlePart] = {};
}
parent = parent[singlePart];
var len = parts.length,
aPackage = null;
for (i = 0; i < len; i += 1) {
var singlePart = parts[i];
// create a property if it doesn't exist
if (typeof parent[singlePart] === "undefined") {
parent[singlePart] = {};
}
parent = parent[singlePart];

}
return parent;
}
return parent;
};
267 changes: 133 additions & 134 deletions js/BubbleDots/BubbleDotsClientGame.js
Original file line number Diff line number Diff line change
@@ -1,136 +1,135 @@
/**
File:
DemoServerGame
Created By:
Mario Gonzalez
Project:
BubbleDots
Abstract:
This is a concrete server instance of our game
Basic Usage:
DemoServerGame = new BubbleDots.DemoServerGame();
DemoServerGame.start();
DemoServerGame.explodeEveryone();
Version:
1.0
*/
(function(){

BubbleDots.DemoClientGame = function() {
BubbleDots.DemoClientGame.superclass.constructor.call(this);

this.startGameClock();
return this;
};

BubbleDots.DemoClientGame.prototype = {
setupView: function(images) {
this.view = new BubbleDots.DemoView( images );
this.view.insertIntoHTMLElementWithId( "gamecontainer" );

BubbleDots.DemoClientGame.superclass.setupView.call( this );
},

/**
* @inheritDoc
*/
tick: function() {
BubbleDots.DemoClientGame.superclass.tick.call(this);
this.view.stats.update();
this.view.update( this.gameClockReal );
this.view.textfield.setText( "Ping: " + this.netChannel.getLatency() );
},

/**
* @inheritDoc
*/
createEntityFromDesc: function(entityDesc) {

// Create a new BubbleDots entity
var newEntity = new BubbleDots.CircleEntity( entityDesc.entityid, entityDesc.clientid );
newEntity.position.set( entityDesc.x, entityDesc.y );

var entityView = this.view.createEntityView( entityDesc );
newEntity.setView( entityView );

this.fieldController.addEntity( newEntity );

// Our own character
if(entityDesc.clientid == this.netChannel.getClientid() && entityDesc.entityType & BubbleDots.Constants.ENTITY_TYPES.PLAYER_ENTITY) {
this.setupClientPlayer( newEntity );
this.view.setFocusCharacter( entityView );
}
},

/**
* Called when the player that represents this user is created
* @param anEntity
*/
setupClientPlayer: function( anEntity ) {
anEntity.addTraitAndExecute( new RealtimeMultiplayerGame.controller.traits.KeyboardInputTrait() );
this.clientCharacter = anEntity;
},

/**
* @inheritDoc
*/
netChannelDidConnect: function (messageData) {
BubbleDots.DemoClientGame.superclass.netChannelDidConnect.call(this, messageData );
BubbleDots.DemoClientGame.prototype.log("DemoClientGame: Joining Game");
this.joinGame("Player" + this.netChannel.getClientid() ); // Automatically join the game with some name
},

/**
* @inheritDoc
*/
netChannelDidDisconnect: function (messageData) {
BubbleDots.DemoClientGame.superclass.netChannelDidDisconnect.call(this, messageData );
BubbleDots.DemoClientGame.prototype.log("DemoClientGame: netChannelDidDisconnect"); // Display disconnect
},

/**
* An array containing values received from the entity
* @param {String} singleWorldUpdate
*/
parseEntityDescriptionArray: function(entityDescAsArray)
{
var entityDescription = {};
// It is up to the user to make sure that their objects are following a certain order
// We do this because we need the performance of sending the tiniest strings possible
entityDescription.entityid = entityDescAsArray[0];
entityDescription.clientid = entityDescAsArray[1];
entityDescription.entityType = +entityDescAsArray[2];
entityDescription.x = +entityDescAsArray[3];
entityDescription.y = +entityDescAsArray[4];
entityDescription.scale = +entityDescAsArray[5];
entityDescription.color = entityDescAsArray[6];
return entityDescription;
},


/**
* This function logs something to the right panel
* @param {Object} An object in the form of: { message: ['Client', 'domReady'] }
*/
log: (function(){
var message = function(message){
var el = document.createElement('p');
el.innerHTML = '<b>' + esc(message) + ':</b> ';

// Log if possible
console.log(message);
document.getElementsByTagName('aside')[0].appendChild(el);
document.getElementsByTagName('aside')[0].scrollTop = 1000000;
};

var esc = function (msg){
return msg.replace(/</g, '&lt;').replace(/>/g, '&gt;');
};

return message;
})()
};

// extend RealtimeMultiplayerGame.AbstractClientGame
RealtimeMultiplayerGame.extend(BubbleDots.DemoClientGame, RealtimeMultiplayerGame.AbstractClientGame, null);
File:
DemoServerGame
Created By:
Mario Gonzalez
Project:
BubbleDots
Abstract:
This is a concrete server instance of our game
Basic Usage:
DemoServerGame = new BubbleDots.DemoServerGame();
DemoServerGame.start();
DemoServerGame.explodeEveryone();
Version:
1.0
*/
(function () {

BubbleDots.DemoClientGame = function () {
BubbleDots.DemoClientGame.superclass.constructor.call(this);

this.startGameClock();
return this;
};

BubbleDots.DemoClientGame.prototype = {
setupView: function (images) {
this.view = new BubbleDots.DemoView(images);
this.view.insertIntoHTMLElementWithId("gamecontainer");

BubbleDots.DemoClientGame.superclass.setupView.call(this);
},

/**
* @inheritDoc
*/
tick: function () {
BubbleDots.DemoClientGame.superclass.tick.call(this);
this.view.stats.update();
this.view.update(this.gameClockReal);
this.view.textfield.setText("Ping: " + this.netChannel.getLatency());
},

/**
* @inheritDoc
*/
createEntityFromDesc: function (entityDesc) {

// Create a new BubbleDots entity
var newEntity = new BubbleDots.CircleEntity(entityDesc.entityid, entityDesc.clientid);
newEntity.position.set(entityDesc.x, entityDesc.y);

var entityView = this.view.createEntityView(entityDesc);
newEntity.setView(entityView);

this.fieldController.addEntity(newEntity);

// Our own character
if (entityDesc.clientid == this.netChannel.getClientid() && entityDesc.entityType & BubbleDots.Constants.ENTITY_TYPES.PLAYER_ENTITY) {
this.setupClientPlayer(newEntity);
this.view.setFocusCharacter(entityView);
}
},

/**
* Called when the player that represents this user is created
* @param anEntity
*/
setupClientPlayer: function (anEntity) {
anEntity.addTraitAndExecute(new RealtimeMultiplayerGame.controller.traits.KeyboardInputTrait());
this.clientCharacter = anEntity;
},

/**
* @inheritDoc
*/
netChannelDidConnect: function (messageData) {
BubbleDots.DemoClientGame.superclass.netChannelDidConnect.call(this, messageData);
BubbleDots.DemoClientGame.prototype.log("DemoClientGame: Joining Game");
this.joinGame("Player" + this.netChannel.getClientid()); // Automatically join the game with some name
},

/**
* @inheritDoc
*/
netChannelDidDisconnect: function (messageData) {
BubbleDots.DemoClientGame.superclass.netChannelDidDisconnect.call(this, messageData);
BubbleDots.DemoClientGame.prototype.log("DemoClientGame: netChannelDidDisconnect"); // Display disconnect
},

/**
* An array containing values received from the entity
* @param {String} singleWorldUpdate
*/
parseEntityDescriptionArray: function (entityDescAsArray) {
var entityDescription = {};
// It is up to the user to make sure that their objects are following a certain order
// We do this because we need the performance of sending the tiniest strings possible
entityDescription.entityid = entityDescAsArray[0];
entityDescription.clientid = entityDescAsArray[1];
entityDescription.entityType = +entityDescAsArray[2];
entityDescription.x = +entityDescAsArray[3];
entityDescription.y = +entityDescAsArray[4];
entityDescription.scale = +entityDescAsArray[5];
entityDescription.color = entityDescAsArray[6];
return entityDescription;
},


/**
* This function logs something to the right panel
* @param {Object} An object in the form of: { message: ['Client', 'domReady'] }
*/
log: (function () {
var message = function (message) {
var el = document.createElement('p');
el.innerHTML = '<b>' + esc(message) + ':</b> ';

// Log if possible
console.log(message);
document.getElementsByTagName('aside')[0].appendChild(el);
document.getElementsByTagName('aside')[0].scrollTop = 1000000;
};

var esc = function (msg) {
return msg.replace(/</g, '&lt;').replace(/>/g, '&gt;');
};

return message;
})()
};

// extend RealtimeMultiplayerGame.AbstractClientGame
RealtimeMultiplayerGame.extend(BubbleDots.DemoClientGame, RealtimeMultiplayerGame.AbstractClientGame, null);
})();
Loading

0 comments on commit a631881

Please sign in to comment.