narraleaf-react 0.0.1-beta.11 → 0.0.1-beta.12
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 +2 -4
- package/dist/game/nlcore/action/actionable.d.ts +8 -3
- package/dist/game/nlcore/action/chain.d.ts +24 -0
- package/dist/game/nlcore/action/constructable.d.ts +17 -9
- package/dist/game/nlcore/common/Utils.d.ts +1 -1
- package/dist/game/nlcore/elements/condition.d.ts +7 -6
- package/dist/game/nlcore/elements/control.d.ts +15 -12
- package/dist/game/nlcore/elements/image.d.ts +20 -18
- package/dist/game/nlcore/elements/menu.d.ts +11 -8
- package/dist/game/nlcore/elements/scene.d.ts +26 -21
- package/dist/game/nlcore/elements/script.d.ts +2 -2
- package/dist/game/nlcore/elements/sound.d.ts +11 -7
- package/dist/game/nlcore/elements/story.d.ts +2 -1
- package/dist/game/nlcore/elements/text.d.ts +14 -13
- package/dist/game/nlcore/game.d.ts +8 -1
- package/dist/main.js +1 -1
- package/dist/util/data.d.ts +4 -0
- package/package.json +82 -80
package/README.md
CHANGED
|
@@ -42,7 +42,6 @@ Read more in [🛠React.NarraLeaf.com](https://react.narraleaf.com)
|
|
|
42
42
|
import {Character, Scene, Story, Image, Player, GameProviders} from "narraleaf-react";
|
|
43
43
|
|
|
44
44
|
export default function App() {
|
|
45
|
-
|
|
46
45
|
const character1 = new Character("character1");
|
|
47
46
|
const image1 = new Image({
|
|
48
47
|
src: "https://placehold.it/200x200",
|
|
@@ -53,14 +52,13 @@ export default function App() {
|
|
|
53
52
|
// Show image1 for 1 second
|
|
54
53
|
image1.show({
|
|
55
54
|
duration: 1000,
|
|
56
|
-
})
|
|
55
|
+
}),
|
|
57
56
|
|
|
58
57
|
// Say something
|
|
59
58
|
character1
|
|
60
59
|
.say("Hello, world!")
|
|
61
60
|
.say("This is my first NarraLeaf story.")
|
|
62
|
-
.say("Start editing this file and enjoy the journey!")
|
|
63
|
-
.toActions(),
|
|
61
|
+
.say("Start editing this file and enjoy the journey!"),
|
|
64
62
|
])
|
|
65
63
|
);
|
|
66
64
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { LogicAction } from "../action/logicAction";
|
|
2
|
-
|
|
2
|
+
import { Chainable, Chained, Proxied } from "../action/chain";
|
|
3
|
+
import GameElement = LogicAction.GameElement;
|
|
4
|
+
export declare class Actionable<StateData extends Record<string, any> = Record<string, any>, Self extends Actionable = any> extends Chainable<LogicAction.Actions, Self> {
|
|
3
5
|
static IdPrefixes: {
|
|
4
6
|
readonly Actionable: "actionable";
|
|
5
7
|
readonly Condition: "$0";
|
|
@@ -11,9 +13,12 @@ export declare class Actionable<StateData extends Record<string, any> = Record<s
|
|
|
11
13
|
readonly Menu: "$6";
|
|
12
14
|
};
|
|
13
15
|
readonly id: string;
|
|
14
|
-
protected actions: LogicAction.Actions[];
|
|
15
16
|
constructor(idPrefix?: string);
|
|
16
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated
|
|
19
|
+
*/
|
|
20
|
+
toActions(): never[];
|
|
17
21
|
toData(): StateData | null;
|
|
18
22
|
fromData(_: StateData): this;
|
|
23
|
+
fromChained(chained: Proxied<GameElement, Chained<LogicAction.Actions>>): LogicAction.Actions[];
|
|
19
24
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { LogicAction } from "../action/logicAction";
|
|
2
|
+
import Actions = LogicAction.Actions;
|
|
3
|
+
import GameElement = LogicAction.GameElement;
|
|
4
|
+
export type Proxied<T extends Record<any, any>, U extends Record<any, any>> = T & U;
|
|
5
|
+
export type ChainedAction = Proxied<GameElement, Chained<LogicAction.Actions>>;
|
|
6
|
+
export type ChainedActions = (ChainedAction | ChainedAction[] | Actions | Actions[])[];
|
|
7
|
+
declare const ChainedFlag: unique symbol;
|
|
8
|
+
export declare class Chained<T> {
|
|
9
|
+
static isChained<T>(value: any): value is Chained<T>;
|
|
10
|
+
static toActions(chainedActions: ChainedActions): Actions[];
|
|
11
|
+
[ChainedFlag]: boolean;
|
|
12
|
+
private __actions;
|
|
13
|
+
push(...actions: T[]): void;
|
|
14
|
+
getActions(): T[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* - T - the action type
|
|
18
|
+
* - U - self constructor
|
|
19
|
+
*/
|
|
20
|
+
export declare class Chainable<T, U extends Record<any, any>> {
|
|
21
|
+
chain(arg0?: T[] | T): Proxied<U, Chained<T>>;
|
|
22
|
+
proxy<T extends Record<any, any>, U extends Record<any, any>>(target: T, chained: U): Proxied<T, U>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { ContentNode, RenderableNode, RootNode } from "../action/tree/actionTree";
|
|
2
2
|
import { LogicAction } from "../action/logicAction";
|
|
3
|
-
|
|
3
|
+
import { Chainable, Chained, Proxied } from "../action/chain";
|
|
4
|
+
import GameElement = LogicAction.GameElement;
|
|
5
|
+
export declare class Constructable<TAction extends LogicAction.Actions = LogicAction.Actions> extends Chainable<any, any> {
|
|
4
6
|
static targetAction: any;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
5
11
|
private readonly actions;
|
|
6
12
|
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated
|
|
15
|
+
* @param root
|
|
16
|
+
*/
|
|
7
17
|
setRoot(root: RootNode): LogicAction.Actions | undefined;
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated
|
|
20
|
+
*/
|
|
21
|
+
_getActions(): TAction[];
|
|
10
22
|
/**@internal */
|
|
11
23
|
getAllActions(includeJumpTo?: boolean, actions?: LogicAction.Actions[]): LogicAction.Actions[];
|
|
12
24
|
/**@internal */
|
|
@@ -28,13 +40,9 @@ export declare class Constructable<T extends typeof Constructable = any, TAction
|
|
|
28
40
|
* Find multiple elements by multiple IDs
|
|
29
41
|
*/
|
|
30
42
|
findElementsByIds(ids: string[], elements: LogicAction.GameElement[]): LogicAction.GameElement[];
|
|
31
|
-
|
|
32
|
-
* Adds an action to the current specified context instance
|
|
33
|
-
*/
|
|
34
|
-
protected _action(actions: (callee: this) => (TAction | TAction[])[]): CAction;
|
|
35
|
-
protected _action(actions: (TAction | TAction[])[]): CAction;
|
|
43
|
+
fromChained(chained: Proxied<GameElement, Chained<LogicAction.Actions>>): LogicAction.Actions[];
|
|
36
44
|
/**
|
|
37
45
|
* Construct the actions into a tree
|
|
38
46
|
*/
|
|
39
|
-
protected construct(parent?: RenderableNode): RenderableNode | null;
|
|
47
|
+
protected construct(actions: LogicAction.Actions[], parent?: RenderableNode): RenderableNode | null;
|
|
40
48
|
}
|
|
@@ -2,6 +2,7 @@ import { RenderableNode } from "../action/tree/actionTree";
|
|
|
2
2
|
import { LogicAction } from "../action/logicAction";
|
|
3
3
|
import { Actionable } from "../action/actionable";
|
|
4
4
|
import { GameState } from "../../player/gameState";
|
|
5
|
+
import { Chained, ChainedActions, Proxied } from "../action/chain";
|
|
5
6
|
export type ConditionConfig = {};
|
|
6
7
|
interface LambdaCtx {
|
|
7
8
|
gameState: GameState;
|
|
@@ -34,18 +35,18 @@ export type ConditionData = {
|
|
|
34
35
|
};
|
|
35
36
|
export declare class Condition extends Actionable {
|
|
36
37
|
static defaultConfig: ConditionConfig;
|
|
38
|
+
static getInitialState(): ConditionData;
|
|
37
39
|
readonly config: ConditionConfig;
|
|
38
40
|
conditions: ConditionData;
|
|
39
41
|
constructor(config?: ConditionConfig);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Else(action: (LogicAction.Actions | LogicAction.Actions[])): this;
|
|
42
|
+
If(condition: Lambda | LambdaHandler<boolean>, action: ChainedActions): Proxied<Condition, Chained<LogicAction.Actions>>;
|
|
43
|
+
ElseIf(condition: Lambda | LambdaHandler<boolean>, action: ChainedActions): Proxied<Condition, Chained<LogicAction.Actions>>;
|
|
44
|
+
Else(action: ChainedActions): Proxied<Condition, Chained<LogicAction.Actions>>;
|
|
44
45
|
evaluate(conditions: ConditionData, { gameState }: {
|
|
45
46
|
gameState: GameState;
|
|
46
47
|
}): LogicAction.Actions[] | null;
|
|
47
|
-
|
|
48
|
-
construct(
|
|
48
|
+
fromChained(chained: Proxied<Condition, Chained<LogicAction.Actions>>): LogicAction.Actions[];
|
|
49
|
+
construct(chainedActions: ChainedActions, lastChild?: RenderableNode, parentChild?: RenderableNode): LogicAction.Actions[];
|
|
49
50
|
_getFutureActions(): LogicAction.Actions[];
|
|
50
51
|
}
|
|
51
52
|
export {};
|
|
@@ -1,38 +1,41 @@
|
|
|
1
1
|
import { Actionable } from "../action/actionable";
|
|
2
2
|
import { LogicAction } from "../action/logicAction";
|
|
3
|
+
import { Chained, ChainedActions, Proxied } from "../action/chain";
|
|
3
4
|
import Actions = LogicAction.Actions;
|
|
5
|
+
type ChainedControl = Proxied<Control, Chained<LogicAction.Actions>>;
|
|
4
6
|
export declare class Control extends Actionable {
|
|
5
7
|
/**
|
|
6
8
|
* Execute actions in order, waiting for each action to complete
|
|
7
9
|
*/
|
|
8
|
-
static do(actions:
|
|
10
|
+
static do(actions: ChainedActions): never;
|
|
9
11
|
/**
|
|
10
12
|
* Execute actions in order, do not wait for this action to complete
|
|
11
13
|
*/
|
|
12
|
-
static doAsync(actions:
|
|
14
|
+
static doAsync(actions: ChainedActions): never;
|
|
13
15
|
/**
|
|
14
16
|
* Execute all actions at the same time, waiting for any one action to complete
|
|
15
17
|
*/
|
|
16
|
-
static any(actions:
|
|
18
|
+
static any(actions: ChainedActions): never;
|
|
17
19
|
/**
|
|
18
20
|
* Execute all actions at the same time, waiting for all actions to complete
|
|
19
21
|
*/
|
|
20
|
-
static all(actions:
|
|
22
|
+
static all(actions: ChainedActions): never;
|
|
21
23
|
/**
|
|
22
24
|
* Execute all actions at the same time, do not wait for all actions to complete
|
|
23
25
|
*/
|
|
24
|
-
static allAsync(actions:
|
|
26
|
+
static allAsync(actions: ChainedActions): never;
|
|
25
27
|
/**
|
|
26
28
|
* Execute actions multiple times
|
|
27
29
|
*/
|
|
28
|
-
static repeat(times: number, actions:
|
|
30
|
+
static repeat(times: number, actions: ChainedActions): never;
|
|
29
31
|
constructor();
|
|
30
|
-
do(actions:
|
|
31
|
-
doAsync(actions:
|
|
32
|
-
any(actions:
|
|
33
|
-
all(actions:
|
|
34
|
-
allAsync(actions:
|
|
35
|
-
repeat(times: number, actions:
|
|
32
|
+
do(actions: ChainedActions): ChainedControl;
|
|
33
|
+
doAsync(actions: ChainedActions): ChainedControl;
|
|
34
|
+
any(actions: ChainedActions): ChainedControl;
|
|
35
|
+
all(actions: ChainedActions): ChainedControl;
|
|
36
|
+
allAsync(actions: ChainedActions): ChainedControl;
|
|
37
|
+
repeat(times: number, actions: ChainedActions): ChainedControl;
|
|
36
38
|
construct(actions: Actions[]): Actions[];
|
|
37
39
|
private push;
|
|
38
40
|
}
|
|
41
|
+
export {};
|
|
@@ -2,10 +2,13 @@ import React from "react";
|
|
|
2
2
|
import type { TransformDefinitions } from "../elements/transform/type";
|
|
3
3
|
import { ImageAction } from "../action/actions";
|
|
4
4
|
import { Actionable } from "../action/actionable";
|
|
5
|
+
import { Scene } from "../elements/scene";
|
|
5
6
|
import { Transform } from "./transform/transform";
|
|
6
7
|
import { CommonImage, StaticImageData } from "../types";
|
|
8
|
+
import { LogicAction } from "../game";
|
|
7
9
|
import { ITransition } from "../elements/transition/type";
|
|
8
10
|
import { DeepPartial, EventDispatcher } from "../../../util/data";
|
|
11
|
+
import { Chained, Proxied } from "../action/chain";
|
|
9
12
|
export type ImageConfig = {
|
|
10
13
|
src: string | StaticImageData;
|
|
11
14
|
display: boolean;
|
|
@@ -25,7 +28,7 @@ export type ImageEventTypes = {
|
|
|
25
28
|
"event:image.elementLoaded": [];
|
|
26
29
|
"event:image.setTransition": [ITransition | null];
|
|
27
30
|
};
|
|
28
|
-
export declare class Image extends Actionable<ImageDataRaw> {
|
|
31
|
+
export declare class Image extends Actionable<ImageDataRaw, Image> {
|
|
29
32
|
static EventTypes: {
|
|
30
33
|
[K in keyof ImageEventTypes]: K;
|
|
31
34
|
};
|
|
@@ -35,18 +38,17 @@ export declare class Image extends Actionable<ImageDataRaw> {
|
|
|
35
38
|
left: "left";
|
|
36
39
|
right: "right";
|
|
37
40
|
};
|
|
41
|
+
static serializeImageState(state: Record<string, any>): Record<string, any>;
|
|
42
|
+
static deserializeImageState(state: Record<string, any>): ImageConfig;
|
|
38
43
|
readonly name: string;
|
|
39
44
|
readonly config: ImageConfig;
|
|
40
45
|
state: ImageConfig;
|
|
41
|
-
|
|
42
|
-
events: EventDispatcher<ImageEventTypes>;
|
|
46
|
+
readonly events: EventDispatcher<ImageEventTypes>;
|
|
43
47
|
ref: React.RefObject<HTMLImageElement> | undefined;
|
|
44
48
|
constructor(name: string, config: DeepPartial<ImageConfig>);
|
|
45
49
|
constructor(config: DeepPartial<ImageConfig>);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
dispose(): this;
|
|
49
|
-
init(): this;
|
|
50
|
+
dispose(): Proxied<Image, Chained<LogicAction.Actions>>;
|
|
51
|
+
init(): Proxied<Image, Chained<LogicAction.Actions>>;
|
|
50
52
|
checkConfig(): this;
|
|
51
53
|
/**
|
|
52
54
|
* Set the source of the image
|
|
@@ -62,7 +64,7 @@ export declare class Image extends Actionable<ImageDataRaw> {
|
|
|
62
64
|
* image.setSrc(yourImage, new Fade(1000));
|
|
63
65
|
* ```
|
|
64
66
|
*/
|
|
65
|
-
setSrc(src: string | StaticImageData, transition?: ITransition):
|
|
67
|
+
setSrc(src: string | StaticImageData, transition?: ITransition): Proxied<Image, Chained<LogicAction.Actions>>;
|
|
66
68
|
/**
|
|
67
69
|
* Apply a transform to the image
|
|
68
70
|
* @example
|
|
@@ -95,7 +97,7 @@ export declare class Image extends Actionable<ImageDataRaw> {
|
|
|
95
97
|
* );
|
|
96
98
|
* ```
|
|
97
99
|
*/
|
|
98
|
-
applyTransform(transform: Transform):
|
|
100
|
+
applyTransform(transform: Transform): Proxied<Image, Chained<LogicAction.Actions>>;
|
|
99
101
|
/**
|
|
100
102
|
* Show the image
|
|
101
103
|
*
|
|
@@ -107,15 +109,15 @@ export declare class Image extends Actionable<ImageDataRaw> {
|
|
|
107
109
|
* });
|
|
108
110
|
* ```
|
|
109
111
|
*/
|
|
110
|
-
show():
|
|
111
|
-
show(options: Transform):
|
|
112
|
-
show(options: Partial<TransformDefinitions.CommonTransformProps>):
|
|
112
|
+
show(): Proxied<Image, Chained<LogicAction.Actions>>;
|
|
113
|
+
show(options: Transform): Proxied<Image, Chained<LogicAction.Actions>>;
|
|
114
|
+
show(options: Partial<TransformDefinitions.CommonTransformProps>): Proxied<Image, Chained<LogicAction.Actions>>;
|
|
113
115
|
/**
|
|
114
116
|
* Hide the image
|
|
115
117
|
*/
|
|
116
|
-
hide():
|
|
117
|
-
hide(transform: Transform):
|
|
118
|
-
hide(transform: Partial<TransformDefinitions.CommonTransformProps>):
|
|
118
|
+
hide(): Proxied<Image, Chained<LogicAction.Actions>>;
|
|
119
|
+
hide(transform: Transform): Proxied<Image, Chained<LogicAction.Actions>>;
|
|
120
|
+
hide(transform: Partial<TransformDefinitions.CommonTransformProps>): Proxied<Image, Chained<LogicAction.Actions>>;
|
|
119
121
|
toTransform(): Transform;
|
|
120
122
|
setScope(scope: React.RefObject<HTMLImageElement>): this;
|
|
121
123
|
getScope(): React.RefObject<HTMLImageElement> | undefined;
|
|
@@ -123,9 +125,9 @@ export declare class Image extends Actionable<ImageDataRaw> {
|
|
|
123
125
|
toData(): ImageDataRaw | null;
|
|
124
126
|
fromData(data: ImageDataRaw): this;
|
|
125
127
|
_$setDispose(): this;
|
|
126
|
-
_setTransition(transition: ITransition | null):
|
|
127
|
-
_applyTransition(transition: ITransition):
|
|
128
|
+
_setTransition(transition: ITransition | null): Proxied<Image, Chained<LogicAction.Actions>>;
|
|
129
|
+
_applyTransition(transition: ITransition): Proxied<Image, Chained<LogicAction.Actions>>;
|
|
128
130
|
private _transitionSrc;
|
|
129
131
|
private _dispose;
|
|
130
|
-
|
|
132
|
+
_init(scene?: Scene): ImageAction<typeof ImageAction.ActionTypes.init>;
|
|
131
133
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { Sentence, Word } from "./text";
|
|
2
|
-
import { RenderableNode } from "../action/tree/actionTree";
|
|
3
2
|
import { LogicAction } from "../action/logicAction";
|
|
4
3
|
import { MenuAction } from "../action/actions";
|
|
5
4
|
import { Actionable } from "../action/actionable";
|
|
6
5
|
import Actions = LogicAction.Actions;
|
|
6
|
+
import { Chained, Proxied } from "../action/chain";
|
|
7
|
+
import GameElement = LogicAction.GameElement;
|
|
7
8
|
export type MenuConfig = {};
|
|
8
9
|
export type MenuChoice = {
|
|
9
|
-
action:
|
|
10
|
+
action: ChainedActions;
|
|
10
11
|
prompt: UnSentencePrompt | Sentence;
|
|
11
12
|
};
|
|
13
|
+
type ChainedAction = Proxied<GameElement, Chained<LogicAction.Actions>>;
|
|
14
|
+
type ChainedActions = (ChainedAction | ChainedAction[] | Actions | Actions[])[];
|
|
12
15
|
type UnSentencePrompt = (string | Word)[] | (string | Word);
|
|
13
16
|
export type Choice = {
|
|
14
17
|
action: Actions[];
|
|
@@ -18,7 +21,7 @@ export type MenuData = {
|
|
|
18
21
|
prompt: Sentence;
|
|
19
22
|
choices: Choice[];
|
|
20
23
|
};
|
|
21
|
-
export declare class Menu extends Actionable {
|
|
24
|
+
export declare class Menu extends Actionable<any, Menu> {
|
|
22
25
|
static defaultConfig: MenuConfig;
|
|
23
26
|
static targetAction: typeof MenuAction;
|
|
24
27
|
prompt: Sentence;
|
|
@@ -33,11 +36,11 @@ export declare class Menu extends Actionable {
|
|
|
33
36
|
* character.say("I went left").toActions()
|
|
34
37
|
* ]);
|
|
35
38
|
*/
|
|
36
|
-
choose(choice: MenuChoice):
|
|
37
|
-
choose(prompt: Sentence, action:
|
|
38
|
-
choose(prompt: UnSentencePrompt, action:
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
choose(choice: MenuChoice): Proxied<Menu, Chained<LogicAction.Actions>>;
|
|
40
|
+
choose(prompt: Sentence, action: ChainedActions): Proxied<Menu, Chained<LogicAction.Actions>>;
|
|
41
|
+
choose(prompt: UnSentencePrompt, action: ChainedActions): Proxied<Menu, Chained<LogicAction.Actions>>;
|
|
42
|
+
fromChained(chained: Proxied<Menu, Chained<LogicAction.Actions>>): LogicAction.Actions[];
|
|
43
|
+
private construct;
|
|
41
44
|
_getFutureActions(choices: Choice[]): LogicAction.Actions[];
|
|
42
45
|
private constructChoices;
|
|
43
46
|
}
|
|
@@ -8,8 +8,10 @@ import { ITransition } from "../elements/transition/type";
|
|
|
8
8
|
import { SrcManager } from "../elements/srcManager";
|
|
9
9
|
import { Sound, SoundDataRaw } from "../elements/sound";
|
|
10
10
|
import { TransformDefinitions } from "../elements/transform/type";
|
|
11
|
+
import { Chained, Proxied } from "../action/chain";
|
|
11
12
|
import Actions = LogicAction.Actions;
|
|
12
13
|
import ImageTransformProps = TransformDefinitions.ImageTransformProps;
|
|
14
|
+
import GameElement = LogicAction.GameElement;
|
|
13
15
|
export type SceneConfig = {
|
|
14
16
|
invertY: boolean;
|
|
15
17
|
invertX: boolean;
|
|
@@ -22,6 +24,8 @@ export type SceneState = {
|
|
|
22
24
|
export type JumpConfig = {
|
|
23
25
|
transition: ITransition;
|
|
24
26
|
};
|
|
27
|
+
type ChainableAction = Proxied<GameElement, Chained<LogicAction.Actions>> | Actions;
|
|
28
|
+
type ChainedScene = Proxied<Scene, Chained<LogicAction.Actions>>;
|
|
25
29
|
export type SceneDataRaw = {
|
|
26
30
|
state: {
|
|
27
31
|
backgroundMusic?: SoundDataRaw | null;
|
|
@@ -30,7 +34,7 @@ export type SceneDataRaw = {
|
|
|
30
34
|
};
|
|
31
35
|
};
|
|
32
36
|
export type SceneEventTypes = {
|
|
33
|
-
"event:scene.
|
|
37
|
+
"event:scene.applyTransition": [ITransition | null];
|
|
34
38
|
"event:scene.remove": [];
|
|
35
39
|
"event:scene.load": [];
|
|
36
40
|
"event:scene.unload": [];
|
|
@@ -42,7 +46,7 @@ export type SceneEventTypes = {
|
|
|
42
46
|
"event:scene.setBackgroundMusic": [Sound | null, number];
|
|
43
47
|
"event:scene.applyTransform": [Transform<ImageTransformProps>];
|
|
44
48
|
};
|
|
45
|
-
export declare class Scene extends Constructable<
|
|
49
|
+
export declare class Scene extends Constructable<Actions> {
|
|
46
50
|
static EventTypes: {
|
|
47
51
|
[K in keyof SceneEventTypes]: K;
|
|
48
52
|
};
|
|
@@ -59,55 +63,56 @@ export declare class Scene extends Constructable<any, Actions, SceneAction<"scen
|
|
|
59
63
|
_liveState: {
|
|
60
64
|
active: boolean;
|
|
61
65
|
};
|
|
62
|
-
|
|
63
|
-
private _actions;
|
|
66
|
+
sceneRoot?: SceneAction<"scene:action">;
|
|
64
67
|
constructor(name: string, config?: DeepPartial<SceneConfig>);
|
|
65
|
-
activate():
|
|
66
|
-
deactivate():
|
|
68
|
+
activate(): ChainedScene;
|
|
69
|
+
deactivate(): ChainedScene;
|
|
67
70
|
/**
|
|
68
71
|
* Set background, if {@link transition} is provided, it will be applied
|
|
69
72
|
*/
|
|
70
|
-
setBackground(background: Background["background"], transition?: ITransition):
|
|
73
|
+
setBackground(background: Background["background"], transition?: ITransition): ChainedScene;
|
|
71
74
|
/**
|
|
72
75
|
* Apply a transform to the scene
|
|
73
76
|
*
|
|
74
77
|
* for example, you can shake the scene by applying a transform with a shake effect
|
|
75
78
|
*/
|
|
76
|
-
applyTransform(transform: Transform<ImageTransformProps>):
|
|
79
|
+
applyTransform(transform: Transform<ImageTransformProps>): ChainedScene;
|
|
77
80
|
/**
|
|
78
81
|
* Jump to the specified scene
|
|
79
82
|
*
|
|
80
83
|
* After calling the method, you **will not be able to return to the context of the scene** that called the jump, so the scene will be unloaded
|
|
81
84
|
*
|
|
82
85
|
* Any operations after the jump operation will not be executed
|
|
86
|
+
* @chainable
|
|
83
87
|
*/
|
|
84
|
-
jumpTo(arg0: Scene, config?: Partial<JumpConfig>):
|
|
85
|
-
transitionSceneBackground(scene?: Scene, transition?: ITransition):
|
|
88
|
+
jumpTo(arg0: Scene, config?: Partial<JumpConfig>): ChainedScene;
|
|
89
|
+
transitionSceneBackground(scene?: Scene, transition?: ITransition): ChainedScene;
|
|
86
90
|
/**
|
|
87
91
|
* Wait for a period of time, the parameter can be the number of milliseconds, a Promise, or an unresolved {@link Awaitable}
|
|
92
|
+
* @chainable
|
|
88
93
|
*/
|
|
89
|
-
sleep(ms: number):
|
|
90
|
-
sleep(promise: Promise<any>):
|
|
91
|
-
sleep(awaitable: Awaitable<any, any>):
|
|
94
|
+
sleep(ms: number): ChainedScene;
|
|
95
|
+
sleep(promise: Promise<any>): ChainedScene;
|
|
96
|
+
sleep(awaitable: Awaitable<any, any>): ChainedScene;
|
|
92
97
|
/**
|
|
93
98
|
* Set background music
|
|
94
99
|
* @param sound Target music
|
|
95
100
|
* @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
|
|
96
101
|
*/
|
|
97
|
-
setBackgroundMusic(sound: Sound, fade?: number):
|
|
98
|
-
toActions(): SceneAction<any>[];
|
|
102
|
+
setBackgroundMusic(sound: Sound, fade?: number): ChainedScene;
|
|
99
103
|
_$getBackgroundMusic(): Sound | null;
|
|
100
104
|
toData(): SceneDataRaw | null;
|
|
101
105
|
fromData(data: SceneDataRaw): this;
|
|
102
|
-
_setTransition(transition: ITransition):
|
|
103
|
-
_applyTransition(transition: ITransition):
|
|
106
|
+
_setTransition(transition: ITransition): ChainedScene;
|
|
107
|
+
_applyTransition(transition: ITransition): ChainedScene;
|
|
104
108
|
_toTransform(): Transform<ImageTransformProps>;
|
|
109
|
+
_initTransform(): Transform<ImageTransformProps>;
|
|
105
110
|
registerSrc(seen?: Set<Scene>): void;
|
|
106
|
-
action(actions: (
|
|
107
|
-
action(actions: ((scene: Scene) =>
|
|
108
|
-
|
|
109
|
-
private _jumpTo;
|
|
111
|
+
action(actions: (ChainableAction | ChainableAction[])[]): this;
|
|
112
|
+
action(actions: ((scene: Scene) => ChainableAction[])): this;
|
|
113
|
+
_jumpTo(scene: Scene): ChainedScene;
|
|
110
114
|
private _exit;
|
|
111
115
|
private _transitionToScene;
|
|
112
116
|
private _init;
|
|
113
117
|
}
|
|
118
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LogicAction } from "../action/logicAction";
|
|
2
2
|
import { Actionable } from "../action/actionable";
|
|
3
3
|
import { GameState } from "../../player/gameState";
|
|
4
|
-
import
|
|
4
|
+
import { Chained, Proxied } from "../action/chain";
|
|
5
5
|
export interface ScriptCtx {
|
|
6
6
|
script: Script;
|
|
7
7
|
gameState: GameState;
|
|
@@ -18,6 +18,6 @@ export declare class Script extends Actionable<object> {
|
|
|
18
18
|
getCtx({ gameState }: {
|
|
19
19
|
gameState: GameState;
|
|
20
20
|
}): ScriptCtx;
|
|
21
|
-
|
|
21
|
+
fromChained(chained: Proxied<Script, Chained<LogicAction.Actions>>): LogicAction.Actions[];
|
|
22
22
|
}
|
|
23
23
|
export {};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Actionable } from "../action/actionable";
|
|
2
2
|
import { DeepPartial } from "../../../util/data";
|
|
3
|
+
import { LogicAction } from "../game";
|
|
3
4
|
import * as Howler from "howler";
|
|
4
5
|
import { HowlOptions } from "howler";
|
|
6
|
+
import { Chained, Proxied } from "../action/chain";
|
|
7
|
+
type ChainedSound = Proxied<Sound, Chained<LogicAction.Actions>>;
|
|
5
8
|
export declare enum SoundType {
|
|
6
9
|
soundEffect = "soundEffect",
|
|
7
10
|
music = "music",
|
|
@@ -40,13 +43,13 @@ export declare class Sound extends Actionable<SoundDataRaw> {
|
|
|
40
43
|
token: any;
|
|
41
44
|
};
|
|
42
45
|
constructor(config?: DeepPartial<SoundConfig>);
|
|
43
|
-
play():
|
|
44
|
-
stop():
|
|
45
|
-
fade(start: number | undefined, end: number, duration: number):
|
|
46
|
-
setVolume(volume: number):
|
|
47
|
-
setRate(rate: number):
|
|
48
|
-
pause(fade?: number):
|
|
49
|
-
resume(fade?: number):
|
|
46
|
+
play(): ChainedSound;
|
|
47
|
+
stop(): ChainedSound;
|
|
48
|
+
fade(start: number | undefined, end: number, duration: number): ChainedSound;
|
|
49
|
+
setVolume(volume: number): ChainedSound;
|
|
50
|
+
setRate(rate: number): ChainedSound;
|
|
51
|
+
pause(fade?: number): ChainedSound;
|
|
52
|
+
resume(fade?: number): ChainedSound;
|
|
50
53
|
getHowlOptions(): HowlOptions;
|
|
51
54
|
getSrc(): string;
|
|
52
55
|
$setToken(token: any): void;
|
|
@@ -58,3 +61,4 @@ export declare class Sound extends Actionable<SoundDataRaw> {
|
|
|
58
61
|
fromData(data: SoundDataRaw): this;
|
|
59
62
|
private pushAction;
|
|
60
63
|
}
|
|
64
|
+
export {};
|
|
@@ -6,12 +6,13 @@ import { Scene } from "../elements/scene";
|
|
|
6
6
|
export type StoryConfig = {};
|
|
7
7
|
export type ElementStateRaw = Record<string, any>;
|
|
8
8
|
export type NodeChildIdMap = Map<string, string>;
|
|
9
|
-
export declare class Story extends Constructable<
|
|
9
|
+
export declare class Story extends Constructable<SceneAction<"scene:action">> {
|
|
10
10
|
static defaultConfig: StoryConfig;
|
|
11
11
|
static targetAction: typeof StoryAction;
|
|
12
12
|
readonly id: string;
|
|
13
13
|
readonly name: string;
|
|
14
14
|
readonly config: StoryConfig;
|
|
15
|
+
entryScene: Scene | null;
|
|
15
16
|
constructor(name: string, config?: StoryConfig);
|
|
16
17
|
/**@internal */
|
|
17
18
|
_setAllElementState(data: RawData<ElementStateRaw>[], actions?: LogicAction.Actions[]): void;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { LogicAction } from "../game";
|
|
1
2
|
import { color, Color } from "../types";
|
|
2
3
|
import { DeepPartial } from "../../../util/data";
|
|
3
4
|
import { Actionable } from "../action/actionable";
|
|
4
5
|
import type { Sound } from "../elements/sound";
|
|
6
|
+
import { Chained, Proxied } from "../action/chain";
|
|
5
7
|
export type SentenceConfig = {
|
|
6
8
|
pause?: boolean | number;
|
|
7
9
|
voice: Sound | string | null | undefined;
|
|
@@ -17,14 +19,14 @@ type UnSentencePrompt = (string | Word)[] | (string | Word);
|
|
|
17
19
|
export declare class Sentence {
|
|
18
20
|
static defaultConfig: SentenceConfig;
|
|
19
21
|
static defaultState: SentenceState;
|
|
22
|
+
static isSentence(obj: any): obj is Sentence;
|
|
23
|
+
static toSentence(prompt: UnSentencePrompt | Sentence): Sentence;
|
|
20
24
|
id: string;
|
|
21
25
|
character: Character | null;
|
|
22
26
|
text: Word[];
|
|
23
27
|
config: SentenceConfig;
|
|
24
28
|
state: SentenceState;
|
|
25
29
|
constructor(character: Character | null, text: (string | Word)[] | (string | Word), config?: Partial<SentenceConfig>);
|
|
26
|
-
static isSentence(obj: any): obj is Sentence;
|
|
27
|
-
static toSentence(prompt: UnSentencePrompt | Sentence): Sentence;
|
|
28
30
|
format(text: (string | Word)[] | (string | Word)): Word[];
|
|
29
31
|
toData(): SentenceDataRaw | null;
|
|
30
32
|
fromData(data: SentenceDataRaw): this;
|
|
@@ -33,10 +35,10 @@ export declare class Sentence {
|
|
|
33
35
|
export declare class Word {
|
|
34
36
|
static defaultConfig: Partial<WordConfig>;
|
|
35
37
|
static defaultColor: color;
|
|
38
|
+
static isWord(obj: any): obj is Word;
|
|
36
39
|
text: string;
|
|
37
40
|
config: Partial<WordConfig>;
|
|
38
41
|
constructor(text: string, config?: Partial<WordConfig>);
|
|
39
|
-
static isWord(obj: any): obj is Word;
|
|
40
42
|
}
|
|
41
43
|
export declare enum CharacterMode {
|
|
42
44
|
"adv" = "adv",
|
|
@@ -46,34 +48,33 @@ export type CharacterConfig = {
|
|
|
46
48
|
mode: CharacterMode;
|
|
47
49
|
};
|
|
48
50
|
export type CharacterStateData = {};
|
|
49
|
-
export declare class Character extends Actionable<CharacterStateData> {
|
|
51
|
+
export declare class Character extends Actionable<CharacterStateData, Character> {
|
|
50
52
|
static Modes: typeof CharacterMode;
|
|
51
53
|
static defaultConfig: CharacterConfig;
|
|
52
|
-
name: string | null;
|
|
53
|
-
config: CharacterConfig;
|
|
54
|
+
readonly name: string | null;
|
|
55
|
+
readonly config: CharacterConfig;
|
|
54
56
|
constructor(name: string | null, config?: DeepPartial<CharacterConfig>);
|
|
55
57
|
/**
|
|
56
58
|
* Say something
|
|
57
59
|
* @example
|
|
58
60
|
* ```typescript
|
|
59
|
-
* character.say("Hello, world!")
|
|
61
|
+
* character.say("Hello, world!");
|
|
60
62
|
* ```
|
|
61
63
|
* @example
|
|
62
64
|
* ```typescript
|
|
63
65
|
* character
|
|
64
66
|
* .say("Hello, world!")
|
|
65
|
-
* .say("Hello, world!")
|
|
66
|
-
* .toActions();
|
|
67
|
+
* .say("Hello, world!");
|
|
67
68
|
* ```
|
|
68
69
|
* @example
|
|
69
70
|
* ```typescript
|
|
70
71
|
* character.say(new Sentence(character, [
|
|
71
72
|
* "Hello, ",
|
|
72
73
|
* new Word("world", {color: "#f00"}), // Some words can be colored
|
|
73
|
-
* ]))
|
|
74
|
+
* ]));
|
|
74
75
|
*/
|
|
75
|
-
say(content: string): Character
|
|
76
|
-
say(content: Sentence): Character
|
|
77
|
-
say(content: (string | Word)[]): Character
|
|
76
|
+
say(content: string): Proxied<Character, Chained<LogicAction.Actions>>;
|
|
77
|
+
say(content: Sentence): Proxied<Character, Chained<LogicAction.Actions>>;
|
|
78
|
+
say(content: (string | Word)[]): Proxied<Character, Chained<LogicAction.Actions>>;
|
|
78
79
|
}
|
|
79
80
|
export {};
|