narraleaf-react
Version:
A React visual novel player framework
98 lines (97 loc) • 3.75 kB
TypeScript
import { LogicAction } from "../action/logicAction";
import { Actionable } from "../action/actionable";
import { Chained, Proxied } from "../action/chain";
import { Sentence, SentencePrompt } from "../elements/character/sentence";
import Actions = LogicAction.Actions;
import { ActionStatements, LambdaHandler } from "./type";
import { Lambda } from "./condition";
export type MenuConfig = {};
export type MenuChoice = {
action: ActionStatements;
prompt: SentencePrompt | Sentence;
config?: {
disabled?: Lambda<boolean> | LambdaHandler<boolean>;
hidden?: Lambda<boolean> | LambdaHandler<boolean>;
};
};
export type Choice = {
action: Actions[];
prompt: Sentence;
config: ChoiceConfig;
};
export type MenuData = {
prompt: Sentence | null;
choices: Choice[];
};
export type ChoiceConfig = {
disabled?: Lambda<boolean>;
hidden?: Lambda<boolean>;
};
export declare class Menu extends Actionable<any, Menu> {
/**
* Create a menu with a prompt
* @param prompt - The prompt to display to the player
* @returns A new menu
*/
static prompt(prompt: SentencePrompt | Sentence | null | undefined, config?: MenuConfig): Menu;
static choose(arg0: Sentence | MenuChoice | SentencePrompt, arg1?: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
constructor(prompt: SentencePrompt, config?: MenuConfig);
constructor(prompt: Sentence, config?: MenuConfig);
constructor(prompt: SentencePrompt | Sentence, config: MenuConfig);
constructor(prompt: null, config?: MenuConfig);
constructor(prompt: SentencePrompt | Sentence | null, config: MenuConfig);
/**
* Add a choice to the menu
* @example
* menu.choose("Go left", [
* character.say("I went left")
* ]);
* @chainable
*/
choose(choice: MenuChoice): Proxied<Menu, Chained<LogicAction.Actions>>;
choose(prompt: Sentence, action: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
choose(prompt: SentencePrompt, action: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
choose(arg0: Sentence | MenuChoice | SentencePrompt, arg1?: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
/**
* Magic method to hide the last choice if the condition is true
* @example
* ```ts
* menu.choose(
* // ...
* ).hideIf(persis.isTrue("flag"));
* ```
*
* **Note**: This method will override the last choice's config.hidden
*/
hideIf(condition: Lambda<boolean> | LambdaHandler<boolean>): Proxied<Menu, Chained<LogicAction.Actions>>;
/**
* Magic method to disable the last choice if the condition is true
* @example
* ```ts
* menu.choose(
* // ...
* ).disableIf(persis.isTrue("flag"));
* ```
*/
disableIf(condition: Lambda<boolean> | LambdaHandler<boolean>): Proxied<Menu, Chained<LogicAction.Actions>>;
/**
* Add a choice, only enable when the condition is true
* @example
* ```ts
* menu.enableWhen(persis.isTrue("flag"), "Go left", [
* character.say("I went left")
* ]);
* ```
*/
enableWhen(condition: Lambda<boolean> | LambdaHandler<boolean>, prompt: Sentence | SentencePrompt, action: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
/**
* Add a choice, only show when the condition is true
* @example
* ```ts
* menu.showWhen(persis.isTrue("flag"), "Go left", [
* character.say("I went left")
* ]);
* ```
*/
showWhen(condition: Lambda<boolean> | LambdaHandler<boolean>, prompt: Sentence | SentencePrompt, action: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
}