ensl_gathers/lib/react/gather.jsx

1014 lines
24 KiB
React
Raw Normal View History

2015-07-28 15:54:29 +00:00
"use strict";
var SelectPlayerButton = React.createClass({
2015-08-11 00:19:04 +00:00
selectPlayer(e) {
2015-07-28 15:54:29 +00:00
e.preventDefault();
2015-07-28 23:32:50 +00:00
socket.emit("gather:select", {
player: parseInt(e.target.value, 10)
})
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
2015-08-08 19:14:16 +00:00
var GathererList = React.createClass({
2015-08-11 00:19:04 +00:00
memberList() {
2015-08-08 19:14:16 +00:00
var 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() {
var 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>
);
}
2015-09-17 11:33:28 +00:00
var members = this.memberList()
.map(extractGatherer);
2015-08-08 19:14:16 +00:00
return (
<table className="table">
<tbody>
{members}
</tbody>
</table>
);
}
});
var 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
2015-07-31 15:54:08 +00:00
var ElectionProgressBar = React.createClass({
2015-08-11 00:19:04 +00:00
componentDidMount() {
2015-07-31 15:54:08 +00:00
var 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() {
2015-07-31 15:54:08 +00:00
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"
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()} />);
}
});
var ProgressBar = React.createClass({
2015-08-11 00:19:04 +00:00
render() {
2015-10-02 14:53:11 +00:00
let progress = this.props.progress;
2015-07-31 15:54:08 +00:00
var 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
};
2015-10-02 14:53:11 +00:00
var 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
);
}
});
2015-07-28 15:54:29 +00:00
var 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() {
2015-07-28 15:54:29 +00:00
var num = this.props.gather.gatherers.length;
var den = 12;
var remaining = den - num;
2015-10-02 14:53:11 +00:00
var message = (remaining === 1) ?
"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() {
var num = this.props.gather.gatherers.reduce((acc, gatherer) => {
2015-07-28 15:54:29 +00:00
if (gatherer.leaderVote) acc++;
return acc;
}, 0);
var den = 12;
return {
num: num,
den: den,
message: den - num + " more votes required"
};
},
2015-08-11 00:19:04 +00:00
selectionProgress() {
var num = this.props.gather.gatherers.reduce((acc, gatherer) => {
2015-07-28 15:54:29 +00:00
if (gatherer.team !== "lobby") acc++;
return acc;
}, 0);
var den = 12;
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() {
2015-07-31 15:54:08 +00:00
var progress, progressBar;
2015-07-28 15:54:29 +00:00
var gatherState = this.props.gather.state;
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
}
});
2015-10-20 16:36:21 +00:00
let teamspeakDefaults = {
url: "ts3server://ensl.org/",
password: "ns2gather",
alien: {
channel: "NS2 Gather/Gather #1/Alien",
password: "ns2gather"
},
marine: {
channel: "NS2 Gather/Gather #1/Marine",
password: "ns2gather"
}
};
2015-08-27 11:57:35 +00:00
var TeamSpeakButton = React.createClass({
getDefaultProps() {
2015-10-20 16:36:21 +00:00
return teamspeakDefaults
2015-08-27 11:57:35 +00:00
},
marineUrl() {
2015-08-27 14:00:10 +00:00
return this.teamSpeakUrl(this.props.marine);
2015-08-27 11:57:35 +00:00
},
alienUrl() {
2015-08-27 14:00:10 +00:00
return this.teamSpeakUrl(this.props.alien);
2015-08-27 11:57:35 +00:00
},
teamSpeakUrl(conn) {
2015-10-02 14:53:11 +00:00
let params = `channel=${encodeURIComponent(conn.channel)}&
channelpassword=${encodeURIComponent(conn.password)}`;
2015-08-27 11:57:35 +00:00
return (`${this.props.url}?${params}`);
},
render() {
return (
2015-10-20 16:36:21 +00:00
<ul className="nav navbar-top-links navbar-right">
<li className="dropdown">
<a className="dropdown-toggle" data-toggle="dropdown" href="#">
Teamspeak &nbsp;<i className="fa fa-caret-down"></i>
</a>
<ul className="dropdown-menu">
<li><a href={this.props.url}>Join Teamspeak Lobby</a></li>
<li><a href={this.marineUrl()}>Join Marine Teamspeak</a></li>
<li><a href={this.alienUrl()}>Join Alien Teamspeak</a></li>
<li role="separator" className="divider"></li>
<li><a href="#" data-toggle="modal" data-target="#teamspeakmodal">Teamspeak Details</a></li>
</ul>
</li>
</ul>
);
}
});
var TeamSpeakModal = React.createClass({
getDefaultProps() {
return teamspeakDefaults;
},
render() {
return <div className="modal fade text-left" id="teamspeakmodal">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button"
className="close"
data-dismiss="modal"
aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 className="modal-title">Teamspeak Server Information</h4>
</div>
<div className="modal-body">
<dl className="dl-horizontal">
<dt>Server</dt>
<dd>{this.props.url}</dd>
<dt>Password</dt>
<dd>{this.props.password}</dd>
<dt>Marine Channel</dt>
<dd>{this.props.marine.channel}</dd>
<dt>Alien Channel</dt>
<dd>{this.props.alien.channel}</dd>
</dl>
2015-09-05 17:22:23 +00:00
</div>
2015-08-27 11:57:35 +00:00
</div>
</div>
2015-10-20 16:36:21 +00:00
</div>
2015-08-27 11:57:35 +00:00
}
});
2015-09-28 13:30:13 +00:00
var JoinGatherButton = React.createClass({
componentDidMount() {
var self = this;
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();
socket.emit("gather:join");
},
2015-08-11 00:19:04 +00:00
leaveGather(e) {
2015-07-28 15:54:29 +00:00
e.preventDefault();
2015-07-28 23:32:50 +00:00
socket.emit("gather:leave");
},
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;
}
});
var CooloffButton = React.createClass({
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>
}
})
var GatherActions = React.createClass({
2015-09-17 13:56:50 +00:00
voteRegather(e) {
e.preventDefault(e);
socket.emit("gather:vote", {
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;
2015-10-02 14:53:11 +00:00
let user = this.props.user;
let gather = this.props.gather;
let thisGatherer = this.props.thisGatherer;
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}
user={user} />
</li>
</ul>
2015-09-14 22:14:36 +00:00
</div>
2015-07-28 23:32:50 +00:00
</div>
);
}
});
2015-08-27 14:53:11 +00:00
var VoteButton = React.createClass({
cancelVote(e) {
socket.emit("gather:vote", {
leader: {
candidate: null
}
});
},
vote(e) {
2015-07-29 13:50:39 +00:00
e.preventDefault();
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
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>
);
}
}
});
var ServerVoting = React.createClass({
voteHandler(serverId) {
return function (e) {
e.preventDefault();
socket.emit("gather:vote", {
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) => {
var aVotes = self.votesForServer(a);
var bVotes = self.votesForServer(b);
return bVotes - aVotes;
}).map(server => {
2015-08-27 14:53:11 +00:00
let votes = self.votesForServer(server);
if (thisGatherer.serverVote.some(voteId => voteId === server.id)) {
2015-08-27 14:53:11 +00:00
return (
2015-08-27 16:59:08 +00:00
<a href="#"
className="list-group-item list-group-item-success"
onClick={ e => e.preventDefault() }
key={server.id}>
2015-08-27 14:53:11 +00:00
<span className="badge">{votes}</span>
2015-10-02 14:53:11 +00:00
{server.name || server.description}
2015-08-27 14:53:11 +00:00
</a>
);
2015-07-29 13:50:39 +00:00
} else {
2015-08-27 14:53:11 +00:00
return (
<a href="#" className="list-group-item"
onClick={self.voteHandler(server.id)}
key={server.id}>
<span className="badge">{votes}</span>
2015-10-02 14:53:11 +00:00
{server.name || server.description}
2015-08-27 14:53:11 +00:00
</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>
);
}
})
var MapVoting = React.createClass({
2015-08-27 14:53:11 +00:00
voteHandler(mapId) {
return function (e) {
e.preventDefault();
socket.emit("gather:vote", {
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() {
2015-07-29 13:50:39 +00:00
var self = this;
2015-10-02 14:53:11 +00:00
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)) {
2015-10-02 14:53:11 +00:00
return (
<a href="#"
key={map.id}
onClick={ e => e.preventDefault() }
className="list-group-item list-group-item-success">
<span className="badge">{votes}</span>
{map.name}
</a>
);
} else {
return (
<a href="#"
key={map.id}
onClick={self.voteHandler(map.id)}
className="list-group-item">
<span className="badge">{votes}</span>
{map.name}
</a>
);
}
});
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>
);
}
})
2015-07-28 23:32:50 +00:00
var Gather = React.createClass({
2015-08-11 00:19:04 +00:00
render() {
2015-10-02 14:53:11 +00:00
let gather = this.props.gather;
2015-10-02 18:39:09 +00:00
let thisGatherer = this.props.thisGatherer;
2015-10-02 14:53:11 +00:00
let servers = this.props.servers;
let maps = this.props.maps;
let 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}
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}
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">
<div className="panel-heading">Current Gather</div>
<div className="panel-body">
<GatherProgress gather={gather} />
<GatherActions gather={gather} user={user} thisGatherer={thisGatherer} />
</div>
2015-09-14 22:14:36 +00:00
</div>
2015-10-20 22:49:21 +00:00
<Gatherers gather={gather} user={user} thisGatherer={thisGatherer} />
{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">
<div className="panel-heading">Current Gather</div>
</div>
<Gatherers gather={gather} user={user} thisGatherer={thisGatherer} />
</div>
);
}
2015-07-28 15:54:29 +00:00
}
});
var 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"
alt={lifeform}
2015-09-27 11:55:00 +00:00
key={lifeform}
src={`/images/${lifeform.toLowerCase()}.png`} />
} else {
return <img
className="lifeform-icon"
2015-09-27 11:55:00 +00:00
key={lifeform}
src={`/images/blank.gif`} />
}
});
return <span className="add-right hidden-xs">{icons}</span>
}
});
2015-07-28 15:54:29 +00:00
var Gatherers = React.createClass({
2015-08-11 00:19:04 +00:00
joinGather(e) {
2015-07-29 14:35:58 +00:00
e.preventDefault();
socket.emit("gather:join");
},
2015-08-11 00:19:04 +00:00
2015-09-17 12:36:18 +00:00
bootGatherer(e) {
e.preventDefault();
socket.emit("gather:leave", {
gatherer: parseInt(e.target.value, 10) || null
});
},
2015-08-11 00:19:04 +00:00
render() {
2015-10-02 14:53:11 +00:00
let self = this;
let user = this.props.user;
let gather = this.props.gather;
2015-10-22 21:59:47 +00:00
let admin = (user && user.admin) || (user && user.moderator);
2015-10-02 14:53:11 +00:00
let thisGatherer = this.props.thisGatherer;
let gatherers = gather.gatherers
2015-09-17 11:37:16 +00:00
.sort((a, b) => {
return (b.user.hive.skill || 1000) - (a.user.hive.skill || 1000);
})
.map(gatherer => {
2015-08-08 17:13:17 +00:00
if (gatherer.user.country) {
2015-10-02 14:53:11 +00:00
var country = (
<img src="images/blank.gif"
className={"flag flag-" + gatherer.user.country.toLowerCase()}
alt={gatherer.user.country} />
);
2015-08-08 17:13:17 +00:00
};
2015-07-28 15:54:29 +00:00
2015-09-20 13:50:59 +00:00
let skill = gatherer.user.profile.skill || "Not Available";
2015-08-28 14:17:08 +00:00
2015-09-20 13:50:59 +00:00
let hiveStats = [];
2015-09-14 16:50:00 +00:00
if (gatherer.user.hive.skill) hiveStats.push(`${gatherer.user.hive.skill} ELO`);
2015-08-31 14:55:42 +00:00
if (gatherer.user.hive.playTime) {
2015-09-14 16:50:00 +00:00
hiveStats.push(`${Math.floor(gatherer.user.hive.playTime / 3600)} Hours`);
2015-08-31 14:55:42 +00:00
}
2015-09-20 13:50:59 +00:00
let hive = (hiveStats.length) ? hiveStats.join(", ") : "Not Available";
2015-09-05 17:22:23 +00:00
2015-09-20 13:50:59 +00:00
let team = (gatherer.user.team) ? gatherer.user.team.name : "None";
2015-07-28 23:32:50 +00:00
2015-09-20 13:50:59 +00:00
let action;
2015-10-02 14:53:11 +00:00
if (gather.state === "election") {
let votes = gather.gatherers.reduce((acc, voter) => {
2015-07-28 15:54:29 +00:00
if (voter.leaderVote === gatherer.id) acc++;
return acc;
}, 0)
action = (
<span>
<span className="badge add-right">{votes + " votes"}</span>
2015-10-02 14:53:11 +00:00
<VoteButton
thisGatherer={thisGatherer}
candidate={gatherer} />
2015-07-28 15:54:29 +00:00
</span>
);
}
2015-10-02 14:53:11 +00:00
if (gather.state === 'selection') {
if (thisGatherer &&
thisGatherer.leader &&
thisGatherer.team === gather.pickingTurn) {
2015-08-08 17:13:17 +00:00
action = (
<span>
<SelectPlayerButton gatherer={gatherer} />
</span>
);
} else {
2015-09-16 15:16:00 +00:00
if (gatherer.leader) {
2015-10-02 14:53:11 +00:00
action = (<span className={`label label-padding
label-${gatherer.team}
team-label`}>Leader</span>);
2015-09-16 15:16:00 +00:00
} else if (gatherer.team !== "lobby") {
2015-10-02 14:53:11 +00:00
action = (<span className={`label label-padding
label-${gatherer.team}
team-label`}>{_.capitalize(gatherer.team)}</span>);
2015-09-20 14:47:43 +00:00
} else {
2015-10-02 14:53:11 +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
}
2015-10-02 14:53:11 +00:00
let adminOptions;
2015-09-17 12:36:18 +00:00
if (admin) {
adminOptions = [
2015-10-03 15:36:58 +00:00
<hr />,
2015-09-17 12:36:18 +00:00
<dt>Admin</dt>,
<dd>
<button
className="btn btn-xs btn-danger"
value={gatherer.user.id}
onClick={this.bootGatherer}>
Boot from Gather
2015-09-27 11:55:00 +00:00
</button>&nbsp;
<AssumeUserIdButton
gatherer={gatherer}
2015-10-02 14:53:11 +00:00
currentUser={user} />
2015-09-17 12:36:18 +00:00
</dd>
]
}
2015-09-27 13:18:32 +00:00
let tabColor = gatherer.team !== "lobby" ? `panel-${gatherer.team}` : "panel-info";
2015-07-28 15:54:29 +00:00
return (
2015-10-02 14:53:11 +00:00
<div className={`panel ${tabColor} gatherer-panel`}
key={gatherer.user.id} data-userid={gatherer.user.id}>
2015-09-05 17:22:23 +00:00
<div className="panel-heading">
<h4 className="panel-title">
2015-09-17 20:40:54 +00:00
{country} {gatherer.user.username}
2015-09-05 17:22:23 +00:00
<span className="pull-right">
2015-09-17 20:40:54 +00:00
<a data-toggle="collapse"
href={"#"+gatherer.user.id.toString() + "-collapse"}
aria-expanded="false"
2015-09-18 15:13:52 +00:00
className="btn btn-xs btn-primary add-right"
2015-09-17 20:40:54 +00:00
aria-controls={gatherer.user.id.toString() + "-collapse"}>
Info <span className="caret"></span></a>
<LifeformIcons gatherer={gatherer} />
2015-09-05 17:22:23 +00:00
{action}
</span>
</h4>
</div>
<div id={gatherer.user.id.toString() + "-collapse"}
className="panel-collapse collapse out" >
<div className="panel-body">
<dl className="dl-horizontal">
<dt>Skill Level</dt>
<dd>{skill}</dd>
<dt>Team</dt>
<dd>{team}</dd>
<dt>Hive Stats</dt>
<dd>{hive}</dd>
2015-10-03 15:36:58 +00:00
<dt>Links</dt>
<dd>
2015-10-18 15:23:39 +00:00
<a href={enslUrl(gatherer)}
2015-10-03 15:36:58 +00:00
className="btn btn-xs btn-primary"
target="_blank">ENSL Profile</a>&nbsp;
2015-10-18 15:23:39 +00:00
<a href={hiveUrl(gatherer)}
2015-10-03 15:36:58 +00:00
className="btn btn-xs btn-primary"
target="_blank">Hive Profile</a>
</dd>
2015-09-17 12:36:18 +00:00
{adminOptions}
2015-09-05 17:22:23 +00:00
</dl>
</div>
</div>
</div>
2015-07-28 15:54:29 +00:00
);
})
2015-10-02 14:53:11 +00:00
if (gather.gatherers.length) {
2015-07-28 15:54:29 +00:00
return (
2015-10-02 14:53:11 +00:00
<div class="panel-group"
role="tablist"
aria-multiselectable="true"
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}
className="btn btn-success btn-lg">Start a Gather</button>
</div>
2015-07-29 10:46:30 +00:00
</div>
);
2015-07-28 15:54:29 +00:00
}
}
});
2015-07-29 14:35:58 +00:00
var 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>
);
}
});
var 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">
<dl className="dl-horizontal">
<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
var ArchivedGathers = React.createClass({
render() {
let archive = this.props.archive
.sort((a, b) => {
return new Date(b.createdAt) - new Date(a.createdAt);
})
.map((archivedGather, index) => {
2015-09-27 11:55:00 +00:00
return <CompletedGather
2015-10-02 14:53:11 +00:00
id={archivedGather.gather.done.time}
show={(index === 0) ? true : false}
2015-09-27 11:55:00 +00:00
gather={archivedGather.gather}
maps={this.props.maps}
servers={this.props.servers} />
});
return (
<div className="panel panel-primary">
<div className="panel-heading">Archived Gathers</div>
<div className="panel-body">
{archive}
</div>
</div>
);
}
});