ensl_gathers/lib/gather/gatherer.js

69 lines
1.6 KiB
JavaScript
Raw Normal View History

"use strict";
/*
* Implements Gatherer
*
* Stores necessary information including:
* - user data
* - voting preferences
* - leader status
2015-07-23 13:36:51 +00:00
* - Team: "lobby" "alien" "marine"
*/
2015-07-22 23:30:14 +00:00
var User = require("../user/user");
var MAX_MAP_VOTES = 2;
var MAX_SERVER_VOTES = 2;
2015-07-22 23:30:14 +00:00
function Gatherer (user) {
2015-07-24 13:34:02 +00:00
this.leaderVote = null;
this.mapVote = [];
this.serverVote = [];
2015-07-24 13:34:02 +00:00
this.confirm = false;
2015-07-22 23:30:14 +00:00
this.id = user.id;
2015-07-23 13:36:51 +00:00
this.user = user;
2015-07-24 13:34:02 +00:00
this.leader = false;
2015-07-23 13:36:51 +00:00
this.team = "lobby";
2015-09-17 13:56:50 +00:00
this.regatherVote = false;
};
2015-12-25 07:50:27 +00:00
Gatherer.prototype.toggleMapVote = function (mapId) {
if (this.mapVote.some(votedId => votedId === mapId)) {
this.mapVote = this.mapVote.filter(voteId => voteId !== mapId);
2015-12-25 07:50:27 +00:00
return;
}
this.mapVote.push(mapId);
this.mapVote = this.mapVote.slice(this.mapVote.length - MAX_MAP_VOTES,
this.mapVote.length);
};
Gatherer.prototype.toggleServerVote = function (serverId) {
if (this.serverVote.some(votedId => votedId === serverId)) {
this.serverVote = this.serverVote.filter(voteId => voteId !== serverId);
return;
}
this.serverVote.push(serverId);
this.serverVote = this.serverVote.slice(this.serverVote.length -
MAX_SERVER_VOTES, this.serverVote.length);
};
2015-09-25 21:23:30 +00:00
Gatherer.prototype.voteForLeader = function (candidate) {
2015-07-27 11:55:36 +00:00
if (candidate === null) {
return this.leaderVote = null;
}
if (typeof candidate === 'number') {
return this.leaderVote = candidate;
}
this.leaderVote = candidate.id;
2015-07-24 13:34:02 +00:00
};
2015-09-25 21:23:30 +00:00
Gatherer.prototype.voteRegather = function (vote) {
2015-09-17 13:56:50 +00:00
if (vote !== undefined && typeof vote === 'boolean') {
return this.regatherVote = vote;
} else {
this.regatherVote = true;
}
return this.regatherVote;
};
module.exports = Gatherer;