narraleaf-react 0.8.1 → 0.8.3

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";
@@ -5,22 +5,12 @@ import { LogicAction } from "../../action/logicAction";
5
5
  import { TypedAction } from "../../action/actions";
6
6
  import { Story } from "../../elements/story";
7
7
  import { ActionSearchOptions } from "../../types";
8
+ import { ActionExecutionInjection } from "../action";
8
9
  export declare class ConditionAction<T extends typeof ConditionActionTypes[keyof typeof ConditionActionTypes] = typeof ConditionActionTypes[keyof typeof ConditionActionTypes]> extends TypedAction<ConditionActionContentType, T, Condition> {
9
10
  static ActionTypes: {
10
11
  readonly action: "condition:action";
11
12
  };
12
- executeAction(gameState: GameState): ({
13
- type: T;
14
- node: import("../../action/tree/actionTree").RenderableNode | null;
15
- wait?: undefined;
16
- } | {
17
- type: T;
18
- node: null;
19
- wait: {
20
- type: "all";
21
- stackModels: import("../stackModel").StackModel[];
22
- };
23
- })[];
13
+ executeAction(gameState: GameState, injection: ActionExecutionInjection): import("../action").ExecutedActionResult;
24
14
  getFutureActions(story: Story, options: ActionSearchOptions): LogicAction.Actions[];
25
15
  stringify(story: Story, seen: Set<LogicAction.Actions>, strict: boolean): string;
26
16
  }
@@ -129,7 +129,7 @@ export declare class Gallery<Metadata extends Record<string, any>> extends Servi
129
129
  * @param name - The name of the item to get the metadata of
130
130
  * @returns The metadata of the item
131
131
  */
132
- $get(name: string): Metadata;
132
+ $get(name: string): Metadata | undefined;
133
133
  /**
134
134
  * Set the metadata of an item
135
135
  * @param name - The name of the item to set the metadata of
@@ -4,7 +4,7 @@ import { Chained, Proxied } from "../action/chain";
4
4
  import { LambdaHandler, ActionStatements } from "../elements/type";
5
5
  export declare class Lambda<T = any> {
6
6
  }
7
- export declare class Condition<Closed extends true | false = false> extends Actionable {
7
+ export declare class Condition<Closed extends true | false = false> extends Actionable<null, Condition<true | false>> {
8
8
  /**
9
9
  * @chainable
10
10
  */
@@ -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,15 @@ 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
27
  */
28
- equals<K extends StringKeyOf<T>>(key: K, value: T[K]): Lambda<boolean>;
28
+ equals<K extends StringKeyOf<T>>(key: K, value: T[K] | ((value: T[K]) => T[K])): Lambda<boolean>;
29
29
  /**
30
30
  * Determine whether the values aren't equal, can be used in {@link Condition}
31
31
  */
32
- notEquals<K extends StringKeyOf<T>>(key: K, value: T[K]): Lambda<boolean>;
32
+ notEquals<K extends StringKeyOf<T>>(key: K, value: T[K] | ((value: T[K]) => T[K])): Lambda<boolean>;
33
33
  /**
34
34
  * Determine whether the value is true, can be used in {@link Condition}
35
35
  */
@@ -24,24 +24,6 @@ export declare class Story extends Constructable<SceneAction<"scene:action">, St
24
24
  * ```
25
25
  */
26
26
  entry(scene: Scene): this;
27
- /**
28
- * Register a scene to the story
29
- * @example
30
- * ```typescript
31
- * // register a scene
32
- * const story = new Story("story");
33
- * const scene1 = new Scene("scene1");
34
- * const scene2 = new Scene("scene2");
35
- *
36
- * story.register(scene1); // Register scene1
37
- *
38
- * scene2.action([
39
- * scene2.jump("scene1") // Jump to scene1
40
- * ]);
41
- * ```
42
- */
43
- registerScene(name: string, scene: Scene): this;
44
- registerScene(scene: Scene): this;
45
27
  /**
46
28
  * Register a Persistent to the story
47
29
  *
@@ -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
+ };