"use strict"; var SelectPlayerButton = React.createClass({ selectPlayer(e) { e.preventDefault(); socket.emit("gather:select", { player: parseInt(e.target.value, 10) }) }, render() { let button; if (this.props.gatherer.leader) { button = ; } else if (this.props.gatherer.team !== "lobby") { button = ; } else { button = ; } return button; } }); var GathererList = React.createClass({ memberList() { var self = this; return this.props.gather.gatherers .filter(gatherer => gatherer.team === self.props.team) .sort(gatherer => { return gatherer.leader ? 1 : -1 }); }, render() { var extractGatherer = gatherer => { let image; if (gatherer.leader) { image = ; } return ( {image}{gatherer.user.username} ); } var members = this.memberList() .map(extractGatherer); return ( {members}
); } }); var GatherTeams = React.createClass({ render() { return (
Marines
Aliens
); } }); 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 (
{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 (

{this.stateDescription()} {progress.message}

{progressBar}
); } }); var TeamSpeakButton = React.createClass({ getDefaultProps() { let password = "ns2gather"; return { url: "ts3server://ensl.org/", password: password, alien: { channel: "NS2 Gather/Gather #1/Alien (Team Y)", password: password }, marine: { channel: "NS2 Gather/Gather #1/Marine (Team X)", password: password } }; }, marineUrl() { return this.teamSpeakUrl(this.props.marine); }, alienUrl() { return this.teamSpeakUrl(this.props.alien); }, teamSpeakUrl(conn) { let params = `channel=${encodeURIComponent(conn.channel)}&channelpassword=${encodeURIComponent(conn.password)}`; return (`${this.props.url}?${params}`); }, render() { return (

Teamspeak Server Information

Server
{this.props.url}
Password
{this.props.password}
Marine Channel
{this.props.marine.channel}
Alien Channel
{this.props.alien.channel}
); } }); var GatherActions = React.createClass({ joinGather(e) { e.preventDefault(); socket.emit("gather:join"); }, leaveGather(e) { e.preventDefault(); socket.emit("gather:leave"); }, voteRegather(e) { e.preventDefault(e); socket.emit("gather:vote", { regather: (e.target.value === "true") }); }, regatherVotes() { if (!this.props.gather) return 0; return this.props.gather.gatherers.reduce((acc, gatherer) => { if (gatherer.regatherVote) acc++; return acc; }, 0); }, render() { var joinButton; var currentGatherer = this.props.currentGatherer; if (currentGatherer) { joinButton = (
  • ); } else if (this.props.gather.state === 'gathering') { joinButton = ( ); } var regatherButton; if (currentGatherer) { let regatherVotes = this.regatherVotes(); if (currentGatherer.regatherVote) { regatherButton = (
  • ); } else { regatherButton = (
  • ); } } return (
        {regatherButton}  {joinButton}
    ); } }); 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 ( ); } else { return ( ); } } }); var ServerVoting = React.createClass({ voteHandler(serverId) { return function (e) { e.preventDefault(); socket.emit("gather:vote", { server: { id: serverId } }); } }, votesForServer(server) { return this.props.gather.gatherers.reduce((acc, gatherer) => { if (server.id === gatherer.serverVote) acc++; return acc; }, 0); }, render() { var self = this; let servers = self.props.servers.map(server => { let votes = self.votesForServer(server); if (self.props.currentGatherer.serverVote === server.id) { return ( e.preventDefault() } key={server.id}> {votes} {server.name || server.description || server.dns} ); } else { return ( {votes} {server.name || server.description || server.dns} ); } }); let voted = self.props.currentGatherer.serverVote !== null; return (
    {voted ? "Server Votes" : "Please Vote for a Server" }
    {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 (map.id === gatherer.mapVote) acc++; return acc; }, 0); }, render() { var self = this; let maps = self.props.maps.map(map => { let votes = self.votesForMap(map); if (self.props.currentGatherer.mapVote === map.id) { return ( e.preventDefault() } className="list-group-item list-group-item-success"> {votes} {map.name} ); } else { return ( {votes} {map.name} ); } }); let voted = (self.props.currentGatherer.mapVote !== null); return (
    { voted ? "Map Votes" : "Please Vote for a Map" }
    {maps}
    ); } }) var Gather = React.createClass({ getDefaultProps() { return { gather: { gatherers: [] } } }, checkForStateChange: function (data) { let previousState = this.props.gather.state; let newState = data.gather.state; if (newState === previousState) return; // Callbacks for new states if (newState === "election" && previousState === "gathering" && data.currentGatherer) { soundController.playGatherMusic(); } }, componentDidMount() { var self = this; socket.on("users:update", data => self.setProps({user: data.currentUser})); socket.on("gather:refresh", (data) => { self.checkForStateChange(data); self.setProps(data) }); }, render() { if (this.props.gather.state === 'done') { return (); } var voting; if (this.props.currentGatherer) { let state = this.props.gather.state; if (state === 'gathering' || state === 'election') { voting = (
    ); } else { voting = ; } } var gatherTeams; if (this.props.gather.state === 'selection') { gatherTeams = } var previousGather; if (this.props.previousGather) { previousGather = (); } return (
    Current Gather
    {gatherTeams} {voting} {previousGather}
    ); } }); var LifeformIcons = React.createClass({ availableLifeforms() { return ["skulk", "gorge", "lerk", "fade", "onos", "commander"]; }, gathererLifeforms() { let lifeforms = []; let gatherer = this.props.gatherer; for (let attr in gatherer.user.profile.abilities) { if (gatherer.user.profile.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 {lifeform} } 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() { var self = this; var user = this.props.user; var admin = (user && user.admin); var gatherers = this.props.gather.gatherers .sort((a, b) => { return (b.user.hive.skill || 1000) - (a.user.hive.skill || 1000); }) .map(gatherer => { if (gatherer.user.country) { var country = ({gatherer.user.country}); }; let skill = gatherer.user.profile.skill || "Not Available"; let lifeform; let abilities = gatherer.user.profile.abilities; if (abilities.length) { lifeform = abilities.map(ability => {return _.capitalize(ability)}).join(", "); } else { lifeform = "None Specified"; } 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 (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 && self.props.currentGatherer.team === self.props.gather.pickingTurn) { action = ( ); } else { if (gatherer.leader) { action = (Leader); } else if (gatherer.team !== "lobby") { action = ({_.capitalize(gatherer.team)}); } else { action = (Lobby); } } } var adminOptions; if (admin) { adminOptions = [
    Admin
    ,
    ] } return (

    {country} {gatherer.user.username} {action}

    Lifeforms
    {lifeform}
    Skill Level
    {skill}
    Team
    {team}
    Hive Stats
    {hive}
    {adminOptions}
    ); }) if (this.props.gather.gatherers.length) { return (
    {gatherers}
    ); } else { return (
    ); } } }); var CompletedGather = React.createClass({ render() { return (
    Previous Gather
    ); } }); var GatherVotingResults = 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() { let maps = this.selectedMaps(); let server = this.selectedServer().pop(); let password; if (server.password) { password = [
    Password
    ,
    {server.password}
    ]; } return (
    Server
    Maps
    {maps.map(map => map.name).join(" & ")}
    Server
    {server.name}
    Address
    {server.ip}:{server.port}
    {password}

    Click to Join

    ); } });