Skip to content

Commit

Permalink
#154 stageとplayerの変数名を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Dec 4, 2024
1 parent 1001aa0 commit 01dcae3
Show file tree
Hide file tree
Showing 37 changed files with 241 additions and 261 deletions.
21 changes: 5 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
// next2d.load("develop");

const { Sprite, Shape } = next2d.display;
const { Sprite, Shape, stage } = next2d.display;
const { PointerEvent } = next2d.events;

const root = await next2d.createRootMovieClip(480, 480);
Expand All @@ -23,25 +23,14 @@
shape1
.graphics
.beginFill("#ff0000")
.drawRect(0, 0, 100, 100);

const shape2 = sprite.addChild(new Shape());
shape2
.graphics
.beginFill("#00ff00")
.drawRect(30, 30, 100, 100);

const shape3 = sprite.addChild(new Shape());
shape3
.graphics
.beginFill("#0000ff")
.drawRect(60, 60, 100, 100);
.drawCircle(0, 50, 50);

sprite.x = 100;
sprite.y = 100;
sprite.addEventListener(PointerEvent.POINTER_DOWN, () =>
sprite.addEventListener(PointerEvent.POINTER_MOVE, () =>
{
console.log(sprite.getBounds(root));
console.log(stage.mouseX, stage.mouseY);
console.log(sprite.hitTestPoint(stage.mouseX, stage.mouseY));
});
});
</script>
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/Canvas/service/CanvasSetPositionService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { $mainCanvasPosition } from "@next2d/text";
import { $stage } from "@next2d/display";
import { stage } from "@next2d/display";
import { $getMainElement } from "../../CoreUtil";

