narraleaf-react 0.8.2 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -118,7 +118,7 @@ export declare const PersistentActionTypes: {
118
118
  readonly assign: "persistent:assign";
119
119
  };
120
120
  export type PersistentActionContentType = {
121
- [K in typeof PersistentActionTypes[keyof typeof PersistentActionTypes]]: K extends "persistent:action" ? any : K extends "persistent:set" ? [string, unknown | ((value: unknown) => unknown)] : K extends "persistent:assign" ? [Partial<unknown>] : any;
121
+ [K in typeof PersistentActionTypes[keyof typeof PersistentActionTypes]]: K extends "persistent:action" ? any : K extends "persistent:set" ? [string, unknown | ((value: unknown) => unknown)] : K extends "persistent:assign" ? [Partial<unknown> | ((value: unknown) => Partial<unknown>)] : any;
122
122
  };
123
123
  export declare const LayerActionTypes: {
124
124
  readonly action: "layer:action";
@@ -3,20 +3,30 @@ import { Actionable } from "../action/actionable";
3
3
  import { Chained, Proxied } from "../action/chain";
4
4
  import { Sentence, SentencePrompt } from "../elements/character/sentence";
5
5
  import Actions = LogicAction.Actions;
6
- import { ActionStatements } from "./type";
6
+ import { ActionStatements, LambdaHandler } from "./type";
7
+ import { Lambda } from "./condition";
7
8
  export type MenuConfig = {};
8
9
  export type MenuChoice = {
9
10
  action: ActionStatements;
10
11
  prompt: SentencePrompt | Sentence;
12
+ config?: {
13
+ disabled?: Lambda<boolean> | LambdaHandler<boolean>;
14
+ hidden?: Lambda<boolean> | LambdaHandler<boolean>;
15
+ };
11
16
  };
12
17
  export type Choice = {
13
18
  action: Actions[];
14
19
  prompt: Sentence;
20
+ config: ChoiceConfig;
15
21
  };
16
22
  export type MenuData = {
17
23
  prompt: Sentence | null;
18
24
  choices: Choice[];
19
25
  };
26
+ export type ChoiceConfig = {
27
+ disabled?: Lambda<boolean>;
28
+ hidden?: Lambda<boolean>;
29
+ };
20
30
  export declare class Menu extends Actionable<any, Menu> {
21
31
  /**
22
32
  * Create a menu with a prompt
@@ -42,4 +52,46 @@ export declare class Menu extends Actionable<any, Menu> {
42
52
  choose(prompt: Sentence, action: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
43
53
  choose(prompt: SentencePrompt, action: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
44
54
  choose(arg0: Sentence | MenuChoice | SentencePrompt, arg1?: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
55
+ /**
56
+ * Magic method to hide the last choice if the condition is true
57
+ * @example
58
+ * ```ts
59
+ * menu.choose(
60
+ * // ...
61
+ * ).hideIf(persis.isTrue("flag"));
62
+ * ```
63
+ *
64
+ * **Note**: This method will override the last choice's config.hidden
65
+ */
66
+ hideIf(condition: Lambda<boolean> | LambdaHandler<boolean>): Proxied<Menu, Chained<LogicAction.Actions>>;
67
+ /**
68
+ * Magic method to disable the last choice if the condition is true
69
+ * @example
70
+ * ```ts
71
+ * menu.choose(
72
+ * // ...
73
+ * ).disableIf(persis.isTrue("flag"));
74
+ * ```
75
+ */
76
+ disableIf(condition: Lambda<boolean> | LambdaHandler<boolean>): Proxied<Menu, Chained<LogicAction.Actions>>;
77
+ /**
78
+ * Add a choice, only enable when the condition is true
79
+ * @example
80
+ * ```ts
81
+ * menu.enableWhen(persis.isTrue("flag"), "Go left", [
82
+ * character.say("I went left")
83
+ * ]);
84
+ * ```
85
+ */
86
+ enableWhen(condition: Lambda<boolean> | LambdaHandler<boolean>, prompt: Sentence, action: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
87
+ /**
88
+ * Add a choice, only show when the condition is true
89
+ * @example
90
+ * ```ts
91
+ * menu.showWhen(persis.isTrue("flag"), "Go left", [
92
+ * character.say("I went left")
93
+ * ]);
94
+ * ```
95
+ */
96
+ showWhen(condition: Lambda<boolean> | LambdaHandler<boolean>, prompt: Sentence, action: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
45
97
  }
@@ -21,15 +21,31 @@ export declare class Persistent<T extends PersistentContent> extends Actionable<
21
21
  * @param value - The value to assign
22
22
  * @returns A chainable persistent action
23
23
  */
24
- assign(value: Partial<T>): ChainedPersistent<T>;
24
+ assign(value: Partial<T> | ((value: T) => Partial<T>)): ChainedPersistent<T>;
25
25
  /**
26
26
  * Determine whether the values are equal, can be used in {@link Condition}
27
+ * @example
28
+ * ```typescript
29
+ * persis.equals("id", persis.get("player_id"));
30
+ *
31
+ * // or
32
+ *
33
+ * persis.equals("id", (ctx) => ctx.storable.getNamespace("player").get("player_id"));
34
+ * ```
27
35
  */
28
- equals<K extends StringKeyOf<T>>(key: K, value: T[K]): Lambda<boolean>;
36
+ equals<K extends StringKeyOf<T>>(key: K, value: T[K] | Lambda<T[K]> | LambdaHandler<T[K]>): Lambda<boolean>;
29
37
  /**
30
38
  * Determine whether the values aren't equal, can be used in {@link Condition}
39
+ * @example
40
+ * ```typescript
41
+ * persis.notEquals("id", persis.get("player_id"));
42
+ *
43
+ * // or
44
+ *
45
+ * persis.notEquals("id", (ctx) => ctx.storable.getNamespace("player").get("player_id"));
46
+ * ```
31
47
  */
32
- notEquals<K extends StringKeyOf<T>>(key: K, value: T[K]): Lambda<boolean>;
48
+ notEquals<K extends StringKeyOf<T>>(key: K, value: T[K] | Lambda<T[K]> | LambdaHandler<T[K]>): Lambda<boolean>;
33
49
  /**
34
50
  * Determine whether the value is true, can be used in {@link Condition}
35
51
  */
@@ -1,16 +1,22 @@
1
1
  import { Game } from "../game";
2
+ import { LogicAction } from "../action/logicAction";
2
3
  import { Actionable } from "../action/actionable";
3
4
  import { GameState } from "../../player/gameState";
4
- import type { Storable } from "../elements/persistent/storable";
5
+ import { Chained, Proxied } from "../action/chain";
6
+ import type { Namespace, Storable } from "../elements/persistent/storable";
5
7
  import { LiveGame } from "../game/liveGame";
8
+ import { NameSpaceContent } from "./persistent/type";
9
+ export type NamespaceGetter = <T extends NameSpaceContent<keyof T>>(namespace: string) => Namespace<T>;
6
10
  export interface ScriptCtx {
7
11
  gameState: GameState;
8
12
  game: Game;
9
13
  liveGame: LiveGame;
10
14
  storable: Storable;
15
+ $: NamespaceGetter;
11
16
  }
12
17
  type ScriptRun = (ctx: ScriptCtx) => ScriptCleaner | void;
13
18
  export declare class Script extends Actionable<object> {
19
+ static execute(handler: ScriptRun): Proxied<Script, Chained<LogicAction.Actions>>;
14
20
  constructor(handler: ScriptRun);
15
21
  }
16
22
  export {};
@@ -1,3 +1,3 @@
1
- import React from "react";
2
1
  import { IUserMenuProps } from "../../elements/menu/type";
2
+ import React from "react";
3
3
  export declare function DefaultMenu({ items }: IUserMenuProps): React.JSX.Element;
@@ -1,13 +1,9 @@
1
- import { Pausing } from "../../../../nlcore/elements/character/pause";
2
- import { Word } from "../../../../nlcore/elements/character/word";
3
- import { Choice } from "../../../../nlcore/elements/menu";
4
1
  import { GameState } from "../../../../../game/player/gameState";
5
2
  import { Chosen } from "../../../type";
6
3
  import React from "react";
4
+ import { ChoiceEvaluated } from "../type";
7
5
  interface UIMenuContext {
8
- evaluated: (Choice & {
9
- words: Word<Pausing | string>[];
10
- })[];
6
+ evaluated: ChoiceEvaluated[];
11
7
  choose: (choice: Chosen) => void;
12
8
  gameState: GameState;
13
9
  }
@@ -14,3 +14,6 @@ export interface MenuElementProps {
14
14
  export interface IUserMenuProps {
15
15
  items: number[];
16
16
  }
17
+ export type ChoiceEvaluated = Choice & {
18
+ words: Word<Pausing | string>[];
19
+ };