Skip to content

Commit

Permalink
不要なクラスや処理を削除、重い処理を改修
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Nov 6, 2023
1 parent 4df5387 commit 923857a
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 141 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
"type": "git",
"url": "git+https://github.com/Next2D/Framework.git"
},
"dependencies": {
"@next2d/player": "*"
},
"devDependencies": {
"@next2d/player": "*",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"eslint": "^8.53.0",
Expand Down
25 changes: 17 additions & 8 deletions src/application/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import type { QueryObjectImpl } from "../interface/QueryObjectImpl";
import { execute as queryParser } from "../domain/parser/QueryParser";
import { execute as requestUseCase } from "../infrastructure/usecase/RequestUseCase";
import { execute as callback } from "../domain/callback/Callback";
import { execute as capture } from "../domain/screen/Capture";
import {
execute as captureExecute,
dispose as captureDispose
} from "../domain/screen/Capture";
import { execute as removeResponse } from "./service/RemoveResponse";
import { $setPackages } from "./variable/Packages";
import { response } from "./variable/Response";
Expand Down Expand Up @@ -113,16 +116,16 @@ export class Application
const promises: Promise<void>[] = [];

/**
* ローディング表示を起動
* Launch loading display
* 現時点の描画をBitmapにして処理の負担を減らす
* Reduce the processing burden by making the current drawing a Bitmap.
*/
promises.push(loadingStart());
promises.push(captureExecute());

/**
* 現時点の描画をBitmapにして処理の負担を減らす
* Reduce the processing burden by making the current drawing a Bitmap.
* ローディング表示を起動
* Launch loading display
*/
promises.push(capture());
promises.push(loadingStart());

await Promise.all(promises);
}
Expand Down Expand Up @@ -201,6 +204,12 @@ export class Application
* ローディング表示を終了
* End loading display
*/
loadingEnd();
await loadingEnd();

/**
* 前の画面のキャプチャーを終了
* End previous screen capture
*/
captureDispose();
}
}
40 changes: 15 additions & 25 deletions src/application/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,19 @@ export class Context
}

/**
* 現在のViewとViewModelを変数にセット
* Set the current View and ViewModel to variables
* 現在のページをstageから削除して、unbind関数を実行
* Delete current page from stage and execute unbind function
*/
const PrevView: View | null = this._$view;
const PrevViewModel: ViewModel | null = this._$viewModel;
if (this._$view) {
if (this._$viewModel) {
this._$viewModel.unbind(this._$view);
}

// remove
if (this._$view.parent === this._$root) {
this._$root.removeChild(this._$view);
}
}

/**
* 遷移先のViewとViewModelを準備
Expand All @@ -156,28 +164,10 @@ export class Context
await Promise.all([this._$viewModel.bind(this._$view)]);

/**
* playerにviewをセットして、前のページで利用していたDisplayObjectを全て削除
* Set player to view and delete all DisplayObjects used in the previous page.
*/
this._$root.addChild(this._$view);

while (this._$root.numChildren > 1) {
this._$root.removeChild(this._$root.getChildAt(0));
}

/**
* マウス(タップ)イベントを有効化
* Enable mouse (tap) events
* stageの一番背面にviewをセット
* Set the view at the very back of the stage
*/
this._$root.mouseChildren = true;

/**
* 前のページのunbind関数を実行
* Execute unbind function on previous page
*/
if (PrevViewModel && PrevView) {
PrevViewModel.unbind(PrevView);
}
this._$root.addChildAt(this._$view, 0);

return this._$view;
}
Expand Down
9 changes: 7 additions & 2 deletions src/domain/loading/Loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ export const start = (): Promise<void> =>
return resolve();
}

resolve($instance.start());
$instance.start();

setTimeout(() =>
{
resolve();
}, 500);
});
};

Expand All @@ -63,7 +68,7 @@ export const end = (): Promise<void> =>
return resolve();
}

const name: string|undefined = config.loading.callback;
const name: string | undefined = config.loading.callback;
if (!name) {
return resolve();
}
Expand Down
138 changes: 138 additions & 0 deletions src/domain/parser/RequestParser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { execute } from "./RequestParser";
import { $setConfig } from "../../../src/application/variable/Config";

