"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 { return ( ); } } }); var GatherTeams = React.createClass({ alienGatherers: function () { return this.props.gather.gatherers.filter(function (gatherer) { return gatherer.team === "alien"; }).sort(function (gatherer) { return (gatherer.leader) ? 1 : -1; }); }, marineGatherers: function () { return this.props.gather.gatherers.filter(function (gatherer) { return gatherer.team === "marine"; }).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 marines = this.marineGatherers().map(extractGatherer); var aliens = this.alienGatherers().map(extractGatherer); return (
Aliens
{aliens}
Marines
{marines}
); } }) 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 picking 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; var gatherState = this.props.gather.state; if (gatherState === 'gathering' && this.props.gather.gatherers.length) { progress = this.gatheringProgress(); } else if (gatherState === 'election') { progress = this.electionProgress(); } else if (gatherState === 'selection') { progress = this.selectionProgress(); } if (progress) { var style = { width: Math.round((progress.num / progress.den * 100)) + "%" }; return (

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

); } else { return false; } } }); 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 (
    ); } }); 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 (
    NS2 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) { // Switch this to online status var online= (
    ); var division = ({gatherer.user.ability.division}); var action; if (self.props.gather.state === 'gathering') { action = ( gatherer.user.ability.lifeforms.map(function (lifeform) { return ({lifeform}); }) ); } 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') { action = ( ); } return ( {online} {gatherer.user.username} {division}  {action}  ); }) if (this.props.gather.gatherers.length) { return (
    {gatherers}
    ); } else { return (
    ); } } }); var CompletedGather = React.createClass({ votedMaps: function () { }, votedServer: function () { }, render: function () { return (
    Gather Completed

    Join Up:

    Map Voted: To be completed

    Server Voted: To be completed

    ); } });