Skip to content

Commit

Permalink
#154 テストケースを追加(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Oct 9, 2024
1 parent 19770a7 commit 396c117
Show file tree
Hide file tree
Showing 22 changed files with 483 additions and 245 deletions.
318 changes: 170 additions & 148 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,18 @@
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.12.0",
"@types/node": "^22.7.4",
"@typescript-eslint/eslint-plugin": "^8.8.0",
"@typescript-eslint/parser": "^8.8.0",
"@types/node": "^22.7.5",
"@typescript-eslint/eslint-plugin": "^8.8.1",
"@typescript-eslint/parser": "^8.8.1",
"@vitest/web-worker": "^2.1.2",
"eslint": "^9.12.0",
"eslint-plugin-unused-imports": "^4.1.4",
"globals": "^15.10.0",
"globals": "^15.11.0",
"jsdom": "^25.0.1",
"typescript": "^5.6.2",
"typescript": "^5.6.3",
"vite": "^5.4.8",
"vitest": "^2.1.2"
"vitest": "^2.1.2",
"vitest-webgl-canvas-mock": "^1.1.0"
},
"peerDependencies": {
"@next2d/cache": "file:packages/cache",
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
2 changes: 1 addition & 1 deletion packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"type": "git",
"url": "git+https://github.com/Next2D/Player.git"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { execute } from "./CacheStoreGenerateFilterKeysService";
import { describe, expect, it } from "vitest";

describe("CacheStoreGenerateFilterKeysService.js test", () =>
{
it("test case1", () =>
{
expect(execute(1, 0, 0, 1)).toBe(1507424);
});

it("test case2", () =>
{
expect(execute(0.25, 0.5, -0.3, 1.25)).toBe(-1648357538);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ describe("CacheStoreGenerateKeysService.js test", () =>
{
expect(execute(0.25, 0.5, 0.3)).toBe(71293087);
});
});
});
18 changes: 18 additions & 0 deletions packages/cache/src/CacheUtil.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { $maps, $poolMap, $getMap } from "./CacheUtil";
import { describe, expect, it } from "vitest";

describe("CacheUtil.js test", () =>
{
it("test case", () =>
{
$maps.length = 0;
expect($maps.length).toBe(0);

const map = $getMap();
$poolMap(map);
expect($maps.length).toBe(1);

$getMap();
expect($maps.length).toBe(0);
});
});
136 changes: 68 additions & 68 deletions packages/display/src/DisplayObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ import type { IParent } from "./interface/IParent";
import type { IPlaceObject } from "./interface/IPlaceObject";
import type { IBlendMode } from "./interface/IBlendMode";
import type { IFilterArray } from "./interface/IFilterArray";
import type { IDisplayObject } from "./interface/IDisplayObject";
import type { MovieClip } from "./MovieClip";
import { execute as displayObjectGetPlaceObjectService } from "./DisplayObject/service/DisplayObjectGetPlaceObjectService";
import { execute as displayObjectBuildFilterService } from "./DisplayObject/service/DisplayObjectBuildFilterService";
import { execute as displayObjectApplyChangesService } from "./DisplayObject/service/DisplayObjectApplyChangesService";
import { execute as displayObjectConcatenatedMatrixUseCase } from "./DisplayObject/usecase/DisplayObjectConcatenatedMatrixUseCase";
import { EventDispatcher } from "@next2d/events";
import type {
ColorTransform,
Matrix,
Rectangle
} from "@next2d/geom";
import { EventDispatcher } from "@next2d/events";
import { execute as displayObjectGetPlaceObjectService } from "./DisplayObject/service/DisplayObjectGetPlaceObjectService";
import { execute as displayObjectApplyChangesService } from "./DisplayObject/service/DisplayObjectApplyChangesService";
import { execute as displayObjectConcatenatedMatrixUseCase } from "./DisplayObject/usecase/DisplayObjectConcatenatedMatrixUseCase";
import { execute as displayObjectGetAlphaUseCase } from "./DisplayObject/usecase/DisplayObjectGetAlphaUseCase";
import { execute as displayObjectGetFiltersUseCase } from "./DisplayObject/usecase/DisplayObjectGetFiltersUseCase";
import { execute as displayObjectSetFiltersUseCase } from "./DisplayObject/usecase/DisplayObjectSetFiltersUseCase";
import {
$getInstanceId,
$parentMap,
Expand Down Expand Up @@ -213,6 +216,9 @@ export class DisplayObject extends EventDispatcher
/**
* @description キャッシュで利用するユニークキー
* Unique key used for caching
*
* @type {string}
* @public
*/
public uniqueKey: string;

Expand All @@ -236,8 +242,25 @@ export class DisplayObject extends EventDispatcher
*/
public $colorTransform: ColorTransform | null;

protected _$filters: IFilterArray | null;
protected _$blendMode: IBlendMode | null;
/**
* @description 表示オブジェクトに現在関連付けられている各フィルターオブジェクトの配列です。
* An array of filter objects currently associated with the display object.
*
* @type {array}
* @default null
* @protected
*/
public $filters: IFilterArray | null;

/**
* @description 使用するブレンドモードを指定する BlendMode クラスの値です。
* A value from the BlendMode class that specifies which blend mode to use.
*
* @type {string}
* @default BlendMode.NORMAL
* @protected
*/
public $blendMode: IBlendMode | null;


// todo
Expand All @@ -247,11 +270,10 @@ export class DisplayObject extends EventDispatcher
protected _$scale9Grid: Rectangle | null;
protected _$isMask: boolean;
protected _$hitObject: Sprite | null;
protected _$mask: DisplayObjectImpl<any> | null;
protected _$mask: IDisplayObject<any> | null;
protected _$visible: boolean;
protected _$variables: Map<any, any> | null;


/**
* @constructor
* @public
Expand All @@ -264,39 +286,42 @@ export class DisplayObject extends EventDispatcher
this.dictionaryId = -1;
this.uniqueKey = "";

// 各小クラスの機能を所持しているか
this.isContainerEnabled = false;
this.isTimelineEnabled = false;
this.isShape = false;
this.isVideo = false;
this.isText = false;

// PlaceObject
this.placeId = -1;
this.placeObject = null;

// Characterパラメーター
this.characterId = -1;
this.clipDepth = 0;
this.name = "";
this.startFrame = 1;
this.endFrame = 0;

this.changed = true;

// フラグ
this.changed = true;
this.$added = false;
this.$addedToStage = false;

// Transform変数
this.$matrix = null;
this.$colorTransform = null;

this._$filters = null;
this._$blendMode = null;
this.$filters = null;
this.$blendMode = null;

this._$hitObject = null;
this._$isMask = false;
this._$isMask = false;

this._$visible = true;
this._$mask = null;
this._$visible = true;
this._$mask = null;
this._$scale9Grid = null;
this._$variables = null;
this._$variables = null;

this._$scaleX = null;
this._$scaleY = null;
Expand All @@ -315,28 +340,24 @@ export class DisplayObject extends EventDispatcher
return displayObjectConcatenatedMatrixUseCase(this);
}

// /**
// * @description 指定されたオブジェクトのアルファ透明度値を示します。
// * 有効な値は 0.0(完全な透明)~ 1.0(完全な不透明)です。
// * デフォルト値は 1.0 です。alpha が 0.0 に設定されている表示オブジェクトは、
// * 表示されない場合でも、アクティブです。
// * Indicates the alpha transparency value of the object specified.
// * Valid values are 0.0 (fully transparent) to 1.0 (fully opaque).
// * The default value is 1.0. Display objects with alpha set to 0.0 are active,
// * even though they are invisible.
// *
// * @member {number}
// * @default 1
// * @public
// */
// get alpha (): number
// {
// const colorTransform: Float32Array = this
// ._$transform
// ._$rawColorTransform();

// return colorTransform[3] + colorTransform[7] / 255;
// }
/**
* @description 指定されたオブジェクトのアルファ透明度値を示します。
* 有効な値は 0.0(完全な透明)~ 1.0(完全な不透明)です。
* デフォルト値は 1.0 です。alpha が 0.0 に設定されている表示オブジェクトは、
* 表示されない場合でも、アクティブです。
* Indicates the alpha transparency value of the object specified.
* Valid values are 0.0 (fully transparent) to 1.0 (fully opaque).
* The default value is 1.0. Display objects with alpha set to 0.0 are active,
* even though they are invisible.
*
* @member {number}
* @default 1
* @public
*/
get alpha (): number
{
return displayObjectGetAlphaUseCase(this);
}
// set alpha (alpha: number)
// {
// alpha = $clamp(alpha, 0, 1, 0);
Expand Down Expand Up @@ -374,8 +395,8 @@ export class DisplayObject extends EventDispatcher
*/
get blendMode (): IBlendMode
{
if (this._$blendMode) {
return this._$blendMode;
if (this.$blendMode) {
return this.$blendMode;
}

const placeObject = displayObjectGetPlaceObjectService(this);
Expand All @@ -385,10 +406,10 @@ export class DisplayObject extends EventDispatcher
}
set blendMode (blend_mode: IBlendMode)
{
if (this._$blendMode === blend_mode) {
if (this.$blendMode === blend_mode) {
return ;
}
this._$blendMode = blend_mode;
this.$blendMode = blend_mode;
displayObjectApplyChangesService(this);
}

Expand All @@ -402,32 +423,11 @@ export class DisplayObject extends EventDispatcher
*/
get filters (): IFilterArray | null
{
if (this._$filters) {
return this._$filters;
}

const placeObject = displayObjectGetPlaceObjectService(this);
if (placeObject && placeObject.surfaceFilterList) {

// build filter
if (!placeObject.filters) {
placeObject.filters = displayObjectBuildFilterService(
placeObject.surfaceFilterList
);
}

return placeObject.filters;
}

return null;
return displayObjectGetFiltersUseCase(this);
}
set filters (filters: IFilterArray | null)
{
if (this._$filters === filters) {
return ;
}
this._$filters = filters;
displayObjectApplyChangesService(this);
displayObjectSetFiltersUseCase(this, filters);
}

// /**
Expand Down Expand Up @@ -604,7 +604,7 @@ export class DisplayObject extends EventDispatcher
* @readonly
* @public
*/
get parent (): IParent<any> | null
get parent (): IParent<MovieClip | Sprite> | null
{
return $parentMap.has(this)
? $parentMap.get(this) as NonNullable<IParent<MovieClip | Sprite>>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { execute } from "./DisplayObjectApplyChangesService";
import { DisplayObject } from "../../DisplayObject";
import { $parentMap } from "../../DisplayObjectUtil";
import { describe, expect, it } from "vitest";

describe("DisplayObjectApplyChangesService.js test", () =>
{
it("execute test case1", () =>
{
const displayObject = new DisplayObject();

displayObject.changed = false;
expect(displayObject.changed).toBe(false);

execute(displayObject);
expect(displayObject.changed).toBe(true);
});

it("execute test case2", () =>
{
const displayObject = new DisplayObject();
const parent = new DisplayObject();
$parentMap.set(displayObject, parent);

parent.changed = false;
displayObject.changed = false;
expect(parent.changed).toBe(false);
expect(displayObject.changed).toBe(false);

execute(displayObject);
expect(parent.changed).toBe(true);
expect(displayObject.changed).toBe(true);

$parentMap.delete(displayObject);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { execute } from "./DisplayObjectBlendToNumberService";
import { describe, expect, it } from "vitest";

describe("DisplayObjectBlendToNumberService.js test", () =>
{
it("execute test case", () =>
{
expect(execute("copy")).toBe(0);
expect(execute("add")).toBe(1);
expect(execute("alpha")).toBe(2);
expect(execute("darken")).toBe(3);
expect(execute("difference")).toBe(4);
expect(execute("erase")).toBe(5);
expect(execute("hardlight")).toBe(6);
expect(execute("invert")).toBe(7);
expect(execute("layer")).toBe(8);
expect(execute("lighten")).toBe(9);
expect(execute("multiply")).toBe(10);
expect(execute("normal")).toBe(11);
expect(execute("overlay")).toBe(12);
expect(execute("screen")).toBe(13);
expect(execute("subtract")).toBe(14);
});
});
Loading

0 comments on commit 396c117

Please sign in to comment.