-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#154 DisplayObjectContainerの関数を実装(WIP)
- Loading branch information
Showing
13 changed files
with
344 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,4 +180,4 @@ export class Next2D | |
width, height, fps, options | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...lay/src/DisplayObjectContainer/usecase/DisplayObjectContainerSetChildIndexUseCase.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { execute } from "./DisplayObjectContainerSetChildIndexUseCase"; | ||
import { Shape } from "../../Shape"; | ||
import { DisplayObjectContainer } from "../../DisplayObjectContainer"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
describe("DisplayObjectContainerSetChildIndexUseCase.js test", () => | ||
{ | ||
it("execute test case1", () => | ||
{ | ||
const container = new DisplayObjectContainer(); | ||
const shape0 = container.addChild(new Shape()); | ||
const shape1 = container.addChild(new Shape()); | ||
const shape2 = container.addChild(new Shape()); | ||
const shape3 = container.addChild(new Shape()); | ||
|
||
expect(container.children[0]).toBe(shape0); | ||
expect(container.children[1]).toBe(shape1); | ||
expect(container.children[2]).toBe(shape2); | ||
expect(container.children[3]).toBe(shape3); | ||
|
||
container.changed = false; | ||
expect(container.changed).toBe(false); | ||
|
||
execute(container, shape1, 2); | ||
|
||
expect(container.children[0]).toBe(shape0); | ||
expect(container.children[1]).toBe(shape2); | ||
expect(container.children[2]).toBe(shape1); | ||
expect(container.children[3]).toBe(shape3); | ||
expect(container.changed).toBe(true); | ||
}); | ||
|
||
it("execute test case2", () => | ||
{ | ||
const container = new DisplayObjectContainer(); | ||
const shape0 = container.addChild(new Shape()); | ||
const shape1 = container.addChild(new Shape()); | ||
const shape2 = container.addChild(new Shape()); | ||
const shape3 = container.addChild(new Shape()); | ||
|
||
expect(container.children[0]).toBe(shape0); | ||
expect(container.children[1]).toBe(shape1); | ||
expect(container.children[2]).toBe(shape2); | ||
expect(container.children[3]).toBe(shape3); | ||
|
||
container.changed = false; | ||
expect(container.changed).toBe(false); | ||
|
||
execute(container, shape0, 3); | ||
|
||
expect(container.children[0]).toBe(shape1); | ||
expect(container.children[1]).toBe(shape2); | ||
expect(container.children[2]).toBe(shape3); | ||
expect(container.children[3]).toBe(shape0); | ||
expect(container.changed).toBe(true); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
.../display/src/DisplayObjectContainer/usecase/DisplayObjectContainerSetChildIndexUseCase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { DisplayObject } from "../../DisplayObject"; | ||
import type { DisplayObjectContainer } from "../../DisplayObjectContainer"; | ||
import { execute as displayObjectApplyChangesService } from "../../DisplayObject/service/DisplayObjectApplyChangesService"; | ||
|
||
/** | ||
* @description 指定されたインデックスに子を移動します | ||
* Moves the child to the specified index | ||
* | ||
* @param {DisplayObjectContainer} display_object_container | ||
* @param {DisplayObject} display_object | ||
* @param {number} index | ||
* @return {void} | ||
* @method | ||
* @protected | ||
*/ | ||
export const execute = <C extends DisplayObjectContainer, D extends DisplayObject>( | ||
display_object_container: C, | ||
display_object: D, | ||
index: number | ||
): void => { | ||
|
||
const currentIndex = display_object_container.getChildIndex(display_object); | ||
if (currentIndex === -1 || currentIndex === index) { | ||
return ; | ||
} | ||
|
||
const children = display_object_container.children; | ||
children.splice(currentIndex, 1); | ||
children.splice(index, 0, display_object); | ||
|
||
displayObjectApplyChangesService(display_object_container); | ||
}; |
57 changes: 57 additions & 0 deletions
57
...ay/src/DisplayObjectContainer/usecase/DisplayObjectContainerSwapChildrenAtUseCase.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { execute } from "./DisplayObjectContainerSwapChildrenAtUseCase"; | ||
import { Shape } from "../../Shape"; | ||
import { DisplayObjectContainer } from "../../DisplayObjectContainer"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
describe("DisplayObjectContainerSwapChildrenAtUseCase.js test", () => | ||
{ | ||
it("execute test case1", () => | ||
{ | ||
const container = new DisplayObjectContainer(); | ||
const shape0 = container.addChild(new Shape()); | ||
const shape1 = container.addChild(new Shape()); | ||
const shape2 = container.addChild(new Shape()); | ||
const shape3 = container.addChild(new Shape()); | ||
|
||
expect(container.children[0]).toBe(shape0); | ||
expect(container.children[1]).toBe(shape1); | ||
expect(container.children[2]).toBe(shape2); | ||
expect(container.children[3]).toBe(shape3); | ||
|
||
container.changed = false; | ||
expect(container.changed).toBe(false); | ||
|
||
execute(container, 1, 2); | ||
|
||
expect(container.children[0]).toBe(shape0); | ||
expect(container.children[1]).toBe(shape2); | ||
expect(container.children[2]).toBe(shape1); | ||
expect(container.children[3]).toBe(shape3); | ||
expect(container.changed).toBe(true); | ||
}); | ||
|
||
it("execute test case2", () => | ||
{ | ||
const container = new DisplayObjectContainer(); | ||
const shape0 = container.addChild(new Shape()); | ||
const shape1 = container.addChild(new Shape()); | ||
const shape2 = container.addChild(new Shape()); | ||
const shape3 = container.addChild(new Shape()); | ||
|
||
expect(container.children[0]).toBe(shape0); | ||
expect(container.children[1]).toBe(shape1); | ||
expect(container.children[2]).toBe(shape2); | ||
expect(container.children[3]).toBe(shape3); | ||
|
||
container.changed = false; | ||
expect(container.changed).toBe(false); | ||
|
||
execute(container, 0, 3); | ||
|
||
expect(container.children[0]).toBe(shape3); | ||
expect(container.children[1]).toBe(shape1); | ||
expect(container.children[2]).toBe(shape2); | ||
expect(container.children[3]).toBe(shape0); | ||
expect(container.changed).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.