);
}
});
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() {
let progress = this.props.progress;
var style = {
width: Math.round((progress.num / progress.den * 100)) + "%"
};
var barMessage = progress.barMessage || "";
return (
{barMessage}
);
}
});
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. Waiting
on ${_.capitalize(this.props.gather.pickingTurn)}s to pick next...`
};
},
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 (
{votes === 2 ? "Server Votes" :
`Please Vote for a Server. ${2 - votes} votes remaining` }
{servers}
);
}
})
var MapVoting = React.createClass({
voteHandler(mapId) {
return function (e) {
e.preventDefault();
socket.emit("gather:vote", {
map: {
id: mapId
}
});
}
},
votesForMap(map) {
return this.props.gather.gatherers.reduce((acc, gatherer) => {
if (gatherer.mapVote.some(voteId => voteId === map.id)) acc++;
return acc;
}, 0);
},
render() {
var self = this;
let thisGatherer = self.props.thisGatherer
let maps = self.props.maps.sort((a, b) => {
var aVotes = self.votesForMap(a);
var bVotes = self.votesForMap(b);
return bVotes - aVotes;
}).map(map => {
let votes = self.votesForMap(map);
if (thisGatherer.mapVote.some(voteId => voteId === map.id)) {
return (
e.preventDefault() }
className="list-group-item list-group-item-success">
{votes}
{map.name}
);
} else {
return (
{votes}
{map.name}
);
}
});
let votes = thisGatherer.mapVote.length;
return (
{votes === 2 ? "Map Votes" :
`Please Vote for a Map. ${2 - votes} votes remaining` }
{maps}
);
}
})
var Gather = React.createClass({
render() {
let gather = this.props.gather;
let thisGatherer = this.props.thisGatherer;
let servers = this.props.servers;
let maps = this.props.maps;
let user = this.props.user;
if (gather === null) return ;
let voting;
if (thisGatherer) {
let state = gather.state;
if (state === 'gathering' || state === 'election') {
voting = (
);
} else {
voting = ;
}
}
let gatherTeams;
if (gather.state === 'selection') {
gatherTeams = ;
}
if (gather.gatherers.length > 0) {
return (
Current Gather
{gatherTeams}
{voting}
);
} else {
return (
Current Gather
);
}
}
});
var LifeformIcons = React.createClass({
availableLifeforms() {
return ["skulk", "gorge", "lerk", "fade", "onos", "commander"];
},
gathererLifeforms() {
let lifeforms = [];
let gatherer = this.props.gatherer;
let abilities = gatherer.user.profile.abilities;
for (let attr in abilities) {
if (abilities[attr]) lifeforms.push(_.capitalize(attr));
}
return lifeforms;
},
render() {
let lifeforms = this.gathererLifeforms();
let availableLifeforms = this.availableLifeforms();
let icons = availableLifeforms.map(lifeform => {
let containsAbility = lifeforms.some(gathererLifeform => {
return gathererLifeform.toLowerCase() === lifeform.toLowerCase()
});
if (containsAbility) {
return
} else {
return
}
});
return {icons}
}
});
var Gatherers = React.createClass({
joinGather(e) {
e.preventDefault();
socket.emit("gather:join");
},
bootGatherer(e) {
e.preventDefault();
socket.emit("gather:leave", {
gatherer: parseInt(e.target.value, 10) || null
});
},
render() {
let self = this;
let user = this.props.user;
let gather = this.props.gather;
let admin = (user && user.admin) || (user && user.moderator);
let thisGatherer = this.props.thisGatherer;
let gatherers = gather.gatherers
.sort((a, b) => {
return (b.user.hive.skill || 1000) - (a.user.hive.skill || 1000);
})
.map(gatherer => {
if (gatherer.user.country) {
var country = (
);
};
let skill = gatherer.user.profile.skill || "Not Available";
let hiveStats = [];
if (gatherer.user.hive.skill) hiveStats.push(`${gatherer.user.hive.skill} ELO`);
if (gatherer.user.hive.playTime) {
hiveStats.push(`${Math.floor(gatherer.user.hive.playTime / 3600)} Hours`);
}
let hive = (hiveStats.length) ? hiveStats.join(", ") : "Not Available";
let team = (gatherer.user.team) ? gatherer.user.team.name : "None";
let action;
if (gather.state === "election") {
let votes = gather.gatherers.reduce((acc, voter) => {
if (voter.leaderVote === gatherer.id) acc++;
return acc;
}, 0)
action = (
{votes + " votes"}
);
}
if (gather.state === 'selection') {
if (thisGatherer &&
thisGatherer.leader &&
thisGatherer.team === gather.pickingTurn) {
action = (
);
} else {
if (gatherer.leader) {
action = (Leader);
} else if (gatherer.team !== "lobby") {
action = ({_.capitalize(gatherer.team)});
} else {
action = (
Lobby);
}
}
}
let adminOptions;
if (admin) {
adminOptions = [
,
);
}
}
});
var CompletedGather = React.createClass({
completionDate() {
let d = new Date(this.props.gather.done.time);
if (d) {
return d.toLocaleTimeString();
} else {
return "Completed Gather"
}
},
getInitialState() {
return {
show: !!this.props.show
};
},
toggleGatherInfo() {
let newState = !this.state.show;
this.setState({
show: newState
});
},
render() {
let gatherInfo = [];
let gather = this.props.gather;
let maps = this.props.maps;
let servers = this.props.servers;
if (this.state.show) {
gatherInfo.push();
gatherInfo.push();
}
return (
{this.completionDate()}
{gatherInfo}
);
}
});
var GatherVotingResults = React.createClass({
// Returns an array of ids voted for e.g. [1,2,5,1,1,3,2]
countVotes(voteType) {
return this.props.gather.gatherers.reduce((acc, gatherer) => {
let votes = gatherer[voteType];
// Temporary fix because some mapvotes are ints and not arrays
if (!Array.isArray(votes)) votes = [votes];
if (votes.length > 0) votes.forEach(vote => acc.push(vote));
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() {
let maps = this.selectedMaps();
let server = this.selectedServer().pop();
let password;
if (server.password) {
password = [