import {Character, CharacterSide, SPType} from "./Character"; import {Clock} from "./Clock"; export interface SessionState { readonly usedSp: {readonly [key in SPType]?: number} } export interface ConflictState { readonly round: number readonly activeSide: CharacterSide readonly activeCharacterId: string|null } export enum TimerDirection { Countup = "up", Countdown = "down", Stopped = "stop" } export interface BaseTimerState { readonly type: TimerDirection readonly id: string readonly text: string readonly order?: number } export interface StoppedTimerState extends BaseTimerState { readonly time: number } export interface CountupTimerState extends BaseTimerState { readonly type: TimerDirection.Countup readonly timeStartAt: number } export interface CountdownTimerState extends BaseTimerState { readonly type: TimerDirection.Countdown readonly timeEndAt: number readonly timeStartAt: number|null } export type TimerState = CountupTimerState|CountdownTimerState|StoppedTimerState; export interface StatusEffect { readonly id: string readonly name: string readonly description: string readonly iconUrl: string } export interface GameState { readonly session: SessionState readonly conflict?: ConflictState readonly clocks: readonly Clock[] readonly characters: readonly Character[] readonly statuses: readonly StatusEffect[] readonly timers: readonly TimerState[] } export interface BaseIdentifierLookupResult { readonly type: string } export interface NullLookupResult extends BaseIdentifierLookupResult { readonly type: "null" } export interface ClockLookupResult extends BaseIdentifierLookupResult { readonly type: "clock" readonly clock: Clock } export interface CharacterLookupResult extends BaseIdentifierLookupResult { readonly type: "character" readonly character: Character } export interface StatusLookupResult extends BaseIdentifierLookupResult { readonly type: "status" readonly status: StatusEffect } export interface TimerLookupResult extends BaseIdentifierLookupResult { readonly type: "timer" readonly timer: TimerState } export type IdentifierLookupResult = NullLookupResult|ClockLookupResult|CharacterLookupResult|StatusLookupResult|TimerLookupResult export function lookupIdentifier(state: GameState, identifier: string): IdentifierLookupResult { const character = state.characters.find((c) => c.id === identifier) if (character) { return {type: "character", character} } const clock = state.clocks.find((c) => c.id === identifier) if (clock) { return {type: "clock", clock} } const status = state.statuses.find((s) => s.id === identifier) if (status) { return {type: "status", status} } const timer = state.timers.find((t) => t.id === identifier) if (timer) { return {type: "timer", timer} } return {type: "null"} }