3D 리플레이 자동 시점 · Tab 점수판: 카메라 "자동"(교전 직전에 이긴 선수 1인칭, 직전 우리 팀 콜이 있으면 그 말부터 · 설치/해체 · 혼자 남은 선수 · 교전이 없으면 살아 있는 선수가 다 보이게 위에서) · Tab 을 누르고 있으면 게임처럼 팀 점수 · 궁극기 · K/D/A · 주무기 · 크레딧 · 변환기 scoreboard (크레딧 · 궁 점수 · 킬/데스/어시 · 전투 점수, BasicCombatStats · PlayerScore 하위 객체 읽기) · self-test · 테스트

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-08 22:46:54 +09:00
parent c539c2b9dc
commit c36db3ef9a
11 changed files with 1020 additions and 27 deletions

View File

@@ -0,0 +1,132 @@
// 사이트 3D 리플레이: 자동 시점(관전) 장면 나누기 · 점수판 (site/web/src/lib/director.ts · scoreboard.ts)
import { test } from 'node:test';
import assert from 'node:assert/strict';
import type { ReplayFile } from '../../web/src/lib/replay.ts';
import { buildDirector, shotIndexAt, FIGHT_LEAD, type Shot } from '../../web/src/lib/director.ts';
import { boardAt, boardIndex, loadoutAt, teamScoreAt } from '../../web/src/lib/scoreboard.ts';
// 선수 0·1·4 아군, 2·3·5 상대. 라운드 1: 구매 0~30초, 교전 30초~, 끝 90초. 라운드 2: 100초~
const still = (n = 2000) => {
const t = Array.from({ length: n }, (_, i) => i * 100);
return { t, x: t.map(() => 0), y: t.map(() => 0), z: t.map(() => 100), yaw: t.map(() => 0), pitch: t.map(() => 0) };
};
function replay(extra: Partial<ReplayFile> = {}): ReplayFile {
return {
format: 'gvr-replay', v: 2, matchId: 'm1', map: null, build: null, recordedAt: 0, durationMs: 200_000, sampleMs: 100,
players: [0, 1, 2, 3, 4, 5].map((i) => ({ puuid: `p${i}`, character: i === 1 ? 'Phoenix_PC_C' : 'Wushu_PC_C', track: still() })),
rounds: [{ num: 1, buy: 0, combat: 30_000, end: 90_000 }, { num: 2, buy: 100_000, combat: 130_000, end: -1 }],
phases: [], shots: [], objects: [], objectKinds: [], kills: [], hits: [],
...extra,
};
}
const ally = [true, true, false, false, true, false];
const at = (shots: Shot[], t: number) => shots[shotIndexAt(shots, t)];
const hit = (t: number, a: number, v: number, killed = 0) => [t, a, v, 0, 0, 0, 0, 0, 0, 2, killed];
test('교전: 킬 시각에는 이긴(죽인) 선수 1인칭, 교전 시작보다 먼저 넘어간다', () => {
const r = replay({ kills: [[40_000, 0, 2, -1]], hits: [hit(38_000, 2, 0), hit(39_000, 0, 2), hit(40_000, 0, 2, 1)] });
const shots = buildDirector({ replay: r, ally, talks: [] });
const s = at(shots, 40_000);
assert.equal(s.kind, 'fight');
assert.equal(s.pov, 0);
// 둘 사이 첫 맞은 기록(38초)보다 FIGHT_LEAD 앞에서 시작
assert.ok(s.t0 <= 38_000 - FIGHT_LEAD, `시작 ${s.t0}`);
// 교전이 없을 때: 구매 단계 · 전략 보기는 위에서
assert.equal(at(shots, 10_000).kind, 'buy');
assert.equal(at(shots, 10_000).pov, null);
assert.equal(at(shots, 70_000).kind, 'overview');
assert.equal(at(shots, 70_000).pov, null);
assert.equal(at(shots, 95_000).kind, 'post');
// 빈틈 · 겹침 없이 처음부터 끝까지
assert.equal(shots[0].t0, 0);
assert.equal(shots[shots.length - 1].t1, r.durationMs);
for (let i = 1; i < shots.length; i++) assert.equal(shots[i].t0, shots[i - 1].t1);
});
test('교전 직전 우리 팀 콜이 있으면 그 말부터 보여 주고 콜 글을 단다', () => {
const r = replay({ kills: [[40_000, 2, 0, -1]], hits: [hit(38_000, 2, 0), hit(40_000, 2, 0, 1)] });
const shots = buildDirector({ replay: r, ally, talks: [{ t0: 33_000, t1: 34_500, text: '비 메인 두 명' }] });
const s = at(shots, 40_000);
// 상대가 이겼으면 상대 시점
assert.equal(s.pov, 2);
assert.equal(s.call, '비 메인 두 명');
assert.ok(s.t0 <= 33_000 && s.t0 >= 32_000, `시작 ${s.t0}`);
// 교전과 먼 대화는 콜로 보지 않는다
const far = buildDirector({ replay: r, ally, talks: [{ t0: 20_000, t1: 21_000, text: '사러 가자' }] });
assert.equal(at(far, 40_000).call, undefined);
});
test('같은 선수가 이어서 죽이면 한 장면 · 거의 동시에 맞바꾼 킬은 넘어가지 않는다 · 짧은 장면 없음', () => {
const r = replay({
kills: [[40_000, 0, 2, -1], [42_000, 0, 3, -1], [60_000, 1, 2, -1], [60_300, 3, 1, -1]],
hits: [hit(39_500, 0, 2, 1), hit(41_800, 0, 3, 1), hit(59_000, 1, 2), hit(60_200, 3, 1)],
});
const shots = buildDirector({ replay: r, ally, talks: [] });
const multi = at(shots, 41_000);
assert.equal(multi.pov, 0);
assert.equal(multi.kills, 2);
assert.equal(at(shots, 42_000), multi);
// 0.3초 뒤 맞킬: 앞 킬을 보여 주던 선수 시점 그대로
assert.equal(at(shots, 60_300).pov, 1);
for (const s of shots) if (s.pov != null) assert.ok(s.t1 - s.t0 >= 900, `짧은 1인칭 ${s.t0}~${s.t1}`);
});
test('스파이크 설치 · 해체는 하는 선수 시점, 혼자 남은 선수는 그 선수 시점', () => {
const r = replay({
actions: [[50_000, 54_000, 3, 0]],
actionKinds: ['Plant'],
kills: [[60_000, 2, 0, -1], [62_000, 3, 4, -1]],
hits: [hit(59_000, 2, 0, 1), hit(61_500, 3, 4, 1)],
});
const shots = buildDirector({ replay: r, ally, talks: [] });
assert.equal(at(shots, 52_000).kind, 'plant');
assert.equal(at(shots, 52_000).pov, 3);
// 60초에 0 이 죽고, 62초에 4 가 죽어 아군은 1 혼자
const c = at(shots, 75_000);
assert.equal(c.kind, 'clutch');
assert.equal(c.pov, 1);
});
test('점수판: 궁극기 점수는 쓴 기록에서 · 공수 교대 초기화는 쓴 것이 아니다 · 안 온 숫자는 0', () => {
// [t, 선수, 크레딧, 궁, 킬, 데스, 어시, 점수]
const sb = [
[1000, 0, 800, -1, -1, -1, -1, -1],
[1000, 1, 800, -1, -1, -1, -1, -1],
[20_000, 1, 800, 7, -1, -1, -1, -1],
[25_000, 1, 800, 0, -1, -1, -1, -1], // 1 이 궁을 씀 (7점)
[40_000, 0, 3900, 5, 2, 1, 1, 400],
[41_000, 1, 2000, 3, -1, -1, -1, -1],
[42_000, 2, 800, 2, -1, -1, -1, -1],
[42_000, 3, 800, 1, -1, -1, -1, -1],
// 공수 교대: 모두 0
[95_000, 0, 800, 0, 2, 1, 1, 400],
[95_000, 1, 800, 0, -1, -1, -1, -1],
[95_100, 2, 800, 0, -1, -1, -1, -1],
[95_100, 3, 800, 0, -1, -1, -1, -1],
];
const r = replay({ scoreboard: sb, kills: [[40_000, 0, 2, -1]], equips: [[31_000, 0, 0], [32_000, 0, 1], [33_000, 0, 2]], equipKinds: ['Classic', 'Vandal', 'Melee'] });
const ix = boardIndex(r);
assert.equal(ix.has, true);
assert.equal(ix.ultMax[1], 7); // 쓴 기록 (요원 표와 상관없이)
assert.equal(ix.ultMax[0], 8); // 쓴 기록 없음: 요원 표 (제트 8)
const b = boardAt(r, ix, 0, 50_000);
assert.deepEqual([b.money, b.ult, b.kills, b.deaths, b.assists, b.score, b.weapon], [3900, 5, 2, 1, 1, 400, 'Vandal']);
// 아직 안 온 킬 · 어시는 0, 크레딧은 처음 값
const b1 = boardAt(r, ix, 1, 50_000);
assert.deepEqual([b1.money, b1.ult, b1.kills, b1.assists], [2000, 3, 0, 0]);
// 주무기는 라운드마다: 다음 라운드에는 아직 없음
assert.equal(loadoutAt(r, 0, 120_000), null);
// 죽은 선수 (시험 이동 기록은 죽은 뒤에도 표본이 있어 죽은 직후로 본다)
assert.equal(boardAt(r, ix, 2, 41_000).dead, true);
});
test('점수판: 예전 리플레이(값 없음)는 킬 · 데스를 킬 기록으로 세고 나머지는 비운다 · 팀 점수는 그 라운드 전까지', () => {
const r = replay({ kills: [[40_000, 0, 2, -1], [50_000, 3, 0, -1]] });
const ix = boardIndex(r);
assert.equal(ix.has, false);
const b = boardAt(r, ix, 0, 60_000);
assert.deepEqual([b.kills, b.deaths, b.money, b.ult, b.assists], [1, 1, null, null, null]);
const rounds = [{ num: 1, score: { ally: 1, enemy: 0 } }, { num: 2, score: { ally: 1, enemy: 1 } }];
assert.deepEqual(teamScoreAt(r, rounds, 50_000), { round: 1, ally: 0, enemy: 0 });
assert.deepEqual(teamScoreAt(r, rounds, 150_000), { round: 2, ally: 1, enemy: 0 });
});