Skip to content

Commit 8010a01

Browse files
authored
Merge pull request #77 from NarraLeaf/dev_nomen
narraleaf-react-0.4.4
2 parents 347ee3c + 203d5ab commit 8010a01

File tree

8 files changed

+34
-17
lines changed

8 files changed

+34
-17
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog
22

3-
## [0.4.3]
3+
## [0.4.4] - 2025/5/9
4+
5+
### Fixed
6+
7+
- Unhandled side effects causing performance issues
8+
- False positive of dead cycle
9+
10+
## [0.4.3] - 2025/5/8
411

512
### Fixed
613

@@ -9,7 +16,7 @@
916
- The behavior of `cps` is incorrect
1017
- The page exit animation is not working
1118

12-
## [0.4.2] - 2025/5/8
19+
## [0.4.2] - 2025/5/7
1320

1421
### Fixed
1522

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "narraleaf-react",
3-
"version": "0.4.2",
3+
"version": "0.4.4",
44
"description": "A React visual novel player framework",
55
"main": "./dist/main.js",
66
"types": "./dist/index.d.ts",

src/game/nlcore/game/liveGame.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ export class LiveGame {
498498
}
499499

500500
if (this.lockedAwaiting) {
501-
if (!this.lockedAwaiting.solved) {
501+
if (!this.lockedAwaiting.isSettled()) {
502502
this._lockedCount++;
503503

504504
if (this._lockedCount > 1000) {
@@ -515,6 +515,7 @@ export class LiveGame {
515515
if (!this.currentAction) {
516516
state.events.emit(GameState.EventTypes["event:state.end"]);
517517
}
518+
this._lockedCount = 0;
518519

519520
state.logger.debug("next action (lockedAwaiting)", next);
520521

@@ -530,6 +531,7 @@ export class LiveGame {
530531
const nextAction = this.currentAction.executeAction(state);
531532
if (Awaitable.isAwaitable<CalledActionResult, CalledActionResult>(nextAction)) {
532533
this.lockedAwaiting = nextAction;
534+
this._lockedCount = 0;
533535

534536
return nextAction;
535537
}

src/game/player/elements/image/AspectScaleImage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default function AspectScaleImage(
9191
onLoad={handleOnLoad}
9292
width={width}
9393
height={height}
94-
alt={"image"}
94+
alt={""}
9595
/>
9696
);
9797
}

src/game/player/elements/preload/Preload.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {usePreloaded} from "@player/provider/preloaded";
55
import {Preloaded} from "@player/lib/Preloaded";
66
import {TaskPool} from "@lib/util/data";
77
import {useGame} from "@player/provider/game-state";
8+
import { Scene } from "@lib/game/nlcore/elements/scene";
89

910
/**@internal */
1011
export function Preload(
@@ -18,7 +19,7 @@ export function Preload(
1819
const cachedSrc = useRef<Set<ActiveSrc>>(new Set());
1920

2021
const LogTag = "Preload";
21-
const lastScene = state.getLastScene();
22+
const lastScene: Scene | null = state.getLastScene() || state.getPreloadingScene();
2223
const currentAction = game.getLiveGame().getCurrentAction();
2324
const story = game.getLiveGame().story;
2425

src/game/player/elements/say/Sentence.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,9 @@ function BaseText(
123123
useEffect(() => {
124124
return dialog.events.depends([
125125
dialog.events.on(DialogState.Events.requestComplete, () => {
126-
gameState.logger.debug("Sentence.tsx", "requestComplete");
127126
taskRef.current?.interact();
128127
}),
129128
dialog.events.on(DialogState.Events.forceSkip, () => {
130-
gameState.logger.debug("Sentence.tsx", "forceSkip");
131129
if (!dialog.isEnded()) {
132130
taskRef.current?.forceSkip();
133131
}
@@ -140,12 +138,14 @@ function BaseText(
140138
* - autoForward, gameSpeed changes
141139
*/
142140
useEffect(() => {
143-
game.preference.onPreferenceChange(Game.Preferences.gameSpeed, () => {
144-
taskRef.current?.update();
145-
});
146-
game.preference.onPreferenceChange(Game.Preferences.autoForward, () => {
147-
taskRef.current?.update();
148-
});
141+
return game.preference.events.depends([
142+
game.preference.onPreferenceChange(Game.Preferences.gameSpeed, () => {
143+
taskRef.current?.update();
144+
}),
145+
game.preference.onPreferenceChange(Game.Preferences.autoForward, () => {
146+
taskRef.current?.update();
147+
})
148+
]).cancel;
149149
}, []);
150150

151151
function roll(): RollingTask {
@@ -202,8 +202,6 @@ function BaseText(
202202
};
203203

204204
const trySkip = (untilEnd: boolean = false) => {
205-
gameState.logger.debug("Sentence.tsx", "skipToEnd");
206-
207205
// Skip to next pause or end
208206
let exited = false;
209207
while (!exited) {

src/game/player/elements/say/UIDialog.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ export default function PlayerDialog({
208208
*/
209209
useEffect(() => {
210210
return gameState.events.on(GameState.EventTypes["event:state.player.skip"], () => {
211-
gameState.logger.log("NarraLeaf-React: Say", "Skipped", dialogState.isIdle());
212211
if (dialogState.isIdle()) {
213212
onFinished?.(true);
214213
} else {

src/game/player/gameState.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export class GameState {
119119
exposedState: Map<Values<ExposedKeys>, object> = new Map();
120120
guard: GameStateGuard;
121121
timelines: Timelines;
122+
preloadingScene: Scene | null = null;
122123
public readonly notificationMgr: NotificationManager;
123124
public readonly events: EventDispatcher<GameStateEvents>;
124125
public readonly logger: Logger;
@@ -191,6 +192,15 @@ export class GameState {
191192
return this;
192193
}
193194

195+
public preloadScene(scene: Scene): this {
196+
this.preloadingScene = scene;
197+
return this;
198+
}
199+
200+
public getPreloadingScene(): Scene | null {
201+
return this.preloadingScene;
202+
}
203+
194204
public addElement(element: PlayerStateElement): this {
195205
this.state.elements.push(element);
196206
return this;

0 commit comments

Comments
 (0)