feat: allow three cumulative selection timeouts per match
This commit is contained in:
@@ -25,10 +25,14 @@ export function createMatchController(config: ControllerConfig) {
|
||||
const emotes = createEmotes();
|
||||
const view = () => ({ ...engine.view(), appearances: config.activeMatch.appearances, emotes: emotes.view(clock.now() + offset) });
|
||||
let timer: any, destroyed = false, started = false, recording = false;
|
||||
function publish() {
|
||||
function saveCheckpoint() {
|
||||
if (destroyed) return;
|
||||
const checkpoint: ControllerCheckpoint = { gameSessionId: config.gameSessionId, activeMatch: config.activeMatch, checkpoint: engine.checkpoint(), epoch: 0, ...friend?.snapshot() };
|
||||
config.storage.setItem(GAME_CHECKPOINT_KEY, JSON.stringify(checkpoint));
|
||||
}
|
||||
function publish() {
|
||||
if (destroyed) return;
|
||||
saveCheckpoint();
|
||||
for (const listener of listeners) listener(view());
|
||||
}
|
||||
async function record() {
|
||||
@@ -67,7 +71,7 @@ export function createMatchController(config: ControllerConfig) {
|
||||
if (config.activeMatch.mode === 'friend') {
|
||||
if (!config.peer) throw new Error('PEER_REQUIRED');
|
||||
friend = createFriendMatch({ matchId: config.activeMatch.matchId, slot: config.selfIndex, engine, peer: config.peer, clock,
|
||||
setOffset: value => { offset = value; }, changed: publish, finished: () => { void record(); }, saved,
|
||||
setOffset: value => { offset = value; }, changed: publish, checkpointChanged: saveCheckpoint, finished: () => { void record(); }, saved,
|
||||
onEmote: (id, variant) => { if (emotes.send(config.selfIndex === 0 ? 1 : 0, id, clock.now() + offset, variant)) publish(); } });
|
||||
await friend.start(); return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user