120 lines
2.7 KiB
JavaScript
120 lines
2.7 KiB
JavaScript
const io = require('./socketio');
|
|
|
|
let enabled = false;
|
|
let teamA = {
|
|
name: "Team A",
|
|
name2: "",
|
|
score: 0,
|
|
isSpielgemeinschaft: 0,
|
|
};
|
|
let teamB = {
|
|
name: "Team B",
|
|
name2: "",
|
|
score: 0,
|
|
isSpielgemeinschaft: 0,
|
|
};
|
|
let sideswitch = false;
|
|
|
|
// Function prototypes
|
|
function setEnabled(status) {};
|
|
function configTeam(team, name, name2, isSpielgemeinschaft) {};
|
|
function setScore(team, score) {};
|
|
function alterScore(team, dir) {};
|
|
function clearScore() {};
|
|
function toggleSideSwitch() {};
|
|
function getEnabled() {};
|
|
function getValues() {};
|
|
|
|
// Enable or disable the scoreboard
|
|
function setEnabled(status) {
|
|
enabled = status;
|
|
}
|
|
|
|
function configTeam(team, name, name2, isSpielgemeinschaft) {
|
|
if(team == "teamA") {
|
|
teamA.name = name;
|
|
teamA.name2 = name2;
|
|
teamA.isSpielgemeinschaft = isSpielgemeinschaft;
|
|
} else if(team == "teamB") {
|
|
teamB.name = name;
|
|
teamB.name2 = name2;
|
|
teamB.isSpielgemeinschaft = isSpielgemeinschaft;
|
|
}
|
|
}
|
|
|
|
// Set score of team to passed value
|
|
function setScore(team, score) {
|
|
if(team == "teamA") {
|
|
teamA.score = score;
|
|
} else if(team == "teamB") {
|
|
teamB.score = score;
|
|
}
|
|
}
|
|
|
|
// Increment score by one
|
|
function alterScore(team, dir) {
|
|
if(team == "teamA") {
|
|
if(dir == "inc") {
|
|
teamA.score++;
|
|
console.log("teamA inc");
|
|
}
|
|
else if(dir == "dec") {
|
|
teamA.score--;
|
|
console.log("teamA dec");
|
|
}
|
|
} else if(team == "teamB") {
|
|
if(dir == "inc") {
|
|
teamB.score++;
|
|
console.log("teamB inc");
|
|
}
|
|
else if(dir == "dec") {
|
|
teamB.score--;
|
|
console.log("teamB dec");
|
|
}
|
|
}
|
|
io.sockets.emit('score', print());
|
|
}
|
|
|
|
// Clears score of both teams
|
|
function clearScore() {
|
|
teamA.score = 0;
|
|
teamB.score = 0;
|
|
io.sockets.emit('score', print());
|
|
}
|
|
|
|
// Toggle sideswitch
|
|
function toggleSideswitch() {
|
|
console.log("Seiten gewechselt");
|
|
sideswitch = !sideswitch;
|
|
io.sockets.emit('score', print());
|
|
io.sockets.emit('scoreSideswitch', '');
|
|
}
|
|
|
|
// Return enabled value
|
|
function getEnabled() {
|
|
return enabled
|
|
}
|
|
|
|
// Print current score depending on sideswitch
|
|
function print() {
|
|
if(sideswitch) {
|
|
return teamB.score + ":" + teamA.score
|
|
} else {
|
|
return teamA.score + ":" + teamB.score
|
|
}
|
|
}
|
|
|
|
// Return all important values
|
|
function getValues() {
|
|
return {
|
|
enabled: enabled,
|
|
teamA: teamA,
|
|
teamB: teamB,
|
|
sideswitch: sideswitch,
|
|
print: print(),
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
setEnabled, configTeam, setScore, alterScore, clearScore, toggleSideswitch, getEnabled, getValues
|
|
} |