narraleaf-react 0.1.4 → 0.1.6
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 -2
- package/dist/game/nlcore/common/game.d.ts +2 -1
- package/dist/game/nlcore/elements/script.d.ts +2 -1
- package/dist/game/nlcore/game/preference.d.ts +31 -0
- package/dist/game/nlcore/game.d.ts +13 -37
- package/dist/game/nlcore/gameTypes.d.ts +4 -0
- package/dist/game/nlcore/liveGame.d.ts +37 -0
- package/dist/game/nlcore/types.d.ts +0 -3
- package/dist/game/player/elements/Player.d.ts +1 -1
- package/dist/game/player/elements/type.d.ts +5 -3
- package/dist/game/player/lib/PlayerFrames.d.ts +25 -0
- package/dist/game/player/lib/UtilComponents.d.ts +5 -0
- package/dist/game/player/libElements.d.ts +3 -1
- package/dist/main.js +6 -30678
- package/dist/util/data.d.ts +9 -0
- package/package.json +2 -2
- package/dist/main.js.map +0 -1
package/README.md
CHANGED
|
@@ -45,9 +45,9 @@ npm start
|
|
|
45
45
|
|
|
46
46
|
## License
|
|
47
47
|
|
|
48
|
-
> NarraLeaf-React is licensed under the MPL License.
|
|
48
|
+
> NarraLeaf-React is licensed under the MPL-2.0 License.
|
|
49
49
|
>
|
|
50
|
-
> We updated the license to MPL on 2024-9-24.
|
|
50
|
+
> We updated the license to MPL-2.0 on 2024-9-24.
|
|
51
51
|
|
|
52
52
|
## Contributing
|
|
53
53
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Game
|
|
1
|
+
import { Game } from "../game";
|
|
2
2
|
import { GameState } from "../../player/gameState";
|
|
3
3
|
import { Storable, Namespace } from "../store/storable";
|
|
4
|
+
import { LiveGame } from "../liveGame";
|
|
4
5
|
export { LiveGame, GameState, Game, Storable, Namespace, };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Game
|
|
1
|
+
import { Game } from "../game";
|
|
2
2
|
import { Actionable } from "../action/actionable";
|
|
3
3
|
import { GameState } from "../../player/gameState";
|
|
4
4
|
import type { Storable } from "../store/storable";
|
|
5
|
+
import { LiveGame } from "../liveGame";
|
|
5
6
|
export interface ScriptCtx {
|
|
6
7
|
gameState: GameState;
|
|
7
8
|
game: Game;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EventDispatcher } from "../../../util/data";
|
|
2
|
+
type PreferenceEventToken = {
|
|
3
|
+
cancel: () => void;
|
|
4
|
+
};
|
|
5
|
+
type StringKeyof<T> = Extract<keyof T, string>;
|
|
6
|
+
export declare class Preference<T extends Record<string, string | boolean | number | null | undefined>> {
|
|
7
|
+
private readonly settings;
|
|
8
|
+
static EventTypes: {
|
|
9
|
+
readonly "event:game.preference.change": "event:game.preference.change";
|
|
10
|
+
};
|
|
11
|
+
readonly events: EventDispatcher<{
|
|
12
|
+
"event:game.preference.change": [StringKeyof<T>, any];
|
|
13
|
+
}>;
|
|
14
|
+
constructor(settings: T);
|
|
15
|
+
setPreference<K extends StringKeyof<T>>(key: K, value: T[K]): void;
|
|
16
|
+
getPreference<K extends StringKeyof<T>>(key: K): T[K];
|
|
17
|
+
getPreferences(): T;
|
|
18
|
+
onPreferenceChange<U extends StringKeyof<T>>(key: U, listener: (value: T[U]) => void): PreferenceEventToken;
|
|
19
|
+
onPreferenceChange(listener: (key: StringKeyof<T>, value: T[StringKeyof<T>]) => void): PreferenceEventToken;
|
|
20
|
+
/**
|
|
21
|
+
* Import preferences
|
|
22
|
+
*
|
|
23
|
+
* Note: This will override the existing preferences, and trigger the change event
|
|
24
|
+
*/
|
|
25
|
+
importPreferences(preferences: Partial<T>): void;
|
|
26
|
+
/**
|
|
27
|
+
* Export preferences
|
|
28
|
+
*/
|
|
29
|
+
exportPreferences(): Partial<T>;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import type { GameConfig
|
|
2
|
-
import { DeepPartial
|
|
3
|
-
import { Storable } from "./store/storable";
|
|
1
|
+
import type { GameConfig } from "./gameTypes";
|
|
2
|
+
import { DeepPartial } from "../../util/data";
|
|
4
3
|
import { LogicAction } from "./action/logicAction";
|
|
5
|
-
import { GameState } from "../player/gameState";
|
|
6
4
|
import { ComponentsTypes } from "../player/elements/type";
|
|
5
|
+
import { LiveGame } from "./liveGame";
|
|
6
|
+
import { Preference } from "./game/preference";
|
|
7
7
|
declare enum GameSettingsNamespace {
|
|
8
8
|
game = "game"
|
|
9
9
|
}
|
|
10
|
+
export type GamePreference = {
|
|
11
|
+
autoForward: boolean;
|
|
12
|
+
skip: boolean;
|
|
13
|
+
};
|
|
10
14
|
export declare class Game {
|
|
11
15
|
static ComponentTypes: {
|
|
12
|
-
[K in keyof ComponentsTypes]: K;
|
|
16
|
+
readonly [K in keyof ComponentsTypes]: K;
|
|
13
17
|
};
|
|
14
18
|
static GameSettingsNamespace: typeof GameSettingsNamespace;
|
|
19
|
+
/**
|
|
20
|
+
* Game settings
|
|
21
|
+
*/
|
|
22
|
+
preference: Preference<GamePreference>;
|
|
15
23
|
/**
|
|
16
24
|
* Create a new game
|
|
17
25
|
* @param config - Game configuration
|
|
@@ -23,38 +31,6 @@ export declare class Game {
|
|
|
23
31
|
useComponent<T extends keyof ComponentsTypes>(key: T, components: ComponentsTypes[T]): this;
|
|
24
32
|
getLiveGame(): LiveGame;
|
|
25
33
|
}
|
|
26
|
-
export declare class LiveGame {
|
|
27
|
-
static DefaultNamespaces: {
|
|
28
|
-
game: {};
|
|
29
|
-
};
|
|
30
|
-
static GameSpacesKey: {
|
|
31
|
-
readonly game: "game";
|
|
32
|
-
};
|
|
33
|
-
game: Game;
|
|
34
|
-
gameLock: MultiLock;
|
|
35
|
-
getStorable(): Storable;
|
|
36
|
-
/**
|
|
37
|
-
* Serialize the current game state
|
|
38
|
-
*
|
|
39
|
-
* You can use this to save the game state to a file or a database
|
|
40
|
-
*
|
|
41
|
-
* Note: Even if you change just a single line of script, the saved game might not be compatible with the new version
|
|
42
|
-
*/
|
|
43
|
-
serialize(): SavedGame;
|
|
44
|
-
/**
|
|
45
|
-
* Load a saved game
|
|
46
|
-
*
|
|
47
|
-
* Note: Even if you change just a single line of script, the saved game might not be compatible with the new version
|
|
48
|
-
*
|
|
49
|
-
* After calling this method, the current game state will be lost, and the stage will trigger force reset
|
|
50
|
-
*/
|
|
51
|
-
deserialize(savedGame: SavedGame): void;
|
|
52
|
-
/**
|
|
53
|
-
* Start a new game
|
|
54
|
-
*/
|
|
55
|
-
newGame(): this;
|
|
56
|
-
getGameState(): GameState | undefined;
|
|
57
|
-
}
|
|
58
34
|
declare const _default: {
|
|
59
35
|
Game: typeof Game;
|
|
60
36
|
LiveGame: typeof LiveGame;
|
|
@@ -89,6 +89,10 @@ export type GameConfig = {
|
|
|
89
89
|
* Text will look smaller when this is enabled
|
|
90
90
|
*/
|
|
91
91
|
useAspectScale: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* The delay in milliseconds before the game automatically shows the next sentence
|
|
94
|
+
*/
|
|
95
|
+
autoForwardDelay: number;
|
|
92
96
|
};
|
|
93
97
|
img: {
|
|
94
98
|
/**
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MultiLock } from "../../util/data";
|
|
2
|
+
import type { SavedGame } from "./gameTypes";
|
|
3
|
+
import { GameState } from "../player/gameState";
|
|
4
|
+
import { Storable } from "./store/storable";
|
|
5
|
+
import { Game } from "./game";
|
|
6
|
+
export declare class LiveGame {
|
|
7
|
+
static DefaultNamespaces: {
|
|
8
|
+
game: {};
|
|
9
|
+
};
|
|
10
|
+
static GameSpacesKey: {
|
|
11
|
+
readonly game: "game";
|
|
12
|
+
};
|
|
13
|
+
game: Game;
|
|
14
|
+
gameLock: MultiLock;
|
|
15
|
+
getStorable(): Storable;
|
|
16
|
+
/**
|
|
17
|
+
* Serialize the current game state
|
|
18
|
+
*
|
|
19
|
+
* You can use this to save the game state to a file or a database
|
|
20
|
+
*
|
|
21
|
+
* Note: Even if you change just a single line of script, the saved game might not be compatible with the new version
|
|
22
|
+
*/
|
|
23
|
+
serialize(): SavedGame;
|
|
24
|
+
/**
|
|
25
|
+
* Load a saved game
|
|
26
|
+
*
|
|
27
|
+
* Note: Even if you change just a single line of script, the saved game might not be compatible with the new version
|
|
28
|
+
*
|
|
29
|
+
* After calling this method, the current game state will be lost, and the stage will trigger force reset
|
|
30
|
+
*/
|
|
31
|
+
deserialize(savedGame: SavedGame): void;
|
|
32
|
+
/**
|
|
33
|
+
* Start a new game
|
|
34
|
+
*/
|
|
35
|
+
newGame(): this;
|
|
36
|
+
getGameState(): GameState | undefined;
|
|
37
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { IPosition, RawPosition } from "./elements/transform/position";
|
|
2
2
|
import { ITransition } from "./elements/transition/type";
|
|
3
3
|
import { Transform } from "./elements/transform/transform";
|
|
4
|
-
import { EventDispatcher } from "../../util/data";
|
|
5
4
|
import React from "react";
|
|
6
5
|
export type color = string | {
|
|
7
6
|
r: number;
|
|
@@ -62,6 +61,4 @@ export type EventfulDisplayableEvents = {
|
|
|
62
61
|
[K in DisplayableAnimationEvents]: K extends "event:displayable.applyTransform" ? [Transform] : K extends "event:displayable.applyTransition" ? [ITransition] : K extends "event:displayable.init" ? [] : never;
|
|
63
62
|
};
|
|
64
63
|
export interface EventfulDisplayable {
|
|
65
|
-
events: EventDispatcher<EventfulDisplayableEvents>;
|
|
66
|
-
toDisplayableTransform(): Transform;
|
|
67
64
|
}
|
|
@@ -2,4 +2,4 @@ import "client-only";
|
|
|
2
2
|
import "@player/lib/styles/style.css";
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { PlayerProps } from "../elements/type";
|
|
5
|
-
export default function Player({ story, width, height, className, onReady, onEnd, }: Readonly<PlayerProps>): React.JSX.Element;
|
|
5
|
+
export default function Player({ story, width, height, className, onReady, onEnd, children, }: Readonly<PlayerProps>): React.JSX.Element;
|
|
@@ -3,9 +3,10 @@ import { SayElementProps } from "../elements/say/type";
|
|
|
3
3
|
import { MenuElementProps } from "../elements/menu/type";
|
|
4
4
|
import { Story } from "../../nlcore/elements/story";
|
|
5
5
|
import clsx from "clsx";
|
|
6
|
-
import { Game
|
|
6
|
+
import { Game } from "../../nlcore/game";
|
|
7
7
|
import { GameState } from "../gameState";
|
|
8
8
|
import { Storable } from "../../nlcore/store/storable";
|
|
9
|
+
import { LiveGame } from "../../nlcore/liveGame";
|
|
9
10
|
export type Components<T extends Record<string, any>> = (props: Readonly<T>) => React.JSX.Element;
|
|
10
11
|
export type SayComponent = Components<SayElementProps>;
|
|
11
12
|
export type MenuComponent = Components<MenuElementProps>;
|
|
@@ -28,13 +29,14 @@ export interface PlayerProps {
|
|
|
28
29
|
/**
|
|
29
30
|
* Once the game is ready to be played
|
|
30
31
|
*
|
|
31
|
-
* only called
|
|
32
|
+
* only called each lifecycle once
|
|
32
33
|
*/
|
|
33
34
|
onReady?: (ctx: PlayerEventContext) => void;
|
|
34
35
|
/**
|
|
35
36
|
* Once the game is ended
|
|
36
37
|
*
|
|
37
|
-
* only called
|
|
38
|
+
* only called each lifecycle once
|
|
38
39
|
*/
|
|
39
40
|
onEnd?: (ctx: PlayerEventContext) => void;
|
|
41
|
+
children?: React.ReactNode;
|
|
40
42
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type ForwardSize = {
|
|
3
|
+
width?: React.CSSProperties["width"];
|
|
4
|
+
height?: React.CSSProperties["height"];
|
|
5
|
+
};
|
|
6
|
+
type ForwardChildren = {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
};
|
|
9
|
+
type FrameComponentProps = ForwardSize & ForwardChildren;
|
|
10
|
+
declare const Top: {
|
|
11
|
+
Left: (props: FrameComponentProps) => React.JSX.Element;
|
|
12
|
+
Center: (props: FrameComponentProps) => React.JSX.Element;
|
|
13
|
+
Right: (props: FrameComponentProps) => React.JSX.Element;
|
|
14
|
+
};
|
|
15
|
+
declare const Center: {
|
|
16
|
+
Left: (props: FrameComponentProps) => React.JSX.Element;
|
|
17
|
+
Center: (props: FrameComponentProps) => React.JSX.Element;
|
|
18
|
+
Right: (props: FrameComponentProps) => React.JSX.Element;
|
|
19
|
+
};
|
|
20
|
+
declare const Bottom: {
|
|
21
|
+
Left: (props: FrameComponentProps) => React.JSX.Element;
|
|
22
|
+
Center: (props: FrameComponentProps) => React.JSX.Element;
|
|
23
|
+
Right: (props: FrameComponentProps) => React.JSX.Element;
|
|
24
|
+
};
|
|
25
|
+
export { Top, Center, Bottom, };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import Isolated from "./lib/isolated";
|
|
2
2
|
import Say from "./elements/say/Say";
|
|
3
|
-
|
|
3
|
+
import { Top, Center, Bottom } from "./lib/PlayerFrames";
|
|
4
|
+
import { VBox, HBox } from "./lib/UtilComponents";
|
|
5
|
+
export { Isolated, Say, Top, Center, Bottom, VBox, HBox, };
|