pixifact 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/builtin-scenes/CenterContainer.d.ts +13 -0
- package/dist/builtin-scenes/CenterContainer.js +71 -0
- package/dist/builtin-scenes/CenterContainer.scene +3 -0
- package/dist/builtin-scenes/CenterContainer.ts +77 -0
- package/dist/builtin-scenes/Control.d.ts +44 -0
- package/dist/builtin-scenes/Control.js +206 -0
- package/dist/builtin-scenes/Control.scene +3 -0
- package/dist/builtin-scenes/Control.ts +233 -0
- package/dist/builtin-scenes/FlexItem.d.ts +45 -0
- package/dist/builtin-scenes/FlexItem.js +164 -0
- package/dist/builtin-scenes/FlexItem.scene +3 -0
- package/dist/builtin-scenes/FlexItem.ts +180 -0
- package/dist/builtin-scenes/FlexLayout.d.ts +29 -0
- package/dist/builtin-scenes/FlexLayout.js +358 -0
- package/dist/builtin-scenes/FlexLayout.scene +3 -0
- package/dist/builtin-scenes/FlexLayout.ts +409 -0
- package/dist/builtin-scenes/HBoxContainer.d.ts +15 -0
- package/dist/builtin-scenes/HBoxContainer.js +70 -0
- package/dist/builtin-scenes/HBoxContainer.scene +3 -0
- package/dist/builtin-scenes/HBoxContainer.ts +75 -0
- package/dist/builtin-scenes/MarginContainer.d.ts +23 -0
- package/dist/builtin-scenes/MarginContainer.js +131 -0
- package/dist/builtin-scenes/MarginContainer.scene +3 -0
- package/dist/builtin-scenes/MarginContainer.ts +139 -0
- package/dist/builtin-scenes/VBoxContainer.d.ts +15 -0
- package/dist/builtin-scenes/VBoxContainer.js +70 -0
- package/dist/builtin-scenes/VBoxContainer.scene +3 -0
- package/dist/builtin-scenes/VBoxContainer.ts +75 -0
- package/dist/builtin-scenes/controlLayout.d.ts +57 -0
- package/dist/builtin-scenes/controlLayout.js +202 -0
- package/dist/builtin-scenes/controlLayout.ts +270 -0
- package/dist/compiler/builtinScenes.d.ts +14 -0
- package/dist/compiler/builtinScenes.js +62 -0
- package/dist/compiler/compileScenes.js +126 -19
- package/dist/compiler/decorators.js +3 -0
- package/dist/compiler/index.d.ts +1 -0
- package/dist/compiler/index.js +1 -0
- package/dist/compiler/sceneAssetPair.js +19 -0
- package/dist/compiler/sceneRuntime.d.ts +5 -4
- package/dist/compiler/scriptInterfaceExtractor.d.ts +5 -0
- package/dist/compiler/scriptInterfaceExtractor.js +214 -8
- package/dist/compiler/spec.d.ts +2 -0
- package/dist/compiler/templateParser.js +4 -3
- package/dist/compiler/templateSerializer.js +2 -1
- package/dist/compiler/typescriptCompiler.js +87 -13
- package/dist/compiler-node/builtinSceneAssets.d.ts +8 -0
- package/dist/compiler-node/builtinSceneAssets.js +57 -0
- package/dist/compiler-node/index.d.ts +1 -0
- package/dist/compiler-node/index.js +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +24 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.js +2 -5
- package/dist/{authoring/ProjectConfig.d.ts → project/index.d.ts} +7 -0
- package/dist/{authoring/ProjectConfig.js → project/index.js} +22 -0
- package/dist/runtime/Group.d.ts +18 -0
- package/dist/runtime/Group.js +45 -0
- package/dist/runtime/index.d.ts +1 -9
- package/dist/runtime/index.js +1 -9
- package/package.json +4 -26
- package/dist/authoring/ActionRegistry.d.ts +0 -10
- package/dist/authoring/ActionRegistry.js +0 -26
- package/dist/authoring/ComponentPalette.d.ts +0 -16
- package/dist/authoring/ComponentPalette.js +0 -50
- package/dist/authoring/DesignToken.d.ts +0 -16
- package/dist/authoring/DesignToken.js +0 -33
- package/dist/authoring/DiffModel.d.ts +0 -10
- package/dist/authoring/DiffModel.js +0 -104
- package/dist/authoring/InspectorModel.d.ts +0 -27
- package/dist/authoring/InspectorModel.js +0 -139
- package/dist/authoring/LogicGraph.d.ts +0 -66
- package/dist/authoring/LogicGraph.js +0 -184
- package/dist/authoring/OverrideJournal.d.ts +0 -18
- package/dist/authoring/OverrideJournal.js +0 -23
- package/dist/authoring/PreferenceMemory.d.ts +0 -21
- package/dist/authoring/PreferenceMemory.js +0 -39
- package/dist/authoring/RuntimePreview.d.ts +0 -11
- package/dist/authoring/RuntimePreview.js +0 -25
- package/dist/authoring/SceneDocument.d.ts +0 -74
- package/dist/authoring/SceneDocument.js +0 -332
- package/dist/authoring/SceneProjectState.d.ts +0 -20
- package/dist/authoring/SceneProjectState.js +0 -8
- package/dist/authoring/SceneSelection.d.ts +0 -11
- package/dist/authoring/SceneSelection.js +0 -1
- package/dist/authoring/index.d.ts +0 -13
- package/dist/authoring/index.js +0 -13
- package/dist/commands/Command.d.ts +0 -63
- package/dist/commands/Command.js +0 -1
- package/dist/commands/CommandStack.d.ts +0 -14
- package/dist/commands/CommandStack.js +0 -45
- package/dist/commands/applyCommand.d.ts +0 -23
- package/dist/commands/applyCommand.js +0 -316
- package/dist/commands/index.d.ts +0 -4
- package/dist/commands/index.js +0 -4
- package/dist/commands/utils.d.ts +0 -17
- package/dist/commands/utils.js +0 -77
- package/dist/commands/validateCommand.d.ts +0 -12
- package/dist/commands/validateCommand.js +0 -285
- package/dist/nodes/Input.d.ts +0 -91
- package/dist/nodes/Input.js +0 -352
- package/dist/nodes/Textarea.d.ts +0 -10
- package/dist/nodes/Textarea.js +0 -38
- package/dist/nodes/components/Button.d.ts +0 -8
- package/dist/nodes/components/Button.js +0 -45
- package/dist/nodes/components/InputField.d.ts +0 -12
- package/dist/nodes/components/InputField.js +0 -53
- package/dist/nodes/components/ProgressBar.d.ts +0 -14
- package/dist/nodes/components/ProgressBar.js +0 -66
- package/dist/nodes/components/ScrollRect.d.ts +0 -23
- package/dist/nodes/components/ScrollRect.js +0 -108
- package/dist/nodes/components/Selectable.d.ts +0 -32
- package/dist/nodes/components/Selectable.js +0 -153
- package/dist/nodes/components/index.d.ts +0 -5
- package/dist/nodes/components/index.js +0 -5
- package/dist/nodes/graphics/Graphic.d.ts +0 -14
- package/dist/nodes/graphics/Graphic.js +0 -47
- package/dist/nodes/graphics/ImageGraphic.d.ts +0 -9
- package/dist/nodes/graphics/ImageGraphic.js +0 -42
- package/dist/nodes/graphics/RoundedRectGraphic.d.ts +0 -13
- package/dist/nodes/graphics/RoundedRectGraphic.js +0 -65
- package/dist/nodes/graphics/TextGraphic.d.ts +0 -13
- package/dist/nodes/graphics/TextGraphic.js +0 -70
- package/dist/nodes/graphics/index.d.ts +0 -4
- package/dist/nodes/graphics/index.js +0 -4
- package/dist/nodes/index.d.ts +0 -3
- package/dist/nodes/index.js +0 -3
- package/dist/runtime/Application.d.ts +0 -15
- package/dist/runtime/Application.js +0 -67
- package/dist/runtime/GameObject.d.ts +0 -100
- package/dist/runtime/GameObject.js +0 -297
- package/dist/runtime/GameObjectEvent.d.ts +0 -52
- package/dist/runtime/GameObjectEvent.js +0 -38
- package/dist/runtime/Transform.d.ts +0 -32
- package/dist/runtime/Transform.js +0 -157
- package/dist/runtime/component/Component.d.ts +0 -13
- package/dist/runtime/component/Component.js +0 -13
- package/dist/runtime/component/ComponentRegistry.d.ts +0 -49
- package/dist/runtime/component/ComponentRegistry.js +0 -25
- package/dist/runtime/component/Flex.d.ts +0 -6
- package/dist/runtime/component/Flex.js +0 -15
- package/dist/runtime/component/FlexGroup.d.ts +0 -26
- package/dist/runtime/component/FlexGroup.js +0 -136
- package/dist/runtime/component/GridLayout.d.ts +0 -47
- package/dist/runtime/component/GridLayout.js +0 -129
- package/dist/runtime/component/Layout.d.ts +0 -104
- package/dist/runtime/component/Layout.js +0 -248
- package/dist/runtime/component/decorators.d.ts +0 -4
- package/dist/runtime/component/decorators.js +0 -52
- package/dist/runtime/component/index.d.ts +0 -7
- package/dist/runtime/component/index.js +0 -7
- package/dist/runtime/graphics/index.d.ts +0 -11
- package/dist/runtime/graphics/index.js +0 -29
- package/dist/runtime/group/index.d.ts +0 -39
- package/dist/runtime/group/index.js +0 -102
- package/dist/runtime/image/Image.d.ts +0 -19
- package/dist/runtime/image/Image.js +0 -60
- package/dist/runtime/image/NineSliceImage.d.ts +0 -23
- package/dist/runtime/image/NineSliceImage.js +0 -64
- package/dist/runtime/image/index.d.ts +0 -2
- package/dist/runtime/image/index.js +0 -2
- package/dist/runtime/label/Label.d.ts +0 -11
- package/dist/runtime/label/Label.js +0 -26
- package/dist/runtime/label/LabelStyle.d.ts +0 -3
- package/dist/runtime/label/LabelStyle.js +0 -3
- package/dist/runtime/label/index.d.ts +0 -2
- package/dist/runtime/label/index.js +0 -2
- package/dist/runtime/utils/index.d.ts +0 -1
- package/dist/runtime/utils/index.js +0 -1
- package/dist/runtime/utils/onlyOnceQueueMicrotask.d.ts +0 -1
- package/dist/runtime/utils/onlyOnceQueueMicrotask.js +0 -12
- package/dist/runtime/utils/setProps.d.ts +0 -10
- package/dist/runtime/utils/setProps.js +0 -17
- package/dist/scene/dsl.d.ts +0 -25
- package/dist/scene/dsl.js +0 -112
- package/dist/scene/index.d.ts +0 -5
- package/dist/scene/index.js +0 -5
- package/dist/scene/instantiate.d.ts +0 -8
- package/dist/scene/instantiate.js +0 -208
- package/dist/scene/nodesDsl.d.ts +0 -42
- package/dist/scene/nodesDsl.js +0 -169
- package/dist/scene/spec.d.ts +0 -100
- package/dist/scene/spec.js +0 -1
- package/dist/scene/templates.d.ts +0 -21
- package/dist/scene/templates.js +0 -239
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import * as PIXI from 'pixi.js';
|
|
2
|
-
import { UPDATE_PRIORITY } from 'pixi.js';
|
|
3
|
-
import { GameObject } from './GameObject.js';
|
|
4
|
-
import { Group } from './group/index.js';
|
|
5
|
-
export class Application extends PIXI.Application {
|
|
6
|
-
root;
|
|
7
|
-
updateTargets = new Set();
|
|
8
|
-
isUpdateTickerRegistered = false;
|
|
9
|
-
updateGameObjects = (ticker) => {
|
|
10
|
-
const dt = ticker.deltaTime;
|
|
11
|
-
for (const target of [...this.updateTargets]) {
|
|
12
|
-
if (target.app !== this || !target.hasUpdateWork()) {
|
|
13
|
-
this.unregisterUpdateTarget(target);
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
target.emitter.emit(GameObject.Event.TICKER_BEFORE, dt);
|
|
17
|
-
target.update?.(dt);
|
|
18
|
-
target.emitter.emit(GameObject.Event.TICKER_AFTER, dt);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
async init(options) {
|
|
22
|
-
await super.init(options);
|
|
23
|
-
this.root = new Group();
|
|
24
|
-
this.root.display = this.stage;
|
|
25
|
-
this.root.width = this.screen.width;
|
|
26
|
-
this.root.height = this.screen.height;
|
|
27
|
-
this.root.setApplication(this);
|
|
28
|
-
}
|
|
29
|
-
registerUpdateTarget(target) {
|
|
30
|
-
if (target.app !== this || !target.hasUpdateWork()) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
this.updateTargets.add(target);
|
|
34
|
-
this.syncUpdateTicker();
|
|
35
|
-
}
|
|
36
|
-
unregisterUpdateTarget(target) {
|
|
37
|
-
if (!this.updateTargets.delete(target)) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
this.syncUpdateTicker();
|
|
41
|
-
}
|
|
42
|
-
syncUpdateTicker() {
|
|
43
|
-
if (!this.ticker) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (this.updateTargets.size > 0) {
|
|
47
|
-
if (!this.isUpdateTickerRegistered) {
|
|
48
|
-
this.ticker.add(this.updateGameObjects, undefined, UPDATE_PRIORITY.NORMAL);
|
|
49
|
-
this.isUpdateTickerRegistered = true;
|
|
50
|
-
}
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (this.isUpdateTickerRegistered) {
|
|
54
|
-
this.ticker.remove(this.updateGameObjects);
|
|
55
|
-
this.isUpdateTickerRegistered = false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
destroy(rendererDestroyOptions, options) {
|
|
59
|
-
this.updateTargets.clear();
|
|
60
|
-
if (this.isUpdateTickerRegistered && this.ticker) {
|
|
61
|
-
this.ticker.remove(this.updateGameObjects);
|
|
62
|
-
this.isUpdateTickerRegistered = false;
|
|
63
|
-
}
|
|
64
|
-
this.root?.setApplication(undefined);
|
|
65
|
-
super.destroy(rendererDestroyOptions, options);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { Container } from "pixi.js";
|
|
2
|
-
import { Transform } from "./Transform.js";
|
|
3
|
-
import { Vector2 } from "@math.gl/core";
|
|
4
|
-
import EventEmitter from "eventemitter3";
|
|
5
|
-
import { Component } from "./component/Component.js";
|
|
6
|
-
import type { GameObjectEventMap } from "./GameObjectEvent.js";
|
|
7
|
-
import type { Group } from "./group/index.js";
|
|
8
|
-
import type { Application } from "./Application.js";
|
|
9
|
-
export type Constructor<T = unknown> = new (...args: any[]) => T;
|
|
10
|
-
export { GameObjectEvent } from "./GameObjectEvent.js";
|
|
11
|
-
export type { GameObjectEventMap } from "./GameObjectEvent.js";
|
|
12
|
-
declare class GameObjectEmitter extends EventEmitter<GameObjectEventMap> {
|
|
13
|
-
private gameObject;
|
|
14
|
-
constructor(gameObject: GameObject);
|
|
15
|
-
private syncUpdateRegistration;
|
|
16
|
-
on<T extends EventEmitter.EventNames<GameObjectEventMap>>(event: T, fn: EventEmitter.EventListener<GameObjectEventMap, T>, context?: unknown): this;
|
|
17
|
-
addListener<T extends EventEmitter.EventNames<GameObjectEventMap>>(event: T, fn: EventEmitter.EventListener<GameObjectEventMap, T>, context?: unknown): this;
|
|
18
|
-
once<T extends EventEmitter.EventNames<GameObjectEventMap>>(event: T, fn: EventEmitter.EventListener<GameObjectEventMap, T>, context?: unknown): this;
|
|
19
|
-
off<T extends EventEmitter.EventNames<GameObjectEventMap>>(event: T, fn?: EventEmitter.EventListener<GameObjectEventMap, T>, context?: unknown, once?: boolean): this;
|
|
20
|
-
removeListener<T extends EventEmitter.EventNames<GameObjectEventMap>>(event: T, fn?: EventEmitter.EventListener<GameObjectEventMap, T>, context?: unknown, once?: boolean): this;
|
|
21
|
-
removeAllListeners(event?: EventEmitter.EventNames<GameObjectEventMap>): this;
|
|
22
|
-
emit<T extends EventEmitter.EventNames<GameObjectEventMap>>(event: T, ...args: EventEmitter.EventArgs<GameObjectEventMap, T>): boolean;
|
|
23
|
-
}
|
|
24
|
-
export declare abstract class BaseGameObject<T extends Container> {
|
|
25
|
-
abstract display: T;
|
|
26
|
-
abstract get width(): number;
|
|
27
|
-
abstract set width(val: number);
|
|
28
|
-
abstract get height(): number;
|
|
29
|
-
abstract set height(val: number);
|
|
30
|
-
abstract get anchor(): Vector2;
|
|
31
|
-
abstract set anchor(val: Vector2);
|
|
32
|
-
protected refreshPivot(): void;
|
|
33
|
-
}
|
|
34
|
-
export declare abstract class GameObject<T extends Container = Container> extends BaseGameObject<T> {
|
|
35
|
-
static Event: {
|
|
36
|
-
readonly ADDED: "added";
|
|
37
|
-
readonly CHILD_ADDED: "childAdded";
|
|
38
|
-
readonly REMOVED: "removed";
|
|
39
|
-
readonly CHILD_REMOVED: "childRemoved";
|
|
40
|
-
readonly RESIZE: "resize";
|
|
41
|
-
readonly REPOSITION: "reposition";
|
|
42
|
-
readonly TRANSFORM_CHANGE: "transformChange";
|
|
43
|
-
readonly TICKER_BEFORE: "tickerBefore";
|
|
44
|
-
readonly TICKER_AFTER: "tickerAfter";
|
|
45
|
-
};
|
|
46
|
-
emitter: GameObjectEmitter;
|
|
47
|
-
display: T;
|
|
48
|
-
transform: Transform;
|
|
49
|
-
app?: Application;
|
|
50
|
-
parent?: Group;
|
|
51
|
-
components: Component[];
|
|
52
|
-
private componentTickerHandlers;
|
|
53
|
-
private _destroying;
|
|
54
|
-
get visible(): boolean;
|
|
55
|
-
set visible(val: boolean);
|
|
56
|
-
get x(): number;
|
|
57
|
-
set x(val: number);
|
|
58
|
-
get y(): number;
|
|
59
|
-
set y(val: number);
|
|
60
|
-
get scaleX(): number;
|
|
61
|
-
set scaleX(val: number);
|
|
62
|
-
get scaleY(): number;
|
|
63
|
-
set scaleY(val: number);
|
|
64
|
-
get width(): number;
|
|
65
|
-
set width(val: number);
|
|
66
|
-
get height(): number;
|
|
67
|
-
set height(val: number);
|
|
68
|
-
protected _anchor: Vector2;
|
|
69
|
-
get anchor(): Vector2;
|
|
70
|
-
set anchor(value: Vector2);
|
|
71
|
-
get anchorX(): number;
|
|
72
|
-
set anchorX(value: number);
|
|
73
|
-
get anchorY(): number;
|
|
74
|
-
set anchorY(value: number);
|
|
75
|
-
get rotation(): number;
|
|
76
|
-
set rotation(val: number);
|
|
77
|
-
get skewX(): number;
|
|
78
|
-
set skewX(val: number);
|
|
79
|
-
get skewY(): number;
|
|
80
|
-
set skewY(val: number);
|
|
81
|
-
/**
|
|
82
|
-
* 透明度
|
|
83
|
-
*/
|
|
84
|
-
get alpha(): number;
|
|
85
|
-
set alpha(val: number);
|
|
86
|
-
start?(): void;
|
|
87
|
-
hasUpdateWork(): boolean;
|
|
88
|
-
syncUpdateRegistration(): void;
|
|
89
|
-
setApplication(app?: Application): void;
|
|
90
|
-
addComponent<T extends Component>(component: Constructor<T>, props?: Partial<T>): T;
|
|
91
|
-
removeComponent<T extends Component>(component: T): T | undefined;
|
|
92
|
-
getComponent<T extends Component>(component: Constructor<T>): T | undefined;
|
|
93
|
-
getComponents<T extends Component>(component: Constructor<T>): T[] | undefined;
|
|
94
|
-
private setDisplay;
|
|
95
|
-
update?(dt: number): void;
|
|
96
|
-
render?(): void;
|
|
97
|
-
onDestroy?(): void;
|
|
98
|
-
static instantiate<T extends GameObject = GameObject>(gameObject: Constructor<T>, parent?: Group, props?: Partial<T>): T;
|
|
99
|
-
static destroy(go: GameObject): Promise<void>;
|
|
100
|
-
}
|
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
import { Transform } from "./Transform.js";
|
|
2
|
-
import { Vector2 } from "@math.gl/core";
|
|
3
|
-
import EventEmitter from "eventemitter3";
|
|
4
|
-
import { setProps } from "./utils/setProps.js";
|
|
5
|
-
import { GameObjectEvent } from "./GameObjectEvent.js";
|
|
6
|
-
export { GameObjectEvent } from "./GameObjectEvent.js";
|
|
7
|
-
function hasChildren(go) {
|
|
8
|
-
return 'children' in go && Array.isArray(go.children);
|
|
9
|
-
}
|
|
10
|
-
class GameObjectEmitter extends EventEmitter {
|
|
11
|
-
gameObject;
|
|
12
|
-
constructor(gameObject) {
|
|
13
|
-
super();
|
|
14
|
-
this.gameObject = gameObject;
|
|
15
|
-
}
|
|
16
|
-
syncUpdateRegistration() {
|
|
17
|
-
this.gameObject.syncUpdateRegistration();
|
|
18
|
-
}
|
|
19
|
-
on(event, fn, context) {
|
|
20
|
-
super.on(event, fn, context);
|
|
21
|
-
this.syncUpdateRegistration();
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
addListener(event, fn, context) {
|
|
25
|
-
return this.on(event, fn, context);
|
|
26
|
-
}
|
|
27
|
-
once(event, fn, context) {
|
|
28
|
-
super.once(event, fn, context);
|
|
29
|
-
this.syncUpdateRegistration();
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
off(event, fn, context, once) {
|
|
33
|
-
super.off(event, fn, context, once);
|
|
34
|
-
this.syncUpdateRegistration();
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
removeListener(event, fn, context, once) {
|
|
38
|
-
return this.off(event, fn, context, once);
|
|
39
|
-
}
|
|
40
|
-
removeAllListeners(event) {
|
|
41
|
-
super.removeAllListeners(event);
|
|
42
|
-
this.syncUpdateRegistration();
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
emit(event, ...args) {
|
|
46
|
-
const result = super.emit(event, ...args);
|
|
47
|
-
if (event === GameObject.Event.TICKER_BEFORE || event === GameObject.Event.TICKER_AFTER) {
|
|
48
|
-
this.syncUpdateRegistration();
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export class BaseGameObject {
|
|
54
|
-
refreshPivot() {
|
|
55
|
-
// console.log(Object.getPrototypeOf(this));
|
|
56
|
-
// console.log(this.width);
|
|
57
|
-
this.display.pivot.x = this.width * this.anchor.x;
|
|
58
|
-
this.display.pivot.y = this.height * this.anchor.y;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
export class GameObject extends BaseGameObject {
|
|
62
|
-
static Event = GameObjectEvent;
|
|
63
|
-
emitter = new GameObjectEmitter(this);
|
|
64
|
-
display;
|
|
65
|
-
transform = new Transform(this);
|
|
66
|
-
app;
|
|
67
|
-
parent;
|
|
68
|
-
components = [];
|
|
69
|
-
componentTickerHandlers = new Map();
|
|
70
|
-
_destroying = false;
|
|
71
|
-
get visible() {
|
|
72
|
-
return this.display.visible;
|
|
73
|
-
}
|
|
74
|
-
set visible(val) {
|
|
75
|
-
this.display.visible = val;
|
|
76
|
-
}
|
|
77
|
-
get x() {
|
|
78
|
-
return this.transform.x;
|
|
79
|
-
}
|
|
80
|
-
set x(val) {
|
|
81
|
-
this.transform.x = val;
|
|
82
|
-
}
|
|
83
|
-
get y() {
|
|
84
|
-
return this.transform.y;
|
|
85
|
-
}
|
|
86
|
-
set y(val) {
|
|
87
|
-
this.transform.y = val;
|
|
88
|
-
}
|
|
89
|
-
get scaleX() {
|
|
90
|
-
return this.transform.scaleX;
|
|
91
|
-
}
|
|
92
|
-
set scaleX(val) {
|
|
93
|
-
this.transform.scaleX = val;
|
|
94
|
-
}
|
|
95
|
-
get scaleY() {
|
|
96
|
-
return this.transform.scaleY;
|
|
97
|
-
}
|
|
98
|
-
set scaleY(val) {
|
|
99
|
-
this.transform.scaleY = val;
|
|
100
|
-
}
|
|
101
|
-
get width() {
|
|
102
|
-
return this.display.width;
|
|
103
|
-
}
|
|
104
|
-
set width(val) {
|
|
105
|
-
this.display.width = val;
|
|
106
|
-
this.refreshPivot();
|
|
107
|
-
this.emitter.emit(GameObject.Event.RESIZE);
|
|
108
|
-
}
|
|
109
|
-
get height() {
|
|
110
|
-
return this.display.height;
|
|
111
|
-
}
|
|
112
|
-
set height(val) {
|
|
113
|
-
this.display.height = val;
|
|
114
|
-
this.refreshPivot();
|
|
115
|
-
this.emitter.emit(GameObject.Event.RESIZE);
|
|
116
|
-
}
|
|
117
|
-
_anchor = new Vector2();
|
|
118
|
-
get anchor() {
|
|
119
|
-
return this._anchor;
|
|
120
|
-
}
|
|
121
|
-
set anchor(value) {
|
|
122
|
-
this.anchorX = value.x;
|
|
123
|
-
this.anchorY = value.y;
|
|
124
|
-
}
|
|
125
|
-
get anchorX() {
|
|
126
|
-
return this._anchor.x;
|
|
127
|
-
}
|
|
128
|
-
set anchorX(value) {
|
|
129
|
-
this.anchor.x = value;
|
|
130
|
-
this.refreshPivot();
|
|
131
|
-
}
|
|
132
|
-
get anchorY() {
|
|
133
|
-
return this._anchor.y;
|
|
134
|
-
}
|
|
135
|
-
set anchorY(value) {
|
|
136
|
-
this.anchor.y = value;
|
|
137
|
-
this.refreshPivot();
|
|
138
|
-
}
|
|
139
|
-
get rotation() {
|
|
140
|
-
return this.transform.rotation;
|
|
141
|
-
}
|
|
142
|
-
set rotation(val) {
|
|
143
|
-
this.transform.rotation = val;
|
|
144
|
-
}
|
|
145
|
-
get skewX() {
|
|
146
|
-
return this.transform.skewX;
|
|
147
|
-
}
|
|
148
|
-
set skewX(val) {
|
|
149
|
-
this.transform.skewX = val;
|
|
150
|
-
}
|
|
151
|
-
get skewY() {
|
|
152
|
-
return this.transform.skewY;
|
|
153
|
-
}
|
|
154
|
-
set skewY(val) {
|
|
155
|
-
this.transform.skewY = val;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* 透明度
|
|
159
|
-
*/
|
|
160
|
-
get alpha() {
|
|
161
|
-
return this.display.alpha;
|
|
162
|
-
}
|
|
163
|
-
set alpha(val) {
|
|
164
|
-
this.display.alpha = val;
|
|
165
|
-
}
|
|
166
|
-
hasUpdateWork() {
|
|
167
|
-
return !!this.update
|
|
168
|
-
|| this.emitter.listenerCount(GameObject.Event.TICKER_BEFORE) > 0
|
|
169
|
-
|| this.emitter.listenerCount(GameObject.Event.TICKER_AFTER) > 0;
|
|
170
|
-
}
|
|
171
|
-
syncUpdateRegistration() {
|
|
172
|
-
if (this._destroying || !this.app) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (this.hasUpdateWork()) {
|
|
176
|
-
this.app.registerUpdateTarget(this);
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
this.app.unregisterUpdateTarget(this);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
setApplication(app) {
|
|
183
|
-
if (this.app === app) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const previousApp = this.app;
|
|
187
|
-
this.app = app;
|
|
188
|
-
if (previousApp) {
|
|
189
|
-
previousApp.unregisterUpdateTarget(this);
|
|
190
|
-
}
|
|
191
|
-
if (hasChildren(this)) {
|
|
192
|
-
for (const child of this.children) {
|
|
193
|
-
child.setApplication(app);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (app && this.hasUpdateWork()) {
|
|
197
|
-
app.registerUpdateTarget(this);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
addComponent(component, props) {
|
|
201
|
-
const _component = new component(this);
|
|
202
|
-
this.components.push(_component);
|
|
203
|
-
props && setProps(_component, props);
|
|
204
|
-
_component.awake && _component.awake();
|
|
205
|
-
if (_component.update) {
|
|
206
|
-
let started = false;
|
|
207
|
-
const tickerHandler = (dt) => {
|
|
208
|
-
if (!started) {
|
|
209
|
-
started = true;
|
|
210
|
-
_component.start?.();
|
|
211
|
-
}
|
|
212
|
-
if (!this.components.includes(_component)) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
_component.update?.(dt);
|
|
216
|
-
};
|
|
217
|
-
this.componentTickerHandlers.set(_component, tickerHandler);
|
|
218
|
-
this.emitter.on(GameObject.Event.TICKER_BEFORE, tickerHandler, _component);
|
|
219
|
-
}
|
|
220
|
-
else if (_component.start) {
|
|
221
|
-
const tickerHandler = () => {
|
|
222
|
-
this.componentTickerHandlers.delete(_component);
|
|
223
|
-
_component.start?.();
|
|
224
|
-
};
|
|
225
|
-
this.componentTickerHandlers.set(_component, tickerHandler);
|
|
226
|
-
this.emitter.once(GameObject.Event.TICKER_BEFORE, tickerHandler, _component);
|
|
227
|
-
}
|
|
228
|
-
this.syncUpdateRegistration();
|
|
229
|
-
return _component;
|
|
230
|
-
}
|
|
231
|
-
removeComponent(component) {
|
|
232
|
-
const index = this.components.indexOf(component);
|
|
233
|
-
if (index == -1) {
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
this.components.splice(index, 1);
|
|
237
|
-
const tickerHandler = this.componentTickerHandlers.get(component);
|
|
238
|
-
if (tickerHandler) {
|
|
239
|
-
this.emitter.off(GameObject.Event.TICKER_BEFORE, tickerHandler, component);
|
|
240
|
-
this.componentTickerHandlers.delete(component);
|
|
241
|
-
}
|
|
242
|
-
component.gameObject.display.off('destroyed', component.destroy, component);
|
|
243
|
-
component.onDestroy && component.onDestroy();
|
|
244
|
-
this.syncUpdateRegistration();
|
|
245
|
-
return component;
|
|
246
|
-
}
|
|
247
|
-
getComponent(component) {
|
|
248
|
-
return this.components.find(val => val instanceof component);
|
|
249
|
-
}
|
|
250
|
-
getComponents(component) {
|
|
251
|
-
return this.components.filter(val => val instanceof component);
|
|
252
|
-
}
|
|
253
|
-
setDisplay(display) {
|
|
254
|
-
this.display = display;
|
|
255
|
-
if (this.start) {
|
|
256
|
-
if (this.display.parent) {
|
|
257
|
-
this.start.call(this);
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
this.display.once('added', this.start, this);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
this.display.once('destroyed', () => {
|
|
264
|
-
this._destroying = true;
|
|
265
|
-
this.setApplication(undefined);
|
|
266
|
-
queueMicrotask(() => {
|
|
267
|
-
this.emitter.removeAllListeners();
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
// destroy() {
|
|
272
|
-
// this.parent?.removeChild(this);
|
|
273
|
-
// this.onDestroy && this.onDestroy();
|
|
274
|
-
// }
|
|
275
|
-
static instantiate(gameObject, parent, props) {
|
|
276
|
-
const go = new gameObject();
|
|
277
|
-
props && setProps(go, props);
|
|
278
|
-
go.setDisplay(go.display);
|
|
279
|
-
go.render?.();
|
|
280
|
-
parent?.addChild(go);
|
|
281
|
-
return go;
|
|
282
|
-
}
|
|
283
|
-
static async destroy(go) {
|
|
284
|
-
go._destroying = true;
|
|
285
|
-
go.setApplication(undefined);
|
|
286
|
-
if (hasChildren(go)) {
|
|
287
|
-
for (let i = go.children.length - 1; i >= 0; i--) {
|
|
288
|
-
GameObject.destroy(go.children[i]);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
go.parent?.removeChild(go);
|
|
292
|
-
go.onDestroy && go.onDestroy();
|
|
293
|
-
go.display.destroy();
|
|
294
|
-
go.emitter.removeAllListeners();
|
|
295
|
-
go.components.length = 0;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { GameObject } from "./GameObject.js";
|
|
2
|
-
import type { Group } from "./group/index.js";
|
|
3
|
-
export declare const GameObjectEvent: {
|
|
4
|
-
/**
|
|
5
|
-
* 当添加到显示舞台时
|
|
6
|
-
*/
|
|
7
|
-
readonly ADDED: "added";
|
|
8
|
-
/**
|
|
9
|
-
* 当添加新的子节点时
|
|
10
|
-
*/
|
|
11
|
-
readonly CHILD_ADDED: "childAdded";
|
|
12
|
-
/**
|
|
13
|
-
* 移除时
|
|
14
|
-
*/
|
|
15
|
-
readonly REMOVED: "removed";
|
|
16
|
-
/**
|
|
17
|
-
* 移除子元素时
|
|
18
|
-
*/
|
|
19
|
-
readonly CHILD_REMOVED: "childRemoved";
|
|
20
|
-
/**
|
|
21
|
-
* 尺寸发生变化时
|
|
22
|
-
*/
|
|
23
|
-
readonly RESIZE: "resize";
|
|
24
|
-
/**
|
|
25
|
-
* 位置发生变化
|
|
26
|
-
*/
|
|
27
|
-
readonly REPOSITION: "reposition";
|
|
28
|
-
/**
|
|
29
|
-
* 变换发生变化
|
|
30
|
-
*/
|
|
31
|
-
readonly TRANSFORM_CHANGE: "transformChange";
|
|
32
|
-
/**
|
|
33
|
-
* 帧刷新前
|
|
34
|
-
*/
|
|
35
|
-
readonly TICKER_BEFORE: "tickerBefore";
|
|
36
|
-
/**
|
|
37
|
-
* 帧刷新后
|
|
38
|
-
*/
|
|
39
|
-
readonly TICKER_AFTER: "tickerAfter";
|
|
40
|
-
};
|
|
41
|
-
export interface GameObjectEventMap {
|
|
42
|
-
[event: string]: any[];
|
|
43
|
-
[GameObjectEvent.ADDED]: [parent: Group];
|
|
44
|
-
[GameObjectEvent.CHILD_ADDED]: [child: GameObject];
|
|
45
|
-
[GameObjectEvent.REMOVED]: [parent: Group];
|
|
46
|
-
[GameObjectEvent.CHILD_REMOVED]: [child: GameObject];
|
|
47
|
-
[GameObjectEvent.RESIZE]: [];
|
|
48
|
-
[GameObjectEvent.REPOSITION]: [];
|
|
49
|
-
[GameObjectEvent.TRANSFORM_CHANGE]: [];
|
|
50
|
-
[GameObjectEvent.TICKER_BEFORE]: [dt: number];
|
|
51
|
-
[GameObjectEvent.TICKER_AFTER]: [dt: number];
|
|
52
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export const GameObjectEvent = {
|
|
2
|
-
/**
|
|
3
|
-
* 当添加到显示舞台时
|
|
4
|
-
*/
|
|
5
|
-
ADDED: 'added',
|
|
6
|
-
/**
|
|
7
|
-
* 当添加新的子节点时
|
|
8
|
-
*/
|
|
9
|
-
CHILD_ADDED: 'childAdded',
|
|
10
|
-
/**
|
|
11
|
-
* 移除时
|
|
12
|
-
*/
|
|
13
|
-
REMOVED: 'removed',
|
|
14
|
-
/**
|
|
15
|
-
* 移除子元素时
|
|
16
|
-
*/
|
|
17
|
-
CHILD_REMOVED: 'childRemoved',
|
|
18
|
-
/**
|
|
19
|
-
* 尺寸发生变化时
|
|
20
|
-
*/
|
|
21
|
-
RESIZE: 'resize',
|
|
22
|
-
/**
|
|
23
|
-
* 位置发生变化
|
|
24
|
-
*/
|
|
25
|
-
REPOSITION: 'reposition',
|
|
26
|
-
/**
|
|
27
|
-
* 变换发生变化
|
|
28
|
-
*/
|
|
29
|
-
TRANSFORM_CHANGE: 'transformChange',
|
|
30
|
-
/**
|
|
31
|
-
* 帧刷新前
|
|
32
|
-
*/
|
|
33
|
-
TICKER_BEFORE: 'tickerBefore',
|
|
34
|
-
/**
|
|
35
|
-
* 帧刷新后
|
|
36
|
-
*/
|
|
37
|
-
TICKER_AFTER: 'tickerAfter'
|
|
38
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Vector2 } from '@math.gl/core';
|
|
2
|
-
import type { GameObject } from './GameObject.js';
|
|
3
|
-
export declare class Transform {
|
|
4
|
-
gameObject: GameObject;
|
|
5
|
-
constructor(gameObject: GameObject);
|
|
6
|
-
private _position;
|
|
7
|
-
get position(): Vector2;
|
|
8
|
-
set position(val: Vector2);
|
|
9
|
-
get x(): number;
|
|
10
|
-
set x(val: number);
|
|
11
|
-
get y(): number;
|
|
12
|
-
set y(val: number);
|
|
13
|
-
setPosition(x: number, y: number): void;
|
|
14
|
-
private emitTransformChange;
|
|
15
|
-
private _scale;
|
|
16
|
-
get scale(): Vector2;
|
|
17
|
-
set scale(val: Vector2);
|
|
18
|
-
get scaleX(): number;
|
|
19
|
-
set scaleX(val: number);
|
|
20
|
-
get scaleY(): number;
|
|
21
|
-
set scaleY(val: number);
|
|
22
|
-
get pivotX(): number;
|
|
23
|
-
set pivotX(val: number);
|
|
24
|
-
get pivotY(): number;
|
|
25
|
-
set pivotY(val: number);
|
|
26
|
-
get rotation(): number;
|
|
27
|
-
set rotation(val: number);
|
|
28
|
-
get skewX(): number;
|
|
29
|
-
set skewX(val: number);
|
|
30
|
-
get skewY(): number;
|
|
31
|
-
set skewY(val: number);
|
|
32
|
-
}
|