Skip to content

Commit 96da053

Browse files
authored
Merge pull request #95 from NarraLeaf/dev_nomen
narraleaf-react-0.8.1
2 parents 3427315 + a34b301 commit 96da053

7 files changed

Lines changed: 32 additions & 42 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [0.8.1]
4+
5+
### Fixed
6+
7+
- Default value of `Transform.propToCSSTransform#optional` is not respected
8+
- Fixed an issue where the top-of-stack action might be executed repeatedly during undo operations.
9+
310
## [0.8.0]
411

512
### _Feature_

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.8.0",
3+
"version": "0.8.1",
44
"description": "A React visual novel player framework",
55
"main": "./dist/main.js",
66
"types": "./dist/index.d.ts",

src/game/nlcore/action/actionHistory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class ActionHistoryManager {
4343
public push<T extends Array<any> = Array<any>>(props: ActionHistoryPushOptions, onUndo?: (...args: T) => void, args?: T): {id: string} {
4444
const id = randId(6);
4545
const { action, timeline, stackModel } = props;
46-
const snapshot = this.liveGame.getStackModelForce().serialize();
46+
const snapshot = this.liveGame.getStackModelForce().serialize(false);
4747
this.history.push({action, id, args: args || [], undo: onUndo, timeline, rootStackSnapshot: snapshot, stackModel});
4848

4949
// Check if the history size exceeds the limit

src/game/nlcore/action/stackModel.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,22 @@ export class StackModel {
370370
return false;
371371
}
372372

373-
serialize(): StackModelRawData {
373+
/**
374+
* Serialize current StackModel into a plain JSON-serialisable structure.
375+
*
376+
* @param frozen - When true (default), the snapshot also contains the
377+
* action currently executing at the top of the stack
378+
* (waitingAction). This is required by save/load so that
379+
* reloading a save resumes exactly at the current dialog or
380+
* async node, keeping the runtime state self-consistent.
381+
* When false, waitingAction is excluded and the snapshot
382+
* reflects the state *before* the current action started.
383+
* The undo/history system will then re-insert the action
384+
* manually (see LiveGame.undo) to avoid having two copies
385+
* of the same action after deserialisation.
386+
* @returns Snapshot that can be passed to {@link StackModel.deserialize}.
387+
*/
388+
serialize(frozen: boolean = true): StackModelRawData {
374389
const toData = (item: CalledActionResult | Awaitable<CalledActionResult>): ArrayValue<StackModelRawData> | null => {
375390
if (StackModel.isCalledActionResult(item)) {
376391
const actionId = item.node?.action?.getId() ?? null;
@@ -392,7 +407,7 @@ export class StackModel {
392407
const data = this.stack.map(toData).filter(function (item): item is Exclude<ArrayValue<StackModelRawData> | null, null> {
393408
return item !== null;
394409
});
395-
if (this.waitingAction) {
410+
if (frozen && this.waitingAction) {
396411
const actionData = toData(this.waitingAction);
397412
if (actionData) {
398413
data.push(actionData);

src/game/nlcore/elements/transform/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export class Transform<T extends TransformDefinitions.Types = CommonDisplayableC
321321
defaultValue?: T | undefined
322322
): string {
323323
if (typeof value === "undefined") {
324-
return defaultValue ? transformer(defaultValue) : "";
324+
return typeof defaultValue !== "undefined" ? transformer(defaultValue) : "";
325325
}
326326
return transformer(value);
327327
};

src/game/nlcore/game/liveGame.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ export class LiveGame {
176176
* After calling this method, the current game state will be lost, and the stage will trigger force reset
177177
*/
178178
public deserialize(savedGame: SavedGame) {
179+
// This check is to prevent invalid usage
180+
if (!savedGame) {
181+
throw new Error("No saved game provided when trying to deserialize game state");
182+
}
183+
179184
this.assertGameState();
180185
const gameState = this.gameState;
181186

test/index.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)