"use strict";
var VoteButton = React.createClass({
cancelVote(e) {
socket.emit("gather:vote", {
leader: {
candidate: null
}
});
},
vote(e) {
e.preventDefault();
socket.emit("gather:vote", {
leader: {
candidate: parseInt(e.target.value, 10)
}
});
},
render() {
if (this.props.currentGatherer === null) {
return false;
}
if (this.props.currentGatherer.leaderVote === this.props.candidate.id) {
return (
Voted
);
} else {
return (
Vote
);
}
}
});
var SelectPlayerButton = React.createClass({
selectPlayer(e) {
e.preventDefault();
socket.emit("gather:select", {
player: parseInt(e.target.value, 10)
})
},
render() {
if (this.props.gatherer.leader) {
return (Leader );
} else if (this.props.gatherer.team !== "lobby") {
return ( Reselect
);
} else {
return ( Select
);
}
}
});
var GathererList = React.createClass({
memberList() {
var self = this;
return this.props.gather.gatherers
.filter(gatherer => gatherer.team === self.props.team )
.sort(gatherer => gatherer.leader ? 1 : -1);
},
render() {
var extractGatherer = gatherer => {
var image;
if (gatherer.leader) {
image = ( );
}
return (
{image}
{gatherer.user.username}
);
}
var members = this.memberList().map(extractGatherer);
return (
);
}
});
var GatherTeams = React.createClass({
render() {
return (
);
}
});
var ElectionProgressBar = React.createClass({
componentDidMount() {
var self = this;
this.timer = setInterval(() => {
self.forceUpdate();
}, 900);
},
progress() {
var interval = this.props.gather.election.interval;
var startTime = (new Date(this.props.gather.election.startTime)).getTime();
var msTranspired = Math.floor((new Date()).getTime() - startTime);
return {
num: msTranspired,
den: interval,
barMessage: Math.floor((interval - msTranspired) / 1000) + "s remaining"
}
},
componentWillUnmount() {
clearInterval(this.timer);
},
render() {
return ( );
}
});
var ProgressBar = React.createClass({
render() {
var style = {
width: Math.round((this.props.progress.num / this.props.progress.den * 100)) + "%"
};
var barMessage = this.props.progress.barMessage || "";
return (
);
}
});
var GatherProgress = React.createClass({
stateDescription() {
switch(this.props.gather.state) {
case "gathering":
return "Waiting for more gatherers.";
case "election":
return "Currently voting for team leaders.";
case "selection":
return "Waiting for leaders to pick teams.";
case "done":
return "Gather completed.";
default:
return "Initialising gather.";
}
},
gatheringProgress() {
var num = this.props.gather.gatherers.length;
var den = 12;
var remaining = den - num;
var message = (remaining === 1) ? "Waiting for last player" : "Waiting for " + remaining + " more players";
return {
num: num,
den: den,
message: message
};
},
electionProgress() {
var num = this.props.gather.gatherers.reduce((acc, gatherer) => {
if (gatherer.leaderVote) acc++;
return acc;
}, 0);
var den = 12;
return {
num: num,
den: den,
message: den - num + " more votes required"
};
},
selectionProgress() {
var num = this.props.gather.gatherers.reduce((acc, gatherer) => {
if (gatherer.team !== "lobby") acc++;
return acc;
}, 0);
var den = 12;
return {
num: num,
den: den,
message: num + " out of " + den + " players assigned"
};
},
render() {
var progress, progressBar;
var gatherState = this.props.gather.state;
if (gatherState === 'gathering' && this.props.gather.gatherers.length) {
progress = this.gatheringProgress();
progressBar = ( );
} else if (gatherState === 'election') {
progress = this.electionProgress();
progressBar = ( );
} else if (gatherState === 'selection') {
progress = this.selectionProgress();
progressBar = ( );
}
if (!progress) return false;
return (
{this.stateDescription()} {progress.message}
{progressBar}
);
}
});
var GatherActions = React.createClass({
joinGather(e) {
e.preventDefault();
socket.emit("gather:join");
},
leaveGather(e) {
e.preventDefault();
socket.emit("gather:leave");
},
confirmTeam(e) {
e.preventDefault();
socket.emit("gather:select:confirm");
},
inviteToGather(e) {
e.preventDefault();
alert("Boop!");
},
render() {
var joinButton;
if (this.props.currentGatherer) {
joinButton = (Leave Gather );
} else if (this.props.gather.state === 'gathering') {
joinButton = (
Join Gather
);
}
var confirmTeam;
if (this.props.currentGatherer &&
this.props.currentGatherer.leader &&
this.props.gather.state === 'selection' &&
this.props.gather.gatherers.every(gatherer => gatherer.team !== 'lobby')) {
if (this.props.currentGatherer.confirm) {
confirmTeam = (
Confirmed
);
} else {
confirmTeam = (
Confirm Team
);
}
}
var inviteButton;
if (this.props.gather.state === 'gathering') {
inviteButton = (Invite to Gather );
}
return (
{confirmTeam}
{inviteButton}
{joinButton}
);
}
});
var ServerVoting = React.createClass({
handleServerVote(e) {
e.preventDefault();
socket.emit("gather:vote", {
server: {
id: parseInt(e.target.value, 10)
}
});
},
votesForServer(server) {
return this.props.gather.gatherers.reduce((acc, gatherer) => {
if (server.id === gatherer.serverVote) acc++;
return acc;
}, 0);
},
render() {
var self = this;
var servers = self.props.servers.map(server => {
var voteButton;
if (self.props.currentGatherer.serverVote === server.id) {
voteButton = (
Voted )
} else {
voteButton = (
Vote );
}
return (
{server.description || server.dns}
{self.votesForServer(server)} Votes
{voteButton}
);
});
return (
);
}
})
var MapVoting = React.createClass({
handleMapVote(e) {
e.preventDefault();
socket.emit("gather:vote", {
map: {
id: parseInt(e.target.value, 10)
}
});
},
votesForMap(map) {
return this.props.gather.gatherers.reduce((acc, gatherer) => {
if (map.id === gatherer.mapVote) acc++;
return acc;
}, 0);
},
render() {
var self = this;
var maps = self.props.maps.map(map => {
var voteButton;
if (self.props.currentGatherer.mapVote === map.id) {
voteButton = (
Voted )
} else {
voteButton = (
Vote );
}
return (
{map.name}
{self.votesForMap(map)} Votes
{voteButton}
);
});
return (
);
}
})
var Gather = React.createClass({
getDefaultProps() {
return {
gather: {
gatherers: []
}
}
},
componentDidMount() {
var self = this;
socket.on("gather:refresh", data => self.setProps(data));
},
render() {
if (this.props.gather.state === 'done') {
return ( );
}
var voting;
if (this.props.currentGatherer) {
voting = (
);
}
var gatherTeams;
if (this.props.gather.state === 'selection') {
gatherTeams =
}
var previousGather;
if (this.props.previousGather) {
previousGather = ( );
}
return (
Current Gather
{this.props.gather.gatherers.length}
{gatherTeams}
{voting}
{previousGather}
);
}
});
var Gatherers = React.createClass({
joinGather(e) {
e.preventDefault();
socket.emit("gather:join");
},
render() {
var self = this;
var gatherers = this.props.gather.gatherers.map(gatherer => {
// Country
var country;
if (gatherer.user.country) {
country = ( );
};
var division = ({gatherer.user.ability.division} );
var lifeform = (
gatherer.user.ability.lifeforms.map(lifeform => {
return ({lifeform} );
})
);
var team;
if (gatherer.user.team) {
team = ({gatherer.user.team.name} );
}
var action;
if (self.props.gather.state === "election") {
var votes = self.props.gather.gatherers.reduce((acc, voter) => {
if (voter.leaderVote === gatherer.id) acc++;
return acc;
}, 0)
action = (
{votes + " votes"}
);
}
if (self.props.gather.state === 'selection') {
if (self.props.currentGatherer && self.props.currentGatherer.leader) {
action = (
);
} else {
if (gatherer.team !== "lobby") {
action = ({gatherer.team} );
}
}
}
return (
{country} {gatherer.user.username} ({gatherer.user.id})
{lifeform} {division} {team}
{action}
);
})
if (this.props.gather.gatherers.length) {
return (
);
} else {
return (
Start a Gather
);
}
}
});
var CompletedGather = React.createClass({
countVotes(voteType) {
return this.props.gather.gatherers.reduce((acc, gatherer) => {
if (gatherer[voteType] !== null) acc.push(gatherer[voteType]);
return acc;
}, []);
},
selectedMaps() {
return rankVotes(this.countVotes('mapVote'), this.props.maps).slice(0, 2)
},
selectedServer() {
return rankVotes(this.countVotes('serverVote'), this.props.servers).slice(0, 1);
},
render() {
var maps = this.selectedMaps();
var server = this.selectedServer().pop();
return (
Previous Gather
Maps
{maps.map(map => map.name).join(" & ")}
Server
{server.name}
Address
{server.ip}:{server.port}
Password
{server.password}
Click to Join
);
}
});