narraleaf-react 0.3.1-alpha.1 → 0.4.0-beta.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.
- package/README.md +33 -33
- package/dist/game/nlcore/action/actionHistory.d.ts +37 -0
- package/dist/game/nlcore/action/actionTypes.d.ts +16 -3
- package/dist/game/nlcore/action/actions/characterAction.d.ts +1 -1
- package/dist/game/nlcore/action/actions/controlAction.d.ts +14 -10
- package/dist/game/nlcore/action/actions/persistentAction.d.ts +1 -0
- package/dist/game/nlcore/action/actions/sceneAction.d.ts +20 -9
- package/dist/game/nlcore/action/actions/videoAction.d.ts +22 -0
- package/dist/game/nlcore/action/gameHistory.d.ts +28 -0
- package/dist/game/nlcore/action/logicAction.d.ts +7 -5
- package/dist/game/nlcore/common/elements.d.ts +2 -1
- package/dist/game/nlcore/common/game.d.ts +2 -0
- package/dist/game/nlcore/common/types.d.ts +6 -3
- package/dist/game/nlcore/elements/character/sentence.d.ts +9 -1
- package/dist/game/nlcore/elements/character/word.d.ts +2 -0
- package/dist/game/nlcore/elements/character.d.ts +1 -1
- package/dist/game/nlcore/elements/menu.d.ts +7 -0
- package/dist/game/nlcore/elements/persistent/storable.d.ts +1 -0
- package/dist/game/nlcore/elements/persistent.d.ts +15 -0
- package/dist/game/nlcore/elements/scene.d.ts +0 -6
- package/dist/game/nlcore/elements/service.d.ts +6 -6
- package/dist/game/nlcore/elements/sound.d.ts +3 -0
- package/dist/game/nlcore/elements/story.d.ts +17 -1
- package/dist/game/nlcore/elements/transform/transform.d.ts +60 -1
- package/dist/game/nlcore/elements/transition/type.d.ts +2 -0
- package/dist/game/nlcore/elements/video.d.ts +23 -0
- package/dist/game/nlcore/game/liveGame.d.ts +27 -0
- package/dist/game/nlcore/game/plugin/plugin.d.ts +16 -0
- package/dist/game/nlcore/game.d.ts +34 -7
- package/dist/game/nlcore/gameTypes.d.ts +235 -265
- package/dist/game/player/Tasks.d.ts +106 -0
- package/dist/game/player/elements/Player.d.ts +1 -1
- package/dist/game/player/elements/elements.d.ts +6 -4
- package/dist/game/player/elements/menu/PlayerMenu.d.ts +3 -0
- package/dist/game/player/elements/menu/UIMenu/Item.d.ts +6 -0
- package/dist/game/player/elements/menu/UIMenu/Menu.d.ts +6 -0
- package/dist/game/player/elements/menu/UIMenu/context.d.ts +23 -0
- package/dist/game/player/elements/menu/type.d.ts +3 -0
- package/dist/game/player/elements/notification/Notifications.d.ts +3 -0
- package/dist/game/player/elements/notification/PlayerNotification.d.ts +4 -0
- package/dist/game/player/elements/notification/context.d.ts +11 -0
- package/dist/game/player/elements/notification/type.d.ts +19 -0
- package/dist/game/player/elements/say/Dialog.d.ts +29 -0
- package/dist/game/player/elements/say/Nametag.d.ts +2 -0
- package/dist/game/player/elements/say/Sentence.d.ts +26 -1
- package/dist/game/player/elements/say/UIDialog.d.ts +3 -0
- package/dist/game/player/elements/say/context.d.ts +19 -0
- package/dist/game/player/elements/say/type.d.ts +19 -3
- package/dist/game/player/elements/type.d.ts +16 -5
- package/dist/game/player/gameState.d.ts +51 -5
- package/dist/game/player/guard.d.ts +3 -2
- package/dist/game/player/lib/ImageCacheManager.d.ts +4 -1
- package/dist/game/player/lib/notification.d.ts +47 -0
- package/dist/game/player/lib/preferences.d.ts +5 -0
- package/dist/game/player/lib/useElementVisibility.d.ts +5 -0
- package/dist/game/player/lib/useExposeState.d.ts +7 -0
- package/dist/game/player/lib/useLiveGame.d.ts +1 -0
- package/dist/game/player/libElements.d.ts +7 -2
- package/dist/game/player/provider/game-state.d.ts +18 -6
- package/dist/game/player/type.d.ts +24 -10
- package/dist/main.js +4 -4
- package/dist/util/data.d.ts +64 -10
- package/package.json +1 -1
- package/dist/game/player/elements/say/Say.d.ts +0 -1
- /package/dist/game/player/elements/{menu/Menu.d.ts → video/video.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -26,50 +26,50 @@ NarraLeaf-React uses TypeScript for all scripting, so you don't have to learn a
|
|
|
26
26
|
It also has a highly abstracted and easy-to-use API, for example:
|
|
27
27
|
|
|
28
28
|
```typescript
|
|
29
|
-
import {Character, Menu, Scene, Word} from "narraleaf-react";
|
|
29
|
+
import {Character, Menu, Scene, Word, c, b} from "narraleaf-react";
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
```typescript
|
|
33
33
|
const scene1 = new Scene("scene1_hello_world", {
|
|
34
|
-
|
|
34
|
+
background: "/background/scene1_hello_world.jpg",
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
const johnSmith = new Character("John Smith");
|
|
38
38
|
const johnDoe = new Character("John Doe");
|
|
39
39
|
|
|
40
40
|
scene1.action([
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
/**
|
|
42
|
+
* John Smith: Hello, world!
|
|
43
|
+
* John Smith: This is my first **NarraLeaf** story.
|
|
44
|
+
* John Smith: Start editing src/story.js and enjoy the journey!
|
|
45
|
+
*/
|
|
46
|
+
johnSmith
|
|
47
|
+
.say("Hello, world!")
|
|
48
|
+
.say`This is my first ${b("NarraLeaf")} story.`
|
|
49
|
+
.say`Start editing ${c("src/story.js", "#00f")} and enjoy the journey!`,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* John Doe: Also, don't forget to check out the documentation!
|
|
53
|
+
*/
|
|
54
|
+
johnDoe.say("Also, don't forget to check out the documentation!"),
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Menu: Start the journey
|
|
58
|
+
* > Yes I will!
|
|
59
|
+
* - John Smith: Great! Let's start the journey!
|
|
60
|
+
* - John Smith: You can open issues on GitHub if you have any questions.
|
|
61
|
+
* > No, I'm going to check the documentation
|
|
62
|
+
* - John Smith: Sure! Take your time!
|
|
63
|
+
*/
|
|
64
|
+
Menu.prompt("Start the journey")
|
|
65
|
+
.choose("Yes I will!", [
|
|
66
|
+
johnSmith
|
|
67
|
+
.say("Great! Let's start the journey!")
|
|
68
|
+
.say("You can open issues on GitHub if you have any questions.")
|
|
69
|
+
])
|
|
70
|
+
.choose("No, I'm going to check the documentation", [
|
|
71
|
+
johnSmith.say("Sure! Take your time!")
|
|
72
|
+
])
|
|
73
73
|
]);
|
|
74
74
|
```
|
|
75
75
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Timeline } from "../../../game/player/Tasks";
|
|
2
|
+
import { Action } from "./action";
|
|
3
|
+
import { LiveGameEventToken } from "../types";
|
|
4
|
+
import { LogicAction } from "../game";
|
|
5
|
+
export type ActionHistory<T extends Array<unknown> = any> = {
|
|
6
|
+
action: Action;
|
|
7
|
+
timeline?: Timeline;
|
|
8
|
+
args: T;
|
|
9
|
+
id: string;
|
|
10
|
+
undo?: (...args: T) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare class ActionHistoryManager {
|
|
13
|
+
private history;
|
|
14
|
+
private readonly maxHistorySize;
|
|
15
|
+
private hooks;
|
|
16
|
+
constructor(maxHistorySize?: number);
|
|
17
|
+
/**
|
|
18
|
+
* Push an action to the history
|
|
19
|
+
*/
|
|
20
|
+
push<T extends Array<any> = Array<any>>(action: Action, onUndo?: (...args: T) => void, args?: T, timeline?: Timeline): {
|
|
21
|
+
id: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Undo all actions until the given id
|
|
25
|
+
*
|
|
26
|
+
* If the given id is not found, nothing will happen
|
|
27
|
+
* @param id random id generated by push
|
|
28
|
+
*/
|
|
29
|
+
undoUntil(id: string): LogicAction.Actions | null;
|
|
30
|
+
undo(): LogicAction.Actions | null;
|
|
31
|
+
onUndo(callback: (affected: ActionHistory<any>[]) => void): LiveGameEventToken;
|
|
32
|
+
offUndo(callback: (affected: ActionHistory<any>[]) => void): void;
|
|
33
|
+
getHistory(): ActionHistory<any>[];
|
|
34
|
+
onHistoryLimit(callback: (removed: ActionHistory<any>[]) => void): LiveGameEventToken;
|
|
35
|
+
offHistoryLimit(callback: (removed: ActionHistory<any>[]) => void): void;
|
|
36
|
+
reset(): void;
|
|
37
|
+
}
|
|
@@ -35,7 +35,6 @@ export type CharacterActionContentType = {
|
|
|
35
35
|
};
|
|
36
36
|
export declare const SceneActionTypes: {
|
|
37
37
|
readonly action: "scene:action";
|
|
38
|
-
readonly sleep: "scene:sleep";
|
|
39
38
|
readonly init: "scene:init";
|
|
40
39
|
readonly exit: "scene:exit";
|
|
41
40
|
readonly jumpTo: "scene:jumpTo";
|
|
@@ -44,7 +43,7 @@ export declare const SceneActionTypes: {
|
|
|
44
43
|
readonly transitionToScene: "scene:transitionToScene";
|
|
45
44
|
};
|
|
46
45
|
export type SceneActionContentType = {
|
|
47
|
-
[K in typeof SceneActionTypes[keyof typeof SceneActionTypes]]: K extends typeof SceneActionTypes["action"] ? Scene : K extends typeof SceneActionTypes["
|
|
46
|
+
[K in typeof SceneActionTypes[keyof typeof SceneActionTypes]]: K extends typeof SceneActionTypes["action"] ? Scene : K extends typeof SceneActionTypes["init"] ? [Scene] : 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["transitionToScene"] ? [ImageTransition, Scene | undefined, ImageSrc | Color | undefined] : any;
|
|
48
47
|
};
|
|
49
48
|
export declare const StoryActionTypes: {
|
|
50
49
|
readonly action: "story:action";
|
|
@@ -116,9 +115,10 @@ export type TextActionContentType = {
|
|
|
116
115
|
export declare const PersistentActionTypes: {
|
|
117
116
|
readonly action: "persistent:action";
|
|
118
117
|
readonly set: "persistent:set";
|
|
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)] : 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>] : any;
|
|
122
122
|
};
|
|
123
123
|
export declare const LayerActionTypes: {
|
|
124
124
|
readonly action: "layer:action";
|
|
@@ -126,3 +126,16 @@ export declare const LayerActionTypes: {
|
|
|
126
126
|
export type LayerActionContentType = {
|
|
127
127
|
[K in typeof LayerActionTypes[keyof typeof LayerActionTypes]]: K extends "layer:action" ? any : any;
|
|
128
128
|
};
|
|
129
|
+
export declare const VideoActionTypes: {
|
|
130
|
+
readonly action: "video:action";
|
|
131
|
+
readonly show: "video:show";
|
|
132
|
+
readonly hide: "video:hide";
|
|
133
|
+
readonly play: "video:play";
|
|
134
|
+
readonly pause: "video:pause";
|
|
135
|
+
readonly resume: "video:resume";
|
|
136
|
+
readonly stop: "video:stop";
|
|
137
|
+
readonly seek: "video:seek";
|
|
138
|
+
};
|
|
139
|
+
export type VideoActionContentType = {
|
|
140
|
+
[K in typeof VideoActionTypes[keyof typeof VideoActionTypes]]: K extends "video:action" ? any : K extends "video:show" | "video:hide" | "video:play" | "video:pause" | "video:stop" ? [] : K extends "video:seek" ? [number] : any;
|
|
141
|
+
};
|
|
@@ -13,5 +13,5 @@ export declare class CharacterAction<T extends typeof CharacterActionTypes[keyof
|
|
|
13
13
|
readonly setName: "character:setName";
|
|
14
14
|
};
|
|
15
15
|
static getVoice(state: GameState, sentence: Sentence): Sound | null;
|
|
16
|
-
executeAction(
|
|
16
|
+
executeAction(gameState: GameState): CalledActionResult | Awaitable<CalledActionResult, any>;
|
|
17
17
|
}
|
|
@@ -4,10 +4,10 @@ import { GameState } from "../../../player/gameState";
|
|
|
4
4
|
import { LogicAction } from "../../action/logicAction";
|
|
5
5
|
import { Awaitable } from "../../../../util/data";
|
|
6
6
|
import type { CalledActionResult } from "../../gameTypes";
|
|
7
|
-
import { ContentNode } from "../../action/tree/actionTree";
|
|
8
7
|
import { TypedAction } from "../../action/actions";
|
|
9
8
|
import { Story } from "../../elements/story";
|
|
10
9
|
import { ActionSearchOptions } from "../../types";
|
|
10
|
+
import { Timeline } from "../../../player/Tasks";
|
|
11
11
|
export declare class ControlAction<T extends typeof ControlActionTypes[keyof typeof ControlActionTypes] = typeof ControlActionTypes[keyof typeof ControlActionTypes]> extends TypedAction<ControlActionContentType, T, Control> {
|
|
12
12
|
static ActionTypes: {
|
|
13
13
|
readonly action: "control:action";
|
|
@@ -20,15 +20,19 @@ export declare class ControlAction<T extends typeof ControlActionTypes[keyof typ
|
|
|
20
20
|
readonly sleep: "control:sleep";
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* Perform an action and all its children. Due to bidirectional bubbling, the Awaitable interrupt returned by the function affects the children who're executing.
|
|
24
|
+
*
|
|
25
|
+
* At the same time, the child interrupt will bubble up to the Awaitable returned by this function and interrupt the execution of the Timeline.
|
|
26
|
+
* This is because all later results of this function depend on the previous result, so it isn't possible to silently ignore interrupted sub operations.
|
|
27
|
+
*
|
|
28
|
+
* @template T The type of the result returned by the onResolved callback.
|
|
29
|
+
* @param {GameState} gameState - The current game state.
|
|
30
|
+
* @param {LogicAction.Actions} action - The action to be executed.
|
|
31
|
+
* @param {function(CalledActionResult): T} onResolved - A callback function that processes the result of the action. The awaitable will be resolved to the value returned by this callback.
|
|
32
|
+
* @returns {[Awaitable<T>, Timeline]} A tuple containing the Awaitable and the Timeline.
|
|
25
33
|
*/
|
|
26
|
-
|
|
27
|
-
executeSingleAction(
|
|
28
|
-
|
|
29
|
-
type: any;
|
|
30
|
-
node: ContentNode<any> | null;
|
|
31
|
-
} | Awaitable<CalledActionResult<any>, any> | Awaitable<any, any>;
|
|
32
|
-
executeAction(state: GameState): CalledActionResult | Awaitable<CalledActionResult, CalledActionResult>;
|
|
34
|
+
executeActionSeries<T>(gameState: GameState, action: LogicAction.Actions, onResolved: (result: CalledActionResult) => T): [awaitable: Awaitable<T>, timeline: Timeline];
|
|
35
|
+
executeSingleAction(gameState: GameState, action: LogicAction.Actions): Awaitable<CalledActionResult> | LogicAction.Actions | null;
|
|
36
|
+
executeAction(gameState: GameState): CalledActionResult | Awaitable<CalledActionResult, CalledActionResult>;
|
|
33
37
|
getFutureActions(story: Story, options: ActionSearchOptions): LogicAction.Actions[];
|
|
34
38
|
}
|
|
@@ -7,6 +7,7 @@ export declare class PersistentAction<T extends Values<typeof PersistentActionTy
|
|
|
7
7
|
static ActionTypes: {
|
|
8
8
|
readonly action: "persistent:action";
|
|
9
9
|
readonly set: "persistent:set";
|
|
10
|
+
readonly assign: "persistent:assign";
|
|
10
11
|
};
|
|
11
12
|
executeAction(gameState: GameState): import("../../gameTypes").CalledActionResult<any> | import("../../../../util/data").Awaitable<import("../../gameTypes").CalledActionResult<any>, any>;
|
|
12
13
|
}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { SceneActionContentType, SceneActionTypes } from "../../action/actionTypes";
|
|
2
|
-
import type { Scene } from "../../elements/scene";
|
|
3
|
-
import { GameState } from "../../../player/gameState";
|
|
2
|
+
import type { Scene, SceneDataRaw } from "../../elements/scene";
|
|
3
|
+
import { GameState, PlayerStateElementSnapshot } from "../../../player/gameState";
|
|
4
4
|
import { Awaitable } from "../../../../util/data";
|
|
5
5
|
import type { CalledActionResult } from "../../gameTypes";
|
|
6
|
+
import { ContentNode } from "../../action/tree/actionTree";
|
|
6
7
|
import { LogicAction } from "../../action/logicAction";
|
|
7
8
|
import { TypedAction } from "../../action/actions";
|
|
8
9
|
import { Story } from "../../elements/story";
|
|
9
10
|
import { ImageTransition } from "../../elements/transition/transitions/image/imageTransition";
|
|
10
11
|
import { ActionSearchOptions } from "../../types";
|
|
11
12
|
import { ExposedState, ExposedStateType } from "../../../player/type";
|
|
13
|
+
import { ImageDataRaw } from "../../elements/displayable/image";
|
|
14
|
+
type SceneSnapshot = {
|
|
15
|
+
state: SceneDataRaw | null;
|
|
16
|
+
local: Record<string, any>;
|
|
17
|
+
element: PlayerStateElementSnapshot;
|
|
18
|
+
background: ImageDataRaw | null;
|
|
19
|
+
};
|
|
12
20
|
export declare class SceneAction<T extends typeof SceneActionTypes[keyof typeof SceneActionTypes] = typeof SceneActionTypes[keyof typeof SceneActionTypes]> extends TypedAction<SceneActionContentType, T, Scene> {
|
|
13
21
|
static ActionTypes: {
|
|
14
22
|
readonly action: "scene:action";
|
|
15
|
-
readonly sleep: "scene:sleep";
|
|
16
23
|
readonly init: "scene:init";
|
|
17
24
|
readonly exit: "scene:exit";
|
|
18
25
|
readonly jumpTo: "scene:jumpTo";
|
|
@@ -20,14 +27,18 @@ export declare class SceneAction<T extends typeof SceneActionTypes[keyof typeof
|
|
|
20
27
|
readonly preUnmount: "scene:preUnmount";
|
|
21
28
|
readonly transitionToScene: "scene:transitionToScene";
|
|
22
29
|
};
|
|
23
|
-
static handleSceneInit(
|
|
24
|
-
type:
|
|
25
|
-
node:
|
|
26
|
-
}
|
|
30
|
+
static handleSceneInit(scene: Scene, next: CalledActionResult, state: GameState, awaitable: Awaitable<CalledActionResult, any>): {
|
|
31
|
+
type: any;
|
|
32
|
+
node: ContentNode<any> | null;
|
|
33
|
+
} | Awaitable<CalledActionResult<any>, any>;
|
|
27
34
|
static initBackgroundMusic(scene: Scene, exposed: ExposedState[ExposedStateType.scene]): void;
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
static createSceneSnapshot(scene: Scene, state: GameState): SceneSnapshot;
|
|
36
|
+
static restoreSceneSnapshot(snapshot: SceneSnapshot, state: GameState): void;
|
|
37
|
+
applyTransition(gameState: GameState, transition: ImageTransition): Awaitable<CalledActionResult<any>, CalledActionResult<any>>;
|
|
38
|
+
exit(state: GameState): void;
|
|
39
|
+
executeAction(gameState: GameState): CalledActionResult | Awaitable<CalledActionResult, any>;
|
|
30
40
|
getFutureActions(story: Story, searchOptions?: ActionSearchOptions): LogicAction.Actions[];
|
|
31
41
|
_sceneNotFoundError(sceneId: string): Error;
|
|
32
42
|
getSceneName(scene: Scene | string): string;
|
|
33
43
|
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { VideoActionContentType, VideoActionTypes } from "../../action/actionTypes";
|
|
2
|
+
import { TypedAction } from "../../action/actions";
|
|
3
|
+
import { Video } from "../../elements/video";
|
|
4
|
+
import { GameState } from "../../../player/gameState";
|
|
5
|
+
import { Awaitable, Values } from "../../../../util/data";
|
|
6
|
+
import type { CalledActionResult } from "../../gameTypes";
|
|
7
|
+
export declare class VideoAction<T extends Values<typeof VideoActionTypes> = Values<typeof VideoActionTypes>> extends TypedAction<VideoActionContentType, T, Video> {
|
|
8
|
+
static ActionTypes: {
|
|
9
|
+
readonly action: "video:action";
|
|
10
|
+
readonly show: "video:show";
|
|
11
|
+
readonly hide: "video:hide";
|
|
12
|
+
readonly play: "video:play";
|
|
13
|
+
readonly pause: "video:pause";
|
|
14
|
+
readonly resume: "video:resume";
|
|
15
|
+
readonly stop: "video:stop";
|
|
16
|
+
readonly seek: "video:seek";
|
|
17
|
+
};
|
|
18
|
+
executeAction(gameState: GameState): Awaitable<CalledActionResult>;
|
|
19
|
+
private changeStateBase;
|
|
20
|
+
private changeState;
|
|
21
|
+
private changeStateAsync;
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Action } from "./action";
|
|
2
|
+
import { ActionHistoryManager } from "./actionHistory";
|
|
3
|
+
type GameHistoryAction = {
|
|
4
|
+
token: string;
|
|
5
|
+
action: Action;
|
|
6
|
+
};
|
|
7
|
+
type GameElementHistory = {
|
|
8
|
+
type: "say";
|
|
9
|
+
text: string;
|
|
10
|
+
voice: string | null;
|
|
11
|
+
} | {
|
|
12
|
+
type: "menu";
|
|
13
|
+
text: string;
|
|
14
|
+
selected: string;
|
|
15
|
+
};
|
|
16
|
+
export type GameHistory = GameHistoryAction & {
|
|
17
|
+
element: GameElementHistory;
|
|
18
|
+
};
|
|
19
|
+
export declare class GameHistoryManager {
|
|
20
|
+
private history;
|
|
21
|
+
private actionHistoryMgr;
|
|
22
|
+
constructor(actionHistoryMgr: ActionHistoryManager);
|
|
23
|
+
push(action: GameHistory): this;
|
|
24
|
+
getHistory(): GameHistory[];
|
|
25
|
+
reset(): void;
|
|
26
|
+
private crossFilter;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -9,7 +9,7 @@ import { StringKeyOf, Values } from "../../../util/data";
|
|
|
9
9
|
import { TypedAction } from "../action/actions";
|
|
10
10
|
import { Sound } from "../elements/sound";
|
|
11
11
|
import { Control } from "../elements/control";
|
|
12
|
-
import { CharacterActionContentType, CharacterActionTypes, ConditionActionContentType, ConditionActionTypes, ControlActionContentType, DisplayableActionContentType, DisplayableActionTypes, ImageActionContentType, ImageActionTypes, LayerActionContentType, LayerActionTypes, MenuActionContentType, MenuActionTypes, PersistentActionContentType, PersistentActionTypes, SceneActionContentType, SceneActionTypes, ScriptActionContentType, ScriptActionTypes, SoundActionContentType, StoryActionContentType, StoryActionTypes, TextActionContentType } from "../action/actionTypes";
|
|
12
|
+
import { CharacterActionContentType, CharacterActionTypes, ConditionActionContentType, ConditionActionTypes, ControlActionContentType, DisplayableActionContentType, DisplayableActionTypes, ImageActionContentType, ImageActionTypes, LayerActionContentType, LayerActionTypes, MenuActionContentType, MenuActionTypes, PersistentActionContentType, PersistentActionTypes, SceneActionContentType, SceneActionTypes, ScriptActionContentType, ScriptActionTypes, SoundActionContentType, StoryActionContentType, StoryActionTypes, TextActionContentType, VideoActionContentType, VideoActionTypes } from "../action/actionTypes";
|
|
13
13
|
import { CharacterAction } from "../action/actions/characterAction";
|
|
14
14
|
import { SceneAction } from "../action/actions/sceneAction";
|
|
15
15
|
import { StoryAction } from "../action/actions/storyAction";
|
|
@@ -30,11 +30,13 @@ import { ServiceAction, ServiceActionContentType } from "../action/serviceAction
|
|
|
30
30
|
import { Layer } from "../elements/layer";
|
|
31
31
|
import { LayerAction } from "../action/actions/layerAction";
|
|
32
32
|
import { ExposedStateType } from "../../player/type";
|
|
33
|
+
import { Video } from "../elements/video";
|
|
34
|
+
import { VideoAction } from "../action/actions/videoAction";
|
|
33
35
|
export declare namespace LogicAction {
|
|
34
36
|
type DisplayableElements = Text | Image | Layer | AbstractDisplayable<any, any>;
|
|
35
37
|
type DisplayableExposed = ExposedStateType.image | ExposedStateType.layer | ExposedStateType.text;
|
|
36
|
-
type GameElement = Character | Scene | Story | Image | Condition | Script | Menu | Sound | Control | Text | AbstractDisplayable<any, any> | Persistent<any> | ServiceSkeleton;
|
|
37
|
-
type Actions = TypedAction | CharacterAction | ConditionAction | ImageAction | SceneAction | ScriptAction | StoryAction | MenuAction | SoundAction | ControlAction | TextAction | DisplayableAction | PersistentAction | ServiceAction | LayerAction;
|
|
38
|
-
type ActionTypes = Values<typeof CharacterActionTypes> | Values<typeof ConditionActionTypes> | Values<typeof ImageActionTypes> | Values<typeof SceneActionTypes> | Values<typeof ScriptActionTypes> | Values<typeof StoryActionTypes> | Values<typeof MenuActionTypes> | Values<typeof SoundAction.ActionTypes> | Values<typeof ControlAction.ActionTypes> | Values<typeof TextAction.ActionTypes> | Values<typeof DisplayableActionTypes> | Values<typeof PersistentActionTypes> | StringKeyOf<ServiceActionContentType> | Values<typeof LayerActionTypes>;
|
|
39
|
-
type ActionContents = CharacterActionContentType & ConditionActionContentType & ImageActionContentType & SceneActionContentType & ScriptActionContentType & StoryActionContentType & MenuActionContentType & SoundActionContentType & ControlActionContentType & TextActionContentType & DisplayableActionContentType & PersistentActionContentType & ServiceActionContentType & LayerActionContentType;
|
|
38
|
+
type GameElement = Character | Scene | Story | Image | Condition | Script | Menu | Sound | Control | Text | AbstractDisplayable<any, any> | Persistent<any> | ServiceSkeleton | Video;
|
|
39
|
+
type Actions = TypedAction | CharacterAction | ConditionAction | ImageAction | SceneAction | ScriptAction | StoryAction | MenuAction | SoundAction | ControlAction | TextAction | DisplayableAction | PersistentAction | ServiceAction | LayerAction | VideoAction;
|
|
40
|
+
type ActionTypes = Values<typeof CharacterActionTypes> | Values<typeof ConditionActionTypes> | Values<typeof ImageActionTypes> | Values<typeof SceneActionTypes> | Values<typeof ScriptActionTypes> | Values<typeof StoryActionTypes> | Values<typeof MenuActionTypes> | Values<typeof SoundAction.ActionTypes> | Values<typeof ControlAction.ActionTypes> | Values<typeof TextAction.ActionTypes> | Values<typeof DisplayableActionTypes> | Values<typeof PersistentActionTypes> | StringKeyOf<ServiceActionContentType> | Values<typeof LayerActionTypes> | Values<typeof VideoActionTypes>;
|
|
41
|
+
type ActionContents = CharacterActionContentType & ConditionActionContentType & ImageActionContentType & SceneActionContentType & ScriptActionContentType & StoryActionContentType & MenuActionContentType & SoundActionContentType & ControlActionContentType & TextActionContentType & DisplayableActionContentType & PersistentActionContentType & ServiceActionContentType & LayerActionContentType & VideoActionContentType;
|
|
40
42
|
}
|
|
@@ -15,4 +15,5 @@ import { Pause } from "../elements/character/pause";
|
|
|
15
15
|
import { Persistent } from "../elements/persistent";
|
|
16
16
|
import { Service } from "../elements/service";
|
|
17
17
|
import { Layer } from "../elements/layer";
|
|
18
|
-
|
|
18
|
+
import { Video } from "../elements/video";
|
|
19
|
+
export { Character, Condition, Control, Image, Lambda, Menu, Scene, Script, Sentence, Sound, Story, Transform, Word, Text, Pause, Persistent, Service, Layer, Video, };
|
|
@@ -2,4 +2,6 @@ import { Game } from "../game";
|
|
|
2
2
|
import { GameState } from "../../player/gameState";
|
|
3
3
|
import { Storable, Namespace } from "../elements/persistent/storable";
|
|
4
4
|
import { LiveGame } from "../game/liveGame";
|
|
5
|
+
import type { SavedGame } from "../gameTypes";
|
|
5
6
|
export { LiveGame, GameState, Game, Storable, Namespace, };
|
|
7
|
+
export type { SavedGame, };
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { TransformDefinitions } from "../elements/transform/type";
|
|
2
|
-
import { Origins } from "../elements/story";
|
|
3
1
|
import { ServiceHandlerCtx } from "../elements/service";
|
|
2
|
+
import { Origins } from "../elements/story";
|
|
3
|
+
import { TransformDefinitions } from "../elements/transform/type";
|
|
4
|
+
import { IGamePluginRegistry } from "../game/plugin/plugin";
|
|
5
|
+
import { LiveGameEventToken } from "../types";
|
|
6
|
+
import { GameHistory } from "../action/gameHistory";
|
|
4
7
|
export * from "../elements/type";
|
|
5
|
-
export type {
|
|
8
|
+
export type { GameHistory, IGamePluginRegistry, LiveGameEventToken, Origins, ServiceHandlerCtx, TransformDefinitions };
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { Sound } from "../../elements/sound";
|
|
2
2
|
import type { Character } from "../../elements/character";
|
|
3
|
+
import { Word } from "../../elements/character/word";
|
|
3
4
|
import { Color, Font } from "../../types";
|
|
5
|
+
import type { ScriptCtx } from "../../elements/script";
|
|
6
|
+
import { Pausing } from "../../elements/character/pause";
|
|
4
7
|
export type SentenceConfig = {
|
|
5
8
|
pause?: boolean | number;
|
|
6
9
|
voice: Sound | null;
|
|
7
10
|
character: Character | null;
|
|
8
11
|
voiceId: string | number | null;
|
|
9
|
-
color
|
|
12
|
+
color?: Color;
|
|
10
13
|
} & Font;
|
|
11
14
|
export type SentenceUserConfig = Partial<Omit<SentenceConfig, "voice"> & {
|
|
12
15
|
voice: Sound | string | null | undefined;
|
|
13
16
|
}>;
|
|
17
|
+
export type DynamicWord = (ctx: ScriptCtx) => DynamicWordResult;
|
|
18
|
+
export type DynamicWordResult = string | Word | Pausing | (string | Word | Pausing)[];
|
|
19
|
+
export type StaticWord<T extends string | DynamicWord | Pausing = string | DynamicWord | Pausing> = string | Pausing | Word<T>;
|
|
20
|
+
export type SingleWord = StaticWord | DynamicWord;
|
|
21
|
+
export type SentencePrompt = SingleWord[] | SingleWord;
|
|
14
22
|
export declare class Sentence {
|
|
15
23
|
constructor(text: SentencePrompt, config?: SentenceUserConfig);
|
|
16
24
|
copy(): Sentence;
|
|
@@ -5,6 +5,8 @@ export type WordConfig = {
|
|
|
5
5
|
className: string;
|
|
6
6
|
ruby: string;
|
|
7
7
|
color: Color;
|
|
8
|
+
pause: boolean;
|
|
9
|
+
cps?: number;
|
|
8
10
|
} & Font;
|
|
9
11
|
export declare class Word<T extends string | DynamicWord | Pausing = string | DynamicWord | Pausing> {
|
|
10
12
|
static isWord(obj: any): obj is Word;
|
|
@@ -5,7 +5,7 @@ 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
7
|
export type CharacterConfig = {
|
|
8
|
-
color
|
|
8
|
+
color?: Color;
|
|
9
9
|
};
|
|
10
10
|
export interface Character {
|
|
11
11
|
(content: string, config?: SentenceUserConfig): Proxied<Character, Chained<LogicAction.Actions>>;
|
|
@@ -17,8 +17,15 @@ export type MenuData = {
|
|
|
17
17
|
choices: Choice[];
|
|
18
18
|
};
|
|
19
19
|
export declare class Menu extends Actionable<any, Menu> {
|
|
20
|
+
/**
|
|
21
|
+
* Create a menu with a prompt
|
|
22
|
+
* @param prompt - The prompt to display to the player
|
|
23
|
+
* @returns A new menu
|
|
24
|
+
*/
|
|
25
|
+
static prompt(prompt: SentencePrompt | Sentence, config?: MenuConfig): Menu;
|
|
20
26
|
constructor(prompt: SentencePrompt, config?: MenuConfig);
|
|
21
27
|
constructor(prompt: Sentence, config?: MenuConfig);
|
|
28
|
+
constructor(prompt: SentencePrompt | Sentence, config: MenuConfig);
|
|
22
29
|
/**
|
|
23
30
|
* Add a choice to the menu
|
|
24
31
|
* @example
|
|
@@ -7,6 +7,7 @@ export declare class Namespace<T extends NameSpaceContent<keyof T>> {
|
|
|
7
7
|
get<Key extends keyof T = any>(key: Key): T[Key];
|
|
8
8
|
equals<Key extends keyof T = any>(key: Key, value: T[Key]): boolean;
|
|
9
9
|
assign(values: Partial<T>): this;
|
|
10
|
+
reset(): this;
|
|
10
11
|
}
|
|
11
12
|
export declare class Storable {
|
|
12
13
|
addNamespace<T extends NameSpaceContent<keyof T>>(namespace: Namespace<T>): this | undefined;
|
|
@@ -7,10 +7,21 @@ import { LambdaHandler } from "../elements/type";
|
|
|
7
7
|
export declare class Persistent<T extends PersistentContent> extends Actionable<null> {
|
|
8
8
|
constructor(namespace: string, defaultContent: T);
|
|
9
9
|
/**
|
|
10
|
+
* Create an action to set a value in the persistent storage for the given key
|
|
10
11
|
* @chainable
|
|
12
|
+
* @param key - The key to set the value for
|
|
13
|
+
* @param value - The value to set
|
|
14
|
+
* @returns A chainable persistent action
|
|
11
15
|
*/
|
|
12
16
|
set<K extends StringKeyOf<T>>(key: K, value: T[K]): ChainedPersistent<T>;
|
|
13
17
|
set<K extends StringKeyOf<T>>(key: K, handler: (value: T[K]) => T[K]): ChainedPersistent<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Create an action to assign a value to the persistent storage
|
|
20
|
+
* @chainable
|
|
21
|
+
* @param value - The value to assign
|
|
22
|
+
* @returns A chainable persistent action
|
|
23
|
+
*/
|
|
24
|
+
assign(value: Partial<T>): ChainedPersistent<T>;
|
|
14
25
|
/**
|
|
15
26
|
* Determine whether the values are equal, can be used in {@link Condition}
|
|
16
27
|
*/
|
|
@@ -36,6 +47,10 @@ export declare class Persistent<T extends PersistentContent> extends Actionable<
|
|
|
36
47
|
* @example
|
|
37
48
|
* ```typescript
|
|
38
49
|
* character.say(["You have ", persis.toWord("gold"), " gold"]);
|
|
50
|
+
*
|
|
51
|
+
* // or
|
|
52
|
+
*
|
|
53
|
+
* character.say`You have ${persis.toWord("gold")} gold`;
|
|
39
54
|
* ```
|
|
40
55
|
*/
|
|
41
56
|
toWord<K extends StringKeyOf<T>>(key: K): Word<DynamicWord>;
|
|
@@ -56,12 +56,6 @@ export declare class Scene extends Constructable<LogicAction.Actions, Scene> {
|
|
|
56
56
|
* @chainable
|
|
57
57
|
*/
|
|
58
58
|
jumpTo(scene: Scene, config?: Partial<JumpConfig> | JumpConfig["transition"]): ChainableAction;
|
|
59
|
-
/**
|
|
60
|
-
* Wait for a period of time, the parameter can be the number of milliseconds or a Promise
|
|
61
|
-
* @chainable
|
|
62
|
-
*/
|
|
63
|
-
sleep(ms: number): ChainedScene;
|
|
64
|
-
sleep(promise: Promise<any>): ChainedScene;
|
|
65
59
|
/**
|
|
66
60
|
* Set background music
|
|
67
61
|
* @param sound Target music
|
|
@@ -16,8 +16,8 @@ export declare class ServiceSkeleton<Content extends ServiceContentType = Servic
|
|
|
16
16
|
* @param key action type
|
|
17
17
|
* @param handler handler, the arguments are the same as the action content type
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
on<K extends StringKeyOf<Content>>(key: K, handler: ServiceHandler<Content[K]>): this;
|
|
20
|
+
trigger<K extends StringKeyOf<Content>>(type: K, ...args: Content[K]): Proxied<this, Chained<ServiceAction, this>>;
|
|
21
21
|
}
|
|
22
22
|
declare class ServiceSkeletonMask<Content extends ServiceContentType = ServiceContentType, RawData extends Record<string, SerializableData> | null = never> extends ServiceSkeleton<Content, RawData> {
|
|
23
23
|
private triggerAction;
|
|
@@ -39,11 +39,7 @@ declare class ServiceSkeletonMask<Content extends ServiceContentType = ServiceCo
|
|
|
39
39
|
private __self;
|
|
40
40
|
private __actions;
|
|
41
41
|
}
|
|
42
|
-
type AbortifyFn<T extends any[]> = ServiceHandler<T> & {
|
|
43
|
-
onAbort: (handler: () => void) => AbortifyFn<T>;
|
|
44
|
-
};
|
|
45
42
|
export declare abstract class Service<Content extends ServiceContentType = ServiceContentType, RawData extends Record<string, SerializableData> | null = Record<string, any>> extends ServiceSkeletonMask<Content, RawData> {
|
|
46
|
-
static abortify<T extends any[]>(fn: ServiceHandler<T>): AbortifyFn<T>;
|
|
47
43
|
/**
|
|
48
44
|
* Serialize the service to data
|
|
49
45
|
*
|
|
@@ -55,5 +51,9 @@ export declare abstract class Service<Content extends ServiceContentType = Servi
|
|
|
55
51
|
* @param data data exported from toData
|
|
56
52
|
*/
|
|
57
53
|
abstract deserialize?(data: RawData): void;
|
|
54
|
+
/**
|
|
55
|
+
* Called when the service is initialized
|
|
56
|
+
*/
|
|
57
|
+
abstract init?(): void;
|
|
58
58
|
}
|
|
59
59
|
export {};
|
|
@@ -41,6 +41,9 @@ export declare class Sound extends Actionable<SoundDataRaw, Sound> {
|
|
|
41
41
|
constructor(config?: Partial<ISoundUserConfig>);
|
|
42
42
|
constructor(src?: string);
|
|
43
43
|
/**
|
|
44
|
+
* Start playing the sound
|
|
45
|
+
*
|
|
46
|
+
* This action will be resolved when the sound reaches the end
|
|
44
47
|
* @chainable
|
|
45
48
|
*/
|
|
46
49
|
play(duration?: number): ChainedSound;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Constructable } from "../action/constructable";
|
|
2
2
|
import { Scene } from "../elements/scene";
|
|
3
3
|
import { SceneAction } from "../action/actions/sceneAction";
|
|
4
|
-
import { Persistent } from "../elements/persistent";
|
|
4
|
+
import { Persistent, PersistentContent } from "../elements/persistent";
|
|
5
5
|
import { Service } from "../elements/service";
|
|
6
6
|
export declare enum Origins {
|
|
7
7
|
topLeft = "top left",
|
|
@@ -48,6 +48,22 @@ export declare class Story extends Constructable<SceneAction<"scene:action">, St
|
|
|
48
48
|
* You can't use a Persistent that isn't registered to the story
|
|
49
49
|
*/
|
|
50
50
|
registerPersistent(persistent: Persistent<any>): this;
|
|
51
|
+
/**
|
|
52
|
+
* Create a Persistent and register it to the story
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const persistent = story.createPersistent("playerData", {
|
|
56
|
+
* name: "persistent",
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* // is equivalent to
|
|
60
|
+
* const persistent = new Persistent("playerData", {
|
|
61
|
+
* name: "persistent",
|
|
62
|
+
* });
|
|
63
|
+
* story.registerPersistent(persistent);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
createPersistent<T extends PersistentContent>(namespace: string, defaultContent: T): Persistent<T>;
|
|
51
67
|
/**
|
|
52
68
|
* Register a Service to the story
|
|
53
69
|
*
|