- tools/replay-extract: ValorantReplayParser(MIT, 고정 커밋) → gvr-replay JSON v1 (선수 이동 10Hz · 라운드 · 킬 · 사격 · 스킬/설치물 · 녹화 시작 시각) - 사이트: 경기 화면 '3D 리플레이' 칸 (three.js 지연 로드). 미니맵 바닥 + 실제 높이, 회전 · 확대 · 선수 선택 · 따라가기 · 킬피드 · 자막 · 말하는 사람 표시 - 동기화: 같은 킬의 경기 기록 시각과 리플레이 시각 차이 중앙값 (못 맞추면 라운드 시작) 현장 모드 시계에 묶어 재생 · 멈춤 · 이동 · 배속이 대화와 같이 움직임 - 목 서버 데모(GVR_MOCK_REPLAY), 동기화 테스트 4개 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
3.2 KiB
TypeScript
60 lines
3.2 KiB
TypeScript
// 사이트 3D 리플레이: 리플레이 시간 ↔ 기록 시각 맞추기 · 위치 보간 · 죽음 판정 (site/web/src/lib/replay.ts)
|
|
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { computeSync, isDead, samplePlayer, type ReplayFile } from '../../web/src/lib/replay.ts';
|
|
|
|
const track = (pts: [number, number][]) => ({ t: pts.map((p) => p[0]), x: pts.map((p) => p[1]), y: pts.map(() => 0), z: pts.map(() => 100), yaw: pts.map(() => 350), pitch: pts.map(() => 0) });
|
|
function replay(): ReplayFile {
|
|
return {
|
|
format: 'gvr-replay', v: 1, matchId: 'm1', map: null, build: null, recordedAt: 1_000_000, durationMs: 200_000, sampleMs: 100,
|
|
players: [
|
|
{ puuid: 'a', character: null, track: track([[0, 0], [10_000, 1000], [50_000, 1000]]) },
|
|
{ puuid: 'b', character: null, track: track([[0, 0], [40_000, 500]]) },
|
|
{ puuid: 'c', character: null, track: track([[0, 0], [90_000, 0]]) },
|
|
],
|
|
rounds: [{ num: 1, buy: 0, combat: 30_000, end: 80_000 }, { num: 2, buy: 100_000, combat: 130_000, end: -1 }],
|
|
phases: [], shots: [], objects: [], objectKinds: [],
|
|
kills: [[40_000, 0, 1], [60_000, 2, 0], [140_000, 0, 2]],
|
|
};
|
|
}
|
|
const kill = (id: string, ts: number, killer: string, victim: string) => ({ kind: 'event', id, ts, type: 'kill', data: { killer: { puuid: killer, name: killer }, victim: { puuid: victim, name: victim }, assists: [], weapon: null } });
|
|
|
|
test('킬 시각 차이의 중앙값으로 맞추고, 킬별 오차를 낸다', () => {
|
|
const r = replay();
|
|
// 경기 기록이 리플레이보다 2.5초 늦게 찍혔고, 한 킬은 0.2초 더 늦다
|
|
const m: any = { startedAt: 0, rounds: [], events: [kill('k1', 1_000_000 + 40_000 + 2500, 'a', 'b'), kill('k2', 1_000_000 + 60_000 + 2500, 'c', 'a'), kill('k3', 1_000_000 + 140_000 + 2700, 'a', 'c')] };
|
|
const s = computeSync(m, r);
|
|
assert.equal(s.matched, 3);
|
|
assert.equal(s.offset, 2500);
|
|
assert.equal(s.spreadMs, 200);
|
|
});
|
|
|
|
test('킬을 못 맞추면 라운드 교전 시작(앱이 저장한 라운드 시작 + 30초)으로 맞춘다', () => {
|
|
const r = replay();
|
|
const m: any = { startedAt: 0, events: [], rounds: [{ num: 1, startedAt: 1_000_000 + 30_000 - 30_000 + 4000 }, { num: 2, startedAt: 1_000_000 + 130_000 - 30_000 + 4000 }] };
|
|
const s = computeSync(m, r);
|
|
assert.equal(s.matched, 0);
|
|
assert.equal(s.offset, 4000);
|
|
assert.equal(s.spreadMs, null);
|
|
});
|
|
|
|
test('위치는 앞뒤 표본 사이를 보간하고, 방향은 짧은 쪽으로 돈다', () => {
|
|
const tr = track([[0, 0], [100, 100]]);
|
|
tr.yaw = [350, 10];
|
|
const p = samplePlayer(tr, 50, 600)!;
|
|
assert.equal(p.x, 50);
|
|
assert.equal(p.yaw, 360);
|
|
assert.equal(samplePlayer(tr, -1000, 600), null);
|
|
});
|
|
|
|
test('죽음: 이 라운드에서 죽은 뒤 다시 움직이지 않으면 죽은 상태, 다음 라운드엔 살아남', () => {
|
|
const r = replay();
|
|
assert.equal(isDead(r, 1, 39_000), false);
|
|
assert.equal(isDead(r, 1, 45_000), true);
|
|
// a 는 60초에 죽었지만 기록은 50초까지뿐 → 죽음. 다음 라운드(100초~)에는 다시 산다
|
|
assert.equal(isDead(r, 0, 70_000), true);
|
|
assert.equal(isDead(r, 0, 110_000), false);
|
|
// c 는 60초 킬 뒤에도 90초까지 움직였으므로 140초 킬 전까지 살아 있음
|
|
assert.equal(isDead(r, 2, 120_000), false);
|
|
});
|