"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 JoinGatherButton = React.createClass({
joinGather: function (e) {
e.preventDefault();
socket.emit("gather:join", {});
},
render: function () {
var message = this.props.buttonName || "Join Gather";
var buttonClass = "btn btn-primary";
if (this.props.buttonClass) {
buttonClass += " " + this.props.buttonClass;
}
return ()
}
});
var SelectPlayerButton = React.createClass({
selectPlayer: function (e) {
e.preventDefault();
},
render: function () {
if (!this.props.currentGatherer.leader) {
return false;
} 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 : 0;
});
},
marineGatherers: function () {
return this.props.gather.gatherers.filter(function (gatherer) {
return gatherer.team === "marine";
}).sort(function (gatherer) {
return (gatherer.leader) ? 1 : 0;
});
},
render: function () {
var extractGatherer = function (gatherer) {
var image;
if (gatherer.leader) {
image = ();
}
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 Gather = React.createClass({
getDefaultProps: function () {
return {
gather: {
gatherers: []
}
}
},
joinedGather: function () {
return this.props.currentGatherer !== null;
},
componentDidMount: function () {
var self = this;
socket.on("gather:refresh", function (data) {
self.setProps({
gather: data.gather,
currentGatherer: data.currentGatherer
});
});
},
leaveGather: function (e) {
e.preventDefault();
socket.emit("gather:leave", {});
},
inviteToGather: function (e) {
e.preventDefault();
},
render: function () {
var joinButton;
if (this.joinedGather()) {
joinButton = ();
} else {
joinButton = (
);
}
var inviteButton;
if (this.props.gather.state === 'gathering') {
inviteButton = ();
}
var gatherTeams;
if (this.props.gather.state === 'selection') {
gatherTeams =
}
return (
NS2 Gather {this.props.gather.gatherers.length}
{gatherTeams}
{inviteButton}
{joinButton}
);
}
});
var Gatherers = React.createClass({
render: function () {
var self = this;
var gatherers = this.props.gather.gatherers.map(function (gatherer) {
var lifeforms = (
gatherer.user.ability.lifeforms.map(function (lifeform) {
return ({lifeform});
})
);
// Switch this to online status
var online= ();
var division = ({gatherer.user.ability.division});
var action = lifeforms;
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"}
);
}
return (
{online}
{gatherer.user.username}
{division}
{action}
);
})
if (this.props.gather.gatherers.length) {
return (