refacto: Changing actions reset windows + display
This commit is contained in:
+2
-2
@@ -170,8 +170,8 @@
|
||||
<code class="infoVal" id="worldSeedDisplay">—</code>
|
||||
</div>
|
||||
<div class="infoRow">
|
||||
<span class="infoKey muted">Prochaine graine (UTC)</span>
|
||||
<code class="infoVal" id="nextPeriodUtc">—</code>
|
||||
<span class="infoKey muted">Réinitialisation des actions dans</span>
|
||||
<code class="infoVal" id="actionsResetCountdown">--:--:--</code>
|
||||
</div>
|
||||
<div class="infoRow">
|
||||
<span class="infoKey muted">Prochaine graine dans</span>
|
||||
|
||||
+29
-4
@@ -22,6 +22,7 @@ const COLOR_OPPONENT_GREY = "rgba(95, 98, 110, 0.72)";
|
||||
|
||||
export const GAME_CONFIG = {
|
||||
dailyActionQuota: 100,
|
||||
actionsResetIntervalHours: 12,
|
||||
databaseWipeoutIntervalSeconds: 21600,
|
||||
configReloadIntervalSeconds: 30,
|
||||
worldSeed: "",
|
||||
@@ -203,7 +204,7 @@ const countdownEl = document.getElementById("countdown");
|
||||
const countdownWrap = document.getElementById("countdownWrap");
|
||||
const cooldownCfgEl = document.getElementById("cooldownConfig");
|
||||
const seedDisplayEl = document.getElementById("worldSeedDisplay");
|
||||
const nextPeriodEl = document.getElementById("nextPeriodUtc");
|
||||
const actionsResetCountdownEl = document.getElementById("actionsResetCountdown");
|
||||
const resetCountEl = document.getElementById("refreshCountdown");
|
||||
const vpBlueEl = document.getElementById("vpBlue");
|
||||
const vpRedEl = document.getElementById("vpRed");
|
||||
@@ -263,6 +264,9 @@ export function isOwnTile(key) { const m = cellMeta(key); return m !== nul
|
||||
|
||||
export function applyConfigPayload(data) {
|
||||
GAME_CONFIG.dailyActionQuota = Number(data.dailyActionQuota) || 100;
|
||||
if (data.actionsResetIntervalHours) {
|
||||
GAME_CONFIG.actionsResetIntervalHours = Number(data.actionsResetIntervalHours) || 12;
|
||||
}
|
||||
GAME_CONFIG.databaseWipeoutIntervalSeconds = Number(data.databaseWipeoutIntervalSeconds) || 21600;
|
||||
GAME_CONFIG.configReloadIntervalSeconds = Math.max(5, Number(data.configReloadIntervalSeconds) || 30);
|
||||
GAME_CONFIG.worldSeed = String(data.worldSeed ?? "");
|
||||
@@ -287,11 +291,9 @@ export function applyConfigPayload(data) {
|
||||
|
||||
cooldownCfgEl.textContent = String(GAME_CONFIG.dailyActionQuota);
|
||||
seedDisplayEl.textContent = GAME_CONFIG.worldSeed || "—";
|
||||
nextPeriodEl.textContent = GAME_CONFIG.seedPeriodEndsAtUtc
|
||||
? new Date(GAME_CONFIG.seedPeriodEndsAtUtc).toISOString().replace("T", " ").slice(0, 19) + "Z"
|
||||
: "—";
|
||||
|
||||
updateResetCountdown();
|
||||
updateActionsResetCountdown();
|
||||
|
||||
}
|
||||
|
||||
@@ -311,6 +313,29 @@ export function updateResetCountdown() {
|
||||
String(ss).padStart(2, "0");
|
||||
}
|
||||
|
||||
/** Computes time until next actions-reset based on the configured interval and updates the display. */
|
||||
export function updateActionsResetCountdown() {
|
||||
if (!actionsResetCountdownEl) return;
|
||||
const intervalHours = GAME_CONFIG.actionsResetIntervalHours ?? 12;
|
||||
const now = Date.now();
|
||||
const date = new Date(now);
|
||||
const utcHours = date.getUTCHours();
|
||||
const slotsPassed = Math.floor(utcHours / intervalHours);
|
||||
const nextSlotHour = (slotsPassed + 1) * intervalHours;
|
||||
const next = nextSlotHour < 24
|
||||
? Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), nextSlotHour, 0, 0, 0)
|
||||
: Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() + 1, 0, 0, 0, 0);
|
||||
const diff = next - now;
|
||||
const s = Math.floor(diff / 1000);
|
||||
const hh = Math.floor(s / 3600);
|
||||
const mm = Math.floor((s % 3600) / 60);
|
||||
const ss = s % 60;
|
||||
actionsResetCountdownEl.textContent =
|
||||
String(hh).padStart(2, "0") + ":" +
|
||||
String(mm).padStart(2, "0") + ":" +
|
||||
String(ss).padStart(2, "0");
|
||||
}
|
||||
|
||||
|
||||
// ── Scores ────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
+3
-1
@@ -2,6 +2,7 @@ import {
|
||||
GAME_CONFIG,
|
||||
seedStr,
|
||||
updateResetCountdown,
|
||||
updateActionsResetCountdown,
|
||||
fetchConfig,
|
||||
fetchGridForSeed,
|
||||
fetchAndApplyActivePlayers,
|
||||
@@ -221,8 +222,9 @@ async function boot() {
|
||||
draw();
|
||||
|
||||
if (resetTimer) clearInterval(resetTimer);
|
||||
resetTimer = setInterval(updateResetCountdown, 1_000);
|
||||
resetTimer = setInterval(() => { updateResetCountdown(); updateActionsResetCountdown(); }, 1_000);
|
||||
updateResetCountdown();
|
||||
updateActionsResetCountdown();
|
||||
|
||||
startRealtimeFlow();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user