"use strict"; var VoteButton = React.createClass({ cancelVote: function (e) { socket.emit("gather:vote", { leader: { candidate: null } }); }, vote: function (e) { e.preventDefault(); socket.emit("gather:vote", { leader: { candidate: parseInt(e.target.value, 10) } }); }, render: function () { if (this.props.currentGatherer === null) { return false; } if (this.props.currentGatherer.leaderVote === this.props.candidate.id) { return ( ); } else { return ( ); } } }); var SelectPlayerButton = React.createClass({ selectPlayer: function (e) { e.preventDefault(); socket.emit("gather:select", { player: parseInt(e.target.value, 10) }) }, render: function () { if (this.props.gatherer.leader) { return (); } else if (this.props.gatherer.team !== "lobby") { return ( ); } else { return ( ); } } }); var GathererList = React.createClass({ memberList: function () { var self = this; return this.props.gather.gatherers.filter(function (gatherer) { return gatherer.team === self.props.team; }).sort(function (gatherer) { return (gatherer.leader) ? 1 : -1; }); }, render: function () { var extractGatherer = function (gatherer) { var image; if (gatherer.leader) { image = (Commander); } return ( {image} {gatherer.user.username} ); } var members = this.memberList().map(extractGatherer); return ( {members}
); } }); var GatherTeams = React.createClass({ render: function () { return (
Aliens
Marines
); } }); var ElectionProgressBar = React.createClass({ componentDidMount: function () { var self = this; this.timer = setInterval(function () { self.forceUpdate(); }, 900); }, progress: function () { 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: function () { clearInterval(this.timer); }, render: function () { return (); } }); var ProgressBar = React.createClass({ render: function () { 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: function () { 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: function () { 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: function () { var num = this.props.gather.gatherers.reduce(function (acc, gatherer) { if (gatherer.leaderVote) acc++; return acc; }, 0); var den = 12; return { num: num, den: den, message: den - num + " more votes required" }; }, selectionProgress: function () { var num = this.props.gather.gatherers.reduce(function (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: function () { 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: function (e) { e.preventDefault(); socket.emit("gather:join"); }, leaveGather: function (e) { e.preventDefault(); socket.emit("gather:leave"); }, confirmTeam: function (e) { e.preventDefault(); socket.emit("gather:select:confirm"); }, inviteToGather: function (e) { e.preventDefault(); alert("Boop!"); }, render: function () { var joinButton; if (this.props.currentGatherer) { joinButton = (
  • ); } else if (this.props.gather.state === 'gathering') { joinButton = ( ); } var confirmTeam; if (this.props.currentGatherer && this.props.currentGatherer.leader && this.props.gather.state === 'selection' && this.props.gather.gatherers.every(function (gatherer) { return gatherer.team !== 'lobby'; }) ) { if (this.props.currentGatherer.confirm) { confirmTeam = (
  • ); } else { confirmTeam = (
  • ); } } var inviteButton; if (this.props.gather.state === 'gathering') { inviteButton = (
  • ); } return (
      {confirmTeam} {inviteButton} {joinButton}
    ); } }); var ServerVoting = React.createClass({ handleServerVote: function (e) { e.preventDefault(); socket.emit("gather:vote", { server: { id: parseInt(e.target.value, 10) } }); }, votesForServer: function (server) { return this.props.gather.gatherers.reduce(function (acc, gatherer) { if (server.id === gatherer.serverVote) acc++; return acc; }, 0); }, render: function () { var self = this; var servers = self.props.servers.map(function (server) { var voteButton; if (self.props.currentGatherer.serverVote === server.id) { voteButton = () } else { voteButton = (); } return ( {server.name} {self.votesForServer(server)} Votes  {voteButton} ); }); return (
    Server Voting
    {servers}
    ); } }) var MapVoting = React.createClass({ handleMapVote: function (e) { e.preventDefault(); socket.emit("gather:vote", { map: { id: parseInt(e.target.value, 10) } }); }, votesForMap: function (map) { return this.props.gather.gatherers.reduce(function (acc, gatherer) { if (map.id === gatherer.mapVote) acc++; return acc; }, 0); }, render: function () { var self = this; var maps = self.props.maps.map(function (map) { var voteButton; if (self.props.currentGatherer.mapVote === map.id) { voteButton = () } else { voteButton = (); } return ( {map.name} {self.votesForMap(map)} Votes  {voteButton} ); }); return (
    Map Voting
    {maps}
    ); } }) var Gather = React.createClass({ getDefaultProps: function () { return { gather: { gatherers: [] } } }, componentDidMount: function () { var self = this; socket.on("gather:refresh", function (data) { self.setProps(data); }); }, render: function () { if (this.props.gather.state === 'done') { return (); } var voting; if (this.props.currentGatherer) { voting = (
    ); } var gatherTeams; if (this.props.gather.state === 'selection') { gatherTeams = } return (
    Current Gather {this.props.gather.gatherers.length}
    {gatherTeams} {voting}
    ); } }); var Gatherers = React.createClass({ joinGather: function (e) { e.preventDefault(); socket.emit("gather:join"); }, render: function () { var self = this; var gatherers = this.props.gather.gatherers.map(function (gatherer) { // Country var country; if (gatherer.user.country) { country = ({gatherer.user.country}); }; var division = ({gatherer.user.ability.division}); var lifeform = ( gatherer.user.ability.lifeforms.map(function (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(function (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 (
    {gatherers}
    ); } else { return (
    ); } } }); var CompletedGather = React.createClass({ countVotes: function (voteType) { return this.props.gather.gatherers.reduce(function (acc, gatherer) { if (gatherer[voteType] !== null) acc.push(gatherer[voteType]); return acc; }, []); }, selectedMaps: function () { return rankVotes(this.countVotes('mapVote'), this.props.maps).slice(0, 2) }, selectedServer: function () { return rankVotes(this.countVotes('serverVote'), this.props.servers).slice(0, 1); }, render: function () { var maps = this.selectedMaps(); var server = this.selectedServer().pop(); return (
    Gather Details
    Maps
    {maps.map(function(map) { return map.name}).join(" & ")}
    Server
    {server.name}
    Address
    {server.ip}:{server.port}
    Password
    {server.password}

     
    Click to Join
    ); } });