From b9123202c115739a12e573138492d33cc410a0bf Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 8 Aug 2015 18:13:17 +0100 Subject: [PATCH] Added flags and other things --- lib/gather/controller.js | 39 +++--- lib/gather/gather.js | 18 ++- lib/react/gather.jsx | 42 +++++-- public/css/flags.css | 259 +++++++++++++++++++++++++++++++++++++++ public/images/blank.gif | Bin 0 -> 43 bytes public/images/flags.png | Bin 0 -> 79881 bytes public/js/app.js | 42 +++++-- views/partials/head.hbs | 1 + 8 files changed, 357 insertions(+), 44 deletions(-) create mode 100644 public/css/flags.css create mode 100644 public/images/blank.gif create mode 100644 public/images/flags.png diff --git a/lib/gather/controller.js b/lib/gather/controller.js index 544d59f..8c70fa9 100644 --- a/lib/gather/controller.js +++ b/lib/gather/controller.js @@ -23,20 +23,10 @@ var Map = require("./map"); var Server = require("./server"); var Gather = require("./gather"); var gather; +var previousGathers = []; module.exports = function (namespace) { - gather = Gather({ - onElectionTimeout: function () { - console.log("Election timeout") - refreshGather(); - } - }); - - // ***** Generate Test Users ***** - // var helper = require("./helper"); - // helper.createTestUsers({ gather: gather }); - var refreshGather = function () { namespace.sockets.forEach(function (socket) { socket.emit("gather:refresh", { @@ -48,12 +38,26 @@ module.exports = function (namespace) { }); }; - namespace.on("connection", function (socket) { - socket.on("gather:join", function (data) { - if (gather.can("addGatherer")) { - gather.addGatherer(socket._user); + var newGather = function () { + if (gather) previousGathers.push(gather); + gather = Gather({ + onEvent: function () { refreshGather(); } + }); + } + + newGather(); + + // ***** Generate Test Users ***** + var helper = require("./helper"); + helper.createTestUsers({ gather: gather }); + + + + namespace.on("connection", function (socket) { + socket.on("gather:join", function (data) { + if (gather.can("addGatherer")) gather.addGatherer(socket._user); }); socket.on("gather:refresh", function () { @@ -64,10 +68,7 @@ module.exports = function (namespace) { }); socket.on("gather:leave", function (data) { - if (gather.can("removeGatherer")) { - gather.removeGatherer(socket._user); - refreshGather(); - } + if (gather.can("removeGatherer")) gather.removeGatherer(socket._user); }); socket.on("gather:select", function (data) { diff --git a/lib/gather/gather.js b/lib/gather/gather.js index 3a19f03..3eb846f 100644 --- a/lib/gather/gather.js +++ b/lib/gather/gather.js @@ -19,8 +19,10 @@ function Gather (options) { return new Gather(options); } - if (options && typeof options.onElectionTimeout === 'function') { - this.onElectionTimeout = options.onElectionTimeout; + if (options && typeof options.onEvent === 'function') { + this.onEvent = options.onEvent; + } else { + this.onEvent = function () {}; // Noop } this.TEAM_SIZE = 6; @@ -214,6 +216,14 @@ StateMachine.create({ { name: "removeGatherer", from: ["gathering", "election", "selection"], to: "gathering" } ], callbacks: { + // Callbacks for events + oninitState: function () { this.onEvent.call(this) }, + onaddGatherer: function () { this.onEvent.call(this) }, + onselectLeader: function () { this.onEvent.call(this) }, + onelectionTimeout: function () { this.onEvent.call(this) }, + onconfirmSelection: function () { this.onEvent.call(this) }, + onremoveGatherer: function () { this.onEvent.call(this) }, + // Gathering State onbeforeaddGatherer: function (event, from, to, user) { this.addUser(user); @@ -238,9 +248,6 @@ StateMachine.create({ if (self.can("electionTimeout")) { self.electionTimeout(); } - if (self.onElectionTimeout) { - self.onElectionTimeout.bind(self)(); - } }, self.ELECTION_INTERVAL); }, @@ -282,6 +289,7 @@ StateMachine.create({ && this.marines().length === this.TEAM_SIZE); }, + // Remove gatherer event onbeforeremoveGatherer: function (event, from, to, user) { this.removeUser(user); } diff --git a/lib/react/gather.jsx b/lib/react/gather.jsx index 42d6366..e3377b3 100644 --- a/lib/react/gather.jsx +++ b/lib/react/gather.jsx @@ -51,6 +51,13 @@ var SelectPlayerButton = React.createClass({ return (); + } else if (this.props.gatherer.team !== "lobby") { + return ( + ); } else { return (