/**
Expand Down Expand Up @@ -31,6 +31,6 @@ export const execute = (): void =>
return ;
}

$mainCanvasPosition.x = (element.clientWidth - $stage.rendererWidth / $devicePixelRatio) / 2;
$mainCanvasPosition.y = (element.clientHeight - $stage.rendererHeight / $devicePixelRatio) / 2;
$mainCanvasPosition.x = (element.clientWidth - stage.rendererWidth / $devicePixelRatio) / 2;
$mainCanvasPosition.y = (element.clientHeight - stage.rendererHeight / $devicePixelRatio) / 2;
};
6 changes: 3 additions & 3 deletions packages/core/src/Canvas/usecase/CanvasWheelEventUseCase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DisplayObject } from "@next2d/display";
import type { TextField } from "@next2d/text";
import { $stage } from "@next2d/display";
import { stage } from "@next2d/display";
import { $hitObject } from "../../CoreUtil";
import {
$setEvent,
Expand Down Expand Up @@ -38,11 +38,11 @@ export const execute = <D extends DisplayObject>(event: WheelEvent): void =>
return ;
}

if ($stage.willTrigger(Next2D_WheelEvent.WHEEL)) {
if (stage.willTrigger(Next2D_WheelEvent.WHEEL)) {
// イベントの伝播を止める
event.preventDefault();

$stage.dispatchEvent(new Next2D_WheelEvent(
stage.dispatchEvent(new Next2D_WheelEvent(
Next2D_WheelEvent.WHEEL
));
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
InteractiveObject,
Loader,
Shape,
Stage
stage
} from "@next2d/display";

const display: IDisplay = {
Expand All @@ -26,7 +26,7 @@ const display: IDisplay = {
InteractiveObject,
Loader,
Shape,
Stage
stage
};

Object.entries(display).forEach(([key, DisplayClass]) =>
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/Next2D/usecase/CreateRootMovieClipUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { execute as playerBootUseCase } from "../../Player/usecase/PlayerBootUse
import { execute as canvasSetPositionService } from "../../Canvas/service/CanvasSetPositionService";
import {
Sprite,
$stage
stage
} from "@next2d/display";

/**
Expand All @@ -30,17 +30,17 @@ export const execute = async (
): Promise<Sprite> => {

// setup
$stage.stageWidth = width | 0;
$stage.stageHeight = height | 0;
$stage.frameRate = $clamp(fps, 1, 60, 60);
stage.stageWidth = width | 0;
stage.stageHeight = height | 0;
stage.frameRate = $clamp(fps, 1, 60, 60);
if (options && options.bgColor) {
$stage.backgroundColor = options.bgColor;
stage.backgroundColor = options.bgColor;
}

// boot player
playerBootUseCase(options);

const root = $stage.addChild<Sprite>(new Sprite());
const root = stage.addChild<Sprite>(new Sprite());

// ready complete
playerReadyCompleteUseCase();
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/Next2D/usecase/LoadUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { execute as playerBootUseCase } from "../../Player/usecase/PlayerBootUse
import { execute as canvasSetPositionService } from "../../Canvas/service/CanvasSetPositionService";
import {
Loader,
$stage
stage
} from "@next2d/display";

/**
Expand Down Expand Up @@ -66,12 +66,12 @@ export const execute = async (url: string, options: IPlayerOptions | null = null

// update properties
const stageData: IStageData = loaderInfo.data.stage;
$stage.stageWidth = stageData.width;
$stage.stageHeight = stageData.height;
$stage.frameRate = $clamp(stageData.fps, 1, 60, 60);
$stage.backgroundColor = stageData.bgColor;
stage.stageWidth = stageData.width;
stage.stageHeight = stageData.height;
stage.frameRate = $clamp(stageData.fps, 1, 60, 60);
stage.backgroundColor = stageData.bgColor;

$stage.addChild<MovieClip>(loaderInfo.content as MovieClip);
stage.addChild<MovieClip>(loaderInfo.content as MovieClip);

// resize
playerResizeEventUseCase();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { execute as playerRegisterEventUseCase } from "./Player/usecase/PlayerRe
* @class
* @public
*/
export class Player
class Player
{
/**
* @description devicePixelRatioを含んだcanvasの描画領域の幅
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DisplayObject } from "@next2d/display";
import { $stage } from "@next2d/display";
import { stage } from "@next2d/display";
import { PointerEvent } from "@next2d/events";
import { $hitObject } from "../../CoreUtil";

Expand All @@ -21,8 +21,8 @@ export const execute = <D extends DisplayObject> (): void =>
);
}
} else {
if ($stage.willTrigger(PointerEvent.DOUBLE_CLICK)) {
$stage.dispatchEvent(
if (stage.willTrigger(PointerEvent.DOUBLE_CLICK)) {
stage.dispatchEvent(
new PointerEvent(PointerEvent.DOUBLE_CLICK)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execute } from "./PlayerKeyDownEventService";
import { $stage } from "@next2d/display";
import { stage } from "@next2d/display";
import { describe, expect, it, vi } from "vitest";

describe("PlayerKeyDownEventService.js test", () =>
Expand All @@ -11,8 +11,8 @@ describe("PlayerKeyDownEventService.js test", () =>
} as unknown as KeyboardEvent;

let result = "ok"
$stage.hasEventListener = vi.fn().mockReturnValue(false);
$stage.dispatchEvent = vi.fn((event) =>
stage.hasEventListener = vi.fn().mockReturnValue(false);
stage.dispatchEvent = vi.fn((event) =>
{
result = event.type;
});
Expand All @@ -28,8 +28,8 @@ describe("PlayerKeyDownEventService.js test", () =>
} as unknown as KeyboardEvent;

let result = "ok"
$stage.hasEventListener = vi.fn().mockReturnValue(true);
$stage.dispatchEvent = vi.fn((event) =>
stage.hasEventListener = vi.fn().mockReturnValue(true);
stage.dispatchEvent = vi.fn((event) =>
{
result = event.type;
});
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/Player/service/PlayerKeyDownEventService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $stage } from "@next2d/display";
import { stage } from "@next2d/display";
import { $getSelectedTextField } from "@next2d/text";
import {
KeyboardEvent as Event,
Expand All @@ -22,10 +22,10 @@ export const execute = (event: KeyboardEvent): void =>
return ;
}

if (!$stage.hasEventListener(Event.KEY_DOWN)) {
if (!stage.hasEventListener(Event.KEY_DOWN)) {
return ;
}

$setEvent(event);
$stage.dispatchEvent(new Event(Event.KEY_DOWN));
stage.dispatchEvent(new Event(Event.KEY_DOWN));
};
10 changes: 5 additions & 5 deletions packages/core/src/Player/service/PlayerKeyUpEventService.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execute } from "./PlayerKeyUpEventService";
import { $stage } from "@next2d/display";
import { stage } from "@next2d/display";
import { describe, expect, it, vi } from "vitest";

describe("PlayerKeyUpEventService.js test", () =>
Expand All @@ -11,8 +11,8 @@ describe("PlayerKeyUpEventService.js test", () =>
} as unknown as KeyboardEvent;

let result = "ok"
$stage.hasEventListener = vi.fn().mockReturnValue(false);
$stage.dispatchEvent = vi.fn((event) =>
stage.hasEventListener = vi.fn().mockReturnValue(false);
stage.dispatchEvent = vi.fn((event) =>
{
result = event.type;
});
Expand All @@ -28,8 +28,8 @@ describe("PlayerKeyUpEventService.js test", () =>
} as unknown as KeyboardEvent;

let result = "ok"
$stage.hasEventListener = vi.fn().mockReturnValue(true);
$stage.dispatchEvent = vi.fn((event) =>
stage.hasEventListener = vi.fn().mockReturnValue(true);
stage.dispatchEvent = vi.fn((event) =>
{
result = event.type;
});
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/Player/service/PlayerKeyUpEventService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $stage } from "@next2d/display";
import { stage } from "@next2d/display";
import { $getSelectedTextField } from "@next2d/text";
import {
KeyboardEvent as Event,
Expand All @@ -21,10 +21,10 @@ export const execute = (event: KeyboardEvent): void =>
return ;
}

if (!$stage.hasEventListener(Event.KEY_UP)) {
if (!stage.hasEventListener(Event.KEY_UP)) {
return ;
}

$setEvent(event);
$stage.dispatchEvent(new Event(Event.KEY_UP));
stage.dispatchEvent(new Event(Event.KEY_UP));
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DisplayObject } from "@next2d/display";
import type { TextField } from "@next2d/text";
import { $stage } from "@next2d/display";
import { stage } from "@next2d/display";
import { PointerEvent } from "@next2d/events";
import {
$setSelectedTextField,
Expand Down Expand Up @@ -62,8 +62,8 @@ export const execute = <D extends DisplayObject> (): void =>

} else {
// ステージ全体のポインターダウンイベントを発火します。
if ($stage.willTrigger(PointerEvent.POINTER_DOWN)) {
$stage.dispatchEvent(
if (stage.willTrigger(PointerEvent.POINTER_DOWN)) {
stage.dispatchEvent(
new PointerEvent(PointerEvent.POINTER_DOWN)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DisplayObject, Sprite } from "@next2d/display";
import { $stage } from "@next2d/display";
import { stage } from "@next2d/display";
import { $getSelectedTextField } from "@next2d/text";
import { PointerEvent } from "@next2d/events";
import { $player } from "../../Player";
Expand All @@ -21,12 +21,12 @@ import {
*/
export const execute = <D extends DisplayObject> (): void =>
{
const dropTarget = $stage.dropTarget as Sprite | null;
const dropTarget = stage.dropTarget as Sprite | null;
if (dropTarget) {

const point = dropTarget.parent
? dropTarget.parent.globalToLocal($stage.pointer)
: dropTarget.globalToLocal($stage.pointer);
? dropTarget.parent.globalToLocal(stage.pointer)
: dropTarget.globalToLocal(stage.pointer);

let dragX = 0;
let dragY = 0;
Expand Down Expand Up @@ -117,8 +117,8 @@ export const execute = <D extends DisplayObject> (): void =>
$setRollOverDisplayObject(null);
}

if ($stage.hasEventListener(PointerEvent.POINTER_MOVE)) {
$stage.dispatchEvent(new PointerEvent(
if (stage.hasEventListener(PointerEvent.POINTER_MOVE)) {
stage.dispatchEvent(new PointerEvent(
PointerEvent.POINTER_MOVE
));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DisplayObject } from "@next2d/display";
import { $stage } from "@next2d/display";
import { stage } from "@next2d/display";
import { PointerEvent } from "@next2d/events";
import { $hitObject } from "../../CoreUtil";

Expand All @@ -13,7 +13,7 @@ import { $hitObject } from "../../CoreUtil";
*/
export const execute = <D extends DisplayObject> (): void =>
{
const dropTarget = $stage.dropTarget as D | null;
const dropTarget = stage.dropTarget as D | null;
const displayObject = $hitObject.hit as D;
if (displayObject) {
if (displayObject.willTrigger(PointerEvent.POINTER_UP)) {
Expand All @@ -36,8 +36,8 @@ export const execute = <D extends DisplayObject> (): void =>
new PointerEvent(PointerEvent.POINTER_UP)
);
} else {
if ($stage.willTrigger(PointerEvent.POINTER_UP)) {
$stage.dispatchEvent(
if (stage.willTrigger(PointerEvent.POINTER_UP)) {
stage.dispatchEvent(
new PointerEvent(PointerEvent.POINTER_UP)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IRemoveCacheMessage } from "../../interface/IRemoveCacheMessage";
import { $stage } from "@next2d/display";
import { stage } from "@next2d/display";
import { $rendererWorker } from "../../RendererWorker";

/**
Expand Down Expand Up @@ -33,8 +33,8 @@ const options: Transferable[] = [];
*/
export const execute = (): void =>
{
const buffer = new Float32Array($stage.$remoceCacheKeys);
$stage.$remoceCacheKeys.length = 0;
const buffer = new Float32Array(stage.$remoceCacheKeys);
stage.$remoceCacheKeys.length = 0;

message.buffer = buffer;
options[0] = buffer.buffer;
Expand Down
Loading

0 comments on commit 01dcae3

Please sign in to comment.