Skip to content

Commit

Permalink
#128 Player v2に合わせる処理を追加、SPAでのページ遷移のasync/await処理を改修
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Feb 5, 2025
1 parent 714efed commit 4ee4aa8
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 98 deletions.
6 changes: 3 additions & 3 deletions src/application/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Application
* Current screen name
*
* @type {string}
* @default "top"
* @default ""
* @public
*/
public currentName: string;
Expand All @@ -44,7 +44,7 @@ export class Application
constructor ()
{
this.popstate = false;
this.currentName = "top";
this.currentName = "";
}

/**
Expand Down Expand Up @@ -85,7 +85,7 @@ export class Application
*/
async gotoView (name: string = ""): Promise<void>
{
applicationGotoViewUseCase(this, name);
await applicationGotoViewUseCase(this, name);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export const execute = (
* Keep history of transitions if SPA setting is enabled
*/
if (config.spa) {
window.addEventListener("popstate", (): void =>
window.addEventListener("popstate", async (): Promise<void> =>
{
application.popstate = true;
application.gotoView();
await application.gotoView();
});
}

Expand Down
24 changes: 12 additions & 12 deletions src/application/Application/usecase/ApplicationGotoViewUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ export const execute = async (application: Application, name: string = ""): Prom
response.set(object.name, object.response);
}

/**
* ローディング表示を終了
* End loading display
*/
await loadingEndService();

/**
* 前の画面のキャプチャーを終了
* End previous screen capture
*/
disposeCaptureService();

/**
* ViewとViewModelを起動
* Start View and ViewModel
Expand All @@ -109,16 +121,4 @@ export const execute = async (application: Application, name: string = ""): Prom
if (view && config.gotoView) {
await callbackService(config.gotoView.callback, view);
}

/**
* ローディング表示を終了
* End loading display
*/
await loadingEndService();

/**
* 前の画面のキャプチャーを終了
* End previous screen capture
*/
disposeCaptureService();
};
11 changes: 0 additions & 11 deletions src/application/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ export class Context
*/
public viewModel: ViewModel | null;

/**
* @description 現在のシーンで利用中のViewクラス名を返却します。
* Returns the name of the View class currently being used in the current scene.
*
* @return {string}
* @default "Top"
* @public
*/
public viewName: string;

/**
* @type {Sprite}
* @private
Expand All @@ -62,7 +52,6 @@ export class Context
// 初期化
this.view = null;
this.viewModel = null;
this.viewName = "Top";
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/application/Context/service/ContextUnbindService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@ export const execute = async (context: Context): Promise<void> =>
}

await context.viewModel.unbind(context.view);
context.root.removeChild(context.view);

const root = context.root;
if (!root) {
return ;
}

root.removeChild(context.view);
};
13 changes: 8 additions & 5 deletions src/application/Context/usecase/ContextBindUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Context } from "../../Context";
import type { View } from "../../../view/View";
import type { ViewModel } from "../../../view/ViewModel";
import { packages } from "../../variable/Packages";
import { execute as cntextToCamelCaseService } from "../service/ContextToCamelCaseService";
import { execute as contextToCamelCaseService } from "../service/ContextToCamelCaseService";

/**
* @description ViewとViewModelのbindを行います。
Expand All @@ -16,9 +16,7 @@ import { execute as cntextToCamelCaseService } from "../service/ContextToCamelCa
*/
export const execute = async (context: Context, name: string): Promise<View> =>
{
context.viewName = cntextToCamelCaseService(name);

const viewName = `${context.viewName}View`;
const viewName = `${contextToCamelCaseService(name)}View`;
const viewModelName = `${viewName}Model`;

if (!packages.size
Expand All @@ -44,11 +42,16 @@ export const execute = async (context: Context, name: string): Promise<View> =>
*/
await context.viewModel.bind(context.view);

const root = context.root;
while (root.numChildren) {
root.removeChildAt(0);
}

/**
* stageの一番背面にviewをセット
* Set the view at the very back of the stage
*/
context.root.addChildAt(context.view, 0);
root.addChildAt(context.view, 0);

return context.view;
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,29 @@ import { $getContext } from "../../../../application/variable/Context";
*/
export const execute = (default_loader: DefaultLoader): void =>
{
const root = $getContext().root;
if (!root) {
return ;
}

const sprite = default_loader.sprite;
root.removeChild(sprite);

for (let idx = 0; idx < 3; ++idx) {

const shape = sprite.getChildAt<Shape>(idx);
if (!shape) {
continue ;
}

const expandJob = shape.getLocalVariable("expandJob") as Job;
expandJob.stop();

const reduceJob = shape.getLocalVariable("reduceJob") as Job;
reduceJob.stop();
}
if (shape.hasLocalVariable("expandJob")) {
const expandJob = shape.getLocalVariable("expandJob") as Job;
expandJob.stop();
}

const root = $getContext().root;
if (!root) {
return ;
if (shape.hasLocalVariable("reduceJob")) {
const reduceJob = shape.getLocalVariable("reduceJob") as Job;
reduceJob.stop();
}
}

root.removeChild(sprite);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import type { Shape } from "@next2d/display";
import type { Job } from "@next2d/ui";
import { $getConfig } from "../../../../application/variable/Config";
import { $getContext } from "../../../../application/variable/Context";
import {
Tween,
Easing
} from "@next2d/ui";

/**
* @description ローダーのアニメーションを実行
Expand All @@ -15,6 +19,11 @@ import { $getContext } from "../../../../application/variable/Context";
*/
export const execute = (default_loader: DefaultLoader): void =>
{
const root = $getContext().root;
if (!root) {
return ;
}

const config = $getConfig();
const sprite = default_loader.sprite;

Expand All @@ -35,7 +44,56 @@ export const execute = (default_loader: DefaultLoader): void =>
shape.scaleY = 0.1;
shape.alpha = 0;

const expandJob = shape.getLocalVariable("expandJob") as Job;
let reduceJob: Job;
if (shape.hasLocalVariable("reduceJob")) {
reduceJob = shape.getLocalVariable("reduceJob") as Job;
reduceJob.stop();
} else {
reduceJob = Tween.add(
shape,
{
"scaleX": 0.1,
"scaleY": 0.1,
"alpha": 0
},
{
"scaleX": 1,
"scaleY": 1,
"alpha": 1
},
0.12,
0.5,
Easing.inOutCubic
);
shape.setLocalVariable("reduceJob", reduceJob);
}

let expandJob: Job;
if (shape.hasLocalVariable("expandJob")) {
expandJob = shape.getLocalVariable("expandJob") as Job;
expandJob.stop();
} else {
expandJob = Tween.add(
shape,
{
"scaleX": 0.1,
"scaleY": 0.1,
"alpha": 0
},
{
"scaleX": 1,
"scaleY": 1,
"alpha": 1
},
0.12,
0.5,
Easing.inOutCubic
);
shape.setLocalVariable("expandJob", expandJob);
}

reduceJob.nextJob = expandJob;
expandJob.nextJob = reduceJob;

if (idx) {
setTimeout((): void =>
Expand All @@ -61,5 +119,5 @@ export const execute = (default_loader: DefaultLoader): void =>

sprite.x = (config.stage.width - sprite.width) / 2;
sprite.y = (config.stage.height - sprite.height) / 2;
$getContext().root.addChild(sprite);
root.addChild(sprite);
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { DefaultLoader } from "../../DefaultLoader";
import { Shape } from "@next2d/display";
import {
Tween,
Easing
} from "@next2d/ui";

/**
* @description ローディング演出の初期登録
Expand All @@ -17,46 +13,6 @@ import {
export const execute = (default_loader: DefaultLoader): void =>
{
for (let idx = 0; idx < 3; ++idx) {

const shape = default_loader.sprite.addChild(new Shape());

const reduceJob = Tween.add(
shape,
{
"scaleX": 0.1,
"scaleY": 0.1,
"alpha": 0
},
{
"scaleX": 1,
"scaleY": 1,
"alpha": 1
},
0.12,
0.5,
Easing.inOutCubic
);
shape.setLocalVariable("reduceJob", reduceJob);

const expandJob = Tween.add(
shape,
{
"scaleX": 0.1,
"scaleY": 0.1,
"alpha": 0
},
{
"scaleX": 1,
"scaleY": 1,
"alpha": 1
},
0.12,
0.5,
Easing.inOutCubic
);
shape.setLocalVariable("expandJob", expandJob);

reduceJob.nextJob = expandJob;
expandJob.nextJob = reduceJob;
default_loader.sprite.addChild(new Shape());
}
};
16 changes: 11 additions & 5 deletions src/domain/screen/Capture/service/AddScreenCaptureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ export const execute = async (): Promise<void> =>
bitmapData.canvas = canvas;
bitmap.x = rectangle.x;
bitmap.y = rectangle.y;
bitmap
.graphics
.clear()
.beginBitmapFill(bitmapData, null, false, false)
.drawRect(0, 0, canvas.width, canvas.height);
if ($devicePixelRatio !== 1) {
bitmap.scaleX = 1 / $devicePixelRatio;
bitmap.scaleY = 1 / $devicePixelRatio;
}

bitmap.setBitmapBuffer(canvas.width, canvas.height, bitmapData.buffer as Uint8Array);
// bitmap
// .graphics
// .clear()
// .beginBitmapFill(bitmapData, null, false, false)
// .drawRect(0, 0, canvas.width, canvas.height);

root.addChild(bitmap);

Expand Down
2 changes: 1 addition & 1 deletion src/domain/screen/Capture/service/DisposeCaptureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const execute = (): void =>
return ;
}

root.removeChild(shape);
root.removeChild(bitmap);
root.removeChild(shape);

/**
* マウス操作を有効化
Expand Down
7 changes: 7 additions & 0 deletions src/infrastructure/Request/usecase/RequestUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import { execute as configParserRequestsPropertyService } from "../../../applica
export const execute = async (name: string): Promise<ResponseDTO[]> =>
{
const responses: ResponseDTO[] = [];
await new Promise<void>((resolve): void =>
{
setTimeout((): void =>
{
return resolve();
}, 3000);
});

const requests = configParserRequestsPropertyService(name);
for (let idx = 0; idx < requests.length; ++idx) {
Expand Down

0 comments on commit 4ee4aa8

Please sign in to comment.