summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2013-03-03 17:10:43 -0500
committerJules Laplace <jules@okfoc.us>2013-03-03 17:10:43 -0500
commita8c3fd6a3fda75c37b6035ae29ba545c0cb823c4 (patch)
tree9bb8f79b22ed1b51341ce84ca0a7e9f392d77361
parentf0e19d5b5962a143d7955cf16bf3714eb4de6a2c (diff)
listing events and UI states
-rw-r--r--public/js/game.js86
1 files changed, 81 insertions, 5 deletions
diff --git a/public/js/game.js b/public/js/game.js
index 010f01f..8fa19e1 100644
--- a/public/js/game.js
+++ b/public/js/game.js
@@ -1,15 +1,26 @@
var socket = io.connect(window.location.hostname);
+var State = {
+ WAITING: 0,
+ DRAWING: 1,
+ VOTING: 2,
+ WIN: 3,
+ RESET: -1,
+}
+
var Game = {
nick: null,
-
+ state: State.WAITING,
+
init: function(){
// Bind events from the server
- socket.on('event-welcome', Events.receive.join);
+ socket.on('event-welcome', Events.receive.welcome);
socket.on('event-join', Events.receive.join);
- socket.on('event-part', Events.receive.join);
+ socket.on('event-part', Events.receive.part);
socket.on('event-message', Events.receive.message);
+ socket.on('event-state', Events.receive.state);
+ socket.on('event-vote', Events.receive.vote);
socket.on('event-image', Events.receive.image);
Auth.init();
Chat.init();
@@ -20,28 +31,56 @@ var Events = {
receive: {
- join: function(data){
+ // Player connects to the game
+ welcome: function(data){
for (var i in data.messages) {
Chat.add(data.messages[i]);
}
},
+ // Another player joins the room
+ join: function(data){
+ },
+
+ // Another player leaves the room
+ part: function(data){
+ },
+
+ // Game state changes
+ state: function(data){
+ if (Game.state == data.state) return;
+ UI[ States.current ].unload();
+ UI[ data.state ].load();
+ Game.state = data.state;
+ },
+
+ // Incoming chat
message: function(msg) {
Chat.add(msg);
},
+ // Incoming image
image: function(data) {
console.log(data);
if (data.nick == Game.nick) return;
$("#image").attr("src", data.url).show();
+ },
+
+ // Another player votes on an image
+ vote: function(data){
}
-
+
},
send: {
+ // Sending a message
message: function(msg) {
socket.emit('event-message', msg);
+ },
+
+ // Sending a vote
+ vote: function(id){
}
},
@@ -49,5 +88,42 @@ var Events = {
};
+var UI = {};
+UI[ State.WAITING ] = {
+ load: function(){
+ },
+ unload: function(){
+ }
+}
+
+UI[ State.DRAWING ] = {
+ load: function(){
+ },
+ unload: function(){
+ }
+}
+
+UI[ State.VOTING ] = {
+ load: function(){
+ },
+ unload: function(){
+ }
+}
+
+UI[ State.WIN ] = {
+ load: function(){
+ },
+ unload: function(){
+ }
+}
+
+UI[ State.RESET ] = {
+ load: function(){
+ },
+ unload: function(){
+ }
+}
+
+
$(Game.init);