mirror of
https://gitlab.com/Oreolek/salet-module.git
synced 2024-05-06 19:18:31 +03:00
TypeScript definitions by @hogart
Also see here: https://gitlab.com/hogart/salet-ts
This commit is contained in:
parent
153199ee46
commit
f39ad09eba
|
@ -16,13 +16,13 @@ A copy of the MIT license is found in the LICENSE file.
|
||||||
|
|
||||||
## List of contributors
|
## List of contributors
|
||||||
The list is alphabetical.
|
The list is alphabetical.
|
||||||
Hopefully it will grow.
|
|
||||||
|
|
||||||
* Alexander Yakovlev - Salet's original author
|
* Alexander Yakovlev - Salet's original author
|
||||||
* Andrew Plotkin
|
* Andrew Plotkin
|
||||||
* Bruno Dias - Raconteur's original author
|
* Bruno Dias - Raconteur's original author
|
||||||
* David Eyk
|
* David Eyk
|
||||||
* Dmitry Eliseev
|
* Dmitry Eliseev
|
||||||
|
* Konstantin Kitmanov
|
||||||
* Ian Millington - Undum's original author
|
* Ian Millington - Undum's original author
|
||||||
* Ivan Narozhny
|
* Ivan Narozhny
|
||||||
* Juhana Leinonen
|
* Juhana Leinonen
|
||||||
|
|
260
typings/salet/index.d.ts
vendored
Normal file
260
typings/salet/index.d.ts
vendored
Normal file
|
@ -0,0 +1,260 @@
|
||||||
|
type TStringLike = string | (() => string);
|
||||||
|
/** Markdown string */
|
||||||
|
type TMDString = string;
|
||||||
|
type TRoomName = string;
|
||||||
|
type TUnitName = string;
|
||||||
|
type TRoomTag = string;
|
||||||
|
type TActionName = string;
|
||||||
|
type TTimerName = string;
|
||||||
|
type TLink = TRoomName | TActionName | string;
|
||||||
|
|
||||||
|
interface Random {
|
||||||
|
modulo: number;
|
||||||
|
|
||||||
|
randn(): number;
|
||||||
|
randf(): number;
|
||||||
|
rand(n: number): number;
|
||||||
|
randomElement(array: any[]): any;
|
||||||
|
randRange(min: number, max: number): number;
|
||||||
|
dice(n: number, dx: number, plus: number): number;
|
||||||
|
diceString(diceDescription: string): number;
|
||||||
|
odds(value: number, target: number, n: number): number;
|
||||||
|
seed(n: number): void;
|
||||||
|
getSeed(): number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Salet {
|
||||||
|
character: Character;
|
||||||
|
game_id: string;
|
||||||
|
game_version: string;
|
||||||
|
autosave: boolean;
|
||||||
|
rnd: Random;
|
||||||
|
time: number;
|
||||||
|
/** epoch */
|
||||||
|
startTime: number;
|
||||||
|
linkRe: RegExp;
|
||||||
|
current: TRoomName;
|
||||||
|
interactive: boolean;
|
||||||
|
linkStack: TLink[];
|
||||||
|
progress: any; // TODO
|
||||||
|
view: SaletView;
|
||||||
|
start: TRoomName;
|
||||||
|
rooms: any; // TODO
|
||||||
|
timers: any; // TODO
|
||||||
|
|
||||||
|
init() : void;
|
||||||
|
|
||||||
|
enter(from: TRoomName, to: TRoomName): void;
|
||||||
|
afterEnter(from: TRoomName, to: TRoomName): void;
|
||||||
|
|
||||||
|
beforeAction(name: TRoomName, action: TActionName): boolean | void;
|
||||||
|
afterAction(name: TRoomName, action: TActionName): boolean | void;
|
||||||
|
|
||||||
|
exit(from: TRoomName, to: TRoomName): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collects rooms by given tag and filters it by size. Gets called for implicit choice autolists
|
||||||
|
* @param tag
|
||||||
|
* @param length
|
||||||
|
*/
|
||||||
|
getSituationIdChoices(tag: TRoomTag, length: number): SaletRoom[];
|
||||||
|
|
||||||
|
getCurrentRoom(): SaletRoom;
|
||||||
|
/** synonym for getCurrentRoom */
|
||||||
|
here(): SaletRoom;
|
||||||
|
|
||||||
|
getSaveId(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves click timestamp, adds turn to history
|
||||||
|
*/
|
||||||
|
processClick(link: TLink): void;
|
||||||
|
/**
|
||||||
|
* Adds link to execution stack, calls processOneLink, scrolls to new text
|
||||||
|
*/
|
||||||
|
processLink(link: TLink): void;
|
||||||
|
/**
|
||||||
|
* Executes transition
|
||||||
|
*/
|
||||||
|
processOneLink(link: TLink): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Go to room which was visited `n` turns ago
|
||||||
|
* n = 1 is current room
|
||||||
|
* @param [n=2]
|
||||||
|
*/
|
||||||
|
goBack(n: number): void;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @param [force=false]
|
||||||
|
*/
|
||||||
|
doTransitionTo(id: TRoomName, force: boolean): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If `force` is false, shows prompt if user sure to erase save.
|
||||||
|
* Silently erases save otherwise
|
||||||
|
* @param [force = false]
|
||||||
|
*/
|
||||||
|
eraseSave(force: boolean): void;
|
||||||
|
|
||||||
|
getRoomsTagged(tag: TRoomTag): SaletRoom[];
|
||||||
|
|
||||||
|
saveGame(): void;
|
||||||
|
loadGame(saveData: any): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes Salet and starts game. Calls `init` and loads game if there's save and `autoload`
|
||||||
|
* is true.
|
||||||
|
*/
|
||||||
|
beginGame(): void;
|
||||||
|
|
||||||
|
/** synonym for `processClick` */
|
||||||
|
goTo(id: TRoomName): void;
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
isVisited(name: TRoomName): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param action
|
||||||
|
* @param [repeat=false]
|
||||||
|
* @param [step=1]
|
||||||
|
*/
|
||||||
|
addTimer(name: TTimerName, action: TStringLike, repeat: boolean, step: number): void;
|
||||||
|
dropTimer(name: TTimerName): void;
|
||||||
|
resetTimer(name: TTimerName): void;
|
||||||
|
/** system handler, called every turn */
|
||||||
|
checkTimer(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Character {
|
||||||
|
inventory: SaletUnit[];
|
||||||
|
|
||||||
|
take(unit: SaletUnit): void;
|
||||||
|
drop(unitName: TUnitName): boolean;
|
||||||
|
has(unitName: TUnitName): boolean;
|
||||||
|
/** Executes `inv` of that unit */
|
||||||
|
inv(unitName: TUnitName): void;
|
||||||
|
/** Generates unit href */
|
||||||
|
listinv(unitName: TUnitName): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SaletUnitProps {
|
||||||
|
name: TUnitName;
|
||||||
|
|
||||||
|
order?: number;
|
||||||
|
visible?: boolean;
|
||||||
|
takeable?: boolean;
|
||||||
|
display?: TStringLike;
|
||||||
|
take?: TStringLike;
|
||||||
|
act?: TStringLike;
|
||||||
|
dsc?: TStringLike;
|
||||||
|
inv?: TStringLike;
|
||||||
|
location?: TRoomName;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SaletUnit extends SaletUnitProps {
|
||||||
|
put(location: TRoomName): void;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param [location='@location']
|
||||||
|
*/
|
||||||
|
delete(location: TRoomName): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SaletRoomProps {
|
||||||
|
name: TRoomName;
|
||||||
|
|
||||||
|
visited?: number;
|
||||||
|
title?: string;
|
||||||
|
units?: SaletUnit[];
|
||||||
|
canView?: boolean;
|
||||||
|
canChoose?: boolean;
|
||||||
|
priority?: number;
|
||||||
|
displayOrder?: number;
|
||||||
|
canSave?: boolean;
|
||||||
|
ways?: TRoomName[];
|
||||||
|
choices?: Array<TRoomName | TRoomTag>;
|
||||||
|
maxChoices?: number;
|
||||||
|
tags?: TRoomTag[];
|
||||||
|
optionText?: TMDString;
|
||||||
|
dsc?: TMDString;
|
||||||
|
extendSection?: boolean;
|
||||||
|
clear?: boolean;
|
||||||
|
writers?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SaletRoom extends SaletRoomProps {
|
||||||
|
canExit(id: TRoomName): boolean;
|
||||||
|
|
||||||
|
exit(to: TRoomName): void;
|
||||||
|
enter(from: TRoomName): void;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param from
|
||||||
|
* @param [forceExit=true]
|
||||||
|
*/
|
||||||
|
entering(from: TRoomName, forceExit?: boolean): void;
|
||||||
|
take(unit: SaletUnit): void;
|
||||||
|
drop(unit: SaletUnit): void;
|
||||||
|
act(linkTarget: TLink): void;
|
||||||
|
register(): void;
|
||||||
|
link(id: TRoomName): void;
|
||||||
|
bilink(id: TRoomName): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SaletView {
|
||||||
|
init(): void;
|
||||||
|
|
||||||
|
disableSaving(): void;
|
||||||
|
enableSaving(): void;
|
||||||
|
|
||||||
|
disableErasing(): void;
|
||||||
|
enableErasing(): void;
|
||||||
|
|
||||||
|
enableLoading(): void;
|
||||||
|
enableLoading(): void;
|
||||||
|
|
||||||
|
/** Scrolls to `distance` pixels from bottom in 500ms */
|
||||||
|
scrollTopTo(distance: number): void;
|
||||||
|
/** Scrolls to `distance` pixels from page bottom in 500ms */
|
||||||
|
scrollBottomTo(distance: number): void;
|
||||||
|
/** Scrolls page bottom in 500ms */
|
||||||
|
scrollToBottom(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears given block
|
||||||
|
* @param [selector='#content']
|
||||||
|
*/
|
||||||
|
clearContent(selector?: string): void;
|
||||||
|
|
||||||
|
/** Transforms argument into text. Calls it if it's function, for jQuery object gets `.html()` */
|
||||||
|
prepareContent(content: any): string;
|
||||||
|
|
||||||
|
/** Prepares content and appends it to given element
|
||||||
|
* @param content
|
||||||
|
* @param [selector='#content']
|
||||||
|
*/
|
||||||
|
append(content: any, selector: string): void;
|
||||||
|
/** Synonym for append
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* @param [selector='#content']
|
||||||
|
*/
|
||||||
|
write(content: any, selector: string): void;
|
||||||
|
|
||||||
|
/** Same as append, but replaces element's content
|
||||||
|
* @param content
|
||||||
|
* @param [selector='#content']
|
||||||
|
*/
|
||||||
|
replace(content: any, selector: string): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface Window {
|
||||||
|
salet: Salet;
|
||||||
|
room: (name: TRoomName, props: SaletRoomProps) => SaletRoom;
|
||||||
|
unit: (name: TUnitName, props: SaletUnitProps) => SaletUnit;
|
||||||
|
}
|
Loading…
Reference in a new issue