narraleaf-react 0.0.2 → 0.0.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.
@@ -31,7 +31,7 @@ export declare const SceneActionTypes: {
31
31
  readonly applyTransform: "scene:applyTransform";
32
32
  };
33
33
  export type SceneActionContentType = {
34
- [K in typeof SceneActionTypes[keyof typeof SceneActionTypes]]: K extends typeof SceneActionTypes["action"] ? Scene : K extends typeof SceneActionTypes["sleep"] ? number | Promise<any> | Awaitable<any, any> : K extends typeof SceneActionTypes["setBackground"] ? [Background["background"]] : K extends typeof SceneActionTypes["setTransition"] ? [ITransition | null] : K extends typeof SceneActionTypes["applyTransition"] ? [ITransition] : K extends typeof SceneActionTypes["init"] ? [] : K extends typeof SceneActionTypes["exit"] ? [] : K extends typeof SceneActionTypes["jumpTo"] ? [Scene] : K extends typeof SceneActionTypes["setBackgroundMusic"] ? [Sound, number?] : K extends typeof SceneActionTypes["preUnmount"] ? [] : K extends typeof SceneActionTypes["applyTransform"] ? [Transform] : any;
34
+ [K in typeof SceneActionTypes[keyof typeof SceneActionTypes]]: K extends typeof SceneActionTypes["action"] ? Scene : K extends typeof SceneActionTypes["sleep"] ? number | Promise<any> | Awaitable<any, any> : K extends typeof SceneActionTypes["setBackground"] ? [Background["background"]] : K extends typeof SceneActionTypes["setTransition"] ? [ITransition | null] : K extends typeof SceneActionTypes["applyTransition"] ? [ITransition] : K extends typeof SceneActionTypes["init"] ? [] : K extends typeof SceneActionTypes["exit"] ? [] : K extends typeof SceneActionTypes["jumpTo"] ? [Scene] : K extends typeof SceneActionTypes["setBackgroundMusic"] ? [Sound | null, number?] : K extends typeof SceneActionTypes["preUnmount"] ? [] : K extends typeof SceneActionTypes["applyTransform"] ? [Transform] : any;
35
35
  };
