Skip to content

Commit

Permalink
Merge pull request #506 from akashic-games/fix-destroyed-check-for-e
Browse files Browse the repository at this point in the history
Fix destroyed check for E
  • Loading branch information
ShinobuTakahashi authored Oct 22, 2024
2 parents 40c7226 + 0a58923 commit d9c9e05
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ChangeLog

## 3.18.3
* `g.E#destroy()` で破棄済みチェックを行うように修正

## 3.18.2
* `OperationHandler#onOperaiton()``instanceof` での判定をやめ `Array.isArray()` を利用するように修正

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.18.2",
"version": "3.18.3",
"description": "The core library of Akashic Engine",
"main": "index.js",
"dependencies": {
Expand Down
13 changes: 13 additions & 0 deletions src/__tests__/ESpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,19 @@ describe("test E", () => {
expect((e as any)._onPointUp).toBeUndefined();
});

it("destroy - check for multiple executions", () => {
const e2 = new E({ scene: runtime.scene });
const spy = jest.spyOn(e2.scene, "unregister");

e2.destroy();
expect(e2.destroyed()).toBeTruthy();
expect(spy.mock.calls.length).toBe(1);

e2.destroy();
expect(spy.mock.calls.length).toBe(1); // 破棄済みの場合、 destory() を実行しても呼ばれないのでカウントは増えない。
spy.mockClear();
});

it("modified", () => {
resetUpdated(runtime);
expect(runtime.game._modified).toBe(false);
Expand Down
2 changes: 2 additions & 0 deletions src/entities/E.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ export class E extends Object2D implements CommonArea {
* 子孫を持っている場合、子孫も破棄される。
*/
destroy(): void {
if (this.destroyed()) return;

if (this.parent) this.remove();

if (this.children) {
Expand Down

0 comments on commit d9c9e05

Please sign in to comment.