Skip to content

Commit

Permalink
fix: fix restoring g.Game#_idx
Browse files Browse the repository at this point in the history
  • Loading branch information
xnv committed Nov 7, 2023
1 parent 5b263ff commit 705563f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ChangeLog

## 3.16.1

不具合修正
* スナップショットからの復元時、 `g.game._idx` が復元できないことがある問題を修正

## 3.16.0
* @akashic/pdi-types@1.12.0 に追従
* `g.PointMoveEvent#button` の値が変更されます。
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@akashic/akashic-engine",
"version": "3.16.0",
"version": "3.16.1",
"description": "The core library of Akashic Engine",
"main": "index.js",
"dependencies": {
Expand Down
3 changes: 1 addition & 2 deletions src/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,6 @@ export class Game {

if (param) {
if (param.age !== undefined) this.age = param.age;
if (param.nextEntityId !== undefined) this._idx = param.nextEntityId;
if (param.randGenSer !== undefined) {
this.random = XorshiftRandomGenerator.deserialize(param.randGenSer);
} else if (param.randSeed !== undefined) {
Expand All @@ -1561,7 +1560,7 @@ export class Game {
this.onJoin.add(this._handleJoinEvent, this);
this.onLeave.add(this._handleLeaveEvent, this);

this._idx = 0;
this._idx = param?.nextEntityId ?? 0;
this._localIdx = 0;
this._cameraIdx = 0;
this.db = new WeakRefKVS();
Expand Down
34 changes: 34 additions & 0 deletions src/__tests__/GameSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,40 @@ describe("test Game", () => {
testDone = true;
});

it("_reset - restore by param", done => {
const game = new Game({
width: 320,
height: 320,
main: "./script/mainScene.js",
assets: {
mainScene: {
type: "script",
global: true,
path: "./script/mainScene.js",
virtualPath: "script/mainScene.js"
}
}
});
game.resourceFactory.scriptContents["./script/mainScene.js"] =
"module.exports = () => { const s = new g.Scene({game: g.game}); g.game.pushScene(s); };";

const randGen = new XorshiftRandomGenerator(100);

let testDone = false;
game._onLoad.add(() => {
expect(game.age).toBe(10);
expect(game._idx).toBe(42);
expect(game.random.serialize()).toEqual(randGen.serialize());
expect(testDone).toBe(true);
done();
});

game._loadAndStart();
game._reset({ age: 10, nextEntityId: 42, randGenSer: randGen.serialize() });
game._loadAndStart();
testDone = true;
});

it("controls audio volume", () => {
const game = new Game({ width: 320, height: 320, main: "", assets: {} });

Expand Down

0 comments on commit 705563f

Please sign in to comment.