aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/lib/stores/editor_state.ts
blob: c0462e1fc65a2b1cac3207174bb8ed6760623c8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { writable } from "svelte/store";

const MAX_MATCHES = 100;

function createMatchHistory() {
  const { subscribe, update } = writable([]);

  function pushMatch(match: object) {
    update((matches) => {
      if (matches.length == MAX_MATCHES) {
        matches.pop();
      }
      matches.unshift(match);

      return matches;
    });
  }

  return {
    subscribe,
    pushMatch,
  };
}

export const matchHistory = createMatchHistory();
export const selectedOpponent = writable(null);
export const selectedMap = writable(null);