narraleaf-react 0.4.4 → 0.5.0

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.
Files changed (34) hide show
  1. package/README.md +31 -33
  2. package/dist/game/nlcore/action/actionHistory.d.ts +3 -1
  3. package/dist/game/nlcore/action/actionTypes.d.ts +4 -2
  4. package/dist/game/nlcore/action/actions/imageAction.d.ts +1 -0
  5. package/dist/game/nlcore/action/actions/layerAction.d.ts +2 -1
  6. package/dist/game/nlcore/action/gameHistory.d.ts +5 -1
  7. package/dist/game/nlcore/common/types.d.ts +2 -2
  8. package/dist/game/nlcore/elements/character.d.ts +1 -0
  9. package/dist/game/nlcore/elements/condition.d.ts +5 -5
  10. package/dist/game/nlcore/elements/control.d.ts +13 -13
  11. package/dist/game/nlcore/elements/displayable/image.d.ts +11 -0
  12. package/dist/game/nlcore/elements/layer.d.ts +10 -0
  13. package/dist/game/nlcore/elements/menu.d.ts +8 -6
  14. package/dist/game/nlcore/elements/scene.d.ts +3 -3
  15. package/dist/game/nlcore/elements/sound.d.ts +15 -1
  16. package/dist/game/nlcore/elements/transform/position.d.ts +3 -1
  17. package/dist/game/nlcore/elements/transition/transitions/image/darkness.d.ts +20 -0
  18. package/dist/game/nlcore/elements/type.d.ts +1 -0
  19. package/dist/game/nlcore/game/liveGame.d.ts +14 -0
  20. package/dist/game/nlcore/game.d.ts +26 -0
  21. package/dist/game/nlcore/gameTypes.d.ts +8 -5
  22. package/dist/game/nlcore/types.d.ts +1 -0
  23. package/dist/game/player/elements/image/AspectScaleImage.d.ts +1 -1
  24. package/dist/game/player/elements/player/PreferenceUpdateAnnouncer.d.ts +4 -0
  25. package/dist/game/player/elements/player/RenderEventAnnoucer.d.ts +4 -0
  26. package/dist/game/player/elements/say/UIDialog.d.ts +2 -0
  27. package/dist/game/player/elements/say/useDialog.d.ts +2 -0
  28. package/dist/game/player/gameState.d.ts +6 -1
  29. package/dist/game/player/lib/AudioManager.d.ts +9 -1
  30. package/dist/game/player/lib/PageRouter/AnimatePresence.d.ts +4 -0
  31. package/dist/game/player/type.d.ts +4 -0
  32. package/dist/main.js +56 -53
  33. package/dist/util/data.d.ts +1 -0
  34. package/package.json +1 -1
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <picture>
2
2
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-transparent.png">
3
3
  <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-light.png">
4
- <img alt="Fallback image description" src="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-light.png">
4
+ <img alt="NarraLeaf Logo" src="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-light.png">
5
5
  </picture>
6
6
 
7
7
  <h1 align="center">NarraLeaf-React</h1>
@@ -31,49 +31,36 @@ NarraLeaf-React uses TypeScript for all scripting, so you don't have to learn a
31
31
  It also has a highly abstracted and easy-to-use API, for example:
32
32
 
33
33
  ```typescript
34
- import {Character, Menu, Scene, Word, c, b} from "narraleaf-react";
34
+ import {Character, Menu, Scene, c, b} from "narraleaf-react";
35
35
  ```
36
36
 
