narraleaf-react 0.4.0 → 0.4.1
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 +21 -10
- package/dist/game/nlcore/common/types.d.ts +5 -3
- package/dist/game/nlcore/game.d.ts +20 -0
- package/dist/game/nlcore/gameTypes.d.ts +56 -31
- package/dist/game/player/elements/menu/UIMenu/Item.d.ts +7 -1
- package/dist/game/player/elements/say/useDialog.d.ts +21 -0
- package/dist/game/player/lib/PageRouter/PageRouter.d.ts +1 -1
- package/dist/game/player/libElements.d.ts +3 -2
- package/dist/main.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
<picture>
|
|
2
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-transparent.png">
|
|
3
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-light.png">
|
|
4
|
+
<img alt="Fallback image description" src="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-light.png">
|
|
5
|
+
</picture>
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
<h1 align="center">NarraLeaf-React</h1>
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
<h4 align="center">A React visual novel player framework</h3>
|
|
10
|
+
|
|
11
|
+
<p align="center">English | <a href="docs/README.zh-CN.md">简体中文</a></p>
|
|
6
12
|
|
|
7
|
-
A React visual novel player framework
|
|
8
13
|
|
|
9
14
|
## What is NarraLeaf-React?
|
|
10
15
|
|
|
@@ -46,7 +51,7 @@ scene1.action([
|
|
|
46
51
|
johnSmith
|
|
47
52
|
.say("Hello, world!")
|
|
48
53
|
.say`This is my first ${b("NarraLeaf")} story.`
|
|
49
|
-
.say`Start editing ${c("src/story.js", "#
|
|
54
|
+
.say`Start editing ${c("src/story.js", "#00f")} and enjoy the journey!`,
|
|
50
55
|
|
|
51
56
|
/**
|
|
52
57
|
* John Doe: Also, don't forget to check out the documentation!
|
|
@@ -85,7 +90,7 @@ npm install narraleaf-react
|
|
|
85
90
|
|
|
86
91
|
### Documentation
|
|
87
92
|
|
|
88
|
-
- [Introduction](https://react.narraleaf.com/documentation/introduction)
|
|
93
|
+
- [Introduction](https://react.narraleaf.com/documentation/introduction)****
|
|
89
94
|
- [Quick Start](https://react.narraleaf.com/documentation/quick-start)
|
|
90
95
|
- [Installation](https://react.narraleaf.com/documentation/installation)
|
|
91
96
|
- [Basic](https://react.narraleaf.com/documentation/basic)
|
|
@@ -100,6 +105,9 @@ npm install narraleaf-react
|
|
|
100
105
|
- [Conditional](https://react.narraleaf.com/documentation/basic/conditional)
|
|
101
106
|
- [Voice](https://react.narraleaf.com/documentation/basic/voice)
|
|
102
107
|
- [Manage Preferences](https://react.narraleaf.com/documentation/basic/manage-preferences)
|
|
108
|
+
- [Solutions](https://react.narraleaf.com/documentation/solutions)
|
|
109
|
+
- [Customizing the font](https://react.narraleaf.com/documentation/solutions/font)
|
|
110
|
+
- [Migration from Ren'Py](https://react.narraleaf.com/documentation/solutions/from-renpy)
|
|
103
111
|
- [Core](https://react.narraleaf.com/documentation/core)
|
|
104
112
|
- [Elements](https://react.narraleaf.com/documentation/core/elements)
|
|
105
113
|
- [Scene](https://react.narraleaf.com/documentation/core/elements/scene)
|
|
@@ -116,13 +124,16 @@ npm install narraleaf-react
|
|
|
116
124
|
- [Text](https://react.narraleaf.com/documentation/core/elements/text)
|
|
117
125
|
- [Persistent](https://react.narraleaf.com/documentation/core/elements/persistent)
|
|
118
126
|
- [Story](https://react.narraleaf.com/documentation/core/elements/story)
|
|
127
|
+
- [Displayable](https://react.narraleaf.com/documentation/core/elements/displayable)
|
|
128
|
+
- [Layer](https://react.narraleaf.com/documentation/core/elements/layer)
|
|
129
|
+
- [Service](https://react.narraleaf.com/documentation/core/elements/service)
|
|
130
|
+
- [Video](https://react.narraleaf.com/documentation/core/elements/video)
|
|
119
131
|
- [Animation](https://react.narraleaf.com/documentation/core/animation)
|
|
120
132
|
- [Game](https://react.narraleaf.com/documentation/core/game)
|
|
133
|
+
- [Plugin](https://react.narraleaf.com/documentation/core/plugin)
|
|
134
|
+
- [Utils](https://react.narraleaf.com/documentation/core/utils)
|
|
121
135
|
- [Player](https://react.narraleaf.com/documentation/player)
|
|
122
|
-
-
|
|
123
|
-
- [Migration](https://react.narraleaf.com/documentation/migration)
|
|
124
|
-
- [From Ren'Py](https://react.narraleaf.com/documentation/migration/from-renpy)
|
|
125
|
-
- Info
|
|
136
|
+
- About
|
|
126
137
|
- [License](https://react.narraleaf.com/documentation/info/license)
|
|
127
138
|
- [Incompatible Changes](https://react.narraleaf.com/documentation/info/incompatible-changes)
|
|
128
139
|
|
|
@@ -1,7 +1,9 @@
|
|
|
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
4
|
import { IGamePluginRegistry } from "../game/plugin/plugin";
|
|
5
5
|
import { LiveGameEventToken } from "../types";
|
|
6
|
+
import { GameHistory } from "../action/gameHistory";
|
|
7
|
+
import { GameConfig } from "../gameTypes";
|
|
6
8
|
export * from "../elements/type";
|
|
7
|
-
export type {
|
|
9
|
+
export type { GameHistory, IGamePluginRegistry, LiveGameEventToken, Origins, ServiceHandlerCtx, TransformDefinitions, GameConfig, };
|
|
@@ -8,9 +8,29 @@ declare enum GameSettingsNamespace {
|
|
|
8
8
|
game = "game"
|
|
9
9
|
}
|
|
10
10
|
export type GamePreference = {
|
|
11
|
+
/**
|
|
12
|
+
* If true, the game will automatically forward to the next sentence when the player has finished the current sentence
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
11
15
|
autoForward: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* If true, the game will allow the player to skip the dialog
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
12
20
|
skip: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* If true, the game will show the dialog
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
13
25
|
showDialog: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The multiplier of the dialog speed
|
|
28
|
+
*
|
|
29
|
+
* Dialog speed will apply to:
|
|
30
|
+
* - The text speed
|
|
31
|
+
* - The auto-forward delay
|
|
32
|
+
*/
|
|
33
|
+
gameSpeed: number;
|
|
14
34
|
};
|
|
15
35
|
export type GameHooks = {
|
|
16
36
|
/**
|
|
@@ -28,36 +28,6 @@ export interface SavedGame {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
export type GameConfig = {
|
|
31
|
-
app: {
|
|
32
|
-
debug: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Log level for the logger
|
|
35
|
-
* Set to true to enable all logs
|
|
36
|
-
*/
|
|
37
|
-
logger: {
|
|
38
|
-
log: boolean;
|
|
39
|
-
info: boolean;
|
|
40
|
-
warn: boolean;
|
|
41
|
-
error: boolean;
|
|
42
|
-
debug: boolean;
|
|
43
|
-
trace: boolean;
|
|
44
|
-
verbose: boolean;
|
|
45
|
-
} | boolean;
|
|
46
|
-
/**
|
|
47
|
-
* If true, the game will show the inspector when you hover over the element
|
|
48
|
-
*/
|
|
49
|
-
inspector: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* The config of {@link GameStateGuard}
|
|
52
|
-
*/
|
|
53
|
-
guard: GuardConfig;
|
|
54
|
-
/**
|
|
55
|
-
* Quality of the screenshot, between 0 and 1
|
|
56
|
-
* @default 1
|
|
57
|
-
* @deprecated Moved to `$root.screenshotQuality`
|
|
58
|
-
*/
|
|
59
|
-
screenshotQuality: number;
|
|
60
|
-
};
|
|
61
31
|
/**
|
|
62
32
|
* The id of the container element for the game
|
|
63
33
|
* @default "__narraleaf_content"
|
|
@@ -176,7 +146,6 @@ export type GameConfig = {
|
|
|
176
146
|
/**
|
|
177
147
|
* Quality of the screenshot, between 0 and 1
|
|
178
148
|
* @default 1
|
|
179
|
-
* @deprecated Moved to `$root.screenshotQuality`
|
|
180
149
|
*/
|
|
181
150
|
screenshotQuality: number;
|
|
182
151
|
/**
|
|
@@ -205,6 +174,13 @@ export type GameConfig = {
|
|
|
205
174
|
* @default 3000
|
|
206
175
|
*/
|
|
207
176
|
autoForwardDelay: number;
|
|
177
|
+
/**
|
|
178
|
+
* The default pause duration in milliseconds when auto-forward is enabled
|
|
179
|
+
*
|
|
180
|
+
* When auto-forward is enabled, any Pause without a custom duration will use this value
|
|
181
|
+
* @default 1000
|
|
182
|
+
*/
|
|
183
|
+
autoForwardDefaultPause: number;
|
|
208
184
|
/**
|
|
209
185
|
* If true, when you press [GameConfig.player.skipKey], the game will skip the image transform
|
|
210
186
|
* @default true
|
|
@@ -292,6 +268,55 @@ export type GameConfig = {
|
|
|
292
268
|
* @default () => {}
|
|
293
269
|
*/
|
|
294
270
|
onError: (error: Error) => void;
|
|
271
|
+
app: {
|
|
272
|
+
debug: boolean;
|
|
273
|
+
/**
|
|
274
|
+
* Log level for the logger
|
|
275
|
+
* Set to true to enable all logs
|
|
276
|
+
*/
|
|
277
|
+
logger: {
|
|
278
|
+
log: boolean;
|
|
279
|
+
info: boolean;
|
|
280
|
+
warn: boolean;
|
|
281
|
+
error: boolean;
|
|
282
|
+
debug: boolean;
|
|
283
|
+
trace: boolean;
|
|
284
|
+
verbose: boolean;
|
|
285
|
+
} | boolean;
|
|
286
|
+
/**
|
|
287
|
+
* If true, the game will show the inspector when you hover over the element
|
|
288
|
+
*/
|
|
289
|
+
inspector: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* The config of {@link GameStateGuard}
|
|
292
|
+
*/
|
|
293
|
+
guard: GuardConfig;
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* Default font size for the game
|
|
297
|
+
* @default "16px"
|
|
298
|
+
*/
|
|
299
|
+
fontSize: React.CSSProperties["fontSize"];
|
|
300
|
+
/**
|
|
301
|
+
* Default font weight for the game
|
|
302
|
+
* @default 400
|
|
303
|
+
*/
|
|
304
|
+
fontWeight: number;
|
|
305
|
+
/**
|
|
306
|
+
* Default font weight for the game
|
|
307
|
+
* @default 700
|
|
308
|
+
*/
|
|
309
|
+
fontWeightBold: number;
|
|
310
|
+
/**
|
|
311
|
+
* Default font family for the game
|
|
312
|
+
* @default "sans-serif"
|
|
313
|
+
*/
|
|
314
|
+
fontFamily: React.CSSProperties["fontFamily"];
|
|
315
|
+
/**
|
|
316
|
+
* Override the default stage
|
|
317
|
+
* @default null
|
|
318
|
+
*/
|
|
319
|
+
stage: React.ReactNode | null;
|
|
295
320
|
};
|
|
296
321
|
export type GameSettings = {
|
|
297
322
|
volume: number;
|
|
@@ -2,5 +2,11 @@ import React from "react";
|
|
|
2
2
|
export interface ItemProps {
|
|
3
3
|
className?: string;
|
|
4
4
|
style?: React.CSSProperties;
|
|
5
|
+
/**
|
|
6
|
+
* The keyboard binding for this item, see [Key_Values](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values) for more information
|
|
7
|
+
*
|
|
8
|
+
* When this key is pressed, the item will be selected and the action will be executed
|
|
9
|
+
*/
|
|
10
|
+
bindKey?: string;
|
|
5
11
|
}
|
|
6
|
-
export default function Item({ className, style }: ItemProps): React.JSX.Element;
|
|
12
|
+
export default function Item({ className, style, bindKey }: ItemProps): React.JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the context of a dialog, containing information about its completion status
|
|
3
|
+
* and the text content.
|
|
4
|
+
*/
|
|
5
|
+
export type DialogContext = {
|
|
6
|
+
/** Whether the dialog has finished displaying */
|
|
7
|
+
done: boolean;
|
|
8
|
+
/** The text content of the dialog */
|
|
9
|
+
text: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A custom hook that provides access to the current dialog's state and content.
|
|
13
|
+
* It retrieves the dialog information from the sentence context and processes
|
|
14
|
+
* the words to generate the final text.
|
|
15
|
+
*
|
|
16
|
+
* @returns {DialogContext} An object containing the dialog's completion status and text content
|
|
17
|
+
*/
|
|
18
|
+
export declare function useDialog(): {
|
|
19
|
+
done: boolean;
|
|
20
|
+
text: string;
|
|
21
|
+
};
|
|
@@ -5,7 +5,7 @@ type PageRouterProps = Readonly<{
|
|
|
5
5
|
/**
|
|
6
6
|
* Page Router for NarraLeaf-React
|
|
7
7
|
*
|
|
8
|
-
* **Note**: only `Page` components are allowed as children, other components will be ignored.
|
|
8
|
+
* **Note**: only `Page` and `Stage` components are allowed as children, other components will be ignored.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```tsx
|
|
@@ -7,5 +7,6 @@ import Item from "./elements/menu/UIMenu/Item";
|
|
|
7
7
|
import Notifications from "./elements/notification/Notifications";
|
|
8
8
|
import Texts from "./elements/say/Sentence";
|
|
9
9
|
import Nametag from "./elements/say/Nametag";
|
|
10
|
-
import Dialog from "
|
|
11
|
-
|
|
10
|
+
import Dialog from "./elements/say/Dialog";
|
|
11
|
+
import { useDialog } from "./elements/say/useDialog";
|
|
12
|
+
export { Isolated, usePreference, Stage, Page, GameMenu, Item, Notifications, Texts, Nametag, Dialog, useDialog, };
|