narraleaf-react 0.0.1-beta.12 → 0.0.1-beta.13

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.
@@ -30,8 +30,8 @@ export type SceneDataRaw = {
30
30
  state: {
31
31
  backgroundMusic?: SoundDataRaw | null;
32
32
  background?: Background["background"];
33
- backgroundImageState?: Partial<CommonImage>;
34
33
  };
34
+ backgroundImageState?: Partial<CommonImage>;
35
35
  };
36
36
  export type SceneEventTypes = {
37
37
  "event:scene.applyTransition": [ITransition | null];
@@ -46,35 +46,48 @@ export type SceneEventTypes = {
46
46
  "event:scene.setBackgroundMusic": [Sound | null, number];
47
47
  "event:scene.applyTransform": [Transform<ImageTransformProps>];
48
48
  };
49
- export declare class Scene extends Constructable<Actions> {
49
+ export declare class Scene extends Constructable<Actions, Scene> {
50
50
  static EventTypes: {
51
51
  [K in keyof SceneEventTypes]: K;
52
52
  };
53
53
  static defaultConfig: SceneConfig;
54
54
  static defaultState: SceneState;
55
- static targetAction: typeof SceneAction;
56
55
  readonly id: string;
57
56
  readonly name: string;
58
57
  readonly config: SceneConfig;
59
58
  state: SceneConfig & SceneState;
60
- srcManager: SrcManager;
61
- events: EventDispatcher<SceneEventTypes>;
59
+ readonly srcManager: SrcManager;
60
+ readonly events: EventDispatcher<SceneEventTypes>;
62
61
  backgroundImageState: Partial<CommonImage>;
63
62
  _liveState: {
64
63
  active: boolean;
65
64
  };
66
65
  sceneRoot?: SceneAction<"scene:action">;
67
66
  constructor(name: string, config?: DeepPartial<SceneConfig>);
67
+ /**
68
+ * Activate the scene
69
+ *
70
+ * This is only used when auto activation is not working
71
+ * @chainable
72
+ */
68
73
  activate(): ChainedScene;
74
+ /**
75
+ * Deactivate the scene
76
+ *
77
+ * This is only used when auto deactivation is not working
78
+ * @chainable
79
+ */
69
80
  deactivate(): ChainedScene;
70
81
  /**
71
82
  * Set background, if {@link transition} is provided, it will be applied
83
+ * @chainable
72
84
  */
73
85
  setBackground(background: Background["background"], transition?: ITransition): ChainedScene;
74
86
  /**
75
87
  * Apply a transform to the scene
76
88
  *
77
89
  * for example, you can shake the scene by applying a transform with a shake effect
90
+ * @chainable
78
91
  */
79
92
  applyTransform(transform: Transform<ImageTransformProps>): ChainedScene;
80
93
  /**
@@ -86,7 +99,6 @@ export declare class Scene extends Constructable<Actions> {
86
99
  * @chainable
87
100
  */
88
101
  jumpTo(arg0: Scene, config?: Partial<JumpConfig>): ChainedScene;
89
- transitionSceneBackground(scene?: Scene, transition?: ITransition): ChainedScene;
90
102
  /**
91
103
  * Wait for a period of time, the parameter can be the number of milliseconds, a Promise, or an unresolved {@link Awaitable}
92
104
  * @chainable
@@ -98,19 +110,26 @@ export declare class Scene extends Constructable<Actions> {
98
110
  * Set background music
99
111
  * @param sound Target music
100
112
  * @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
113
+ * @chainable
101
114
  */
102
115
  setBackgroundMusic(sound: Sound, fade?: number): ChainedScene;
103
- _$getBackgroundMusic(): Sound | null;
104
116
  toData(): SceneDataRaw | null;
105
117
  fromData(data: SceneDataRaw): this;
106
- _setTransition(transition: ITransition): ChainedScene;
107
- _applyTransition(transition: ITransition): ChainedScene;
108
- _toTransform(): Transform<ImageTransformProps>;
109
- _initTransform(): Transform<ImageTransformProps>;
110
- registerSrc(seen?: Set<Scene>): void;
118
+ getInitTransform(): Transform<ImageTransformProps>;
111
119
  action(actions: (ChainableAction | ChainableAction[])[]): this;
112
120
  action(actions: ((scene: Scene) => ChainableAction[])): this;
113
- _jumpTo(scene: Scene): ChainedScene;
121
+ registerSrc(seen?: Set<Scene>): void;
122
+ /**
123
+ * @internal STILL IN DEVELOPMENT
124
+ */
125
+ assignActionId(): void;
126
+ /**
127
+ * @internal STILL IN DEVELOPMENT
128
+ */
129
+ assignElementId(): void;
130
+ private _applyTransition;
131
+ private _transitionSceneBackground;
132
+ private _jumpTo;
114
133
  private _exit;
115
134
  private _transitionToScene;
116
135
  private _init;
@@ -1,41 +1,17 @@
1
1
  import { Constructable } from "../action/constructable";
2
- import { LogicAction } from "../game";
3
- import { SceneAction, StoryAction } from "../action/actions";
4
- import { RawData, RenderableNode } from "../action/tree/actionTree";
2
+ import { SceneAction } from "../action/actions";
5
3
  import { Scene } from "../elements/scene";
4
+ import { RawData } from "../action/tree/actionTree";
6
5
  export type StoryConfig = {};
7
6
  export type ElementStateRaw = Record<string, any>;
8
7
  export type NodeChildIdMap = Map<string, string>;
9
- export declare class Story extends Constructable<SceneAction<"scene:action">> {
8
+ export declare class Story extends Constructable<SceneAction<"scene:action">, Story> {
10
9
  static defaultConfig: StoryConfig;
11
- static targetAction: typeof StoryAction;
12
10
  readonly id: string;
13
11
  readonly name: string;
14
12
  readonly config: StoryConfig;
15
13
  entryScene: Scene | null;
16
14
  constructor(name: string, config?: StoryConfig);
17
- /**@internal */
18
- _setAllElementState(data: RawData<ElementStateRaw>[], actions?: LogicAction.Actions[]): void;
19
- /**@internal */
20
- _getAllElementState(actions?: LogicAction.Actions[]): RawData<ElementStateRaw>[];
21
- /**
22
- * @internal
23
- * Generate node descendant ID mapping
24
- * The key is the node ID, and the value is the child node ID
25
- */
26
- _getNodeChildIdMap(actions?: LogicAction.Actions[]): NodeChildIdMap;
27
- /**
28
- * @internal
29
- * Use the specified mapping table to restore the node descendants
30
- */
31
- _setNodeChildByMap(map: NodeChildIdMap | Record<string, string>, actions?: LogicAction.Actions[]): void;
32
- /**
33
- * @internal
34
- * Generate node ID mapping
35
- */
36
- _getMappedNodes(nodes: RenderableNode[]): Map<string, RenderableNode>;
37
- toData(): null;
38
- fromData(_: any): this;
39
15
  /**
40
16
  * Set the entry scene of the story
41
17
  * @example
@@ -46,4 +22,7 @@ export declare class Story extends Constructable<SceneAction<"scene:action">> {
46
22
  * ```
47
23
  */
48
24
  entry(scene: Scene): this;
25
+ constructStory(): this;
26
+ getAllElementStates(): RawData<ElementStateRaw>[];
27
+ private runStaticCheck;
49
28
  }
@@ -16,12 +16,6 @@ declare class IdManager extends IdManager_base {
16
16
  getStringId(): string;
17
17
  prefix(prefix: string, value: string, separator?: string): string;
18
18
  }
19
- declare class GameIdManager {
20
- private id;
21
- getId(): number;
22
- getStringId(): string;
23
- prefix(prefix: string, value: string, separator?: string): string;
24
- }
25
19
  declare enum GameSettingsNamespace {
26
20
  game = "game"
27
21
  }
@@ -53,18 +47,12 @@ export declare class LiveGame {
53
47
  };
54
48
  game: Game;
55
49
  storable: Storable;
56
- /**
57
- * @deprecated
58
- */
59
- currentSceneNumber: number | null;
60
50
  currentSavedGame: SavedGame | null;
61
51
  story: Story | null;
62
52
  lockedAwaiting: Awaitable<CalledActionResult, any> | null;
63
- idManager: GameIdManager;
64
53
  _lockedCount: number;
65
54
  private currentAction;
66
55
  constructor(game: Game);
67
- getDefaultSavedGame(): SavedGame;
68
56
  initNamespaces(): this;
69
57
  getStorable(): Storable;
70
58
  loadStory(story: Story): this;
@@ -75,21 +63,22 @@ export declare class LiveGame {
75
63
  /**
76
64
  * Load a saved game
77
65
  *
78
- * Note: Different versions of the game won't be able to load each other's saved games
66
+ * Note: Even if you change just a single line of code, the saved game might not be compatible with the new version
79
67
  *
80
- * @internal - DO NOT USE IT, it's not ready yet
68
+ * After calling this method, the current game state will be lost, can the stage will trigger force reset
81
69
  */
82
70
  deserialize(savedGame: SavedGame, { gameState }: {
83
71
  gameState: GameState;
84
72
  }): void;
73
+ reset({ gameState }: {
74
+ gameState: GameState;
75
+ }): void;
85
76
  /**
86
77
  * Serialize the current game state
87
78
  *
88
79
  * You can use this to save the game state to a file or a database
89
80
  *
90
- * Note: Different versions of the game won't be able to load each other's saved games
91
- *
92
- * @internal - DO NOT USE IT, it's not ready yet
81
+ * Note: Even if you change just a single line of code, the saved game might not be compatible with the new version
93
82
  */
94
83
  serialize({ gameState }: {
95
84
  gameState: GameState;
@@ -99,6 +88,7 @@ export declare class LiveGame {
99
88
  next(state: GameState): CalledActionResult | Awaitable<CalledActionResult, CalledActionResult> | null;
100
89
  abortAwaiting(): void;
101
90
  executeAction(state: GameState, action: LogicAction.Actions): LogicAction.Actions | Awaitable<CalledActionResult, CalledActionResult> | null;
91
+ private getNewSavedGame;
102
92
  }
103
93
  declare const _default: {
104
94
  Game: typeof Game;
@@ -6,7 +6,6 @@ import { StorableData } from "./store/type";
6
6
  import { MenuComponent, SayComponent } from "../player/elements/type";
7
7
  export interface SavedGame {
8
8
  name: string;
9
- version: string;
10
9
  meta: {
11
10
  created: number;
12
11
  updated: number;
@@ -15,10 +14,8 @@ export interface SavedGame {
15
14
  store: {
16
15
  [key: string]: StorableData;
17
16
  };
18
- elementState: RawData<ElementStateRaw>[];
19
- nodeChildIdMap: Record<string, string>;
17
+ elementStates: RawData<ElementStateRaw>[];
20
18
  stage: PlayerStateData;
21
- currentScene: number;
22
19
  currentAction: string | null;
23
20
  };
24
21
  }
@@ -25,9 +25,9 @@ export type PlayerState = {
25
25
  }[];
26
26
  };
27
27
  export type PlayerStateData = {
28
- elements: {
29
- scene: string;
30
- ele: {
28
+ scenes: {
29
+ sceneId: string;
30
+ elements: {
31
31
  images: string[];
32
32
  };
33
33
  }[];
@@ -76,6 +76,7 @@ export declare class GameState {
76
76
  createMenu(menu: MenuData, afterChoose?: (choice: Choice) => void, scene?: Scene): void;
77
77
  createImage(image: Image, scene?: Scene): this;
78
78
  disposeImage(image: Image, scene?: Scene): this;
79
+ forceReset(): void;
79
80
  playSound(howl: Howler.Howl, onEnd?: () => void): any;
80
81
  getHowl(): typeof Howler.Howl;
81
82
  animateImage<T extends keyof ImageEventTypes>(type: T, target: Image, args: ImageEventTypes[T], onEnd: () => void): undefined;
@@ -83,7 +84,7 @@ export declare class GameState {
83
84
  offSrcManager(srcManager: SrcManager): this;
84
85
  getStorable(): Storable;
85
86
  toData(): PlayerStateData;
86
- loadData(data: PlayerStateData, actions: LogicAction.Actions[]): void;
87
+ loadData(data: PlayerStateData, elementMap: Map<string, LogicAction.GameElement>): void;
87
88
  private getElementMap;
88
89
  private removeElements;
89
90
  private _getLastSceneIfNot;