UNPKG

@kitten-science/kitten-analysts

Version:
128 lines 4.44 kB
import type { GamePage } from "@kitten-science/kitten-scientists/types/game.js"; import { type I18nEngine, type KGNetSavePersisted, type TabId } from "@kitten-science/kitten-scientists/types/index.js"; declare global { interface Window { kittenAnalysts?: KittenAnalysts; } } export type KittenAnalystsMessageId = "connected" | "getBuildings" | "getCalendar" | "getPollution" | "getRaces" | "getResourcePool" | "getStatistics" | "getTechnologies" | "injectSavegame" | "reportFrame" | "reportSavegame"; export type PayloadBuildings = Array<{ group: string; label: string; name: string; on: number; tab: TabId; value: number; }>; export type PayloadCalendar = Array<{ cryptoPrice: number; cycle: number; cycleYear: number; day: number; eventChance: number; festivalDays: number; futureSeasonTemporalParadox: number; season: number; seasonsPerYear: number; year: number; yearsPerCycle: number; }>; export type PayloadPollution = Array<{ label: string; name: string; pollution: number; }>; export type PayloadRaces = Array<{ embassyLevel: number; energy: number; name: string; standing: number; title: string; unlocked: boolean; }>; export type PayloadResources = Array<{ craftable: boolean; label: string; maxValue: number; name: string; rate: number; value: number; }>; export type PayloadStatistics = Array<{ label: string; name: string; type: "all_time" | "current"; value: number; }>; export type PayloadTechnologies = Array<{ label: string; name: string; researched: boolean; tab: TabId; unlocked: boolean; }>; export interface KittenAnalystsMessage<TMessage extends KittenAnalystsMessageId, TData = TMessage extends "getBuildings" ? PayloadBuildings : TMessage extends "getCalendar" ? PayloadCalendar : TMessage extends "getPollution" ? PayloadPollution : TMessage extends "getRaces" ? PayloadRaces : TMessage extends "getResourcePool" ? PayloadResources : TMessage extends "getStatistics" ? PayloadStatistics : TMessage extends "getTechnologies" ? PayloadTechnologies : TMessage extends "reportFrame" ? unknown : TMessage extends "reportSavegame" ? unknown : TMessage extends "injectSavegame" ? KGNetSavePersisted : never> { /** * The payload of the message. */ data?: TData; client_type: "backend" | "browser" | "headless"; /** * The HTTP URL that identifies the context of the client that sent the message. */ location: string; /** * The telemetry guid of the client that sent the message. */ guid: string; /** * If the message requires a response, it should declare a `responseId`, which the receiver * will also put on the response. */ responseId?: string; /** * The type identifier for the message. */ type: TMessage; } export declare class KittenAnalysts { #private; /** * A reference to the Kittens Game. */ readonly game: GamePage; /** * The websocket we're using to talk to the backend. */ ws: WebSocket | null; /** * A function in the game that allows to retrieve translated messages. * * Ideally, you should never access this directly and instead use the * i18n interface provided by `Engine`. */ readonly i18nEngine: I18nEngine; readonly location: string; constructor(game: GamePage, i18nEngine: I18nEngine); /** * Start the user script after loading and configuring it. */ run(): void; /** * Connect the Kitten Analysts to all systems. * @param withAnalyticsBackend Should the Kitten Analysts report information to the * Kitten DnA backend? Because this only makes sense in a strict development environment, * this should usually be kept disabled for most users. * @returns Nothing */ connect(withAnalyticsBackend: boolean): void; processMessage(message: KittenAnalystsMessage<KittenAnalystsMessageId>): KittenAnalystsMessage<KittenAnalystsMessageId> | undefined; reportFrameListener: (event: Event) => void; reportSavegameListener: (event: Event) => void; heartbeat(): void; reconnect(): void; postMessage<TMessage extends KittenAnalystsMessageId>(message: KittenAnalystsMessage<TMessage>): void; start(): void; stop(): void; } //# sourceMappingURL=KittenAnalysts.d.ts.map