37
37
  ```typescript
38
- const scene1 = new Scene("scene1_hello_world", {
39
- background: "/background/scene1_hello_world.jpg",
38
+ const scene1 = new Scene("Scene1: Hello World", {
39
+ background: "/link/to/background.jpg",
40
40
  });
41
41
 
42
- const johnSmith = new Character("John Smith");
43
- const johnDoe = new Character("John Doe");
42
+ const jS = new Character("John Smith");
43
+ const jD = new Character("John Doe");
44
44
 
45
45
  scene1.action([
46
- /**
47
- * John Smith: Hello, world!
48
- * John Smith: This is my first **NarraLeaf** story.
49
- * John Smith: Start editing src/story.js and enjoy the journey!
50
- */
51
- johnSmith
52
- .say("Hello, world!")
53
- .say`This is my first ${b("NarraLeaf")} story.`
54
- .say`Start editing ${c("src/story.js", "#00f")} and enjoy the journey!`,
55
-
56
- /**
57
- * John Doe: Also, don't forget to check out the documentation!
58
- */
59
- johnDoe.say("Also, don't forget to check out the documentation!"),
60
-
61
- /**
62
- * Menu: Start the journey
63
- * > Yes I will!
64
- * - John Smith: Great! Let's start the journey!
65
- * - John Smith: You can open issues on GitHub if you have any questions.
66
- * > No, I'm going to check the documentation
67
- * - John Smith: Sure! Take your time!
68
- */
46
+ jS`Hello, world!`,
47
+ jS`This is my first ${b("NarraLeaf")} story.`,
48
+ jS`Start editing ${c("src/story.js", "#00f")} and enjoy the journey!`,
49
+
50
+ jD`Also, don't forget to check out the ${c("documentation", "#00f")}!`,
51
+
52
+ "By the way, the documentation is available on https://react.narraleaf.com/documentation",
53
+ "You can also visit the website for demo and more information.",
54
+
69
55
  Menu.prompt("Start the journey")
56
+
70
57
  .choose("Yes I will!", [
71
- johnSmith
72
- .say("Great! Let's start the journey!")
73
- .say("You can open issues on GitHub if you have any questions.")
58
+ jS`Great! Let's start the journey!`,
59
+ jS`You can open issues on GitHub if you have any questions.`
74
60
  ])
61
+
75
62
  .choose("No, I'm going to check the documentation", [
76
- johnSmith.say("Sure! Take your time!")
63
+ jS`Sure! Take your time!`
77
64
  ])
78
65
  ]);
