narraleaf-react 0.9.0 → 0.10.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 (46) hide show
  1. package/LICENSE +373 -373
  2. package/README.md +165 -147
  3. package/dist/built-in.d.ts +3 -0
  4. package/dist/built-in.js +1 -0
  5. package/dist/game/nlcore/action/action.d.ts +9 -5
  6. package/dist/game/nlcore/action/actionTypes.d.ts +10 -10
  7. package/dist/game/nlcore/action/actions/menuAction.d.ts +1 -4
  8. package/dist/game/nlcore/action/logicAction.d.ts +29 -29
  9. package/dist/game/nlcore/common/elements.d.ts +4 -2
  10. package/dist/game/nlcore/common/transition.d.ts +2 -1
  11. package/dist/game/nlcore/elements/built-in/DevTools.d.ts +2 -0
  12. package/dist/game/nlcore/elements/built-in/built-in.d.ts +2 -0
  13. package/dist/game/nlcore/elements/built-in/screenEffects.d.ts +31 -0
  14. package/dist/game/nlcore/elements/character/avatar.d.ts +35 -0
  15. package/dist/game/nlcore/elements/character/sentence.d.ts +14 -0
  16. package/dist/game/nlcore/elements/character.d.ts +30 -0
  17. package/dist/game/nlcore/elements/displayable/displayable.d.ts +84 -0
  18. package/dist/game/nlcore/elements/displayable/image.d.ts +2 -2
  19. package/dist/game/nlcore/elements/displayable/text.d.ts +2 -2
  20. package/dist/game/nlcore/elements/layer.d.ts +1 -2
  21. package/dist/game/nlcore/elements/scene.d.ts +2 -1
  22. package/dist/game/nlcore/elements/transform/transform.d.ts +26 -3
  23. package/dist/game/nlcore/elements/transform/type.d.ts +30 -2
  24. package/dist/game/nlcore/elements/transition/transitions/image/maskTransition.d.ts +38 -0
  25. package/dist/game/nlcore/game.d.ts +60 -0
  26. package/dist/game/nlcore/gameTypes.d.ts +1 -36
  27. package/dist/game/player/Tasks.d.ts +4 -1
  28. package/dist/game/player/elements/Player.d.ts +1 -1
  29. package/dist/game/player/elements/menu/UIMenu/Item.d.ts +3 -2
  30. package/dist/game/player/elements/menu/type.d.ts +1 -0
  31. package/dist/game/player/elements/say/Avatar.d.ts +13 -0
  32. package/dist/game/player/elements/say/Nametag.d.ts +6 -3
  33. package/dist/game/player/elements/say/Sentence.d.ts +76 -13
  34. package/dist/game/player/elements/say/UIDialog.d.ts +6 -2
  35. package/dist/game/player/elements/say/type.d.ts +4 -2
  36. package/dist/game/player/elements/say/useDialog.d.ts +3 -0
  37. package/dist/game/player/elements/type.d.ts +27 -2
  38. package/dist/game/player/gameState.d.ts +5 -0
  39. package/dist/game/player/lib/AudioManager.d.ts +1 -0
  40. package/dist/game/player/lib/ErrorFallback.d.ts +5 -1
  41. package/dist/game/player/lib/Preloaded.d.ts +1 -0
  42. package/dist/game/player/libElements.d.ts +7 -2
  43. package/dist/game/player/provider/game-state.d.ts +1 -0
  44. package/dist/main.js +42 -40
  45. package/dist/util/data.d.ts +15 -2
  46. package/package.json +114 -107
@@ -4,12 +4,22 @@ import { Word } from "../../elements/character/word";
4
4
  import type { ScriptCtx } from "../../elements/script";
5
5
  import { Sound } from "../../elements/sound";
6
6
  import { Color, Font } from "../../types";
7
+ import type { DialogAvatar } from "../../elements/character/avatar";
8
+ /**
9
+ * User-provided runtime metadata attached to a sentence; not serialized with saves.
10
+ * Use plain serializable values when possible.
11
+ */
12
+ export type SentenceMetadata = Record<string, unknown>;
7
13
  export type SentenceConfig = {
8
14
  pause?: boolean | number;
9
15
  voice: Sound | null;
10
16
  character: Character | null;
11
17
  voiceId: string | number | null;
12
18
  color?: Color;
19
+ /** Optional runtime-only metadata for UI hooks and integrations */
20
+ metadata?: SentenceMetadata;
21
+ /** Optional per-line dialog avatar override. Use `false` to hide the avatar for this sentence. */
22
+ avatar?: DialogAvatar | false;
13
23
  } & Font;
