mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-01-31 13:30:37 +00:00
More cleanup
This commit is contained in:
parent
d850a3e34c
commit
affa015258
1 changed files with 10 additions and 13 deletions
|
@ -19,7 +19,7 @@ function Gather (options) {
|
|||
return new Gather(options);
|
||||
}
|
||||
|
||||
var noop = () => {};
|
||||
let noop = () => {};
|
||||
|
||||
if (options && typeof options.onEvent === 'function') {
|
||||
this.onEvent = options.onEvent;
|
||||
|
@ -70,7 +70,7 @@ StateMachine.create({
|
|||
|
||||
onenterelection: () => {
|
||||
// Setup timer for elections
|
||||
var self = this;
|
||||
let self = this;
|
||||
self.electionStartTime = new Date();
|
||||
setTimeout(() => {
|
||||
if (self.can("electionTimeout")) {
|
||||
|
@ -94,11 +94,11 @@ StateMachine.create({
|
|||
// Assign leaders based on vote
|
||||
// 1st place alien comm
|
||||
// 2nd place marine comm
|
||||
var voteCount = {};
|
||||
let voteCount = {};
|
||||
this.gatherers.forEach(gatherer => { voteCount[gatherer.id] = 0 });
|
||||
this.leaderVotes().forEach(candidateId => { voteCount[candidateId]++ });
|
||||
var rank = [];
|
||||
for (var candidate in voteCount) {
|
||||
let rank = [];
|
||||
for (let candidate in voteCount) {
|
||||
rank.push({ candidate: candidate, count: voteCount[candidate] });
|
||||
}
|
||||
rank.sort((a, b) => {
|
||||
|
@ -164,7 +164,7 @@ Gather.prototype.containsUser = user => {
|
|||
|
||||
Gather.prototype.addUser = user => {
|
||||
if (this.containsUser(user)) return null;
|
||||
var gatherer = new Gatherer(user);
|
||||
let gatherer = new Gatherer(user);
|
||||
this.gatherers.push(gatherer);
|
||||
return gatherer;
|
||||
};
|
||||
|
@ -234,12 +234,11 @@ Gather.prototype.voteForServer = (voter, serverId) => {
|
|||
|
||||
// Returns an array of IDs representing votes for leaders
|
||||
Gather.prototype.leaderVotes = () => {
|
||||
var self = this;
|
||||
return self.gatherers.map(gatherer => gatherer.leaderVote)
|
||||
let self = this;
|
||||
return self.gatherers
|
||||
.map(gatherer => gatherer.leaderVote)
|
||||
.filter(leaderId => typeof leaderId === 'number')
|
||||
.filter(candidate => {
|
||||
return self.gatherers.some(gatherer => gatherer.id === candidate);
|
||||
});
|
||||
.filter(leaderId => self.containsUser({id: leaderId}));
|
||||
};
|
||||
|
||||
Gather.prototype.voteForLeader = (voter, candidate) => {
|
||||
|
@ -252,6 +251,4 @@ Gather.prototype.getGatherer = (user) => {
|
|||
.pop() || null;
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.exports = Gather;
|
||||
|
|
Loading…
Reference in a new issue