describe("RequestParserTest", () =>
{
test("request parse no match test case1", () =>
{
// mock
const config = {
"platform": "web",
"spa": true,
"stage": {
"width": 240,
"height": 240,
"fps": 12,
"options": {}
},
"routing": {}
};

$setConfig(config);

const requests: Object[] = execute("top");
expect(requests.length).toBe(0);
});

test("request parse no match test case2", () =>
{
// mock
const config = {
"platform": "web",
"spa": true,
"stage": {
"width": 240,
"height": 240,
"fps": 12,
"options": {}
},
"routing": {
"top": {}
}
};

$setConfig(config);

const requests: Object[] = execute("top");
expect(requests.length).toBe(0);
});

test("request parse match test case1", () =>
{
// mock
const config = {
"platform": "web",
"spa": true,
"stage": {
"width": 240,
"height": 240,
"fps": 12,
"options": {}
},
"routing": {
"top": {
"requests": [
{
"type": "json",
"name": "TopTest",
"path": "local"
}
]
}
}
};

$setConfig(config);

const requests: Object[] = execute("top");
expect(requests.length).toBe(1);

const object: Object = requests[0];
expect(object.type).toBe("json");
expect(object.name).toBe("TopTest");
expect(object.path).toBe("local");
});

test("request parse cluster test case1", () =>
{
// mock
const config = {
"platform": "web",
"spa": true,
"stage": {
"width": 240,
"height": 240,
"fps": 12,
"options": {}
},
"routing": {
"@sample": {
"requests": [
{
"type": "content",
"path": "{{ content.endPoint }}content/sample.json",
"name": "MainContent",
"cache": true
}
]
},
"top": {
"requests": [
{
"type": "cluster",
"path": "@sample"
},
{
"type": "json",
"path": "{{ api.endPoint }}api/top.json",
"name": "TopText"
}
]
}
}
};

$setConfig(config);

const requests: Object[] = execute("top");
expect(requests.length).toBe(2);

const object1: Object = requests[0];
expect(object1.type).toBe("content");
expect(object1.name).toBe("MainContent");

const object2: Object = requests[1];
expect(object2.type).toBe("json");
expect(object2.name).toBe("TopText");
});
});
62 changes: 51 additions & 11 deletions src/domain/screen/Capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ import type { Player } from "@next2d/core";

/**
* @type {Shape}
* @default null
* @private
*/
let shape: Shape | null = null;
const shape: Shape = new Shape();

/**
* @type {number}
* @default 0
* @private
*/
let cacheX: number = 0;

/**
* @type {number}
* @default 0
* @private
*/
let cacheY: number = 0;

/**
* @description 現時点の描画キャプチャーを生成
Expand All @@ -26,11 +39,10 @@ export const execute = (): Promise<void> =>
{
const width: number = config.stage.width;
const height: number = config.stage.height;

if (!shape) {
shape = new Shape();
if (shape.width !== width || shape.width !== height) {
shape
.graphics
.clear()
.beginFill(0, 0.8)
.drawRect(0, 0, width, height)
.endFill();
Expand All @@ -39,28 +51,56 @@ export const execute = (): Promise<void> =>
const player: Player = $currentPlayer();

const tx: number = player.x;
if (tx) {
if (tx && cacheX !== tx) {
cacheX = tx;
const scaleX: number = player.scaleX;
shape.scaleX = (width + tx * 2 / scaleX) / width;
shape.x = -tx / scaleX;
}

const ty: number = player.y;
if (ty) {
if (ty && cacheY !== ty) {
cacheY = ty;
const scaleY: number = player.scaleY;
shape.scaleY = (height + ty * 2 / scaleY) / height;
shape.y = -ty / scaleY;
}

const root: Sprite = context.root;
if (root) {
/**
* マウス操作を強制停止
* Mouse operation is forced to stop
*/
root.mouseChildren = false;
root.addChild(shape);
}

setTimeout(() =>
{
resolve();
}, 350);
resolve();
});
};

/**
* @description 画面キャプチャーのShapeをStageから削除
* Delete Screen Capture Shape from Stage
*
* @return {void}
* @method
* @public
*/
export const dispose = (): void =>
{
const root: Sprite = context.root;
if (root) {

if (shape.parent === root) {
root.removeChild(shape);
}

/**
* マウス操作を有効化
* Enable Mouse Operation
*/
root.mouseChildren = true;
}
};
Loading

0 comments on commit 923857a

Please sign in to comment.