mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-26 06:10:58 +00:00
Remove captain confirmation
This commit is contained in:
parent
934b707434
commit
973015e927
9 changed files with 177 additions and 103 deletions
|
@ -13,9 +13,10 @@
|
|||
* gather:vote - Assigns vote to map, leader or server
|
||||
* gather:leave - Leave gather
|
||||
* gather:select - Select player for team
|
||||
* gather:select:confirm - Confirm selected team
|
||||
* gather:refresh - Refresh gather for client
|
||||
*
|
||||
* gather:reset - Resets gather (ADMIN)
|
||||
*
|
||||
*/
|
||||
|
||||
var Map = require("./map");
|
||||
|
@ -24,8 +25,8 @@ var Gather = require("./gather");
|
|||
var gather = new Gather();
|
||||
|
||||
// ***** Generate Test Users *****
|
||||
// var helper = require("./helper");
|
||||
// helper.createTestUsers({ gather: gather });
|
||||
var helper = require("./helper");
|
||||
helper.createTestUsers({ gather: gather });
|
||||
|
||||
module.exports = function (namespace) {
|
||||
var refreshGather = function () {
|
||||
|
@ -83,14 +84,11 @@ module.exports = function (namespace) {
|
|||
var method = (team === 'alien') ? gather.moveToAlien : gather.moveToMarine;
|
||||
method.call(gather, selectedPlayer.user);
|
||||
|
||||
refreshGather();
|
||||
});
|
||||
|
||||
socket.on("gather:select:confirm", function () {
|
||||
var user = socket._user;
|
||||
if (gather.can("confirmSelection")) {
|
||||
gather.confirmSelection(user);
|
||||
}
|
||||
|
||||
refreshGather();
|
||||
});
|
||||
|
||||
socket.on("disconnect", function () {
|
||||
|
@ -113,6 +111,13 @@ module.exports = function (namespace) {
|
|||
refreshGather();
|
||||
});
|
||||
|
||||
socket.on("gather:reset", function () {
|
||||
if (socket._user.admin) {
|
||||
gather = Gather();
|
||||
refreshGather();
|
||||
}
|
||||
});
|
||||
|
||||
refreshGather();
|
||||
});
|
||||
};
|
||||
|
|
|
@ -23,14 +23,6 @@ function Gather () {
|
|||
this.initState();
|
||||
}
|
||||
|
||||
Gather.prototype.confirmTeam = function (user) {
|
||||
this.modifyGatherer(user, function (gatherer) {
|
||||
if (!gatherer.leader) return gatherer
|
||||
gatherer.confirm = true;
|
||||
return gatherer;
|
||||
});
|
||||
};
|
||||
|
||||
Gather.prototype.alienLeader = function () {
|
||||
return this.gatherers.reduce(function (acc, gatherer) {
|
||||
if (gatherer.team === "alien" && gatherer.leader) acc.push(gatherer);
|
||||
|
@ -229,7 +221,6 @@ StateMachine.create({
|
|||
// Remove all leaders and teams
|
||||
this.gatherers.forEach(function (gatherer, index, array) {
|
||||
array[index].leader = false;
|
||||
array[index].confirm = false;
|
||||
array[index].team = "lobby";
|
||||
});
|
||||
|
||||
|
@ -254,10 +245,7 @@ StateMachine.create({
|
|||
this.assignMarineLeader(parseInt(rank.pop().candidate, 0));
|
||||
},
|
||||
onbeforeconfirmSelection: function (event, from, to, leader) {
|
||||
this.confirmTeam(leader);
|
||||
return (this.marineLeader().confirm
|
||||
&& this.alienLeader().confirm
|
||||
&& this.aliens().length === this.TEAM_SIZE
|
||||
return (this.aliens().length === this.TEAM_SIZE
|
||||
&& this.marines().length === this.TEAM_SIZE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,23 +39,6 @@ var VoteButton = React.createClass({
|
|||
}
|
||||
});
|
||||
|
||||
var JoinGatherButton = React.createClass({
|
||||
joinGather: function (e) {
|
||||
e.preventDefault();
|
||||
socket.emit("gather:join", {});
|
||||
},
|
||||
render: function () {
|
||||
var message = this.props.buttonName || "Join Gather";
|
||||
var buttonClass = "btn btn-success";
|
||||
if (this.props.buttonClass) {
|
||||
buttonClass += " " + this.props.buttonClass;
|
||||
}
|
||||
return (<button
|
||||
onClick={this.joinGather}
|
||||
className={buttonClass}>{message}</button>)
|
||||
}
|
||||
});
|
||||
|
||||
var SelectPlayerButton = React.createClass({
|
||||
selectPlayer: function (e) {
|
||||
e.preventDefault();
|
||||
|
@ -231,6 +214,10 @@ var GatherProgress = React.createClass({
|
|||
});
|
||||
|
||||
var GatherActions = React.createClass({
|
||||
joinGather: function (e) {
|
||||
e.preventDefault();
|
||||
socket.emit("gather:join");
|
||||
},
|
||||
leaveGather: function (e) {
|
||||
e.preventDefault();
|
||||
socket.emit("gather:leave");
|
||||
|
@ -241,6 +228,7 @@ var GatherActions = React.createClass({
|
|||
},
|
||||
inviteToGather: function (e) {
|
||||
e.preventDefault();
|
||||
alert("Boop!");
|
||||
},
|
||||
render: function () {
|
||||
var joinButton;
|
||||
|
@ -248,8 +236,12 @@ var GatherActions = React.createClass({
|
|||
joinButton = (<li><button
|
||||
onClick={this.leaveGather}
|
||||
className="btn btn-danger">Leave Gather</button></li>);
|
||||
} else {
|
||||
joinButton = (<li><JoinGatherButton /></li>);
|
||||
} else if (this.props.gather.state === 'gathering') {
|
||||
joinButton = (
|
||||
<button
|
||||
onClick={this.joinGather}
|
||||
className="btn btn-success">Join Gather</button>
|
||||
);
|
||||
}
|
||||
|
||||
var confirmTeam;
|
||||
|
@ -428,7 +420,7 @@ var Gather = React.createClass({
|
|||
|
||||
render: function () {
|
||||
if (this.props.gather.state === 'done') {
|
||||
return (<h1>Gather Completed! Now restart the app</h1>);
|
||||
return (<CompletedGather {...this.props} />);
|
||||
}
|
||||
|
||||
var voting;
|
||||
|
@ -459,8 +451,8 @@ var Gather = React.createClass({
|
|||
</div>
|
||||
<GatherProgress gather={this.props.gather} />
|
||||
<Gatherers gather={this.props.gather} currentGatherer={this.props.currentGatherer} />
|
||||
{voting}
|
||||
{gatherTeams}
|
||||
{voting}
|
||||
<GatherActions {...this.props} />
|
||||
</div>
|
||||
);
|
||||
|
@ -468,6 +460,10 @@ var Gather = React.createClass({
|
|||
});
|
||||
|
||||
var Gatherers = React.createClass({
|
||||
joinGather: function (e) {
|
||||
e.preventDefault();
|
||||
socket.emit("gather:join");
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
var gatherers = this.props.gather.gatherers.map(function (gatherer) {
|
||||
|
@ -529,12 +525,49 @@ var Gatherers = React.createClass({
|
|||
} else {
|
||||
return (
|
||||
<div className="panel-body text-center join-hero">
|
||||
<JoinGatherButton buttonClass="btn-lg" buttonName="Start a Gather" />
|
||||
<button
|
||||
onClick={this.joinGather}
|
||||
className="btn btn-success btn-lg">Start a Gather</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var CompletedGather = React.createClass({
|
||||
votedMaps: function () {
|
||||
var maps = this.props.maps;
|
||||
var mapVotes = this.props.gather.gatherers.map(function (gatherer) {
|
||||
return gatherer.mapVote;
|
||||
}).filter(function (elem) {
|
||||
return elem !== null;
|
||||
}).map(function (mapId) {
|
||||
var result;
|
||||
maps.forEach(function (map) {
|
||||
if (map.id === mapId) result = map;
|
||||
});
|
||||
return result;
|
||||
});
|
||||
},
|
||||
votedServer: function () {
|
||||
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
<div className="panel panel-default">
|
||||
<div className="panel-heading">
|
||||
<strong>Gather Completed</strong>
|
||||
</div>
|
||||
<div className="panel-body">
|
||||
<h3>Join Up:</h3>
|
||||
<p>{this.votedMaps()
|
||||
.map(function (map) {return map.name})
|
||||
.join(",")}</p>
|
||||
</div>
|
||||
<GatherTeams gather={this.props.gather} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -47,4 +47,5 @@ function initialiseComponents () {
|
|||
React.render(<Chatroom />, document.getElementById('chatroom'));
|
||||
React.render(<Gather />, document.getElementById('gathers'));
|
||||
React.render(<CurrentUser />, document.getElementById('currentuser'));
|
||||
React.render(<AdminPanel />, document.getElementById('admin-menu'));
|
||||
};
|
||||
|
|
|
@ -89,6 +89,28 @@ var UserMenu = React.createClass({
|
|||
}
|
||||
});
|
||||
|
||||
var AdminPanel = React.createClass({
|
||||
handleGatherReset: function () {
|
||||
socket.emit("gather:reset");
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
<ul className="nav" id="admin-menu">
|
||||
<li>
|
||||
<div className="admin-panel">
|
||||
<h5>Admin</h5>
|
||||
<button
|
||||
className="btn btn-danger"
|
||||
onClick={this.handleGatherReset}>
|
||||
Reset Gather</button>
|
||||
<p className="text-center"><small>Only responds for admins on staging.ensl.org</small></p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
var CurrentUser = React.createClass({
|
||||
componentDidMount: function () {
|
||||
var self = this;
|
||||
|
|
|
@ -21,6 +21,10 @@
|
|||
margin: 0px 10px;
|
||||
}
|
||||
|
||||
.admin-panel {
|
||||
margin: 10px 10px;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
|
|
100
public/js/app.js
100
public/js/app.js
|
@ -39,23 +39,6 @@ var VoteButton = React.createClass({displayName: "VoteButton",
|
|||
}
|
||||
});
|
||||
|
||||
var JoinGatherButton = React.createClass({displayName: "JoinGatherButton",
|
||||
joinGather: function (e) {
|
||||
e.preventDefault();
|
||||
socket.emit("gather:join", {});
|
||||
},
|
||||
render: function () {
|
||||
var message = this.props.buttonName || "Join Gather";
|
||||
var buttonClass = "btn btn-success";
|
||||
if (this.props.buttonClass) {
|
||||
buttonClass += " " + this.props.buttonClass;
|
||||
}
|
||||
return (React.createElement("button", {
|
||||
onClick: this.joinGather,
|
||||
className: buttonClass}, message))
|
||||
}
|
||||
});
|
||||
|
||||
var SelectPlayerButton = React.createClass({displayName: "SelectPlayerButton",
|
||||
selectPlayer: function (e) {
|
||||
e.preventDefault();
|
||||
|
@ -231,6 +214,10 @@ var GatherProgress = React.createClass({displayName: "GatherProgress",
|
|||
});
|
||||
|
||||
var GatherActions = React.createClass({displayName: "GatherActions",
|
||||
joinGather: function (e) {
|
||||
e.preventDefault();
|
||||
socket.emit("gather:join");
|
||||
},
|
||||
leaveGather: function (e) {
|
||||
e.preventDefault();
|
||||
socket.emit("gather:leave");
|
||||
|
@ -241,6 +228,7 @@ var GatherActions = React.createClass({displayName: "GatherActions",
|
|||
},
|
||||
inviteToGather: function (e) {
|
||||
e.preventDefault();
|
||||
alert("Boop!");
|
||||
},
|
||||
render: function () {
|
||||
var joinButton;
|
||||
|
@ -248,8 +236,12 @@ var GatherActions = React.createClass({displayName: "GatherActions",
|
|||
joinButton = (React.createElement("li", null, React.createElement("button", {
|
||||
onClick: this.leaveGather,
|
||||
className: "btn btn-danger"}, "Leave Gather")));
|
||||
} else {
|
||||
joinButton = (React.createElement("li", null, React.createElement(JoinGatherButton, null)));
|
||||
} else if (this.props.gather.state === 'gathering') {
|
||||
joinButton = (
|
||||
React.createElement("button", {
|
||||
onClick: this.joinGather,
|
||||
className: "btn btn-success"}, "Join Gather")
|
||||
);
|
||||
}
|
||||
|
||||
var confirmTeam;
|
||||
|
@ -428,7 +420,7 @@ var Gather = React.createClass({displayName: "Gather",
|
|||
|
||||
render: function () {
|
||||
if (this.props.gather.state === 'done') {
|
||||
return (React.createElement("h1", null, "Gather Completed! Now restart the app"));
|
||||
return (React.createElement(CompletedGather, React.__spread({}, this.props)));
|
||||
}
|
||||
|
||||
var voting;
|
||||
|
@ -459,8 +451,8 @@ var Gather = React.createClass({displayName: "Gather",
|
|||
),
|
||||
React.createElement(GatherProgress, {gather: this.props.gather}),
|
||||
React.createElement(Gatherers, {gather: this.props.gather, currentGatherer: this.props.currentGatherer}),
|
||||
voting,
|
||||
gatherTeams,
|
||||
voting,
|
||||
React.createElement(GatherActions, React.__spread({}, this.props))
|
||||
)
|
||||
);
|
||||
|
@ -468,6 +460,10 @@ var Gather = React.createClass({displayName: "Gather",
|
|||
});
|
||||
|
||||
var Gatherers = React.createClass({displayName: "Gatherers",
|
||||
joinGather: function (e) {
|
||||
e.preventDefault();
|
||||
socket.emit("gather:join");
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
var gatherers = this.props.gather.gatherers.map(function (gatherer) {
|
||||
|
@ -529,13 +525,50 @@ var Gatherers = React.createClass({displayName: "Gatherers",
|
|||
} else {
|
||||
return (
|
||||
React.createElement("div", {className: "panel-body text-center join-hero"},
|
||||
React.createElement(JoinGatherButton, {buttonClass: "btn-lg", buttonName: "Start a Gather"})
|
||||
React.createElement("button", {
|
||||
onClick: this.joinGather,
|
||||
className: "btn btn-success btn-lg"}, "Start a Gather")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var CompletedGather = React.createClass({displayName: "CompletedGather",
|
||||
votedMaps: function () {
|
||||
var maps = this.props.maps;
|
||||
var mapVotes = this.props.gather.gatherers.map(function (gatherer) {
|
||||
return gatherer.mapVote;
|
||||
}).filter(function (elem) {
|
||||
return elem !== null;
|
||||
}).map(function (mapId) {
|
||||
var result;
|
||||
maps.forEach(function (map) {
|
||||
if (map.id === mapId) result = map;
|
||||
});
|
||||
return result;
|
||||
});
|
||||
},
|
||||
votedServer: function () {
|
||||
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
React.createElement("div", {className: "panel panel-default"},
|
||||
React.createElement("div", {className: "panel-heading"},
|
||||
React.createElement("strong", null, "Gather Completed")
|
||||
),
|
||||
React.createElement("div", {className: "panel-body"},
|
||||
React.createElement("h3", null, "Join Up:"),
|
||||
React.createElement("p", null, this.votedMaps()
|
||||
.map(function (map) {return map.name})
|
||||
.join(","))
|
||||
),
|
||||
React.createElement(GatherTeams, {gather: this.props.gather})
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
@ -588,6 +621,7 @@ function initialiseComponents () {
|
|||
React.render(React.createElement(Chatroom, null), document.getElementById('chatroom'));
|
||||
React.render(React.createElement(Gather, null), document.getElementById('gathers'));
|
||||
React.render(React.createElement(CurrentUser, null), document.getElementById('currentuser'));
|
||||
React.render(React.createElement(AdminPanel, null), document.getElementById('admin-menu'));
|
||||
};
|
||||
|
||||
"use strict";
|
||||
|
@ -828,6 +862,28 @@ var UserMenu = React.createClass({displayName: "UserMenu",
|
|||
}
|
||||
});
|
||||
|
||||
var AdminPanel = React.createClass({displayName: "AdminPanel",
|
||||
handleGatherReset: function () {
|
||||
socket.emit("gather:reset");
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
React.createElement("ul", {className: "nav", id: "admin-menu"},
|
||||
React.createElement("li", null,
|
||||
React.createElement("div", {className: "admin-panel"},
|
||||
React.createElement("h5", null, "Admin"),
|
||||
React.createElement("button", {
|
||||
className: "btn btn-danger",
|
||||
onClick: this.handleGatherReset},
|
||||
"Reset Gather"),
|
||||
React.createElement("p", {className: "text-center"}, React.createElement("small", null, "Only responds for admins on staging.ensl.org"))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
var CurrentUser = React.createClass({displayName: "CurrentUser",
|
||||
componentDidMount: function () {
|
||||
var self = this;
|
||||
|
|
|
@ -123,21 +123,14 @@ describe("Gather Model:", function () {
|
|||
}
|
||||
});
|
||||
});
|
||||
it ("transitions to 'done' when players selected and leaders confirm", function () {
|
||||
assert.equal(gather.current, "selection");
|
||||
gather.confirmSelection(leaderA);
|
||||
assert.equal(gather.current, "selection");
|
||||
gather.confirmSelection(leaderB);
|
||||
it ("transitions to 'done' when players selected", function () {
|
||||
gather.confirmSelection();
|
||||
assert.equal(gather.current, "done");
|
||||
});
|
||||
it ("does not transition to 'done' unless all players selected", function () {
|
||||
var lobbyPlayer = gather.gatherers[11];
|
||||
gather.moveToLobby(lobbyPlayer);
|
||||
assert.equal(gather.current, "selection");
|
||||
gather.confirmSelection(leaderA);
|
||||
assert.equal(gather.current, "selection");
|
||||
gather.confirmSelection(leaderB);
|
||||
assert.equal(gather.current, "selection");
|
||||
});
|
||||
it ("transitions to picking if a player leaves", function () {
|
||||
var leaver = gather.gatherers[11];
|
||||
|
@ -388,33 +381,4 @@ describe("Gather Model:", function () {
|
|||
assert.equal(gatherer.serverVote, serverId);
|
||||
});
|
||||
});
|
||||
|
||||
describe("confirmTeam", function () {
|
||||
var leader;
|
||||
beforeEach(function () {
|
||||
gatherers.forEach(function (gatherer) {
|
||||
gather.addGatherer(gatherer);
|
||||
});
|
||||
leader = gather.gatherers[0];
|
||||
gather.assignMarineLeader(leader.id);
|
||||
});
|
||||
it ("marks leader as confirmed", function () {
|
||||
gather.confirmTeam(leader);
|
||||
gather.gatherers.forEach(function (gatherer) {
|
||||
if (gatherer.leader) {
|
||||
assert.isTrue(gatherer.confirm);
|
||||
} else {
|
||||
assert.isFalse(gatherer.confirm);
|
||||
}
|
||||
});
|
||||
});
|
||||
it ("does nothing if user is not leader", function () {
|
||||
var player = gather.gatherers[1];
|
||||
assert.isFalse(player.leader);
|
||||
gather.confirmTeam(player);
|
||||
gather.gatherers.forEach(function (gatherer) {
|
||||
assert.isFalse(gatherer.confirm);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -64,6 +64,7 @@
|
|||
<div class="navbar-default sidebar" role="navigation">
|
||||
<div class="sidebar-nav navbar-collapse">
|
||||
<ul class="nav" id="side-menu"></ul>
|
||||
<ul class="nav" id="admin-menu"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
Loading…
Reference in a new issue