Harden gameplay timing and map loading

This commit is contained in:
2026-10-05 15:15:35 +05:00
parent 8b31891776
commit dcc3779262
36 changed files with 1050 additions and 205 deletions

20
tests/round-clock.test.ts Normal file
View File

@@ -0,0 +1,20 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { roundClock } from "../shared/round-clock";
test("round timer accounts for return latency and stops at the server deadline", () => {
const clock = roundClock(100000, 1000, 5000);
const deadline = new Date(105000).toISOString();
assert.equal(clock.remaining(deadline, 5000), 3);
assert.equal(clock.remaining(deadline, 7001), 1);
assert.equal(clock.remaining(deadline, 8000), 0);
assert.equal(clock.remaining(deadline, 9000), 0);
});
test("round timer relies on elapsed time even if the device wall clock changes", (t) => {
const clock = roundClock(100000, 1000, 1000);
t.mock.method(Date, "now", () => -10000000);
assert.equal(clock.remaining(new Date(110000).toISOString(), 5000), 6);
t.mock.method(Date, "now", () => 10000000);
assert.equal(clock.remaining(new Date(110000).toISOString(), 11000), 0);
});