Split The code is public; the app answers only to the crew.

A resumed match comes back on the map it was played on: `restoreWorld` reads the save, not a default #170

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/cs:scout/161-a-resumed-match-comes-back-on-the-map-it → main 1 commit fork

  • Merged. scout/161-a-resumed-match-comes-back-on-the-map-it was merged into main as 246ba57.

Review

Sign in to review this change.
2 files changed +11 −3
src/client/world.test.ts +9
@@ -693,6 +693,15 @@ test("a restored round leaves bot money alone", () => {
693693 for (const p of restored.players) if (p.bot) expect(p.money).toBe(5000);
694694 });
695695
696 test("restoreWorld builds on the map the snapshot was played on, not the default", () => {
697 const world = createWorld(SHORT, "me", "ct", 5, 401, "normal", MAPS.de_cinder);
698 const saved = snapshot(world, crypto.randomUUID());
699 const restored = restoreWorld(saved);
700 expect(restored).not.toBeNull();
701 if (restored === null) return;
702 expect(restored.map.name).toBe("de_cinder");
703 });
704
696705 test("a snapshot whose player count does not match the team size is refused before it can build half a world", () => {
697706 const world = createWorld(SHORT, "me", "ct", 5, 501);
698707 const saved = snapshot(world, crypto.randomUUID());
src/client/world.ts +2 −3
@@ -14,7 +14,7 @@ import {
1414 blastDamage, GRENADE, step as stepGrenade, thrown, type Grenade,
1515 } from "./grenades.ts";
1616 import { pose, remember, rememberPos, type Pose } from "./interpolate.ts";
17 import { DE_FORGE, siteAt, type MapDef } from "./map.ts";
17 import { DE_FORGE, MAPS, siteAt, type MapDef } from "./map.ts";
1818 export { DEFAULT_MAP, MAP_NAMES, mapFor } from "./map.ts";
1919 import { angleVectors, angleDelta, clamp, dist, dist2d, normalize, rng, sub, type Vec3 } from "./math.ts";
2020 import * as rules from "./match.ts";
@@ -333,13 +333,12 @@ const RESTORE_TEAM_SIZE = 5;
333333 export function restoreWorld(
334334 save: Saved,
335335 difficulty: Difficulty = DEFAULT_DIFFICULTY,
336 map: MapDef = DE_FORGE,
337336 ): World | null {
338337 if (save.players.length !== RESTORE_TEAM_SIZE * 2) return null;
339338 if (save.score.t >= save.rules.winScore || save.score.ct >= save.rules.winScore) return null;
340339 const pastHalf = save.round > rules.halfTime(save.rules);
341340 const startTeam = pastHalf ? rules.other(save.playerTeam) : save.playerTeam;
342 const world = buildWorld(save.rules, save.name, startTeam, RESTORE_TEAM_SIZE, save.seed, difficulty, map);
341 const world = buildWorld(save.rules, save.name, startTeam, RESTORE_TEAM_SIZE, save.seed, difficulty, MAPS[save.map]);
343342 world.match.round = save.round;
344343 world.match.score = { ...save.score };
345344 world.match.losses = { ...save.losses };

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs