Open-source interactive fiction engine, powered by React, Redux and TypeScript. _ https://discoteque.pub/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

87 lines
2.3 KiB

import { Dispatch, Reducer } from "redux";
export interface ILineOption<ST = object> {
text: string;
value: string;
skill?: { name: string, difficulty: number, failTo: string }
onPick?: (state: ST, dispatch: Dispatch<any>) => void;
}
export interface ILineRaw<ST, MT = undefined> {
actorId?: string;
text: string;
options?: ILineOption<ST>[];
meta?: MT;
time?: number;
}
export type LineFn<ST = any, MT = undefined, SST extends string = string, CF = EngineConfig<ST, MT, SST>> =
(engineState: EngineState<ST, MT, SST>, gameState: ST, gameDispatch: Dispatch<any>, config: CF) =>
ILineRaw<ST, MT> | null | void;
export type BuiltinNodeKind = 'node' | 'actor' | 'location';
export interface INode<GS = object, MT = undefined, KT = BuiltinNodeKind> {
id: string;
image?: string;
kind: KT;
lines: Array<ILineRaw<GS, MT> | LineFn<GS, MT>>;
next?: string;
name?: string;
meta?: MT,
}
export interface IActor<GS = object, MT = undefined> extends INode<GS, MT, 'actor'> {
name: string;
}
export interface ILocation<GS = object, MT = undefined> extends INode<GS, MT, 'location'> {
name: string;
}
export interface ILine<GS = object, MT = undefined> extends ILineRaw<GS, MT> {
actor: IActor<GS, MT> | null,
}
export type Node<GS = object, MT = undefined, KT = BuiltinNodeKind> = INode<GS, MT, KT> | IActor<GS, MT> | ILocation<GS, MT>;
export type Chrono = {
time: number;
date?: string;
}
export type DayCycleFn = (chrono: Chrono) => Chrono;
export type EngineConfig<GS = object, MT = undefined, ST extends string = string, KT = BuiltinNodeKind> = {
nodes: Node<GS, MT, KT>[];
skills: SkillSet<ST>;
skillPointsOnStart: number;
startNode: string;
chrono?: Chrono;
onDayCycle?: DayCycleFn;
skillDescriptoins?: Record<ST, string>;
reducer: Reducer,
}
export type NodeMap<GS = object, MT = undefined, KT = BuiltinNodeKind> = Record<string, Node<GS, MT, KT>>;
export type EngineState<GS = object, MT = undefined, ST extends string = string, KT = BuiltinNodeKind> = {
nodeMap: NodeMap<GS, MT, KT>,
line: number;
node: string;
location?: string;
protectSkills: boolean;
backlog: ILine<GS, MT>[];
chrono?: Chrono;
skills: SkillSet<ST>
skillPoints: number;
ui: {
isOver: boolean;
skillsOpen: boolean;
menuOpen: boolean;
}
}
export type SkillSet<IT extends string> = Record<IT, number>;