narraleaf-react 0.4.1 → 0.4.2
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 +1 -1
- package/dist/game/nlcore/action/gameHistory.d.ts +1 -1
- package/dist/game/nlcore/action/logicAction.d.ts +10 -0
- package/dist/game/nlcore/elements/character/sentence.d.ts +3 -3
- package/dist/game/nlcore/elements/menu.d.ts +4 -1
- package/dist/game/nlcore/gameTypes.d.ts +5 -0
- package/dist/game/player/elements/Player.d.ts +0 -1
- package/dist/game/player/elements/menu/type.d.ts +2 -2
- package/dist/game/player/elements/say/Dialog.d.ts +3 -19
- package/dist/game/player/elements/say/Sentence.d.ts +17 -6
- package/dist/game/player/elements/say/UIDialog.d.ts +64 -2
- package/dist/game/player/elements/say/context.d.ts +3 -18
- package/dist/game/player/elements/say/type.d.ts +25 -7
- package/dist/game/player/gameState.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/main.js +96 -31
- package/dist/util/data.d.ts +19 -0
- package/package.json +27 -25
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ npm install narraleaf-react
|
|
|
90
90
|
|
|
91
91
|
### Documentation
|
|
92
92
|
|
|
93
|
-
- [Introduction](https://react.narraleaf.com/documentation/introduction)
|
|
93
|
+
- [Introduction](https://react.narraleaf.com/documentation/introduction)
|
|
94
94
|
- [Quick Start](https://react.narraleaf.com/documentation/quick-start)
|
|
95
95
|
- [Installation](https://react.narraleaf.com/documentation/installation)
|
|
96
96
|
- [Basic](https://react.narraleaf.com/documentation/basic)
|
|
@@ -32,6 +32,15 @@ import { LayerAction } from "../action/actions/layerAction";
|
|
|
32
32
|
import { ExposedStateType } from "../../player/type";
|
|
33
33
|
import { Video } from "../elements/video";
|
|
34
34
|
import { VideoAction } from "../action/actions/videoAction";
|
|
35
|
+
export interface LogicActionInterface {
|
|
36
|
+
DisplayableElements: Text | Image | Layer | AbstractDisplayable<any, any>;
|
|
37
|
+
DisplayableExposed: ExposedStateType.image | ExposedStateType.layer | ExposedStateType.text;
|
|
38
|
+
GameElement: Character | Scene | Story | Image | Condition | Script | Menu | Sound | Control | Text | AbstractDisplayable<any, any> | Persistent<any> | ServiceSkeleton | Video;
|
|
39
|
+
Actions: TypedAction | CharacterAction | ConditionAction | ImageAction | SceneAction | ScriptAction | StoryAction | MenuAction | SoundAction | ControlAction | TextAction | DisplayableAction | PersistentAction | ServiceAction | LayerAction | VideoAction;
|
|
40
|
+
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
|
+
ActionContents: CharacterActionContentType & ConditionActionContentType & ImageActionContentType & SceneActionContentType & ScriptActionContentType & StoryActionContentType & MenuActionContentType & SoundActionContentType & ControlActionContentType & TextActionContentType & DisplayableActionContentType & PersistentActionContentType & ServiceActionContentType & LayerActionContentType & VideoActionContentType;
|
|
42
|
+
}
|
|
43
|
+
export declare const LogicAction: {};
|
|
35
44
|
export declare namespace LogicAction {
|
|
36
45
|
type DisplayableElements = Text | Image | Layer | AbstractDisplayable<any, any>;
|
|
37
46
|
type DisplayableExposed = ExposedStateType.image | ExposedStateType.layer | ExposedStateType.text;
|
|
@@ -40,3 +49,4 @@ export declare namespace LogicAction {
|
|
|
40
49
|
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
50
|
type ActionContents = CharacterActionContentType & ConditionActionContentType & ImageActionContentType & SceneActionContentType & ScriptActionContentType & StoryActionContentType & MenuActionContentType & SoundActionContentType & ControlActionContentType & TextActionContentType & DisplayableActionContentType & PersistentActionContentType & ServiceActionContentType & LayerActionContentType & VideoActionContentType;
|
|
42
51
|
}
|
|
52
|
+
export type LogicAction = typeof LogicAction;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Sound } from "../../elements/sound";
|
|
2
1
|
import type { Character } from "../../elements/character";
|
|
2
|
+
import { Pausing } from "../../elements/character/pause";
|
|
3
3
|
import { Word } from "../../elements/character/word";
|
|
4
|
-
import { Color, Font } from "../../types";
|
|
5
4
|
import type { ScriptCtx } from "../../elements/script";
|
|
6
|
-
import {
|
|
5
|
+
import { Sound } from "../../elements/sound";
|
|
6
|
+
import { Color, Font } from "../../types";
|
|
7
7
|
export type SentenceConfig = {
|
|
8
8
|
pause?: boolean | number;
|
|
9
9
|
voice: Sound | null;
|
|
@@ -13,7 +13,7 @@ export type Choice = {
|
|
|
13
13
|
prompt: Sentence;
|
|
14
14
|
};
|
|
15
15
|
export type MenuData = {
|
|
16
|
-
prompt: Sentence;
|
|
16
|
+
prompt: Sentence | null;
|
|
17
17
|
choices: Choice[];
|
|
18
18
|
};
|
|
19
19
|
export declare class Menu extends Actionable<any, Menu> {
|
|
@@ -23,9 +23,11 @@ export declare class Menu extends Actionable<any, Menu> {
|
|
|
23
23
|
* @returns A new menu
|
|
24
24
|
*/
|
|
25
25
|
static prompt(prompt: SentencePrompt | Sentence, config?: MenuConfig): Menu;
|
|
26
|
+
static choose(arg0: Sentence | MenuChoice | SentencePrompt, arg1?: ChainedActions): Proxied<Menu, Chained<LogicAction.Actions>>;
|
|
26
27
|
constructor(prompt: SentencePrompt, config?: MenuConfig);
|
|
27
28
|
constructor(prompt: Sentence, config?: MenuConfig);
|
|
28
29
|
constructor(prompt: SentencePrompt | Sentence, config: MenuConfig);
|
|
30
|
+
constructor(prompt: null, config?: MenuConfig);
|
|
29
31
|
/**
|
|
30
32
|
* Add a choice to the menu
|
|
31
33
|
* @example
|
|
@@ -37,4 +39,5 @@ export declare class Menu extends Actionable<any, Menu> {
|
|
|
37
39
|
choose(choice: MenuChoice): Proxied<Menu, Chained<LogicAction.Actions>>;
|
|
38
40
|
choose(prompt: Sentence, action: ChainedActions): Proxied<Menu, Chained<LogicAction.Actions>>;
|
|
39
41
|
choose(prompt: SentencePrompt, action: ChainedActions): Proxied<Menu, Chained<LogicAction.Actions>>;
|
|
42
|
+
choose(arg0: Sentence | MenuChoice | SentencePrompt, arg1?: ChainedActions): Proxied<Menu, Chained<LogicAction.Actions>>;
|
|
40
43
|
}
|
|
@@ -317,6 +317,11 @@ export type GameConfig = {
|
|
|
317
317
|
* @default null
|
|
318
318
|
*/
|
|
319
319
|
stage: React.ReactNode | null;
|
|
320
|
+
/**
|
|
321
|
+
* The default color for the menu choices
|
|
322
|
+
* @default "#000"
|
|
323
|
+
*/
|
|
324
|
+
defaultMenuChoiceColor: Color;
|
|
320
325
|
};
|
|
321
326
|
export type GameSettings = {
|
|
322
327
|
volume: number;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import "client-only";
|
|
2
|
-
import "@player/lib/styles/style.css";
|
|
3
2
|
import { PlayerProps } from "../elements/type";
|
|
4
3
|
import React from "react";
|
|
5
4
|
export default function Player({ story, width, height, className, onReady, onEnd, children, active, }: Readonly<PlayerProps>): React.JSX.Element;
|
|
@@ -5,11 +5,11 @@ import { Word } from "../../../nlcore/elements/character/word";
|
|
|
5
5
|
import { Pausing } from "../../../nlcore/elements/character/pause";
|
|
6
6
|
import { Chosen } from "../../type";
|
|
7
7
|
export interface MenuElementProps {
|
|
8
|
-
prompt: Sentence;
|
|
8
|
+
prompt: Sentence | null;
|
|
9
9
|
choices: Choice[];
|
|
10
10
|
afterChoose: (choice: Chosen) => void;
|
|
11
11
|
state: GameState;
|
|
12
|
-
words: Word<Pausing | string>[];
|
|
12
|
+
words: Word<Pausing | string>[] | null;
|
|
13
13
|
}
|
|
14
14
|
export interface IUserMenuProps {
|
|
15
15
|
items: number[];
|
|
@@ -1,27 +1,11 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import { DialogProps } from "../../elements/say/type";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import { Word } from "../../../nlcore/elements/character/word";
|
|
6
|
-
import { Pausing } from "../../../nlcore/elements/character/pause";
|
|
7
|
-
/**
|
|
8
|
-
* Props-based wrapper component
|
|
9
|
-
* Provides a clean interface for direct prop usage
|
|
10
|
-
*/
|
|
11
|
-
export interface RawDialogProps extends Omit<DialogProps, "onClick"> {
|
|
12
|
-
sentence: Sentence;
|
|
13
|
-
words: Word<Pausing | string>[];
|
|
14
|
-
gameState: GameState;
|
|
15
|
-
useTypeEffect?: boolean;
|
|
16
|
-
onClick?: (skiped?: boolean) => void;
|
|
17
|
-
onFinished?: () => void;
|
|
18
|
-
}
|
|
19
|
-
export declare function RawDialog(props: RawDialogProps): React.JSX.Element;
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare function RawDialog(props: DialogProps): React.JSX.Element;
|
|
20
4
|
/**
|
|
21
5
|
* Context-based wrapper component
|
|
22
6
|
* Provides integration with the say context
|
|
23
7
|
*/
|
|
24
|
-
export declare function Dialog({ children, ...props }: DialogProps): React.JSX.Element;
|
|
8
|
+
export declare function Dialog({ children, ...props }: DialogProps): React.JSX.Element | null;
|
|
25
9
|
export default Dialog;
|
|
26
10
|
/**
|
|
27
11
|
* Default dialog component with Texts as children
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Word } from "../../../nlcore/elements/character/word";
|
|
3
1
|
import { Pausing } from "../../../nlcore/elements/character/pause";
|
|
4
|
-
import { DialogElementProps } from "./type";
|
|
5
|
-
import { GameState } from "../../../../game/nlcore/common/game";
|
|
6
2
|
import { Sentence } from "../../../nlcore/elements/character/sentence";
|
|
3
|
+
import { Word } from "../../../nlcore/elements/character/word";
|
|
4
|
+
import { GameState } from "../../../../game/nlcore/common/game";
|
|
5
|
+
import { Color } from "../../../../game/nlcore/types";
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { DialogElementProps } from "./type";
|
|
8
|
+
import { DialogState } from "./UIDialog";
|
|
9
|
+
type BaseTextsProps = {
|
|
10
|
+
/**
|
|
11
|
+
* The default color of the text
|
|
12
|
+
*/
|
|
13
|
+
defaultColor?: Color;
|
|
14
|
+
className?: string;
|
|
15
|
+
style?: React.CSSProperties;
|
|
16
|
+
dialog?: DialogState;
|
|
17
|
+
} & React.HTMLAttributes<HTMLDivElement>;
|
|
7
18
|
/**
|
|
8
19
|
* Props-based wrapper component
|
|
9
20
|
* Provides a clean interface for direct prop usage
|
|
@@ -17,10 +28,10 @@ export interface TextsProps extends DialogElementProps {
|
|
|
17
28
|
count?: number;
|
|
18
29
|
words?: Word<Pausing | string>[];
|
|
19
30
|
}
|
|
20
|
-
export declare function RawTexts(props:
|
|
31
|
+
export declare function RawTexts(props: BaseTextsProps): React.JSX.Element;
|
|
21
32
|
/**
|
|
22
33
|
* Context-based wrapper component
|
|
23
34
|
* Provides integration with the sentence context
|
|
24
35
|
*/
|
|
25
|
-
export declare function Texts(props:
|
|
36
|
+
export declare function Texts(props: BaseTextsProps): React.JSX.Element;
|
|
26
37
|
export default Texts;
|
|
@@ -1,3 +1,65 @@
|
|
|
1
|
+
import { Pausing } from "../../../nlcore/elements/character/pause";
|
|
2
|
+
import { Word } from "../../../nlcore/elements/character/word";
|
|
3
|
+
import { GameState } from "../../../../game/nlcore/common/game";
|
|
4
|
+
import { EventDispatcher } from "../../../../util/data";
|
|
1
5
|
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
6
|
+
import { DialogAction, DialogStateType, SayElementProps } from "./type";
|
|
7
|
+
type DialogEvents = {
|
|
8
|
+
"event:dialog.requestComplete": [];
|
|
9
|
+
"event:dialog.complete": [];
|
|
10
|
+
"event:dialog.forceSkip": [];
|
|
11
|
+
};
|
|
12
|
+
type DialogStateConfig = {
|
|
13
|
+
useTypeEffect: boolean;
|
|
14
|
+
action: DialogAction;
|
|
15
|
+
evaluatedWords: Word<Pausing | string>[];
|
|
16
|
+
gameState: GameState;
|
|
17
|
+
};
|
|
18
|
+
export declare class DialogState {
|
|
19
|
+
static Events: {
|
|
20
|
+
requestComplete: "event:dialog.requestComplete";
|
|
21
|
+
complete: "event:dialog.complete";
|
|
22
|
+
forceSkip: "event:dialog.forceSkip";
|
|
23
|
+
};
|
|
24
|
+
readonly config: Readonly<DialogStateConfig>;
|
|
25
|
+
readonly events: EventDispatcher<DialogEvents>;
|
|
26
|
+
private _state;
|
|
27
|
+
private _count;
|
|
28
|
+
private _forceSkipped;
|
|
29
|
+
private _idle;
|
|
30
|
+
private autoForwardScheduler;
|
|
31
|
+
constructor(config: DialogStateConfig);
|
|
32
|
+
get state(): DialogStateType;
|
|
33
|
+
get deps(): React.DependencyList;
|
|
34
|
+
isIdle(): boolean;
|
|
35
|
+
setIdle(idle: boolean): void;
|
|
36
|
+
/**
|
|
37
|
+
* Only for dialog component to call
|
|
38
|
+
*
|
|
39
|
+
* Calling this method will request the sentence to be completed
|
|
40
|
+
* If the sentence is already completed, it will exit the dialog
|
|
41
|
+
*/
|
|
42
|
+
requestComplete(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Only for dialog state to call
|
|
45
|
+
*
|
|
46
|
+
* Force the sentence to cancel/skip all the tasks
|
|
47
|
+
*/
|
|
48
|
+
forceSkip(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Only for sentence component to call
|
|
51
|
+
*
|
|
52
|
+
* Only call this method when the sentence is completed
|
|
53
|
+
* Calling this method will schedule the exit of the dialog
|
|
54
|
+
*/
|
|
55
|
+
dispatchComplete(): void;
|
|
56
|
+
emitComplete(): void;
|
|
57
|
+
isEnded(): boolean;
|
|
58
|
+
setPause(pause: boolean): void;
|
|
59
|
+
isForceSkipped(): boolean;
|
|
60
|
+
tryScheduleAutoForward(): void;
|
|
61
|
+
cancelAutoForward(): void;
|
|
62
|
+
private scheduleAutoForward;
|
|
63
|
+
}
|
|
64
|
+
export default function PlayerDialog({ action, onFinished, useTypeEffect, gameState, }: Readonly<SayElementProps>): React.JSX.Element;
|
|
65
|
+
export {};
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
import { GameState } from "../../../../game/nlcore/common/game";
|
|
2
|
-
import { SayElementProps } from "./type";
|
|
3
1
|
import React from "react";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare const SayContext: React.Context<SayElementProps | null>;
|
|
8
|
-
export declare function useSayContext(): SayElementProps;
|
|
9
|
-
export interface SentenceContext {
|
|
10
|
-
sentence: Sentence;
|
|
11
|
-
gameState: GameState;
|
|
12
|
-
finished: boolean;
|
|
13
|
-
useTypeEffect: boolean;
|
|
14
|
-
onCompleted?: () => void;
|
|
15
|
-
count: number;
|
|
16
|
-
words: Word<Pausing | string>[];
|
|
17
|
-
}
|
|
18
|
-
export declare const SentenceContext: React.Context<SentenceContext | null>;
|
|
19
|
-
export declare function useSentenceContext(): SentenceContext;
|
|
2
|
+
import { DialogState } from "./UIDialog";
|
|
3
|
+
export declare const DialogContext: React.Context<DialogState | null>;
|
|
4
|
+
export declare function useDialogContext(): DialogState;
|
|
@@ -6,23 +6,21 @@ import { Pausing } from "../../../nlcore/elements/character/pause";
|
|
|
6
6
|
import React from "react";
|
|
7
7
|
export interface SayElementProps {
|
|
8
8
|
action: {
|
|
9
|
-
sentence: Sentence;
|
|
9
|
+
sentence: Sentence | null;
|
|
10
10
|
character: Character | null;
|
|
11
|
-
words: Word<Pausing | string>[];
|
|
11
|
+
words: Word<Pausing | string>[] | null;
|
|
12
|
+
id?: string;
|
|
12
13
|
};
|
|
13
14
|
/**
|
|
15
|
+
* @deprecated
|
|
14
16
|
* Callback function to be called when the player triggers the next action
|
|
15
17
|
*/
|
|
16
18
|
onClick?: (skiped?: boolean) => void;
|
|
17
|
-
onFinished?: () => void;
|
|
19
|
+
onFinished?: (skiped?: boolean) => void;
|
|
18
20
|
useTypeEffect?: boolean;
|
|
19
21
|
gameState: GameState;
|
|
20
22
|
}
|
|
21
|
-
export interface PlayerDialogProps extends SayElementProps {
|
|
22
|
-
onFinished?: () => void;
|
|
23
|
-
}
|
|
24
23
|
export interface IDialogProps {
|
|
25
|
-
isFinished: boolean;
|
|
26
24
|
}
|
|
27
25
|
export type DialogProps = {
|
|
28
26
|
children: React.ReactNode;
|
|
@@ -33,3 +31,23 @@ export type DialogElementProps = {
|
|
|
33
31
|
export interface IDialogElementProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
34
32
|
children?: never;
|
|
35
33
|
}
|
|
34
|
+
export declare enum DialogStateType {
|
|
35
|
+
Pending = "pending",
|
|
36
|
+
Paused = "paused",
|
|
37
|
+
Ended = "ended"
|
|
38
|
+
}
|
|
39
|
+
export interface DialogContext {
|
|
40
|
+
gameState: GameState;
|
|
41
|
+
action: {
|
|
42
|
+
sentence: Sentence | null;
|
|
43
|
+
character: Character | null;
|
|
44
|
+
words: Word<Pausing | string>[] | null;
|
|
45
|
+
};
|
|
46
|
+
state: DialogStateType;
|
|
47
|
+
}
|
|
48
|
+
export type DialogAction = {
|
|
49
|
+
sentence: Sentence | null;
|
|
50
|
+
character: Character | null;
|
|
51
|
+
words: Word<Pausing | string>[] | null;
|
|
52
|
+
id?: string;
|
|
53
|
+
};
|
|
@@ -125,7 +125,7 @@ export declare class GameState {
|
|
|
125
125
|
text: string;
|
|
126
126
|
};
|
|
127
127
|
createMenu(menu: MenuData, afterChoose?: (choice: Chosen) => void, scene?: Scene): LiveGameEventToken & {
|
|
128
|
-
prompt: string;
|
|
128
|
+
prompt: null | string;
|
|
129
129
|
};
|
|
130
130
|
createDisplayable(displayable: LogicAction.DisplayableElements, scene?: Scene | null, layer?: Layer | null): this;
|
|
131
131
|
disposeDisplayable(displayable: LogicAction.DisplayableElements, scene?: Scene | null, layer?: Layer | null): this;
|
package/dist/index.d.ts
CHANGED