14
24
  export type SentenceUserConfig = Partial<Omit<SentenceConfig, "voice"> & {
15
25
  voice: Sound | string | null | undefined;
@@ -20,6 +30,10 @@ export type StaticWord<T extends string | DynamicWord | Pausing = string | Dynam
20
30
  export type SingleWord = StaticWord | DynamicWord;
21
31
  export type SentencePrompt = SingleWord[] | SingleWord;
22
32
  export declare class Sentence {
33
+ /**
34
+ * Returns runtime-only user metadata from sentence config; undefined when not set.
35
+ */
36
+ getMetadata(): SentenceMetadata | undefined;
23
37
  /**
24
38
  * Build a new sentence from a prompt or mix of words, pauses, and dynamic data.
25
39
  * @param text - The sentence prompt used to render the dialogue.
@@ -4,8 +4,12 @@ import { DeepPartial } from "../../../util/data";
4
4
  import { Actionable } from "../action/actionable";
5
5
  import { Chained, Proxied } from "../action/chain";
6
6
  import { Sentence, SentencePrompt, SentenceUserConfig, SingleWord } from "../elements/character/sentence";
7
+ import type { CharacterPortraitConfig, DialogAvatar } from "../elements/character/avatar";
8
+ import type { Image } from "../elements/displayable/image";
7
9
  export type CharacterConfig = {
8
10
  color?: Color;
11
+ avatar?: DialogAvatar | false;
12
+ portraits: (Image | CharacterPortraitConfig)[];
9
13
  };
10
14
  export interface Character {
11
15
  (content: string, config?: SentenceUserConfig): Proxied<Character, Chained<LogicAction.Actions>>;
@@ -58,6 +62,32 @@ export declare class Character extends Actionable<CharacterStateData, Character>
58
62
  * ```
59
63
  */
60
64
  setName(name: string): Proxied<Character, Chained<LogicAction.Actions>>;
65
+ /**
66
+ * Set the avatar strategy used by dialogs for this character.
67
+ * @param avatar - Image source, resolver, `false` to hide by default, or `null` for no avatar.
68
+ * @example
69
+ * ```ts
70
+ * character.setAvatar("alice-avatar.png");
71
+ * ```
72
+ */
73
+ setAvatar(avatar: DialogAvatar | false | null): this;
74
+ /**
75
+ * Register a portrait image as a possible visual source for this character's dialog avatar.
76
+ * @param image - The stage image that represents the character.
77
+ * @param config - Optional avatar override for this portrait.
78
+ * @example
79
+ * ```ts
80
+ * character.addPortrait(aliceSprite, { avatar: "alice-happy-avatar.png" });
81
+ * ```
82
+ */
83
+ addPortrait(image: Image, config?: {
84
+ avatar?: DialogAvatar;
85
+ }): this;
86
+ /**
87
+ * Replace all portrait bindings for this character.
88
+ * @param portraits - Stage images or image/avatar pairs.
89
+ */
90
+ setPortraits(portraits: (Image | CharacterPortraitConfig)[]): this;
61
91
  apply(content: string, config?: SentenceUserConfig): Proxied<Character, Chained<LogicAction.Actions>>;
62
92
  apply(content: Sentence): Proxied<Character, Chained<LogicAction.Actions>>;
63
93
  apply(content: SentencePrompt, config?: SentenceUserConfig): Proxied<Character, Chained<LogicAction.Actions>>;
@@ -4,6 +4,7 @@ import { Chained, Proxied } from "../../action/chain";
4
4
  import { LogicAction } from "../../action/logicAction";
5
5
  import { EventfulDisplayable } from "../../../player/elements/displayable/type";
6
6
  import type { TransformDefinitions } from "../../elements/transform/type";
7
+ import type { ImageSrc } from "../../types";
7
8
  export declare abstract class Displayable<StateData extends Record<string, any>, Self extends Displayable<any, any, any>, TransformType extends TransformDefinitions.Types = TransformDefinitions.Types> extends Actionable<StateData, Self> implements EventfulDisplayable {
8
9
  /**
9
10
  * Set Image Position
@@ -92,6 +93,83 @@ export declare abstract class Displayable<StateData extends Record<string, any>,
92
93
  * ```
93
94
  */
94
95
  opacity(opacity: number, duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Self, Chained<LogicAction.Actions>>;
96
+ /**
97
+ * Apply visual effects to the Displayable.
98
+ *
99
+ * This is the low-level effect entry. Resource-aware helpers such as
100
+ * {@link Displayable.mask} should be preferred when an effect depends on an image source.
101
+ *
102
+ * @chainable
103
+ */
104
+ effect(effect: TransformDefinitions.VisualEffectTransformProps, options?: TransformDefinitions.VisualEffectOptions): Proxied<Self, Chained<LogicAction.Actions, Self>>;
105
+ /**
106
+ * Apply an image mask to the Displayable.
107
+ *
108
+ * The source is registered for image preload and resolved to a CSS `url(...)` mask image.
109
+ *
110
+ * @chainable
111
+ */
112
+ mask(src: ImageSrc, options?: TransformDefinitions.MaskOptions): Proxied<Self, Chained<LogicAction.Actions, Self>>;
113
+ /**
114
+ * Clear the current CSS mask from the Displayable.
115
+ *
116
+ * @chainable
117
+ */
118
+ clearMask(options?: TransformDefinitions.VisualEffectOptions): Proxied<Self, Chained<LogicAction.Actions, Self>>;
119
+ /**
120
+ * Apply a CSS clip-path to the Displayable.
121
+ *
122
+ * @chainable
123
+ */
124
+ clip(clipPath: TransformDefinitions.VisualEffectTransformProps["clipPath"], options?: TransformDefinitions.VisualEffectOptions): Proxied<Self, Chained<LogicAction.Actions, Self>>;
125
+ /**
126
+ * Clear the current CSS clip-path from the Displayable.
127
+ *
128
+ * @chainable
129
+ */
130
+ clearClip(options?: TransformDefinitions.VisualEffectOptions): Proxied<Self, Chained<LogicAction.Actions, Self>>;
131
+ /**
132
+ * Reveal the Displayable with an animated circular clip-path.
133
+ *
134
+ * @chainable
135
+ */
136
+ circleReveal(options?: TransformDefinitions.CircleRevealOptions): Proxied<Self, Chained<LogicAction.Actions, Self>>;
137
+ /**
138
+ * Close the Displayable with an animated circular clip-path.
139
+ *
140
+ * @chainable
141
+ */
142
+ circleClose(options?: TransformDefinitions.CircleCloseOptions): Proxied<Self, Chained<LogicAction.Actions, Self>>;
143
+ /**
144
+ * Reveal or close the Displayable with an animated directional wipe.
145
+ *
146
+ * @chainable
147
+ */
148
+ wipe(options?: TransformDefinitions.WipeOptions): Proxied<Self, Chained<LogicAction.Actions, Self>>;
149
+ /**
150
+ * Apply a CSS filter to the Displayable.
151
+ *
152
+ * @chainable
153
+ */
154
+ filter(filter: TransformDefinitions.VisualEffectTransformProps["filter"], options?: TransformDefinitions.VisualEffectOptions): Proxied<Self, Chained<LogicAction.Actions, Self>>;
155
+ /**
156
+ * Clear the current CSS filter from the Displayable.
157
+ *
158
+ * @chainable
159
+ */
160
+ clearFilter(options?: TransformDefinitions.VisualEffectOptions): Proxied<Self, Chained<LogicAction.Actions, Self>>;
161
+ /**
162
+ * Apply a CSS backdrop-filter to the Displayable.
163
+ *
164
+ * @chainable
165
+ */
166
+ backdrop(backdropFilter: TransformDefinitions.VisualEffectTransformProps["backdropFilter"], options?: TransformDefinitions.VisualEffectOptions): Proxied<Self, Chained<LogicAction.Actions, Self>>;
167
+ /**
168
+ * Apply a CSS mix-blend-mode to the Displayable.
169
+ *
170
+ * @chainable
171
+ */
172
+ blend(mixBlendMode: TransformDefinitions.VisualEffectTransformProps["mixBlendMode"], options?: TransformDefinitions.VisualEffectOptions): Proxied<Self, Chained<LogicAction.Actions, Self>>;
95
173
  /**
96
174
  * Apply a transform to the Displayable
97
175
  * @chainable
@@ -101,6 +179,12 @@ export declare abstract class Displayable<StateData extends Record<string, any>,
101
179
  * ```
102
180
  */
103
181
  transform(transform: Transform<TransformType>): Proxied<Self, Chained<LogicAction.Actions, Self>>;
182
+ private registerEffectSrc;
183
+ private static toCSSUrl;
184
+ private static extractCSSUrls;
185
+ private static createClipPathTransform;
186
+ private static circleClipPath;
187
+ private static wipeClipPath;
104
188
  /**
105
189
  * Show the Displayable
106
190
  *
@@ -1,5 +1,5 @@
1
1
  import type { TransformDefinitions } from "../../elements/transform/type";
2
- import { Color, CommonDisplayableConfig, ImageSrc } from "../../types";
2
+ import { Color, ImageSrc } from "../../types";
3
3
  import { LogicAction } from "../../game";
4
4
  import { FlexibleTuple, SelectElementFromEach } from "../../../../util/data";
5
5
  import { Chained, Proxied } from "../../action/chain";
@@ -14,7 +14,7 @@ export type TagDefinitionObject<T extends TagGroupDefinition> = {
14
14
  resolve: TagSrcResolver<T>;
15
15
  };
16
16
  type ImageSrcType<T extends TagGroupDefinition | null = TagGroupDefinition | null> = T extends TagGroupDefinition ? TagDefinition<T> : (Color | ImageSrc);
17
- export interface IImageUserConfig<Tag extends TagGroupDefinition | null = TagGroupDefinition | null> extends CommonDisplayableConfig {
17
+ export interface IImageUserConfig<Tag extends TagGroupDefinition | null = TagGroupDefinition | null> extends TransformDefinitions.ImageTransformProps {
18
18
  /**
19
19
  * The name of the image, only for debugging purposes
20
20
  */
@@ -1,4 +1,4 @@
1
- import { Color, CommonDisplayableConfig } from "../../types";
1
+ import { Color } from "../../types";
2
2
  import { Chained, Proxied } from "../../action/chain";
3
3
  import { LogicAction } from "../../action/logicAction";
4
4
  import type { TransformDefinitions } from "../../elements/transform/type";
@@ -16,7 +16,7 @@ export type TextState = {
16
16
  display: boolean;
17
17
  text: string;
18
18
  };
19
- export interface ITextUserConfig extends CommonDisplayableConfig {
19
+ export interface ITextUserConfig extends TransformDefinitions.TextTransformProps {
20
20
  /**
21
21
  * Where to align the text horizontally
22
22
  * @default "center"
@@ -1,4 +1,3 @@
1
- import { CommonDisplayableConfig } from "../types";
2
1
  import { LogicAction } from "../action/logicAction";
3
2
  import { TransformDefinitions } from "../elements/transform/type";
4
3
  import { Displayable } from "../elements/displayable/displayable";
@@ -6,7 +5,7 @@ import { EventfulDisplayable } from "../../player/elements/displayable/type";
6
5
  import { Image } from "../elements/displayable/image";
7
6
  import { Text } from "../elements/displayable/text";
8
7
  import { Chained, Proxied } from "../action/chain";
9
- export interface ILayerUserConfig extends CommonDisplayableConfig {
8
+ export interface ILayerUserConfig extends TransformDefinitions.ImageTransformProps {
10
9
  /**
11
10
  * The z-index of the layer, higher z-index will be rendered on top of the lower z-index, allows negative values.
12
11
  *
@@ -3,12 +3,13 @@ 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 { ActionStatements, Persistent } from "../common/core";
7
6
  import { Chained, Proxied } from "../action/chain";
8
7
  import { ImageTransition } from "../elements/transition/transitions/image/imageTransition";
9
8
  import { Layer } from "../elements/layer";
10
9
  import { NVLToken } from "./nvl";
11
10
  import type { TransformDefinitions } from "../elements/transform/type";
11
+ import type { ActionStatements } from "../elements/type";
12
+ import type { Persistent } from "../elements/persistent";
12
13
  export interface ISceneUserConfig {
13
14
  /**
14
15
  * Background music
@@ -1,4 +1,3 @@
1
- import type { CommonDisplayableConfig } from "../../types";
2
1
  import { TransformDefinitions } from "./type";
3
2
  import { CSSProps } from "../../elements/transition/type";
4
3
  type OverwriteMap = {
@@ -8,7 +7,7 @@ export type OverwriteDefinition = {
8
7
  [K in keyof OverwriteMap]?: OverwriteHandler<OverwriteMap[K]>;
9
8
  };
10
9
  type OverwriteHandler<T> = (value: Partial<TransformDefinitions.Types>) => T;
11
- export declare class Transform<T extends TransformDefinitions.Types = CommonDisplayableConfig> {
10
+ export declare class Transform<T extends TransformDefinitions.Types = TransformDefinitions.Types> {
12
11
  /**
13
12
  * Apply transform immediately
14
13
  */
@@ -30,7 +29,7 @@ export declare class Transform<T extends TransformDefinitions.Types = CommonDisp
30
29
  * @param config - The config for the transform.
31
30
  * @returns A new transform with the given config.
32
31
  */
33
- static create<T extends TransformDefinitions.Types = CommonDisplayableConfig>(config?: Partial<TransformDefinitions.TransformConfig>): Transform<T>;
32
+ static create<T extends TransformDefinitions.Types = TransformDefinitions.Types>(config?: Partial<TransformDefinitions.TransformConfig>): Transform<T>;
34
33
  /**
35
34
  * @example
36
35
  * ```ts
@@ -124,5 +123,29 @@ export declare class Transform<T extends TransformDefinitions.Types = CommonDisp
124
123
  * @returns {this} The current Transform instance for method chaining.
125
124
  */
126
125
  fontColor(fontColor: TransformDefinitions.Types["fontColor"]): this;
126
+ /**
127
+ * Set visual effect fields in the current staging sequence.
128
+ */
129
+ effect(effect: TransformDefinitions.VisualEffectTransformProps): this;
130
+ /**
131
+ * Set the CSS mask image of the current staging sequence.
132
+ */
133
+ maskImage(maskImage: TransformDefinitions.Types["maskImage"]): this;
134
+ /**
135
+ * Set the CSS clip-path of the current staging sequence.
136
+ */
137
+ clipPath(clipPath: TransformDefinitions.Types["clipPath"]): this;
138
+ /**
139
+ * Set the CSS filter of the current staging sequence.
140
+ */
141
+ filter(filter: TransformDefinitions.Types["filter"]): this;
142
+ /**
143
+ * Set the CSS backdrop-filter of the current staging sequence.
144
+ */
145
+ backdropFilter(backdropFilter: TransformDefinitions.Types["backdropFilter"]): this;
146
+ /**
147
+ * Set the CSS mix-blend-mode of the current staging sequence.
148
+ */
149
+ mixBlendMode(mixBlendMode: TransformDefinitions.Types["mixBlendMode"]): this;
127
150
  }
128
151
  export {};
@@ -1,4 +1,5 @@
1
1
  import { Color, CommonDisplayableConfig } from "../../types";
2
+ import type React from "react";
2
3
  export declare namespace TransformDefinitions {
3
4
  type BezierDefinition = [number, number, number, number];
4
5
  type CustomEasingFunction = (t: number) => number;
@@ -17,10 +18,37 @@ export declare namespace TransformDefinitions {
17
18
  repeat?: number;
18
19
  repeatDelay?: number;
19
20
  };
20
- type ImageTransformProps = CommonDisplayableConfig & {};
21
+ type VisualEffectTransformProps = {
22
+ maskImage?: React.CSSProperties["maskImage"];
23
+ maskSize?: React.CSSProperties["maskSize"];
24
+ maskPosition?: React.CSSProperties["maskPosition"];
25
+ maskRepeat?: React.CSSProperties["maskRepeat"];
26
+ maskMode?: React.CSSProperties["maskMode"];
27
+ clipPath?: React.CSSProperties["clipPath"];
28
+ filter?: React.CSSProperties["filter"];
29
+ backdropFilter?: React.CSSProperties["backdropFilter"];
30
+ mixBlendMode?: React.CSSProperties["mixBlendMode"];
31
+ };
32
+ type VisualEffectOptions = Partial<CommonTransformProps>;
33
+ type MaskOptions = VisualEffectOptions & Pick<VisualEffectTransformProps, "maskSize" | "maskPosition" | "maskRepeat" | "maskMode">;
34
+ type WipeDirection = "left" | "right" | "top" | "bottom";
35
+ type CircleClipOptions = VisualEffectOptions & {
36
+ center?: string;
37
+ from?: number;
38
+ to?: number;
39
+ clearClip?: boolean;
40
+ };
41
+ type CircleRevealOptions = CircleClipOptions;
42
+ type CircleCloseOptions = CircleClipOptions;
43
+ type WipeOptions = VisualEffectOptions & {
44
+ direction?: WipeDirection;
45
+ reverse?: boolean;
46
+ clearClip?: boolean;
47
+ };
48
+ type ImageTransformProps = CommonDisplayableConfig & VisualEffectTransformProps;
21
49
  type TextTransformProps = CommonDisplayableConfig & {
22
50
  fontColor?: Color;
23
- };
51
+ } & VisualEffectTransformProps;
24
52
  type Types = CommonDisplayableConfig & ImageTransformProps & TextTransformProps;
25
53
  type SequenceProps<T> = Partial<T>;
26
54
  type SequenceOptions = Partial<CommonTransformProps>;
@@ -0,0 +1,38 @@
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 type MaskTransitionCircleOptions = {
6
+ duration: number;
7
+ easing?: TransformDefinitions.EasingDefinition;
8
+ center?: string;
9
+ from?: number;
10
+ to?: number;
11
+ };
12
+ export type MaskTransitionWipeOptions = {
13
+ duration: number;
14
+ easing?: TransformDefinitions.EasingDefinition;
15
+ direction?: TransformDefinitions.WipeDirection;
16
+ reverse?: boolean;
17
+ };
18
+ export declare class MaskTransition extends ImageTransition<AnimationType> {
19
+ private duration;
20
+ private easing;
21
+ private clipPathResolver;
22
+ private constructor();
23
+ /**
24
+ * Reveal the target image through an animated circular clip-path.
25
+ */
26
+ static circle(options: MaskTransitionCircleOptions): MaskTransition;
27
+ /**
28
+ * Reveal or close the target image through an animated directional wipe.
29
+ */
30
+ static wipe(options: MaskTransitionWipeOptions): MaskTransition;
31
+ createTask(): TransitionTask<HTMLImageElement, AnimationType>;
32
+ copy(): MaskTransition;
33
+ private static lerp;
34
+ private static circleClipPath;
35
+ private static wipeClipPath;
36
+ private static formatNumber;
37
+ }
38
+ export {};
@@ -3,9 +3,13 @@ import { DeepPartial, Hooks, StringKeyOf } from "../../util/data";
3
3
  import { LogicAction } from "./action/logicAction";
4
4
  import { LiveGame } from "./game/liveGame";
5
5
  import { Preference } from "./game/preference";
6
+ import { GameState } from "../player/gameState";
6
7
  import { Plugins, IGamePluginRegistry } from "./game/plugin/plugin";
7
8
  import { LayoutRouter } from "../player/lib/PageRouter/router";
8
9
  import { KeyMap } from "./game/keyMap";
10
+ import type { Storable } from "./elements/persistent/storable";
11
+ import type { Scene } from "./elements/scene";
12
+ import type { LiveGameEventHandler, LiveGameEventToken } from "./types";
9
13
  declare enum GameSettingsNamespace {
10
14
  game = "game"
11
15
  }
@@ -34,6 +38,17 @@ export type GameHooks = {
34
38
  */
35
39
  "afterRestore": [];
36
40
  };
41
+ export type GameLifecycleEventContext = {
42
+ game: Game;
43
+ gameState: GameState;
44
+ liveGame: LiveGame;
45
+ storable: Storable;
46
+ scene: Scene | null;
47
+ };
48
+ export type GameLifecycleEvents = {
49
+ "event:game.preloadComplete": [ctx: GameLifecycleEventContext];
50
+ "event:game.firstSceneReady": [ctx: GameLifecycleEventContext];
51
+ };
37
52
  export declare class Game {
38
53
  static GameSettingsNamespace: typeof GameSettingsNamespace;
39
54
  readonly hooks: Hooks<GameHooks>;
@@ -45,11 +60,17 @@ export declare class Game {
45
60
  * Game key bindings
46
61
  */
47
62
  keyMap: KeyMap;
63
+ static LifecycleEventTypes: {
64
+ [K in keyof GameLifecycleEvents]: K;
65
+ };
48
66
  /**
49
67
  * Plugin registry
50
68
  */
51
69
  plugins: Plugins;
52
70
  router: LayoutRouter;
71
+ private readonly lifecycleEvents;
72
+ private preloadCompleteContext;
73
+ private firstSceneReadyContext;
53
74
  /**
54
75
  * Create a new game
55
76
  * @param config - Game configuration
@@ -78,6 +99,45 @@ export declare class Game {
78
99
  * @param plugin - The plugin to use
79
100
  */
80
101
  use(plugin: IGamePluginRegistry): this;
102
+ /**
103
+ * Listen for the initial preload pass completing.
104
+ *
105
+ * This is the point where the initial preload pass has actually finished.
106
+ * Use {@link whenPreloadComplete} if the listener may be registered after the event has fired.
107
+ */
108
+ onPreloadComplete(fc: LiveGameEventHandler<GameLifecycleEvents["event:game.preloadComplete"]>): LiveGameEventToken;
109
+ /**
110
+ * Listen once for the initial preload pass completing.
111
+ */
112
+ oncePreloadComplete(fc: LiveGameEventHandler<GameLifecycleEvents["event:game.preloadComplete"]>): LiveGameEventToken;
113
+ /**
114
+ * Resolve when the initial preload pass has completed.
115
+ */
116
+ whenPreloadComplete(): Promise<GameLifecycleEventContext>;
117
+ /**
118
+ * Whether the initial preload pass has completed.
119
+ */
120
+ isPreloadComplete(): boolean;
121
+ /**
122
+ * Listen for the first scene being fully ready.
123
+ *
124
+ * This fires after the initial preload pass has actually finished, after the first
125
+ * scene component is mounted, and after the browser has had a frame to render it.
126
+ * Use {@link whenFirstSceneReady} if the listener may be registered after the event has fired.
127
+ */
128
+ onFirstSceneReady(fc: LiveGameEventHandler<GameLifecycleEvents["event:game.firstSceneReady"]>): LiveGameEventToken;
129
+ /**
130
+ * Listen once for the first scene being fully ready.
131
+ */
132
+ onceFirstSceneReady(fc: LiveGameEventHandler<GameLifecycleEvents["event:game.firstSceneReady"]>): LiveGameEventToken;
133
+ /**
134
+ * Resolve when the first scene is fully ready.
135
+ */
136
+ whenFirstSceneReady(): Promise<GameLifecycleEventContext>;
137
+ /**
138
+ * Whether the first scene is fully ready.
139
+ */
140
+ isFirstSceneReady(): boolean;
81
141
  getLiveGame(): LiveGame;
82
142
  /**
83
143
  * Dispose the game and all its resources
@@ -8,7 +8,7 @@ import { GuardConfig } from "../player/guard";
8
8
  import React from "react";
9
9
  import { StackModel, StackModelRawData } from "./action/stackModel";
10
10
  import { MenuComponent, NotificationComponent, NvlDialogComponent, SayComponent } from "./common/player";
11
- import { Color, LiveGameEventToken } from "./types";
11
+ import { LiveGameEventToken } from "./types";
12
12
  export interface SavedGameMetaData {
13
13
  /**
14
14
  * The timestamp of when the game was created
@@ -251,16 +251,6 @@ export type GameConfig = {
251
251
  * @default false
252
252
  */
253
253
  allowSkipVideo: boolean;
254
- /**
255
- * The default text color for the dialog
256
- * @default "#000"
257
- */
258
- defaultTextColor: Color;
259
- /**
260
- * The default text color for the character nametag
261
- * @default "#000"
262
- */
263
- defaultNametagColor: Color;
264
254
  /**
265
255
  * The component to use for the notification
266
256
  * @default DefaultNotification
@@ -310,36 +300,11 @@ export type GameConfig = {
310
300
  */
311
301
  guard: GuardConfig;
312
302
  };
313
- /**
314
- * Default font size for the game
315
- * @default "16px"
316
- */
317
- fontSize: React.CSSProperties["fontSize"];
318
- /**
319
- * Default font weight for the game
320
- * @default 400
321
- */
322
- fontWeight: number;
323
- /**
324
- * Default font weight for the game
325
- * @default 700
326
- */
327
- fontWeightBold: number;
328
- /**
329
- * Default font family for the game
330
- * @default "sans-serif"
331
- */
332
- fontFamily: React.CSSProperties["fontFamily"];
333
303
  /**
334
304
  * Override the default stage
335
305
  * @default null
336
306
  */
337
307
  stage: React.ReactNode | null;
338
- /**
339
- * The default color for the menu choices
340
- * @default "#000"
341
- */
342
- defaultMenuChoiceColor: Color;
343
308
  /**
344
309
  * The maximum number of times a stack model can loop
345
310
  * @default 1000
@@ -1,6 +1,6 @@
1
1
  import { Awaitable } from "../../util/data";
2
2
  import { GameStateGuard } from "./guard";
3
- type TimelineStatus = "pending" | "cancelled" | "resolved";
3
+ type TimelineStatus = "pending" | "cancelled" | "resolved" | "failed";
4
4
  export declare class Timeline {
5
5
  awaitable: Awaitable;
6
6
  guard?: GameStateGuard | undefined;
@@ -74,6 +74,7 @@ export declare class Timeline {
74
74
  private children;
75
75
  private _onResolved;
76
76
  private _onCancelled;
77
+ private _onFailed;
77
78
  private _onTimelineRegistered;
78
79
  private _ableToAttach;
79
80
  private _status;
@@ -82,8 +83,10 @@ export declare class Timeline {
82
83
  isSettled(): boolean;
83
84
  isResolved(): boolean;
84
85
  isCancelled(): boolean;
86
+ isFailed(): boolean;
85
87
  onResolved(callback: () => void): void;
86
88
  onCancelled(callback: () => void): void;
89
+ onFailed(callback: (error: unknown) => void): void;
87
90
  onSettled(callback: () => void): void;
88
91
  abort(): void;
89
92
  attachChild(arg0: Awaitable | Timeline): this;
@@ -1,4 +1,4 @@
1
1
  import "client-only";
2
2
  import { PlayerProps } from "../elements/type";
3
3
  import React from "react";
4
- export default function Player({ story, width, height, className, onReady, onEnd, onError, children, active, }: Readonly<PlayerProps>): React.JSX.Element;
4
+ export default function Player({ story, width, height, className, onReady, onPreloadComplete, onPreloadedReady, onFirstSceneReady, onEnd, onError, children, active, }: Readonly<PlayerProps>): React.JSX.Element;
@@ -1,5 +1,6 @@
1
+ import { type TextAppearanceProps } from "../../../elements/say/Sentence";
1
2
  import React from "react";
2
- export interface ItemProps {
3
+ export interface ItemProps extends TextAppearanceProps {
3
4
  className?: string;
4
5
  style?: React.CSSProperties;
5
6
  /**
@@ -9,4 +10,4 @@ export interface ItemProps {
9
10
  */
10
11
  bindKey?: string;
11
12
  }
12
- export default function Item({ className, style, bindKey }: ItemProps): React.JSX.Element;
13
+ export default function Item({ className, style, bindKey, defaultColor, fontSize, fontWeight, fontWeightBold, fontFamily, }: ItemProps): React.JSX.Element;
@@ -10,6 +10,7 @@ export interface MenuElementProps {
10
10
  afterChoose: (choice: Chosen) => void;
11
11
  state: GameState;
12
12
  words: Word<Pausing | string>[] | null;
13
+ renderPrompt?: boolean;
13
14
  }
14
15
  export interface IUserMenuProps {
15
16
  items: number[];
@@ -0,0 +1,13 @@
1
+ import type { Character } from "../../../nlcore/elements/character";
2
+ import type { Image } from "../../../nlcore/elements/displayable/image";
3
+ import React from "react";
4
+ export type DialogAvatarContext = {
5
+ visible: boolean;
6
+ src: string | null;
7
+ character: Character | null;
8
+ portrait: Image | null;
9
+ alt: string;
10
+ };
11
+ export declare function useAvatar(): DialogAvatarContext;
12
+ export declare function Avatar({ className, style, alt, ...props }: React.ImgHTMLAttributes<HTMLImageElement>): React.JSX.Element | null;
13
+ export default Avatar;
@@ -1,9 +1,12 @@
1
1
  import React from "react";
2
2
  import type { Character } from "../../../nlcore/elements/character";
3
3
  import type { NvlDialogEntry } from "../../gameState";
4
- type NametagProps = React.HTMLAttributes<HTMLDivElement> & {
4
+ import type { Color } from "../../../../game/nlcore/types";
5
+ export type NametagProps = Omit<React.HTMLAttributes<HTMLDivElement>, "children" | "color"> & {
5
6
  entry?: NvlDialogEntry;
6
7
  character?: Character | null;
8
+ name?: React.ReactNode;
9
+ color?: Color;
10
+ children?: React.ReactNode;
7
11
  };
8
- export default function Nametag({ entry, character, ...props }: Readonly<NametagProps>): React.JSX.Element;
9
- export {};
12
+ export default function Nametag({ entry, character, name, color, children, style, ...props }: Readonly<NametagProps>): React.JSX.Element;