79
66
  ```
@@ -133,6 +120,17 @@ npm install narraleaf-react
133
120
  - [Plugin](https://react.narraleaf.com/documentation/core/plugin)
134
121
  - [Utils](https://react.narraleaf.com/documentation/core/utils)
135
122
  - [Player](https://react.narraleaf.com/documentation/player)
123
+ - [Player](https://react.narraleaf.com/documentation/player/player)
124
+ - [GameProviders](https://react.narraleaf.com/documentation/player/game-providers)
125
+ - Hooks
126
+ - [useGame](https://react.narraleaf.com/documentation/player/hooks/useGame)
127
+ - [usePreferences](https://react.narraleaf.com/documentation/player/hooks/usePreferences)
128
+ - [useRouter](https://react.narraleaf.com/documentation/player/hooks/useRouter)
129
+ - [useDialog](https://react.narraleaf.com/documentation/player/hooks/useDialog)
130
+ - [Page Router](https://react.narraleaf.com/documentation/player/page-router)
131
+ - [Dialog](https://react.narraleaf.com/documentation/player/dialog)
132
+ - [Notification](https://react.narraleaf.com/documentation/player/notification)
133
+ - [Menu](https://react.narraleaf.com/documentation/player/menu)
136
134
  - About
137
135
  - [License](https://react.narraleaf.com/documentation/info/license)
138
136
  - [Incompatible Changes](https://react.narraleaf.com/documentation/info/incompatible-changes)
@@ -2,6 +2,7 @@ import { Timeline } from "../../../game/player/Tasks";
2
2
  import { Action } from "./action";
3
3
  import { LiveGameEventToken } from "../types";
4
4
  import { LogicAction } from "../game";
5
+ import { GameHistoryManager } from "./gameHistory";
5
6
  export type ActionHistory<T extends Array<unknown> = any> = {
6
7
  action: Action;
7
8
  timeline?: Timeline;
@@ -27,7 +28,8 @@ export declare class ActionHistoryManager {
27
28
  * @param id random id generated by push
28
29
  */
29
30
  undoUntil(id: string): LogicAction.Actions | null;
30
- undo(): LogicAction.Actions | null;
31
+ undo(gameHistory: GameHistoryManager): LogicAction.Actions | null;
32
+ ableToUndo(gameHistory: GameHistoryManager): boolean;
31
33
  onUndo(callback: (affected: ActionHistory<any>[]) => void): LiveGameEventToken;
32
34
  offUndo(callback: (affected: ActionHistory<any>[]) => void): void;
33
35
  getHistory(): ActionHistory<any>[];
@@ -56,9 +56,10 @@ export declare const ImageActionTypes: {
56
56
  readonly flush: "image:flush";
57
57
  readonly initWearable: "image:initWearable";
58
58
  readonly setAppearance: "image:setAppearance";
59
+ readonly setDarkness: "image:setDarkness";
59
60
  };
60
61
  export type ImageActionContentType = {
61
- [K in typeof ImageActionTypes[keyof typeof ImageActionTypes]]: K extends "image:setSrc" ? [ImageSrc | Color] : K extends "image:flush" ? [] : K extends "image:initWearable" ? [Image] : K extends "image:setAppearance" ? [FlexibleTuple<SelectElementFromEach<TagGroupDefinition>> | string[], ImageTransition | undefined] : any;
62
+ [K in typeof ImageActionTypes[keyof typeof ImageActionTypes]]: K extends "image:setSrc" ? [ImageSrc | Color] : K extends "image:flush" ? [] : K extends "image:initWearable" ? [Image] : K extends "image:setAppearance" ? [FlexibleTuple<SelectElementFromEach<TagGroupDefinition>> | string[], ImageTransition | undefined] : K extends "image:setDarkness" ? [darkness: number, duration?: number, easing?: TransformDefinitions.EasingDefinition] : any;
62
63
  } & DisplayableActionContentType<ImageTransition>;
63
64
  export declare const ConditionActionTypes: {
64
65
  readonly action: "condition:action";
@@ -121,9 +122,10 @@ export type PersistentActionContentType = {
121
122
  };
122
123
  export declare const LayerActionTypes: {
123
124
  readonly action: "layer:action";
125
+ readonly setZIndex: "layer:setZIndex";
124
126
  };
125
127
  export type LayerActionContentType = {
126
- [K in typeof LayerActionTypes[keyof typeof LayerActionTypes]]: K extends "layer:action" ? any : any;
128
+ [K in typeof LayerActionTypes[keyof typeof LayerActionTypes]]: K extends "layer:action" ? any : K extends "layer:setZIndex" ? [number] : any;
127
129
  };
128
130
  export declare const VideoActionTypes: {
129
131
  readonly action: "video:action";
@@ -13,6 +13,7 @@ export declare class ImageAction<T extends typeof ImageActionTypes[keyof typeof
13
13
  readonly flush: "image:flush";
14
14
  readonly initWearable: "image:initWearable";
15
15
  readonly setAppearance: "image:setAppearance";
16
+ readonly setDarkness: "image:setDarkness";
16
17
  };
17
18
  static resolveTagSrc(image: Image, tags: string[]): string;
18
19
  static resolveCurrentSrc(image: Image): string | Color;
@@ -7,6 +7,7 @@ import { Layer } from "../../elements/layer";
7
7
  export declare class LayerAction<T extends Values<typeof LayerActionTypes> = Values<typeof LayerActionTypes>> extends TypedAction<LayerActionContentType, T, Layer> {
8
8
  static ActionTypes: {
9
9
  readonly action: "layer:action";
10
+ readonly setZIndex: "layer:setZIndex";
10
11
  };
11
- executeAction(state: GameState): CalledActionResult | Awaitable<CalledActionResult, any>;
12
+ executeAction(gameState: GameState): CalledActionResult | Awaitable<CalledActionResult, any>;
12
13
  }
@@ -3,15 +3,17 @@ import { ActionHistoryManager } from "./actionHistory";
3
3
  type GameHistoryAction = {
4
4
  token: string;
5
5
  action: Action;
6
+ isPending?: boolean;
6
7
  };
7
8
  type GameElementHistory = {
8
9
  type: "say";
9
10
  text: string;
10
11
  voice: string | null;
12
+ character: string | null;
11
13
  } | {
12
14
  type: "menu";
13
15
  text: string | null;
14
- selected: string;
16
+ selected: string | null;
15
17
  };
16
18
  export type GameHistory = GameHistoryAction & {
17
19
  element: GameElementHistory;
@@ -23,6 +25,8 @@ export declare class GameHistoryManager {
23
25
  push(action: GameHistory): this;
24
26
  getHistory(): GameHistory[];
25
27
  reset(): void;
28
+ updateByToken(id: string, handler: (result: GameHistory | null) => void): void;
29
+ resolvePending(id: string): void;
26
30
  private crossFilter;
27
31
  }
28
32
  export {};
@@ -4,6 +4,6 @@ import { TransformDefinitions } from "../elements/transform/type";
4
4
  import { IGamePluginRegistry } from "../game/plugin/plugin";
5
5
  import { LiveGameEventToken } from "../types";
6
6
  import { GameHistory } from "../action/gameHistory";
7
- import { GameConfig } from "../gameTypes";
7
+ import { GameConfig, SavedGame } from "../gameTypes";
8
8
  export * from "../elements/type";
9
- export type { GameHistory, IGamePluginRegistry, LiveGameEventToken, Origins, ServiceHandlerCtx, TransformDefinitions, GameConfig, };
9
+ export type { GameHistory, IGamePluginRegistry, LiveGameEventToken, Origins, ServiceHandlerCtx, TransformDefinitions, GameConfig, SavedGame, };
@@ -49,3 +49,4 @@ export declare class Character extends Actionable<CharacterStateData, Character>
49
49
  apply(content: SentencePrompt, config?: SentenceUserConfig): Proxied<Character, Chained<LogicAction.Actions>>;
50
50
  apply(texts: TemplateStringsArray, ...words: SingleWord[]): Proxied<Character, Chained<LogicAction.Actions>>;
51
51
  }
52
+ export declare const Narrator: Character;
@@ -1,20 +1,20 @@
1
1
  import { LogicAction } from "../action/logicAction";
2
2
  import { Actionable } from "../action/actionable";
3
- import { Chained, ChainedActions, Proxied } from "../action/chain";
4
- import { LambdaHandler } from "../elements/type";
3
+ import { Chained, Proxied } from "../action/chain";
4
+ import { LambdaHandler, ActionStatements } from "../elements/type";
5
5
  export declare class Lambda<T = any> {
6
6
  }
7
7
  export declare class Condition<Closed extends true | false = false> extends Actionable {
8
8
  /**
9
9
  * @chainable
10
10
  */
11
- static If(condition: Lambda | LambdaHandler<boolean>, action: ChainedActions): Proxied<Condition, Chained<LogicAction.Actions>>;
11
+ static If(condition: Lambda | LambdaHandler<boolean>, action: ActionStatements): Proxied<Condition, Chained<LogicAction.Actions>>;
12
12
  /**
13
13
  * @chainable
14
14
  */
15
- ElseIf(condition: Closed extends false ? (Lambda | LambdaHandler<boolean>) : never, action: Closed extends false ? ChainedActions : never): Closed extends false ? Proxied<Condition, Chained<LogicAction.Actions>> : never;
15
+ ElseIf(condition: Closed extends false ? (Lambda | LambdaHandler<boolean>) : never, action: Closed extends false ? ActionStatements : never): Closed extends false ? Proxied<Condition, Chained<LogicAction.Actions>> : never;
16
16
  /**
17
17
  * @chainable
18
18
  */
19
- Else(action: Closed extends false ? ChainedActions : never): Closed extends false ? Proxied<Condition<true>, Chained<LogicAction.Actions>> : never;
19
+ Else(action: Closed extends false ? ActionStatements : never): Closed extends false ? Proxied<Condition<true>, Chained<LogicAction.Actions>> : never;
20
20
  }
@@ -1,37 +1,37 @@
1
1
  import { Actionable } from "../action/actionable";
2
2
  import { Awaitable } from "../../../util/data";
3
- import { ChainedActions } from "../action/chain";
3
+ import { ActionStatements } from "./type";
4
4
  export declare class Control extends Actionable {
5
5
  /**
6
6
  * Execute actions in order, waiting for each action to complete
7
7
  * @chainable
8
8
  */
9
- static do(actions: ChainedActions): ChainedControl;
9
+ static do(actions: ActionStatements): ChainedControl;
10
10
  /**
11
11
  * Execute actions in order, do not wait for this action to complete
12
12
  * @chainable
13
13
  */
14
- static doAsync(actions: ChainedActions): ChainedControl;
14
+ static doAsync(actions: ActionStatements): ChainedControl;
15
15
  /**
16
16
  * Execute all actions at the same time, waiting for any one action to complete
17
17
  * @chainable
18
18
  */
19
- static any(actions: ChainedActions): ChainedControl;
19
+ static any(actions: ActionStatements): ChainedControl;
20
20
  /**
21
21
  * Execute all actions at the same time, waiting for all actions to complete
22
22
  * @chainable
23
23
  */
24
- static all(actions: ChainedActions): ChainedControl;
24
+ static all(actions: ActionStatements): ChainedControl;
25
25
  /**
26
26
  * Execute all actions at the same time, do not wait for all actions to complete
27
27
  * @chainable
28
28
  */
29
- static allAsync(actions: ChainedActions): ChainedControl;
29
+ static allAsync(actions: ActionStatements): ChainedControl;
30
30
  /**
31
31
  * Execute actions multiple times
32
32
  * @chainable
33
33
  */
34
- static repeat(times: number, actions: ChainedActions): ChainedControl;
34
+ static repeat(times: number, actions: ActionStatements): ChainedControl;
35
35
  /**
36
36
  * Sleep for a duration
37
37
  * @chainable
@@ -42,32 +42,32 @@ export declare class Control extends Actionable {
42
42
  * Execute actions in order, waiting for each action to complete
43
43
  * @chainable
44
44
  */
45
- do(actions: ChainedActions): ChainedControl;
45
+ do(actions: ActionStatements): ChainedControl;
46
46
  /**
47
47
  * Execute actions in order, do not wait for this action to complete
48
48
  * @chainable
49
49
  */
50
- doAsync(actions: ChainedActions): ChainedControl;
50
+ doAsync(actions: ActionStatements): ChainedControl;
51
51
  /**
52
52
  * Execute all actions at the same time, waiting for any one action to complete
53
53
  * @chainable
54
54
  */
55
- any(actions: ChainedActions): ChainedControl;
55
+ any(actions: ActionStatements): ChainedControl;
56
56
  /**
57
57
  * Execute all actions at the same time, waiting for all actions to complete
58
58
  * @chainable
59
59
  */
60
- all(actions: ChainedActions): ChainedControl;
60
+ all(actions: ActionStatements): ChainedControl;
61
61
  /**
62
62
  * Execute all actions at the same time, do not wait for all actions to complete
63
63
  * @chainable
64
64
  */
65
- allAsync(actions: ChainedActions): ChainedControl;
65
+ allAsync(actions: ActionStatements): ChainedControl;
66
66
  /**
67
67
  * Execute actions multiple times
68
68
  * @chainable
69
69
  */
70
- repeat(times: number, actions: ChainedActions): ChainedControl;
70
+ repeat(times: number, actions: ActionStatements): ChainedControl;
71
71
  /**
72
72
  * Sleep for a duration
73
73
  * @chainable
@@ -37,6 +37,11 @@ export interface IImageUserConfig<Tag extends TagGroupDefinition | null = TagGro
37
37
  * layer of the image
38
38
  */
39
39
  layer?: Layer;
40
+ /**
41
+ * Darkness of the image, between 0 and 1
42
+ * @default 0
43
+ */
44
+ darkness?: number;
40
45
  }
41
46
  export type TagGroupDefinition = string[][];
42
47
  export type TagSrcResolver<T extends TagGroupDefinition> = (...tags: SelectElementFromEach<T>) => string;
@@ -59,6 +64,12 @@ export declare class Image<Tags extends TagGroupDefinition | null = TagGroupDefi
59
64
  */
60
65
  char(src: ImageSrc | Color, transition?: ImageTransition): Proxied<Image, Chained<LogicAction.Actions>>;
61
66
  char(tags: SelectElementFromEach<Tags> | FlexibleTuple<SelectElementFromEach<Tags>>, transition?: ImageTransition): Proxied<Image, Chained<LogicAction.Actions>>;
67
+ /**
68
+ * Set the darkness of the image
69
+ * @param darkness - The darkness of the image, between 0 and 1
70
+ * @chainable
71
+ */
72
+ darken(darkness: number, duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Image, Chained<LogicAction.Actions>>;
62
73
  /**
63
74
  * Add a wearable to the image
64
75
  * @param children - Wearable image or images
@@ -1,9 +1,11 @@
1
1
  import { CommonDisplayableConfig } from "../types";
2
+ import { LogicAction } from "../action/logicAction";
2
3
  import { TransformDefinitions } from "../elements/transform/type";
3
4
  import { Displayable } from "../elements/displayable/displayable";
4
5
  import { EventfulDisplayable } from "../../player/elements/displayable/type";
5
6
  import { Image } from "../elements/displayable/image";
6
7
  import { Text } from "../elements/displayable/text";
8
+ import { Chained, Proxied } from "../action/chain";
7
9
  export interface ILayerUserConfig extends CommonDisplayableConfig {
8
10
  /**
9
11
  * The z-index of the layer, higher z-index will be rendered on top of the lower z-index, allows negative values.
@@ -20,4 +22,12 @@ export declare class Layer extends Displayable<LayerDataRaw, Layer, TransformDef
20
22
  * Same as {@link Displayable.useLayer}
21
23
  */
22
24
  include(elements: (Image | Text)[] | Image | Text): this;
25
+ /**
26
+ * Set the z-index of the layer
27
+ *
28
+ * @chainable
29
+ * @param zIndex - The z-index of the layer
30
+ * @returns The layer itself
31
+ */
32
+ setZIndex(zIndex: number): Proxied<Layer, Chained<LogicAction.Actions>>;
23
33
  }
@@ -3,9 +3,10 @@ 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
7
  export type MenuConfig = {};
7
8
  export type MenuChoice = {
8
- action: ChainedActions;
9
+ action: ActionStatements;
9
10
  prompt: SentencePrompt | Sentence;
10
11
  };
11
12
  export type Choice = {
@@ -22,12 +23,13 @@ export declare class Menu extends Actionable<any, Menu> {
22
23
  * @param prompt - The prompt to display to the player
23
24
  * @returns A new menu
24
25
  */
25
- static prompt(prompt: SentencePrompt | Sentence, config?: MenuConfig): Menu;
26
- static choose(arg0: Sentence | MenuChoice | SentencePrompt, arg1?: ChainedActions): Proxied<Menu, Chained<LogicAction.Actions>>;
26
+ static prompt(prompt: SentencePrompt | Sentence | null | undefined, config?: MenuConfig): Menu;
27
+ static choose(arg0: Sentence | MenuChoice | SentencePrompt, arg1?: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
27
28
  constructor(prompt: SentencePrompt, config?: MenuConfig);
28
29
  constructor(prompt: Sentence, config?: MenuConfig);
29
30
  constructor(prompt: SentencePrompt | Sentence, config: MenuConfig);
30
31
  constructor(prompt: null, config?: MenuConfig);
32
+ constructor(prompt: SentencePrompt | Sentence | null, config: MenuConfig);
31
33
  /**
32
34
  * Add a choice to the menu
33
35
  * @example
@@ -37,7 +39,7 @@ export declare class Menu extends Actionable<any, Menu> {
37
39
  * @chainable
38
40
  */
39
41
  choose(choice: MenuChoice): Proxied<Menu, Chained<LogicAction.Actions>>;
40
- choose(prompt: Sentence, action: ChainedActions): Proxied<Menu, Chained<LogicAction.Actions>>;
41
- choose(prompt: SentencePrompt, action: ChainedActions): Proxied<Menu, Chained<LogicAction.Actions>>;
42
- choose(arg0: Sentence | MenuChoice | SentencePrompt, arg1?: ChainedActions): Proxied<Menu, Chained<LogicAction.Actions>>;
42
+ choose(prompt: Sentence, action: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
43
+ choose(prompt: SentencePrompt, action: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
44
+ choose(arg0: Sentence | MenuChoice | SentencePrompt, arg1?: ActionStatements): Proxied<Menu, Chained<LogicAction.Actions>>;
43
45
  }
@@ -3,7 +3,7 @@ import { Color, ImageSrc } from "../types";
3
3
  import { LogicAction } from "../action/logicAction";
4
4
  import { Sound, VoiceIdMap, VoiceSrcGenerator } from "../elements/sound";
5
5
  import { Image } from "../elements/displayable/image";
6
- import { Persistent } from "../common/core";
6
+ import { ActionStatements, Persistent } from "../common/core";
7
7
  import { Chained, Proxied } from "../action/chain";
8
8
  import { ImageTransition } from "../elements/transition/transitions/image/imageTransition";
9
9
  import { Layer } from "../elements/layer";
@@ -66,8 +66,8 @@ export declare class Scene extends Constructable<LogicAction.Actions, Scene> {
66
66
  /**
67
67
  * Add actions to the scene
68
68
  */
69
- action(actions: (ChainableAction | ChainableAction[])[]): this;
70
- action(actions: ((scene: Scene) => ChainableAction[]) | (() => ChainableAction[])): this;
69
+ action(actions: ActionStatements): this;
70
+ action(actions: ((scene: Scene) => ActionStatements) | (() => ActionStatements)): this;
71
71
  /**
72
72
  * Manually register image sources
73
73
  */
@@ -2,6 +2,11 @@ import { Actionable } from "../action/actionable";
2
2
  import { LogicAction } from "../game";
3
3
  import { Chained, Proxied } from "../action/chain";
4
4
  type ChainedSound = Proxied<Sound, Chained<LogicAction.Actions>>;
5
+ export declare enum SoundType {
6
+ Voice = "voice",
7
+ Bgm = "bgm",
8
+ Sound = "sound"
9
+ }
5
10
  export type VoiceIdMap = Record<string | number, string | Sound>;
6
11
  export type VoiceSrcGenerator = (id: string | number) => string | Sound;
7
12
  export interface ISoundUserConfig {
@@ -36,12 +41,21 @@ export interface ISoundUserConfig {
36
41
  * @default 0
37
42
  */
38
43
  seek: number;
44
+ /**
45
+ * The type of the sound
46
+ * @default SoundType.Sound
47
+ */
48
+ type: SoundType;
39
49
  }
40
50
  export declare class Sound extends Actionable<SoundDataRaw, Sound> {
51
+ static voice(arg0: Partial<ISoundUserConfig> | string): Sound;
52
+ static bgm(arg0: Partial<ISoundUserConfig> | string): Sound;
53
+ static sound(arg0: Partial<ISoundUserConfig> | string): Sound;
41
54
  constructor(config?: Partial<ISoundUserConfig>);
42
55
  constructor(src?: string);
56
+ constructor(arg0: Partial<ISoundUserConfig> | string);
43
57
  /**
44
- * Start playing the sound
58
+ * Start playing the sound and **wait for it to finish**
45
59
  *
46
60
  * This action will be resolved when the sound reaches the end
47
61
  * @chainable
@@ -50,7 +50,7 @@ export declare class CommonPosition implements IPosition {
50
50
  export declare class Coord2D implements IPosition {
51
51
  static isCoord2DPosition(arg: any): arg is Coord2D;
52
52
  static fromCommonPosition(position: CommonPosition): Coord2D;
53
- static fromAlignPosition(position: AlignPosition): Coord2D;
53
+ static fromAlignPosition(position: Partial<AlignPosition>): Coord2D;
54
54
  static merge(a: Coord2D, b: Coord2D): Coord2D;
55
55
  readonly x: UnknownAble<Coord2DPosition["x"]>;
56
56
  readonly y: UnknownAble<Coord2DPosition["y"]>;
@@ -72,6 +72,7 @@ export declare class Coord2D implements IPosition {
72
72
  yoffset?: UnknownAble<number>;
73
73
  });
74
74
  constructor(x: UnknownAble<Coord2DPosition["x"]>, y: UnknownAble<Coord2DPosition["y"]>);
75
+ check(): void;
75
76
  toCSS(): D2Position<Coord2DPosition["x"], Coord2DPosition["y"]>;
76
77
  }
77
78
  export declare class Align implements IPosition {
@@ -96,6 +97,7 @@ export declare class Align implements IPosition {
96
97
  xoffset?: UnknownAble<number>;
97
98
  yoffset?: UnknownAble<number>;
98
99
  });
100
+ check(): void;
99
101
  toCSS(): D2Position;
100
102
  }
101
103
  export {};
@@ -0,0 +1,20 @@
1
+ import { TransitionAnimationType, TransitionTask } from "../../../../elements/transition/type";
2
+ import { TransformDefinitions } from "../../../../elements/transform/type";
3
+ import { ImageTransition } from "../../../../elements/transition/transitions/image/imageTransition";
4
+ type AnimationType = [TransitionAnimationType.Number];
5
+ export declare class Darkness extends ImageTransition<AnimationType> {
6
+ private prevDarkness;
7
+ private targetDarkness;
8
+ private duration;
9
+ private easing?;
10
+ /**
11
+ * Darken the original image and fade in the target image at the same time.
12
+ * @param darkness darkness of the image, between 0 and 1
13
+ * @param duration duration in milliseconds
14
+ * @param easing easing definition or existing easing name
15
+ */
16
+ constructor(prevDarkness: number, targetDarkness: number, duration: number, easing?: TransformDefinitions.EasingDefinition | undefined);
17
+ createTask(): TransitionTask<HTMLImageElement, AnimationType>;
18
+ copy(): Darkness;
19
+ }
20
+ export {};
@@ -12,4 +12,5 @@ export type FadeOptions = {
12
12
  duration: number;
13
13
  };
14
14
  export type ChainedActions = (Proxied<LogicAction.GameElement, Chained<LogicAction.Actions>> | LogicAction.Actions)[];
15
+ export type ActionStatements = ChainedActions | string[];
15
16
  export type { TransitionAnimationType, TransitionTask, };
@@ -102,6 +102,10 @@ export declare class LiveGame {
102
102
  newGame(): this & {
103
103
  gameState: GameState;
104
104
  };
105
+ waitForRouterExit(): {
106
+ promise: Promise<void>;
107
+ cancel: VoidFunction;
108
+ };
105
109
  /**
106
110
  * Request full screen on Chrome/Safari/Firefox/IE/Edge/Opera, the player element will be full screen
107
111
  *
@@ -120,5 +124,15 @@ export declare class LiveGame {
120
124
  * Listen to the events of the player element
121
125
  */
122
126
  onPlayerEvent<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): LiveGameEventToken;
127
+ /**
128
+ * Listen to the events of the window
129
+ */
130
+ onWindowEvent<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): LiveGameEventToken;
131
+ /**
132
+ * Reset the game state
133
+ *
134
+ * **Note**: calling this method will lose the current game state
135
+ */
136
+ reset(): void;
123
137
  getGameState(): GameState | undefined;
124
138
  }
@@ -29,8 +29,34 @@ export type GamePreference = {
29
29
  * Dialog speed will apply to:
30
30
  * - The text speed
31
31
  * - The auto-forward delay
32
+ * @default 1.0
32
33
  */
33
34
  gameSpeed: number;
35
+ /**
36
+ * The speed of the text effects in characters per second.
37
+ * @default 10
38
+ */
39
+ cps: number;
40
+ /**
41
+ * The volume of the voice
42
+ * @default 1
43
+ */
44
+ voiceVolume: number;
45
+ /**
46
+ * The volume of the background music
47
+ * @default 1
48
+ */
49
+ bgmVolume: number;
50
+ /**
51
+ * The volume of the sound effects
52
+ * @default 1
53
+ */
54
+ soundVolume: number;
55
+ /**
56
+ * The volume of the global audio
57
+ * @default 1
58
+ */
59
+ globalVolume: number;
34
60
  };
35
61
  export type GameHooks = {
36
62
  /**
@@ -77,6 +77,14 @@ export type GameConfig = {
77
77
  * @default 100
78
78
  */
79
79
  skipInterval: number;
80
+ /**
81
+ * If true, the game will listen to the window events instead of the player element
82
+ *
83
+ * Using this will allow the game to listen to the keyboard events even when the player is not focused
84
+ * Resulting in a better user experience on skipping actions
85
+ * @default false
86
+ */
87
+ useWindowListener: boolean;
80
88
  /**
81
89
  * The debounced interval in milliseconds for updating the aspect ratio
82
90
  *
@@ -155,11 +163,6 @@ export type GameConfig = {
155
163
  * @default [" "]
156
164
  */
157
165
  nextKey: React.KeyboardEvent["key"][];
158
- /**
159
- * The speed of the text effects in characters per second.
160
- * @default 10
161
- */
162
- cps: number;
163
166
  /**
164
167
  * If true, the game will scale the dialog to fit the screen
165
168
  *
@@ -64,3 +64,4 @@ export type NamedColor = "aliceblue" | "antiquewhite" | "aqua" | "aquamarine" |
64
64
  export interface ActionSearchOptions {
65
65
  allowFutureScene?: boolean;
66
66
  }
67
+ export type { SavedGame } from "./gameTypes";
@@ -1 +1 @@
1
- export {};
1
+ export default AspectScaleImage;
@@ -0,0 +1,4 @@
1
+ import { GameState } from "../../../../game/nlcore/common/game";
2
+ export default function PreferenceUpdateAnnouncer({ gameState }: Readonly<{
3
+ gameState: GameState;
4
+ }>): null;
@@ -0,0 +1,4 @@
1
+ import { GameState } from "../../gameState";
2
+ export declare function RenderEventAnnoucer({ gameState }: {
3
+ gameState: GameState;
4
+ }): null;
@@ -9,6 +9,7 @@ type DialogEvents = {
9
9
  "event:dialog.complete": [];
10
10
  "event:dialog.forceSkip": [];
11
11
  "event:dialog.onFlush": [];
12
+ "event:dialog.simulateClick": [];
12
13
  };
13
14
  type DialogStateConfig = {
14
15
  useTypeEffect: boolean;
@@ -22,6 +23,7 @@ export declare class DialogState {
22
23
  complete: "event:dialog.complete";
23
24
  forceSkip: "event:dialog.forceSkip";
24
25
  onFlush: "event:dialog.onFlush";
26
+ simulateClick: "event:dialog.simulateClick";
25
27
  };
26
28
  readonly config: Readonly<DialogStateConfig>;
27
29
  readonly events: EventDispatcher<DialogEvents>;