ensl_gathers/app/javascripts/components/gather.js

1006 lines
24 KiB
JavaScript
Raw Normal View History

2016-01-26 10:44:34 +00:00
import {AssumeUserIdButton} from "javascripts/components/user";
2016-01-22 10:12:23 +00:00
const React = require("react");
2016-01-22 21:39:03 +00:00
const helper = require("javascripts/helper");
const enslUrl = helper.enslUrl;
2016-02-12 23:22:46 +00:00
const rankVotes = helper.rankVotes;
2016-01-22 21:39:03 +00:00
const hiveUrl = helper.hiveUrl;
2015-07-28 15:54:29 +00:00
2016-01-26 10:44:34 +00:00
const SelectPlayerButton = React.createClass({
propTypes: {
socket: React.PropTypes.object.isRequired,
gatherer: React.PropTypes.object.isRequired
},
2015-08-11 00:19:04 +00:00
selectPlayer(e) {
2015-07-28 15:54:29 +00:00
e.preventDefault();
2016-01-26 10:44:34 +00:00
this.props.socket.emit("gather:select", {
2015-07-28 23:32:50 +00:00
player: parseInt(e.target.value, 10)
2016-01-26 10:44:34 +00:00
});
2015-07-28 15:54:29 +00:00
},
2015-08-11 00:19:04 +00:00
render() {
2015-09-16 15:16:00 +00:00
let button;
2015-07-28 23:32:50 +00:00
if (this.props.gatherer.leader) {
2015-09-16 15:16:00 +00:00
button = <button
2015-09-20 14:47:43 +00:00
className="btn btn-xs btn-default team-label"
2015-09-16 15:16:00 +00:00
data-disabled="true">Leader</button>;
2015-08-08 17:13:17 +00:00
} else if (this.props.gatherer.team !== "lobby") {
2015-09-16 15:16:00 +00:00
button = <button
data-disabled="true"
2015-10-02 14:53:11 +00:00
className="btn btn-xs btn-default team-label">
{_.capitalize(this.props.gatherer.team)}
2015-09-16 15:16:00 +00:00
</button>;
2015-07-28 15:54:29 +00:00
} else {
2015-09-16 15:16:00 +00:00
button = <button
2015-07-28 15:54:29 +00:00
onClick={this.selectPlayer}
2015-07-28 23:32:50 +00:00
value={this.props.gatherer.id}
2015-09-20 14:47:43 +00:00
className="btn btn-xs btn-primary team-label"> Select
2015-09-16 15:16:00 +00:00
</button>;
2015-07-28 15:54:29 +00:00
}
2015-09-16 15:16:00 +00:00
return button;
2015-07-28 15:54:29 +00:00
}
2015-07-28 23:32:50 +00:00
});
2015-07-28 15:54:29 +00:00
2016-01-26 10:44:34 +00:00
const GathererList = React.createClass({
2015-08-11 00:19:04 +00:00
memberList() {
2016-01-26 10:44:34 +00:00
const self = this;
2015-08-11 00:19:04 +00:00
return this.props.gather.gatherers
.filter(gatherer => gatherer.team === self.props.team)
.sort(gatherer => { return gatherer.leader ? 1 : -1 });
2015-07-28 15:54:29 +00:00
},
2015-08-11 00:19:04 +00:00
render() {
2016-01-26 10:44:34 +00:00
const extractGatherer = gatherer => {
let image;
2015-07-28 15:54:29 +00:00
if (gatherer.leader) {
image = <i className="fa fa-star add-right"></i>;
2015-07-28 15:54:29 +00:00
}
return (
<tr key={gatherer.id}>
<td className="col-md-12">
{image}{gatherer.user.username}
<span className="pull-right">
<LifeformIcons gatherer={gatherer} />
</span>
</td>
2015-07-28 15:54:29 +00:00
</tr>
);
2016-01-26 10:44:34 +00:00
};
const members = this.memberList()
2015-09-17 11:33:28 +00:00
.map(extractGatherer);
2015-08-08 19:14:16 +00:00
return (
<table className="table">
<tbody>
{members}
</tbody>
</table>
);
}
});
2016-01-26 10:44:34 +00:00
const GatherTeams = React.createClass({
2015-08-11 00:19:04 +00:00
render() {
2015-07-28 15:54:29 +00:00
return (
2015-09-05 17:22:23 +00:00
<div className="row add-top">
2015-09-16 15:16:00 +00:00
<div className="col-sm-6">
<div className="panel panel-primary panel-light-background">
2015-09-05 17:22:23 +00:00
<div className="panel-heading">
2015-09-17 11:47:37 +00:00
Marines
2015-07-28 15:54:29 +00:00
</div>
2015-09-17 11:47:37 +00:00
<GathererList gather={this.props.gather} team="marine" />
2015-07-28 15:54:29 +00:00
</div>
2015-09-05 17:22:23 +00:00
</div>
2015-09-16 15:16:00 +00:00
<div className="col-sm-6">
<div className="panel panel-primary panel-light-background">
2015-09-05 17:22:23 +00:00
<div className="panel-heading">
2015-09-17 11:47:37 +00:00
Aliens
2015-07-28 15:54:29 +00:00
</div>
2015-09-17 11:47:37 +00:00
<GathererList gather={this.props.gather} team="alien" />
2015-07-28 15:54:29 +00:00
</div>
</div>
</div>
);
}
2015-08-08 19:14:16 +00:00
});
2015-07-28 15:54:29 +00:00
2016-01-26 10:44:34 +00:00
const ElectionProgressBar = React.createClass({
2015-08-11 00:19:04 +00:00
componentDidMount() {
2016-01-26 10:44:34 +00:00
const self = this;
2015-08-11 00:19:04 +00:00
this.timer = setInterval(() => {
2015-07-31 15:54:08 +00:00
self.forceUpdate();
}, 900);
},
2015-08-11 00:19:04 +00:00
progress() {
2016-01-26 10:44:34 +00:00
const interval = this.props.gather.election.interval;
const startTime = (new Date(this.props.gather.election.startTime)).getTime();
const msTranspired = Math.floor((new Date()).getTime() - startTime);
2015-07-31 15:54:08 +00:00
return {
num: msTranspired,
den: interval,
barMessage: Math.floor((interval - msTranspired) / 1000) + "s remaining"
2015-07-31 15:54:08 +00:00
}
},
2015-08-11 00:19:04 +00:00
componentWillUnmount() {
2015-07-31 15:54:08 +00:00
clearInterval(this.timer);
},
2015-08-11 00:19:04 +00:00
render() {
2015-07-31 15:54:08 +00:00
return (<ProgressBar progress={this.progress()} />);
}
});
2016-01-26 10:44:34 +00:00
const ProgressBar = React.createClass({
2015-08-11 00:19:04 +00:00
render() {
2016-01-26 10:44:34 +00:00
const progress = this.props.progress;
const style = {
2015-10-02 14:53:11 +00:00
width: Math.round((progress.num / progress.den * 100)) + "%"
2015-07-31 15:54:08 +00:00
};
2016-01-26 10:44:34 +00:00
const barMessage = progress.barMessage || "";
2015-07-31 15:54:08 +00:00
return (
<div className="progress">
2015-09-05 17:22:23 +00:00
<div className="progress-bar progress-bar-striped active"
data-role="progressbar"
2015-10-02 14:53:11 +00:00
data-aria-valuenow={progress.num}
2015-09-05 17:22:23 +00:00
data-aria-valuemin="0"
2015-10-02 14:53:11 +00:00
data-aria-valuemax={progress.den}
2015-09-05 17:22:23 +00:00
style={style}>{barMessage}
</div>
</div>
2015-07-31 15:54:08 +00:00
);
}
});
2016-01-26 10:44:34 +00:00
const GatherProgress = React.createClass({
2015-08-11 00:19:04 +00:00
stateDescription() {
2015-07-28 15:54:29 +00:00
switch(this.props.gather.state) {
case "gathering":
return "Waiting for more gatherers.";
case "election":
return "Currently voting for team leaders.";
case "selection":
2015-07-31 16:34:27 +00:00
return "Waiting for leaders to pick teams.";
2015-07-28 15:54:29 +00:00
case "done":
return "Gather completed.";
default:
return "Initialising gather.";
}
},
2015-08-11 00:19:04 +00:00
gatheringProgress() {
2016-01-26 10:44:34 +00:00
const num = this.props.gather.gatherers.length;
const den = 12;
const remaining = den - num;
const message = (remaining === 1) ?
2015-10-02 14:53:11 +00:00
"Waiting for last player" : `Waiting for ${remaining} more players`;
2015-07-28 15:54:29 +00:00
return {
num: num,
den: den,
message: message
};
},
2015-08-11 00:19:04 +00:00
electionProgress() {
2016-01-26 10:44:34 +00:00
const num = this.props.gather.gatherers.reduce((acc, gatherer) => {
2015-07-28 15:54:29 +00:00
if (gatherer.leaderVote) acc++;
return acc;
}, 0);
2016-01-26 10:44:34 +00:00
const den = 12;
2015-07-28 15:54:29 +00:00
return {
num: num,
den: den,
message: den - num + " more votes required"
};
},
2015-08-11 00:19:04 +00:00
selectionProgress() {
2016-01-26 10:44:34 +00:00
const num = this.props.gather.gatherers.reduce((acc, gatherer) => {
2015-07-28 15:54:29 +00:00
if (gatherer.team !== "lobby") acc++;
return acc;
}, 0);
2016-01-26 10:44:34 +00:00
const den = 12;
2015-07-28 15:54:29 +00:00
return {
num: num,
den: den,
2015-09-16 15:16:00 +00:00
message: `${num} out of ${den} players assigned. Waiting
on ${_.capitalize(this.props.gather.pickingTurn)}s to pick next...`
2015-07-28 15:54:29 +00:00
};
},
2015-08-11 00:19:04 +00:00
render() {
2016-01-26 10:44:34 +00:00
let progress, progressBar;
const gatherState = this.props.gather.state;
2015-07-28 15:54:29 +00:00
if (gatherState === 'gathering' && this.props.gather.gatherers.length) {
progress = this.gatheringProgress();
2015-07-31 15:54:08 +00:00
progressBar = (<ProgressBar progress={progress} />);
2015-07-28 15:54:29 +00:00
} else if (gatherState === 'election') {
progress = this.electionProgress();
2015-07-31 15:54:08 +00:00
progressBar = (<ElectionProgressBar {...this.props} progress={progress} />);
2015-07-28 15:54:29 +00:00
} else if (gatherState === 'selection') {
progress = this.selectionProgress();
2015-07-31 15:54:08 +00:00
progressBar = (<ProgressBar progress={progress} />);
2015-07-28 15:54:29 +00:00
}
2015-07-31 15:54:08 +00:00
if (!progress) return false;
return (
2015-09-05 17:22:23 +00:00
<div className="no-bottom">
2015-07-31 15:54:08 +00:00
<p><strong>{this.stateDescription()}</strong> {progress.message}</p>
{progressBar}
</div>
);
2015-07-28 15:54:29 +00:00
}
});
2016-01-26 10:44:34 +00:00
const JoinGatherButton = React.createClass({
propTypes: {
thisGatherer: React.PropTypes.object,
user: React.PropTypes.object.isRequired,
socket: React.PropTypes.object.isRequired,
gather: React.PropTypes.object.isRequired
2015-10-20 16:36:21 +00:00
},
2015-08-27 11:57:35 +00:00
2015-09-28 13:30:13 +00:00
componentDidMount() {
2016-01-26 10:44:34 +00:00
const self = this;
2015-09-28 13:30:13 +00:00
this.timer = setInterval(() => {
self.forceUpdate();
}, 30000);
},
componentWillUnmount() {
clearInterval(this.timer);
},
2015-08-11 00:19:04 +00:00
joinGather(e) {
2015-07-29 14:35:58 +00:00
e.preventDefault();
2016-01-26 10:44:34 +00:00
this.props.socket.emit("gather:join");
2015-07-29 14:35:58 +00:00
},
2015-08-11 00:19:04 +00:00
leaveGather(e) {
2015-07-28 15:54:29 +00:00
e.preventDefault();
2016-01-26 10:44:34 +00:00
this.props.socket.emit("gather:leave");
2015-07-28 23:32:50 +00:00
},
2015-08-11 00:19:04 +00:00
2015-09-28 13:30:13 +00:00
cooldownTime() {
let user = this.props.user;
if (!user) return false;
let cooloffTime = this.props.gather.cooldown[user.id];
if (!cooloffTime) return false;
let timeRemaining = new Date(cooloffTime) - new Date();
return timeRemaining > 0 ? timeRemaining : false;
},
render() {
2015-10-02 14:53:11 +00:00
let gather = this.props.gather;
let thisGatherer = this.props.thisGatherer;
if (thisGatherer) {
2015-09-28 13:30:13 +00:00
return <button
onClick={this.leaveGather}
className="btn btn-danger">Leave Gather</button>;
}
2015-10-02 14:53:11 +00:00
if (gather.state === 'gathering') {
2015-09-28 13:30:13 +00:00
let cooldownTime = this.cooldownTime();
if (cooldownTime) {
return <CooloffButton timeRemaining={cooldownTime} />;
} else {
return <button
onClick={this.joinGather}
className="btn btn-success">Join Gather</button>;
}
}
return false;
}
});
2016-01-26 10:44:34 +00:00
const CooloffButton = React.createClass({
propTypes: {
timeRemaining: React.PropTypes.number.isRequired
},
2015-09-28 13:30:13 +00:00
timeRemaining() {
return `${Math.floor(this.props.timeRemaining / 60000) + 1} minutes remaining`;
},
render() {
return <button
disabled="true"
className="btn btn-success">
Leaver Cooloff ({this.timeRemaining()})
</button>
}
})
2016-01-26 10:44:34 +00:00
const GatherActions = React.createClass({
propTypes: {
socket: React.PropTypes.object.isRequired,
gather: React.PropTypes.object.isRequired,
thisGatherer: React.PropTypes.object
},
2015-09-17 13:56:50 +00:00
voteRegather(e) {
e.preventDefault(e);
2016-01-26 10:44:34 +00:00
this.props.socket.emit("gather:vote", {
2015-09-17 13:56:50 +00:00
regather: (e.target.value === "true")
});
},
regatherVotes() {
2015-10-02 14:53:11 +00:00
let gather = this.props.gather;
if (!gather) return 0;
return gather.gatherers.reduce((acc, gatherer) => {
2015-09-17 13:56:50 +00:00
if (gatherer.regatherVote) acc++;
return acc;
}, 0);
2015-07-28 15:54:29 +00:00
},
2015-08-11 00:19:04 +00:00
render() {
2015-09-28 13:30:13 +00:00
let regatherButton;
2016-01-26 10:44:34 +00:00
const user = this.props.user;
const gather = this.props.gather;
const socket = this.props.socket;
const thisGatherer = this.props.thisGatherer;
2015-10-02 14:53:11 +00:00
if (thisGatherer) {
2015-09-17 13:56:50 +00:00
let regatherVotes = this.regatherVotes();
2015-10-02 14:53:11 +00:00
if (thisGatherer.regatherVote) {
regatherButton = <button value="false" onClick={this.voteRegather}
className="btn btn-danger">
{`Voted Regather (${regatherVotes}/8)`}
</button>;
2015-07-28 23:32:50 +00:00
} else {
2015-10-02 14:53:11 +00:00
regatherButton = <button value="true" onClick={this.voteRegather}
className="btn btn-danger">
{`Vote Regather (${regatherVotes}/8)`}
</button>;
2015-07-28 23:32:50 +00:00
}
}
return (
2015-10-20 16:36:21 +00:00
<div>
<div className="text-right">
<ul className="list-inline no-bottom">
<li>
{regatherButton}
</li>
<li>
<JoinGatherButton gather={gather} thisGatherer={thisGatherer}
2016-01-26 10:44:34 +00:00
user={user} socket={socket} />
2015-10-20 16:36:21 +00:00
</li>
</ul>
2015-09-14 22:14:36 +00:00
</div>
2015-07-28 23:32:50 +00:00
</div>
);
}
});
2016-01-26 10:44:34 +00:00
const VoteButton = React.createClass({
propTypes: {
socket: React.PropTypes.object.isRequired,
candidate: React.PropTypes.object.isRequired,
thisGatherer: React.PropTypes.object
},
2015-08-27 14:53:11 +00:00
cancelVote(e) {
2016-01-26 10:44:34 +00:00
this.props.socket.emit("gather:vote", {
2015-08-27 14:53:11 +00:00
leader: {
candidate: null
}
});
},
vote(e) {
2015-07-29 13:50:39 +00:00
e.preventDefault();
2016-01-26 10:44:34 +00:00
this.props.socket.emit("gather:vote", {
2015-08-27 14:53:11 +00:00
leader: {
candidate: parseInt(e.target.value, 10)
2015-07-29 13:50:39 +00:00
}
});
},
2015-08-11 00:19:04 +00:00
stopGatherMusic() {
soundController.stop();
},
2015-08-27 14:53:11 +00:00
render() {
2015-10-02 14:53:11 +00:00
let candidate = this.props.candidate;
let thisGatherer = this.props.thisGatherer;
if (thisGatherer === null) {
2015-08-27 14:53:11 +00:00
return false;
}
2015-10-02 14:53:11 +00:00
if (thisGatherer.leaderVote === candidate.id) {
2015-08-27 14:53:11 +00:00
return (
<button
onClick={this.cancelVote}
2015-09-20 13:50:59 +00:00
className="btn btn-xs btn-success vote-button">Voted
2015-08-27 14:53:11 +00:00
</button>
);
} else {
return (
<button
onClick={this.vote}
2015-09-20 13:50:59 +00:00
className="btn btn-xs btn-primary vote-button"
2015-10-02 14:53:11 +00:00
value={candidate.id}>Vote
2015-08-27 14:53:11 +00:00
</button>
);
}
}
});
2016-01-26 10:44:34 +00:00
const ServerVoting = React.createClass({
propTypes: {
socket: React.PropTypes.object.isRequired,
gather: React.PropTypes.object.isRequired,
thisGatherer: React.PropTypes.object,
servers: React.PropTypes.array.isRequired,
},
2015-08-27 14:53:11 +00:00
voteHandler(serverId) {
2016-01-26 10:44:34 +00:00
return e => {
2015-08-27 14:53:11 +00:00
e.preventDefault();
2016-01-26 10:44:34 +00:00
this.props.socket.emit("gather:vote", {
2015-08-27 14:53:11 +00:00
server: {
id: serverId
}
});
}
},
2015-08-11 00:19:04 +00:00
votesForServer(server) {
return this.props.gather.gatherers.reduce((acc, gatherer) => {
if (gatherer.serverVote.some(voteId => voteId === server.id)) acc++;
2015-07-29 13:50:39 +00:00
return acc;
}, 0);
},
2015-08-11 00:19:04 +00:00
render() {
2015-10-02 14:53:11 +00:00
let self = this;
let thisGatherer = self.props.thisGatherer;
let servers = self.props.servers.sort((a, b) => {
2016-01-26 10:44:34 +00:00
const aVotes = self.votesForServer(a);
const bVotes = self.votesForServer(b);
2015-10-02 14:53:11 +00:00
return bVotes - aVotes;
}).map(server => {
2015-08-27 14:53:11 +00:00
let votes = self.votesForServer(server);
let style = thisGatherer.serverVote.some(voteId => voteId === server.id) ?
2016-02-18 14:59:42 +00:00
"list-group-item list-group-item-default" : "list-group-item";
return (
<a href="#"
className={style}
2015-12-25 08:03:06 +00:00
onClick={self.voteHandler(server.id)}
key={server.id}>
<span className="badge">{votes}</span>
{server.name || server.description}
</a>
);
2015-07-29 13:50:39 +00:00
});
2015-08-27 14:53:11 +00:00
let votes = thisGatherer.serverVote.length;
2015-08-27 14:53:11 +00:00
2015-07-29 13:50:39 +00:00
return (
2015-09-21 20:15:27 +00:00
<div className="panel panel-primary">
2015-07-29 13:50:39 +00:00
<div className="panel-heading">
{votes === 2 ? "Server Votes" :
`Please Vote for a Server. ${2 - votes} votes remaining` }
2015-07-29 13:50:39 +00:00
</div>
2015-08-27 14:53:11 +00:00
<div className="list-group gather-voting">
2015-07-29 13:50:39 +00:00
{servers}
2015-08-27 14:53:11 +00:00
</div>
2015-07-29 13:50:39 +00:00
</div>
);
}
})
2016-01-26 10:44:34 +00:00
const MapVoting = React.createClass({
propTypes: {
socket: React.PropTypes.object.isRequired,
gather: React.PropTypes.object.isRequired,
thisGatherer: React.PropTypes.object,
maps: React.PropTypes.array.isRequired,
},
2015-08-27 14:53:11 +00:00
voteHandler(mapId) {
2016-01-26 10:44:34 +00:00
return e => {
2015-08-27 14:53:11 +00:00
e.preventDefault();
2016-01-26 10:44:34 +00:00
this.props.socket.emit("gather:vote", {
2015-08-27 14:53:11 +00:00
map: {
id: mapId
}
});
}
2015-07-29 13:50:39 +00:00
},
2015-08-11 00:19:04 +00:00
votesForMap(map) {
return this.props.gather.gatherers.reduce((acc, gatherer) => {
if (gatherer.mapVote.some(voteId => voteId === map.id)) acc++;
2015-07-29 13:50:39 +00:00
return acc;
}, 0);
},
2015-08-11 00:19:04 +00:00
render() {
2016-01-26 10:44:34 +00:00
const self = this;
2015-10-02 14:53:11 +00:00
let thisGatherer = self.props.thisGatherer
let maps = self.props.maps.sort((a, b) => {
2016-01-26 10:44:34 +00:00
const aVotes = self.votesForMap(a);
const bVotes = self.votesForMap(b);
2015-10-02 14:53:11 +00:00
return bVotes - aVotes;
}).map(map => {
let votes = self.votesForMap(map);
2015-12-25 07:50:27 +00:00
let style = thisGatherer.mapVote.some(voteId => voteId === map.id) ?
"list-group-item list-group-item-success" : "list-group-item";
return (
<a href="#"
key={map.id}
onClick={self.voteHandler(map.id)}
className={style}>
<span className="badge">{votes}</span>
{map.name}
</a>
);
2015-10-02 14:53:11 +00:00
});
2015-08-27 15:11:54 +00:00
let votes = thisGatherer.mapVote.length;
2015-08-27 15:11:54 +00:00
2015-07-29 13:50:39 +00:00
return (
2015-09-21 20:15:27 +00:00
<div className="panel panel-primary">
2015-07-29 13:50:39 +00:00
<div className="panel-heading">
{votes === 2 ? "Map Votes" :
`Please Vote for a Map. ${2 - votes} votes remaining` }
2015-07-29 13:50:39 +00:00
</div>
2015-08-27 14:53:11 +00:00
<div className="list-group gather-voting">
2015-07-29 13:50:39 +00:00
{maps}
2015-08-27 14:53:11 +00:00
</div>
2015-07-29 13:50:39 +00:00
</div>
);
}
})
2016-01-26 10:44:34 +00:00
const Gather = exports.Gather = React.createClass({
propTypes: {
thisGatherer: React.PropTypes.object,
maps: React.PropTypes.array.isRequired,
servers: React.PropTypes.array.isRequired,
socket: React.PropTypes.object.isRequired,
gather: React.PropTypes.object.isRequired
},
2015-08-11 00:19:04 +00:00
render() {
2016-01-26 10:44:34 +00:00
const socket = this.props.socket;
const gather = this.props.gather;
const thisGatherer = this.props.thisGatherer;
2016-02-18 11:06:35 +00:00
const soundController = this.props.soundController;
2016-01-26 10:44:34 +00:00
const servers = this.props.servers;
const maps = this.props.maps;
const user = this.props.user;
if (gather === null) return <div></div>;
2015-07-28 23:32:50 +00:00
2015-10-02 14:53:11 +00:00
let voting;
if (thisGatherer) {
let state = gather.state;
2015-09-05 17:37:43 +00:00
if (state === 'gathering' || state === 'election') {
voting = (
<div className="row add-top">
2015-09-16 15:16:00 +00:00
<div className="col-sm-6">
2015-10-02 14:53:11 +00:00
<MapVoting gather={gather} maps={maps}
2016-01-26 10:44:34 +00:00
socket={socket} thisGatherer={thisGatherer} />
2015-09-05 17:37:43 +00:00
</div>
2015-09-16 15:16:00 +00:00
<div className="col-sm-6">
2015-10-02 14:53:11 +00:00
<ServerVoting gather={gather} servers={servers}
2016-01-26 10:44:34 +00:00
socket={socket} thisGatherer={thisGatherer} />
2015-09-05 17:37:43 +00:00
</div>
2015-07-29 13:50:39 +00:00
</div>
2015-09-05 17:37:43 +00:00
);
} else {
2015-10-02 14:53:11 +00:00
voting = <GatherVotingResults gather={gather}
servers={servers}
maps={maps} />;
2015-09-05 17:37:43 +00:00
}
2015-07-29 13:50:39 +00:00
}
2015-10-02 14:53:11 +00:00
let gatherTeams;
if (gather.state === 'selection') {
gatherTeams = <GatherTeams gather={gather} />;
2015-07-28 15:54:29 +00:00
}
2015-10-20 22:49:21 +00:00
if (gather.gatherers.length > 0) {
return (
<div>
<div className="panel panel-primary add-bottom">
2016-03-18 14:48:17 +00:00
<div className="panel-heading">{gather.name}</div>
2015-10-20 22:49:21 +00:00
<div className="panel-body">
<GatherProgress gather={gather} />
2016-01-26 10:44:34 +00:00
<GatherActions gather={gather} user={user} thisGatherer={thisGatherer}
socket={socket} />
2015-10-20 22:49:21 +00:00
</div>
2015-09-14 22:14:36 +00:00
</div>
2016-02-18 11:06:35 +00:00
<Gatherers gather={gather} user={user} thisGatherer={thisGatherer}
socket={socket} soundController={soundController}/>
2015-10-20 22:49:21 +00:00
{gatherTeams}
{voting}
2015-09-14 22:14:36 +00:00
</div>
2015-10-20 22:49:21 +00:00
);
} else {
return (
<div>
<div className="panel panel-primary add-bottom">
2016-03-18 14:48:17 +00:00
<div className="panel-heading">{gather.name}</div>
2015-10-20 22:49:21 +00:00
</div>
2016-01-26 10:44:34 +00:00
<Gatherers gather={gather} user={user} thisGatherer={thisGatherer}
2016-02-18 11:06:35 +00:00
socket={socket} soundController={soundController}/>
2015-10-20 22:49:21 +00:00
</div>
);
}
2015-07-28 15:54:29 +00:00
}
});
2016-01-26 10:44:34 +00:00
const LifeformIcons = exports.LifeformIcons = React.createClass({
availableLifeforms() {
return ["skulk", "gorge", "lerk", "fade", "onos", "commander"];
},
gathererLifeforms() {
let lifeforms = [];
let gatherer = this.props.gatherer;
2015-10-02 14:53:11 +00:00
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 <img
className="lifeform-icon"
2015-09-27 11:55:00 +00:00
key={lifeform}
2016-01-22 10:12:23 +00:00
src={`/${lifeform.toLowerCase()}.png`} />
} else {
return <img
className="lifeform-icon"
2015-09-27 11:55:00 +00:00
key={lifeform}
2016-01-22 10:12:23 +00:00
src={`/blank.gif`} />
}
});
return <span className="add-right hidden-xs">{icons}</span>
}
});
2016-02-18 11:06:35 +00:00
const GathererListItem = React.createClass({
2016-01-26 10:44:34 +00:00
propTypes: {
2016-02-18 11:06:35 +00:00
user: React.PropTypes.object.isRequired,
gather: React.PropTypes.object.isRequired,
2016-01-26 10:44:34 +00:00
socket: React.PropTypes.object.isRequired,
2016-02-18 11:06:35 +00:00
gatherer: React.PropTypes.object.isRequired,
thisGatherer: React.PropTypes.object,
soundController: React.PropTypes.object.isRequired
2015-07-29 14:35:58 +00:00
},
2015-08-11 00:19:04 +00:00
2015-09-17 12:36:18 +00:00
bootGatherer(e) {
e.preventDefault();
2016-01-26 10:44:34 +00:00
this.props.socket.emit("gather:leave", {
2015-09-17 12:36:18 +00:00
gatherer: parseInt(e.target.value, 10) || null
});
},
2016-02-18 11:06:35 +00:00
getInitialState() {
return {
collapse: true
};
},
toggleCollapse(e) {
e.preventDefault();
this.setState({ collapse: !this.state.collapse });
},
2016-02-18 14:59:42 +00:00
caret() {
if (this.state.collapse) {
return <i className="fa fa-caret-down"></i>;
} else {
return <i className="fa fa-caret-up"></i>;
}
},
2016-02-18 11:06:35 +00:00
collapseState() {
return `panel-collapse out collapse ${this.state.collapse ? "" : "in"}`;
},
2015-08-11 00:19:04 +00:00
render() {
2016-01-26 10:44:34 +00:00
const user = this.props.user;
const gather = this.props.gather;
2016-02-18 11:06:35 +00:00
const socket = this.props.socket;
const gatherer = this.props.gatherer;
2016-01-26 10:44:34 +00:00
const thisGatherer = this.props.thisGatherer;
2016-02-18 11:06:35 +00:00
const soundController = this.props.soundController;
let country;
if (gatherer.user.country) {
country = (
<img src="/blank.gif"
className={"flag flag-" + gatherer.user.country.toLowerCase()}
alt={gatherer.user.country} />
);
};
2015-07-28 15:54:29 +00:00
2016-02-18 11:06:35 +00:00
const skill = gatherer.user.profile.skill || "Not Available";
2015-08-28 14:17:08 +00:00
2016-02-18 11:06:35 +00:00
const hiveStats = [];
if (gatherer.user.hive.skill) hiveStats.push(`${gatherer.user.hive.skill} ELO`);
2015-08-31 14:55:42 +00:00
2016-02-18 11:06:35 +00:00
if (gatherer.user.hive.playTime) {
hiveStats.push(`${Math.floor(gatherer.user.hive.playTime / 3600)} Hours`);
}
2015-08-31 14:55:42 +00:00
2016-02-18 11:06:35 +00:00
const hive = (hiveStats.length) ? hiveStats.join(", ") : "Not Available";
const 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 = (
<span>
<span className="badge add-right">{votes + " votes"}</span>
<VoteButton
socket={socket}
thisGatherer={thisGatherer}
soundController={soundController}
candidate={gatherer} />
</span>
);
}
2015-07-28 23:32:50 +00:00
2016-02-18 11:06:35 +00:00
if (gather.state === 'selection') {
if (thisGatherer &&
thisGatherer.leader &&
thisGatherer.team === gather.pickingTurn) {
2015-07-28 15:54:29 +00:00
action = (
<span>
2016-02-18 11:06:35 +00:00
<SelectPlayerButton gatherer={gatherer} socket={socket}/>
2015-07-28 15:54:29 +00:00
</span>
);
2016-02-18 11:06:35 +00:00
} else {
if (gatherer.leader) {
action = (<span className={`label label-padding
label-${gatherer.team}
team-label`}>Leader</span>);
} else if (gatherer.team !== "lobby") {
action = (<span className={`label label-padding
label-${gatherer.team}
team-label`}>{_.capitalize(gatherer.team)}</span>);
2015-08-08 17:13:17 +00:00
} else {
2016-02-18 11:06:35 +00:00
action = (<span className="label label-padding label-default team-label">
Lobby</span>);
2015-08-08 17:13:17 +00:00
}
2015-07-28 23:32:50 +00:00
}
2016-02-18 11:06:35 +00:00
}
2015-07-28 23:32:50 +00:00
2016-02-18 11:06:35 +00:00
let adminOptions;
if ((user && user.admin) || (user && user.moderator)) {
adminOptions = [
<hr />,
<dt>Admin</dt>,
<dd>
<button
className="btn btn-xs btn-danger"
value={gatherer.user.id}
onClick={this.bootGatherer}>
Boot from Gather
</button>&nbsp;
<AssumeUserIdButton socket={socket}
gatherer={gatherer} currentUser={user} />
</dd>
]
}
2015-09-17 12:36:18 +00:00
2016-02-18 11:06:35 +00:00
let tabColor = gatherer.team !== "lobby" ? `panel-${gatherer.team}` : "panel-info";
return (
<div className={`panel ${tabColor} gatherer-panel`}
key={gatherer.user.id} data-userid={gatherer.user.id}>
<div className="panel-heading">
<h4 className="panel-title">
{country} {gatherer.user.username}
<span className="pull-right">
<a href="#" className="btn btn-xs btn-primary add-right"
onClick={this.toggleCollapse}>
2016-02-18 14:59:42 +00:00
Info {this.caret()}</a>
2016-02-18 11:06:35 +00:00
<LifeformIcons gatherer={gatherer} />
{action}
</span>
</h4>
</div>
<div id={gatherer.user.id.toString() + "-collapse"}
className={this.collapseState()} >
<div className="panel-body">
2016-02-18 14:59:42 +00:00
<dl>
2016-02-18 11:06:35 +00:00
<dt>Skill Level</dt>
<dd>{skill}</dd>
<dt>Team</dt>
<dd>{team}</dd>
<dt>Hive Stats</dt>
<dd>{hive}</dd>
<dt>Links</dt>
<dd>
<a href={enslUrl(gatherer)}
className="btn btn-xs btn-primary"
target="_blank">ENSL Profile</a>&nbsp;
<a href={hiveUrl(gatherer)}
className="btn btn-xs btn-primary"
target="_blank">Hive Profile</a>
</dd>
{adminOptions}
</dl>
2015-09-05 17:22:23 +00:00
</div>
</div>
2016-02-18 11:06:35 +00:00
</div>
);
}
});
const Gatherers = React.createClass({
propTypes: {
user: React.PropTypes.object,
thisGatherer: React.PropTypes.object,
socket: React.PropTypes.object.isRequired,
gather: React.PropTypes.object.isRequired,
soundController: React.PropTypes.object.isRequired
},
joinGather(e) {
e.preventDefault();
this.props.socket.emit("gather:join");
},
render() {
const self = this;
const user = this.props.user;
const socket = this.props.socket;
const gather = this.props.gather;
const thisGatherer = this.props.thisGatherer;
const gatherers = gather.gatherers
.sort((a, b) => {
return (b.user.hive.skill || 1000) - (a.user.hive.skill || 1000);
})
.map(gatherer => {
return <GathererListItem socket={socket} gatherer={gatherer} thisGatherer={thisGatherer}
soundController={this.props.soundController}
user={user} gather={gather}/>
});
2015-10-02 14:53:11 +00:00
if (gather.gatherers.length) {
2015-07-28 15:54:29 +00:00
return (
2016-02-18 14:59:42 +00:00
<div id="gatherers-panel">
2015-09-05 17:22:23 +00:00
{gatherers}
2015-07-28 15:54:29 +00:00
</div>
);
} else {
2015-07-29 10:46:30 +00:00
return (
2015-09-21 20:15:27 +00:00
<div className="panel panel-primary add-bottom">
2015-09-14 23:02:52 +00:00
<div className="panel-body text-center join-hero">
<button
onClick={this.joinGather}
2016-03-18 14:48:17 +00:00
className="btn btn-success btn-lg">Start Gather</button>
2015-09-14 23:02:52 +00:00
</div>
2015-07-29 10:46:30 +00:00
</div>
);
2015-07-28 15:54:29 +00:00
}
}
});
2016-02-18 15:36:03 +00:00
const CompletedGather = exports.CompletedGather = React.createClass({
completionDate() {
let d = new Date(this.props.gather.done.time);
if (d) {
return d.toLocaleTimeString();
} else {
return "Completed Gather"
}
},
2015-09-27 11:55:00 +00:00
getInitialState() {
return {
show: !!this.props.show
};
},
toggleGatherInfo() {
let newState = !this.state.show;
this.setState({
show: newState
});
},
2015-09-05 17:37:43 +00:00
render() {
2015-09-27 11:55:00 +00:00
let gatherInfo = [];
2015-10-02 14:53:11 +00:00
let gather = this.props.gather;
let maps = this.props.maps;
let servers = this.props.servers;
2015-09-27 11:55:00 +00:00
if (this.state.show) {
2015-10-02 14:53:11 +00:00
gatherInfo.push(<GatherTeams gather={gather} />);
gatherInfo.push(<GatherVotingResults gather={gather}
maps={maps}
servers={servers}/>);
2015-09-27 11:55:00 +00:00
}
2015-09-05 17:37:43 +00:00
return (
2015-09-27 11:55:00 +00:00
<div>
<div className="panel panel-success add-bottom pointer"
onClick={this.toggleGatherInfo}>
<div className="panel-heading"><strong>{this.completionDate()}</strong></div>
2015-09-14 23:10:06 +00:00
</div>
2015-09-27 11:55:00 +00:00
{gatherInfo}
2015-09-05 17:37:43 +00:00
</div>
);
}
});
2016-01-26 10:44:34 +00:00
const GatherVotingResults = React.createClass({
2015-10-22 09:34:40 +00:00
// Returns an array of ids voted for e.g. [1,2,5,1,1,3,2]
2015-08-11 00:19:04 +00:00
countVotes(voteType) {
return this.props.gather.gatherers.reduce((acc, gatherer) => {
let votes = gatherer[voteType];
2015-10-04 12:25:06 +00:00
// 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));
2015-08-08 19:14:16 +00:00
return acc;
}, []);
2015-07-29 14:35:58 +00:00
},
2015-08-11 00:19:04 +00:00
selectedMaps() {
2015-08-08 19:14:16 +00:00
return rankVotes(this.countVotes('mapVote'), this.props.maps).slice(0, 2)
},
2015-08-11 00:19:04 +00:00
selectedServer() {
2015-08-08 19:14:16 +00:00
return rankVotes(this.countVotes('serverVote'), this.props.servers).slice(0, 1);
2015-07-29 14:35:58 +00:00
},
2015-08-11 00:19:04 +00:00
render() {
2015-09-14 17:27:50 +00:00
let maps = this.selectedMaps();
let server = this.selectedServer().pop();
let password;
if (server.password) {
password = [
<dt>Password</dt>,
<dd>{server.password}</dd>
];
}
2015-07-29 14:35:58 +00:00
return (
2015-09-21 21:33:05 +00:00
<div className="panel panel-primary">
2015-09-14 17:27:50 +00:00
<div className="panel-heading">
Server
</div>
<div className="panel-body">
2016-02-18 14:59:42 +00:00
<dl>
2015-09-14 17:27:50 +00:00
<dt>Maps</dt>
<dd>{maps.map(map => map.name).join(" & ")}</dd>
<dt>Server</dt>
<dd>{server.name}</dd>
<dt>Address</dt>
<dd>{server.ip}:{server.port}</dd>
{password}
</dl>
<p>
2015-10-20 16:48:44 +00:00
<a href={`steam://run/4920/connect+%20${server.ip}:${server.port}%20+password%20${server.password}`}
2015-09-21 21:33:05 +00:00
className="btn btn-primary max-width">Join Server</a>
2015-09-14 17:27:50 +00:00
</p>
</div>
2015-07-29 14:35:58 +00:00
</div>
);
}
});
2015-09-27 11:55:00 +00:00