Added scoreboard functionality, seperate update admin frontend
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
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 setName(team, name) {};
|
||||
function configTeam() {};
|
||||
function setScore(team, score) {};
|
||||
function alterScore(team, dir) {};
|
||||
function clearScore() {};
|
||||
function toggleSwitch() {};
|
||||
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 team name
|
||||
function setName(team, name) {
|
||||
if(team == "teamA") {
|
||||
teamA.name = name;
|
||||
} else if(team == "teamB") {
|
||||
teamB.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 toggleSwitch() {
|
||||
sideswitch = !sideswitch;
|
||||
}
|
||||
|
||||
// Return enabled value
|
||||
function getEnabled() {
|
||||
return enabled
|
||||
}
|
||||
|
||||
function print() {
|
||||
if(sideswitch) {
|
||||
return teamB.score + ":" + teamA.score
|
||||
} else {
|
||||
return teamA.score + ":" + teamB.score
|
||||
}
|
||||
}
|
||||
|
||||
function getValues() {
|
||||
return {
|
||||
enabled: enabled,
|
||||
teamA: teamA,
|
||||
teamB: teamB,
|
||||
sideswitch: sideswitch,
|
||||
print: print(),
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setEnabled, setScore, alterScore, clearScore, getEnabled, getValues
|
||||
}
|
||||
Reference in New Issue
Block a user