narraleaf-react
Version:
A React visual novel player framework
103 lines (102 loc) • 3.77 kB
TypeScript
import { Actionable } from "../action/actionable";
import { BooleanValueKeyOf, StringKeyOf } from "../../../util/data";
import { Lambda } from "../elements/condition";
import { Word } from "../elements/character/word";
import { DynamicWord, DynamicWordResult } from "../elements/character/sentence";
import { LambdaHandler } from "../elements/type";
export declare class Persistent<T extends PersistentContent> extends Actionable<null> {
constructor(namespace: string, defaultContent: T);
/**
* Create an action to set a value in the persistent storage for the given key
* @chainable
* @param key - The key to set the value for
* @param value - The value to set
* @returns A chainable persistent action
*/
set<K extends StringKeyOf<T>>(key: K, value: T[K]): ChainedPersistent<T>;
set<K extends StringKeyOf<T>>(key: K, handler: (value: T[K]) => T[K]): ChainedPersistent<T>;
/**
* Create an action to assign a value to the persistent storage
* @chainable
* @param value - The value to assign
* @returns A chainable persistent action
*/
assign(value: Partial<T> | ((value: T) => Partial<T>)): ChainedPersistent<T>;
/**
* Determine whether the values are equal, can be used in {@link Condition}
* @example
* ```typescript
* persis.equals("id", persis.get("player_id"));
*
* // or
*
* persis.equals("id", (ctx) => ctx.storable.getNamespace("player").get("player_id"));
* ```
*/
equals<K extends StringKeyOf<T>>(key: K, value: T[K] | Lambda<T[K]> | LambdaHandler<T[K]>): Lambda<boolean>;
/**
* Determine whether the values aren't equal, can be used in {@link Condition}
* @example
* ```typescript
* persis.notEquals("id", persis.get("player_id"));
*
* // or
*
* persis.notEquals("id", (ctx) => ctx.storable.getNamespace("player").get("player_id"));
* ```
*/
notEquals<K extends StringKeyOf<T>>(key: K, value: T[K] | Lambda<T[K]> | LambdaHandler<T[K]>): Lambda<boolean>;
/**
* Determine whether the value is true, can be used in {@link Condition}
*/
isTrue<K extends Extract<keyof T, BooleanValueKeyOf<T>>>(key: K): Lambda<boolean>;
/**
* Determine whether the value is false, can be used in {@link Condition}
*/
isFalse<K extends Extract<keyof T, BooleanValueKeyOf<T>>>(key: K): Lambda<boolean>;
/**
* Determine whether the value isn't null or undefined, can be used in {@link Condition}
*/
isNotNull<K extends StringKeyOf<T>>(key: K): Lambda<boolean>;
/**
* Convert to a dynamic word
* @example
* ```typescript
* character.say(["You have ", persis.toWord("gold"), " gold"]);
*
* // or
*
* character.say`You have ${persis.toWord("gold")} gold`;
* ```
*/
toWord<K extends StringKeyOf<T>>(key: K): Word<DynamicWord>;
/**
* Alias of {@link toWord}
*/
get<K extends StringKeyOf<T>>(key: K): Word<DynamicWord>;
/**
* Create a conditional word
*
* @example
* ```typescript
* character.say([
* "Your flag is ",
* persis.conditional(
* persis.isTrue("flag"),
* "on",
* "off"
* )
* ]);
* ```
*/
conditional(condition: Lambda<boolean> | LambdaHandler<boolean>, ifTrue: DynamicWordResult, ifFalse: DynamicWordResult): Word;
/**
* Evaluate the JavaScript function and determine whether the result is true
*/
evaluate<K extends StringKeyOf<T>>(key: K, fn: (value: T[K]) => boolean): Lambda<boolean>;
}
/**
* Only for internal use, don't use this class directly
*/
export declare class DynamicPersistent extends Persistent<DynamicPersistentData> {
}