added timer dialogue after finish up
This commit is contained in:
77
server.js
77
server.js
@@ -53,6 +53,7 @@ const initialState = {
|
||||
activityLog: [],
|
||||
togetherUsedToday: 0,
|
||||
lastResetDate: new Date().toDateString(),
|
||||
lastWeeklyReset: '',
|
||||
connectedClients: 0
|
||||
};
|
||||
|
||||
@@ -579,6 +580,79 @@ app.get('/api/config', (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Scheduled tasks
|
||||
function scheduleResets() {
|
||||
// Check every minute for reset times
|
||||
setInterval(() => {
|
||||
const now = new Date();
|
||||
const hours = now.getHours();
|
||||
const minutes = now.getMinutes();
|
||||
const day = now.getDay(); // 0 = Sunday, 1 = Monday, etc.
|
||||
|
||||
// Daily reset at 00:01
|
||||
if (hours === 0 && minutes === 1) {
|
||||
// Reset daily limit
|
||||
const today = new Date().toDateString();
|
||||
if (gameState.lastResetDate !== today) {
|
||||
gameState.togetherUsedToday = 0;
|
||||
gameState.lastResetDate = today;
|
||||
addLogEntry('Daily together limit reset automatically');
|
||||
io.emit('stateUpdate', gameState);
|
||||
saveGameState();
|
||||
}
|
||||
}
|
||||
|
||||
// Weekly reset on Monday at 00:01
|
||||
if (day === 1 && hours === 0 && minutes === 1) {
|
||||
// Check if we haven't already reset this week
|
||||
const lastWeeklyReset = gameState.lastWeeklyReset || '';
|
||||
const thisWeek = `${now.getFullYear()}-W${getWeekNumber(now)}`;
|
||||
|
||||
if (lastWeeklyReset !== thisWeek) {
|
||||
// Reset to 5 solo and 4 together
|
||||
gameState.soloPoints = Array(5).fill(null).map((_, i) => ({
|
||||
id: `solo_${Date.now()}_${i}`,
|
||||
type: 'solo',
|
||||
status: 'available',
|
||||
duration: CONFIG.timers.solo,
|
||||
label: '15m'
|
||||
}));
|
||||
|
||||
gameState.togetherPoints = Array(4).fill(null).map((_, i) => ({
|
||||
id: `together_${Date.now()}_${i}`,
|
||||
type: 'together',
|
||||
status: 'available',
|
||||
duration: CONFIG.timers.together,
|
||||
label: '1h'
|
||||
}));
|
||||
|
||||
// Clear custom points and timers
|
||||
gameState.customPoints = [];
|
||||
gameState.activeTimers = {};
|
||||
gameState.pausedTimers = {};
|
||||
gameState.lastWeeklyReset = thisWeek;
|
||||
|
||||
// Clear all timer intervals
|
||||
timerIntervals.forEach((interval) => clearInterval(interval));
|
||||
timerIntervals.clear();
|
||||
|
||||
addLogEntry('Weekly points reset automatically (Monday 00:01)');
|
||||
io.emit('stateUpdate', gameState);
|
||||
saveGameState();
|
||||
}
|
||||
}
|
||||
}, 60000); // Check every minute
|
||||
}
|
||||
|
||||
// Helper function to get week number
|
||||
function getWeekNumber(date) {
|
||||
const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
||||
const dayNum = d.getUTCDay() || 7;
|
||||
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
||||
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
||||
return Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
|
||||
}
|
||||
|
||||
// Start server
|
||||
server.listen(CONFIG.port, () => {
|
||||
console.log(`Point Tracker Server running on port ${CONFIG.port}`);
|
||||
@@ -587,6 +661,9 @@ server.listen(CONFIG.port, () => {
|
||||
// Check day reset on startup
|
||||
checkDayReset();
|
||||
|
||||
// Start scheduled resets
|
||||
scheduleResets();
|
||||
|
||||
// Restore any active timers
|
||||
Object.entries(gameState.activeTimers).forEach(([pointId, timer]) => {
|
||||
const elapsed = Date.now() - timer.startTime;
|
||||
|
Reference in New Issue
Block a user