36
36
  export declare const StoryActionTypes: {
37
37
  readonly action: "story:action";
@@ -8,10 +8,9 @@ export type RawData<T> = {
8
8
  data: T;
9
9
  };
10
10
  export declare class Node<C = any> {
11
- id: string;
12
11
  type: string;
13
12
  content: C | undefined;
14
- constructor(id: string, type: string);
13
+ constructor(type: string);
15
14
  setContent(content: C): this;
16
15
  getContent(): C;
17
16
  }
@@ -28,7 +27,7 @@ export declare class ContentNode<T = any> extends Node<T> {
28
27
  action: LogicAction.Actions | null;
29
28
  private child?;
30
29
  private parent;
31
- constructor(id: string, callee?: LogicAction.Actions, parent?: RenderableNode | null, child?: RenderableNode);
30
+ constructor(callee?: LogicAction.Actions, parent?: RenderableNode | null, child?: RenderableNode);
32
31
  setParent(parent: RenderableNode | null): this;
33
32
  setChild(child: RenderableNode | null): this;
34
33
  getChild(): RenderableNode | null;
@@ -2,8 +2,8 @@ import { Sentence, Word } from "./text";
2
2
  import { LogicAction } from "../action/logicAction";
3
3
  import { MenuAction } from "../action/actions";
4
4
  import { Actionable } from "../action/actionable";
5
- import Actions = LogicAction.Actions;
6
5
  import { Chained, Proxied } from "../action/chain";
6
+ import Actions = LogicAction.Actions;
7
7
  import GameElement = LogicAction.GameElement;
8
8
  export type MenuConfig = {};
9
9
  export type MenuChoice = {
@@ -99,7 +99,7 @@ export declare class Scene extends Constructable<Actions, Scene> {
99
99
  * @param fade If set, the fade-out effect will be applied to the previous music, and the fade-in effect will be applied to the current music, with a duration of {@link fade} milliseconds
100
100
  * @chainable
101
101
  */
102
- setBackgroundMusic(sound: Sound, fade?: number): ChainedScene;
102
+ setBackgroundMusic(sound: Sound | null, fade?: number): ChainedScene;
103
103
  /**
104
104
  * Add actions to the scene
105
105
  */
@@ -31,12 +31,8 @@ export declare namespace TransformDefinitions {
31
31
  background: Background["background"];
32
32
  backgroundOpacity: number;
33
33
  };
34
- type ImageTransformProps = ({
35
- opacity: number;
36
- scale: number;
37
- rotation: number;
34
+ type ImageTransformProps = CommonImage & {
38
35
  display: boolean;
39
- }) & {
40
36
  position: CommonImage["position"];
41
37
  };
42
38
  type Types = ImageTransformProps | SceneBackgroundTransformProps;
@@ -3,10 +3,10 @@ import { Base } from "../../elements/transition/base";
3
3
  import { Scene } from "../../elements/scene";
4
4
  import { StaticImageData } from "../../types";
5
5
  type FadeInProps = {
6
- style?: {
6
+ style?: Partial<{
7
7
  opacity: number;
8
8
  transform: string;
9
- };
9
+ }>;
10
10
  src?: string;
11
11
  };
12
12
  export declare class FadeIn extends Base<FadeInProps> implements ITransition {
@@ -1,21 +1,9 @@
1
- import type { CalledActionResult, GameConfig, GameSettings, SavedGame } from "./gameTypes";
2
- import { Awaitable, DeepPartial } from "../../util/data";
1
+ import type { GameConfig, GameSettings, SavedGame } from "./gameTypes";
2
+ import { DeepPartial } from "../../util/data";
3
3
  import { Storable } from "./store/storable";
4
- import { Story } from "./elements/story";
5
4
  import { LogicAction } from "./action/logicAction";
6
5
  import { GameState } from "../player/gameState";
7
6
  import { ComponentsTypes } from "../player/elements/type";
8
- declare const IdManager_base: {
9
- new (): {};
10
- _instance: {} | null;
11
- getInstance(): IdManager;
12
- };
13
- declare class IdManager extends IdManager_base {
14
- private id;
15
- getId(): number;
16
- getStringId(): string;
17
- prefix(prefix: string, value: string, separator?: string): string;
18
- }
19
7
  declare enum GameSettingsNamespace {
20
8
  game = "game"
21
9
  }
@@ -26,17 +14,16 @@ export declare class Game {
26
14
  };
27
15
  static DefaultConfig: GameConfig;
28
16
  static GameSettingsNamespace: typeof GameSettingsNamespace;
29
- static getIdManager(): IdManager;
30
- readonly config: Readonly<GameConfig>;
31
- liveGame: LiveGame | null;
32
17
  /**
33
18
  * Create a new game
34
19
  * @param config - Game configuration
35
20
  */
36
21
  constructor(config: DeepPartial<GameConfig>);
22
+ /**
23
+ * Override the default component
24
+ */
37
25
  useComponent<T extends keyof ComponentsTypes>(key: T, components: ComponentsTypes[T]): this;
38
26
  getLiveGame(): LiveGame;
39
- private createLiveGame;
40
27
  }
41
28
  export declare class LiveGame {
42
29
  static DefaultNamespaces: {
@@ -46,33 +33,23 @@ export declare class LiveGame {
46
33
  readonly game: "game";
47
34
  };
48
35
  game: Game;
49
- storable: Storable;
50
- currentSavedGame: SavedGame | null;
51
- story: Story | null;
52
- lockedAwaiting: Awaitable<CalledActionResult, any> | null;
53
- _lockedCount: number;
54
- private currentAction;
55
- constructor(game: Game);
56
- initNamespaces(): this;
57
36
  getStorable(): Storable;
58
- loadStory(story: Story): this;
59
37
  /**
60
38
  * Start a new game
61
39
  */
62
- newGame(): this;
40
+ newGame({ gameState }: {
41
+ gameState: GameState;
42
+ }): this;
63
43
  /**
64
44
  * Load a saved game
65
45
  *
66
46
  * Note: Even if you change just a single line of code, the saved game might not be compatible with the new version
67
47
  *
68
- * After calling this method, the current game state will be lost, can the stage will trigger force reset
48
+ * After calling this method, the current game state will be lost, and the stage will trigger force reset
69
49
  */
70
50
  deserialize(savedGame: SavedGame, { gameState }: {
71
51
  gameState: GameState;
72
52
  }): void;
73
- reset({ gameState }: {
74
- gameState: GameState;
75
- }): void;
76
53
  /**
77
54
  * Serialize the current game state
78
55
  *
@@ -83,12 +60,6 @@ export declare class LiveGame {
83
60
  serialize({ gameState }: {
84
61
  gameState: GameState;
85
62
  }): SavedGame;
86
- getCurrentAction(): LogicAction.Actions | null;
87
- setCurrentAction(action: LogicAction.Actions | null): this;
88
- next(state: GameState): CalledActionResult | Awaitable<CalledActionResult, CalledActionResult> | null;
89
- abortAwaiting(): void;
90
- executeAction(state: GameState, action: LogicAction.Actions): LogicAction.Actions | Awaitable<CalledActionResult, CalledActionResult> | null;
91
- private getNewSavedGame;
92
63
  }
93
64
  declare const _default: {
94
65
  Game: typeof Game;
@@ -20,7 +20,6 @@ export interface SavedGame {
20
20
  };
21
21
  }
22
22
  export type GameConfig = {
23
- version: string;
24
23
  player: {
25
24
  contentContainerId: string;
26
25
  /**
@@ -1,31 +1,12 @@
1
- import { BaseStorableTypeName, NameSpaceContent, StorableData, StorableType, WrappedStorableData } from "../store/type";
1
+ import { NameSpaceContent } from "../store/type";
2
2
  export declare class Namespace<T extends NameSpaceContent<keyof T>> {
3
+ static isSerializable(value: any): boolean;
3
4
  name: string;
4
- key: string;
5
- content: NameSpaceContent<keyof T>;
6
5
  constructor(name: string, initContent: T, key?: string);
7
- static isSerializable(value: any): boolean;
8
6
  set<Key extends keyof T>(key: Key, value: T[Key]): this;
9
7
  get<Key extends keyof T = any>(key: Key): T[Key];
10
- toData(): {
11
- [key: string]: WrappedStorableData;
12
- };
13
- load(data: T): void;
14
- serialize(): {
15
- [key: string]: WrappedStorableData<any>;
16
- };
17
- deserialize(data: {
18
- [key: string]: WrappedStorableData;
19
- }): void;
20
- toTypeName(value: StorableType): BaseStorableTypeName;
21
- wrap(data: StorableType): WrappedStorableData<any>;
22
- unwrap(data: WrappedStorableData): StorableType;
23
8
  }
24
9
  export declare class Storable {
25
- namespaces: {
26
- [key: string]: Namespace<any>;
27
- };
28
- constructor();
29
10
  addNamespace<T extends NameSpaceContent<keyof T>>(namespace: Namespace<T>): this;
30
11
  getNamespace<T extends NameSpaceContent<keyof T> = any>(key: string): Namespace<T>;
31
12
  setNamespace<T extends NameSpaceContent<keyof T> = any>(key: string, namespace: Namespace<T>): this;
@@ -35,10 +16,4 @@ export declare class Storable {
35
16
  keys(): string[];
36
17
  values(): Namespace<any>[];
37
18
  entries(): [string, Namespace<any>][];
38
- toData(): {
39
- [key: string]: StorableData<string>;
40
- };
41
- load(data: {
42
- [key: string]: StorableData;
43
- }): void;
44
19
  }
@@ -3,8 +3,9 @@ import { SayElementProps } from "../elements/say/type";
3
3
  import { MenuElementProps } from "../elements/menu/type";
4
4
  import { Story } from "../../nlcore/elements/story";
5
5
  import clsx from "clsx";
6
- import { Game } from "../../nlcore/game";
6
+ import { Game, LiveGame } from "../../nlcore/game";
7
7
  import { GameState } from "../gameState";
8
+ import { Storable } from "../../nlcore/store/storable";
8
9
  export type Components<T extends Record<string, any>> = (props: Readonly<T>) => React.JSX.Element;
9
10
  export type SayComponent = Components<SayElementProps>;
10
11
  export type MenuComponent = Components<MenuElementProps>;
@@ -15,7 +16,9 @@ export type ComponentsTypes = {
15
16
  export type { SayElementProps, MenuElementProps, };
16
17
  export type PlayerEventContext = {
17
18
  game: Game;
18
- state: GameState;
19
+ gameState: GameState;
20
+ liveGame: LiveGame;
21
+ storable: Storable;
19
22
  };
20
23
  export interface PlayerProps {
21
24
  story: Story;
@@ -34,6 +34,7 @@ export type PlayerStateData = {
34
34
  };
35
35
  export type PlayerAction = CalledActionResult;
36
36
  interface StageUtils {
37
+ update: () => void;
37
38
  forceUpdate: () => void;
38
39
  next: () => void;
39
40
  dispatch: (action: PlayerAction) => void;
@@ -42,6 +43,7 @@ type GameStateEvents = {
42
43
  "event:state.ready": [];
43
44
  "event:state.end": [];
44
45
  "event:state.player.skip": [];
46
+ "event:state.preload.unmount": [];
45
47
  };
46
48
  export declare class GameState {
47
49
  static EventTypes: {