mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
81 lines
1.6 KiB
JavaScript
81 lines
1.6 KiB
JavaScript
import game from "./game.js";
|
|
|
|
class TimeoutManager {
|
|
constructor() {
|
|
this.timeouts = new Map();
|
|
}
|
|
|
|
set(key, callback, delay) {
|
|
const newCallback = () => {
|
|
this.timeouts.delete(key);
|
|
callback();
|
|
}
|
|
|
|
if (this.timeouts.has(key)) clearTimeout(this.timeouts.get(key));
|
|
this.timeouts.set(key, setTimeout(newCallback, delay));
|
|
}
|
|
|
|
clear(key) {
|
|
if (this.timeouts.has(key)) {
|
|
clearTimeout(this.timeouts.get(key));
|
|
this.timeouts.delete(key);
|
|
}
|
|
}
|
|
|
|
clearAll() {
|
|
this.timeouts.forEach(timeout => clearTimeout(timeout));
|
|
this.timeouts = new Map();
|
|
}
|
|
}
|
|
|
|
export const sendPositionTimeouts = {
|
|
timeoutManager: new TimeoutManager(),
|
|
delay: 10, // Minutes
|
|
|
|
set(teamID) {
|
|
const callback = () => {
|
|
game.sendLocation(teamID);
|
|
this.set(teamID);
|
|
}
|
|
|
|
this.timeoutManager.set(teamID, callback, this.delay * 60 * 1000);
|
|
},
|
|
|
|
clear(teamID) {
|
|
this.timeoutManager.clear(teamID);
|
|
},
|
|
|
|
clearAll() {
|
|
this.timeoutManager.clearAll();
|
|
},
|
|
|
|
setDelay(delay) {
|
|
this.delay = delay;
|
|
}
|
|
}
|
|
|
|
export const outOfZoneTimeouts = {
|
|
timeoutManager: new TimeoutManager(),
|
|
delay: 10, // Minutes
|
|
|
|
set(teamID) {
|
|
const callback = () => {
|
|
game.handicapTeam(teamID);
|
|
}
|
|
|
|
this.timeoutManager.set(teamID, callback, this.delay * 60 * 1000);
|
|
},
|
|
|
|
clear(teamID) {
|
|
this.timeoutManager.clear(teamID);
|
|
},
|
|
|
|
clearAll() {
|
|
this.timeoutManager.clearAll();
|
|
},
|
|
|
|
setDelay(delay) {
|
|
this.delay = delay;
|
|
}
|
|
}
|