@combos-fun/plugin-renderer-event 0.0.1
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 -0
- package/dist/plugin-renderer-event.cjs.js +183 -0
- package/dist/plugin-renderer-event.cjs.js.map +1 -0
- package/dist/plugin-renderer-event.cjs.prod.js +1 -0
- package/dist/plugin-renderer-event.d.ts +74 -0
- package/dist/plugin-renderer-event.esm.js +180 -0
- package/dist/plugin-renderer-event.esm.js.map +1 -0
- package/index.js +7 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var pluginRenderer = require('@combos-fun/plugin-renderer');
|
|
5
|
+
var engine = require('@combos-fun/engine');
|
|
6
|
+
var pixi_js = require('pixi.js');
|
|
7
|
+
|
|
8
|
+
function pointerEventData(e, container) {
|
|
9
|
+
return {
|
|
10
|
+
pointerId: e.pointerId,
|
|
11
|
+
position: {
|
|
12
|
+
x: e.global.x,
|
|
13
|
+
y: e.global.y,
|
|
14
|
+
},
|
|
15
|
+
localPosition: e.getLocalPosition(container),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const hitAreaFunc = {
|
|
19
|
+
Circle: pixi_js.Circle,
|
|
20
|
+
Ellipse: pixi_js.Ellipse,
|
|
21
|
+
Polygon: pixi_js.Polygon,
|
|
22
|
+
Rect: pixi_js.Rectangle,
|
|
23
|
+
RoundedRect: pixi_js.RoundedRectangle,
|
|
24
|
+
};
|
|
25
|
+
const propertyForHitArea = {
|
|
26
|
+
Circle: ['x', 'y', 'radius'],
|
|
27
|
+
Ellipse: ['x', 'y', 'width', 'height'],
|
|
28
|
+
Rect: ['x', 'y', 'width', 'height'],
|
|
29
|
+
RoundedRect: ['x', 'y', 'width', 'height', 'radius'],
|
|
30
|
+
Polygon: ['paths'],
|
|
31
|
+
};
|
|
32
|
+
let EventSystem = class EventSystem extends pluginRenderer.Renderer {
|
|
33
|
+
constructor() {
|
|
34
|
+
super(...arguments);
|
|
35
|
+
this.name = 'Event';
|
|
36
|
+
}
|
|
37
|
+
static { this.systemName = 'Event'; }
|
|
38
|
+
init({ moveWhenInside = false } = {}) {
|
|
39
|
+
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
40
|
+
this.renderSystem.rendererManager.register(this);
|
|
41
|
+
const events = this.renderSystem.application?.renderer?.events;
|
|
42
|
+
if (events) {
|
|
43
|
+
events.features.globalMove = !moveWhenInside;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
componentChanged(changed) {
|
|
47
|
+
switch (changed.type) {
|
|
48
|
+
case engine.OBSERVER_TYPE.ADD:
|
|
49
|
+
this.add(changed);
|
|
50
|
+
break;
|
|
51
|
+
case engine.OBSERVER_TYPE.REMOVE:
|
|
52
|
+
this.remove(changed);
|
|
53
|
+
break;
|
|
54
|
+
case engine.OBSERVER_TYPE.CHANGE:
|
|
55
|
+
this.change(changed);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
add(changed) {
|
|
60
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
61
|
+
container.interactive = true;
|
|
62
|
+
container.interactiveChildren = true;
|
|
63
|
+
const component = changed.component;
|
|
64
|
+
if (component.hitArea) {
|
|
65
|
+
this.addHitArea(changed, container, component.hitArea);
|
|
66
|
+
}
|
|
67
|
+
container.on('pointertap', (e) => {
|
|
68
|
+
component.emit('tap', {
|
|
69
|
+
stopPropagation: () => e.stopPropagation(),
|
|
70
|
+
data: pointerEventData(e, container),
|
|
71
|
+
gameObject: component.gameObject,
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
container.on('pointerdown', (e) => {
|
|
75
|
+
component.emit('touchstart', {
|
|
76
|
+
stopPropagation: () => e.stopPropagation(),
|
|
77
|
+
data: pointerEventData(e, container),
|
|
78
|
+
gameObject: component.gameObject,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
container.on('pointermove', (e) => {
|
|
82
|
+
component.emit('touchmove', {
|
|
83
|
+
stopPropagation: () => e.stopPropagation(),
|
|
84
|
+
data: pointerEventData(e, container),
|
|
85
|
+
gameObject: component.gameObject,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
container.on('pointerup', (e) => {
|
|
89
|
+
component.emit('touchend', {
|
|
90
|
+
stopPropagation: () => e.stopPropagation(),
|
|
91
|
+
data: pointerEventData(e, container),
|
|
92
|
+
gameObject: component.gameObject,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
container.on('pointerupoutside', (e) => {
|
|
96
|
+
component.emit('touchendoutside', {
|
|
97
|
+
stopPropagation: () => e.stopPropagation(),
|
|
98
|
+
data: pointerEventData(e, container),
|
|
99
|
+
gameObject: component.gameObject,
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
container.on('pointercancel', (e) => {
|
|
103
|
+
component.emit('touchcancel', {
|
|
104
|
+
stopPropagation: () => e.stopPropagation(),
|
|
105
|
+
data: pointerEventData(e, container),
|
|
106
|
+
gameObject: component.gameObject,
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
remove(changed) {
|
|
111
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
112
|
+
container.interactive = false;
|
|
113
|
+
container.off('tap');
|
|
114
|
+
container.off('pointerdown');
|
|
115
|
+
container.off('pointermove');
|
|
116
|
+
container.off('pointerup');
|
|
117
|
+
container.off('pointerupoutside');
|
|
118
|
+
container.off('pointercancel');
|
|
119
|
+
changed.component.removeAllListeners();
|
|
120
|
+
}
|
|
121
|
+
change(changed) {
|
|
122
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
123
|
+
container.interactive = true;
|
|
124
|
+
const component = changed.component;
|
|
125
|
+
if (component.hitArea) {
|
|
126
|
+
this.addHitArea(changed, container, component.hitArea);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
component.hitArea = null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
addHitArea(changed, container, hitArea) {
|
|
133
|
+
const { type, style } = hitArea;
|
|
134
|
+
if (!hitAreaFunc[type]) {
|
|
135
|
+
console.error(`${changed.gameObject.name}'s hitArea type is not defined`);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const params = [];
|
|
139
|
+
for (const key of propertyForHitArea[type]) {
|
|
140
|
+
params.push(style[key]);
|
|
141
|
+
}
|
|
142
|
+
const hitAreaShape = new hitAreaFunc[type](...params);
|
|
143
|
+
container.hitArea = hitAreaShape;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
EventSystem = tslib.__decorate([
|
|
147
|
+
engine.decorators.componentObserver({
|
|
148
|
+
Event: [{ prop: ['hitArea'], deep: true }],
|
|
149
|
+
})
|
|
150
|
+
], EventSystem);
|
|
151
|
+
var EventSystem_default = EventSystem;
|
|
152
|
+
|
|
153
|
+
exports.HIT_AREA_TYPE = void 0;
|
|
154
|
+
(function (HIT_AREA_TYPE) {
|
|
155
|
+
HIT_AREA_TYPE["Circle"] = "Circle";
|
|
156
|
+
HIT_AREA_TYPE["Ellipse"] = "Ellipse";
|
|
157
|
+
HIT_AREA_TYPE["Polygon"] = "Polygon";
|
|
158
|
+
HIT_AREA_TYPE["Rect"] = "Rect";
|
|
159
|
+
HIT_AREA_TYPE["RoundedRect"] = "RoundedRect";
|
|
160
|
+
})(exports.HIT_AREA_TYPE || (exports.HIT_AREA_TYPE = {}));
|
|
161
|
+
class Event extends engine.Component {
|
|
162
|
+
constructor() {
|
|
163
|
+
super(...arguments);
|
|
164
|
+
this.hitArea = undefined;
|
|
165
|
+
}
|
|
166
|
+
static { this.componentName = 'Event'; }
|
|
167
|
+
init(params) {
|
|
168
|
+
params && Object.assign(this, params);
|
|
169
|
+
}
|
|
170
|
+
emit(en, ...args) {
|
|
171
|
+
return super.emit(en, ...args);
|
|
172
|
+
}
|
|
173
|
+
once(en, fn, context) {
|
|
174
|
+
return super.once(en, fn, context);
|
|
175
|
+
}
|
|
176
|
+
on(en, fn, context) {
|
|
177
|
+
return super.on(en, fn, context);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
exports.Event = Event;
|
|
182
|
+
exports.EventSystem = EventSystem_default;
|
|
183
|
+
//# sourceMappingURL=plugin-renderer-event.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-renderer-event.cjs.js","sources":["../lib/system.ts","../lib/component.ts"],"sourcesContent":["import { Renderer, RendererSystem, RendererManager, ContainerManager } from '@combos-fun/plugin-renderer';\nimport { decorators, ComponentChanged, OBSERVER_TYPE } from '@combos-fun/engine';\nimport { Circle, Ellipse, Polygon, RoundedRectangle, Rectangle } from 'pixi.js';\nimport type { Container as PixiContainer } from 'pixi.js';\nimport type { FederatedPointerEvent } from 'pixi.js';\nimport EventComponent from './component';\n\nfunction pointerEventData(e: FederatedPointerEvent, container: PixiContainer) {\n return {\n pointerId: e.pointerId,\n position: {\n x: e.global.x,\n y: e.global.y,\n },\n localPosition: e.getLocalPosition(container),\n };\n}\n\nconst hitAreaFunc = {\n Circle,\n Ellipse,\n Polygon,\n Rect: Rectangle,\n RoundedRect: RoundedRectangle,\n};\n\nconst propertyForHitArea = {\n Circle: ['x', 'y', 'radius'],\n Ellipse: ['x', 'y', 'width', 'height'],\n Rect: ['x', 'y', 'width', 'height'],\n RoundedRect: ['x', 'y', 'width', 'height', 'radius'],\n Polygon: ['paths'],\n};\n\nexport interface EventSystemParams {\n moveWhenInside?: boolean\n}\n\n@decorators.componentObserver({\n Event: [{ prop: ['hitArea'], deep: true }],\n})\nexport default class EventSystem extends Renderer<EventSystemParams> {\n static systemName = 'Event';\n name: string = 'Event';\n renderSystem: RendererSystem;\n rendererManager: RendererManager;\n containerManager: ContainerManager;\n init({ moveWhenInside = false }: EventSystemParams = {}) {\n this.renderSystem = this.game.getSystem(RendererSystem) as RendererSystem;\n this.renderSystem.rendererManager.register(this);\n const events = this.renderSystem.application?.renderer?.events;\n if (events) {\n events.features.globalMove = !moveWhenInside;\n }\n }\n componentChanged(changed: ComponentChanged) {\n switch (changed.type) {\n case OBSERVER_TYPE.ADD:\n this.add(changed);\n break;\n case OBSERVER_TYPE.REMOVE:\n this.remove(changed);\n break;\n case OBSERVER_TYPE.CHANGE:\n this.change(changed);\n break;\n }\n }\n add(changed: ComponentChanged) {\n const container = this.containerManager.getContainer(changed.gameObject.id);\n container.interactive = true;\n container.interactiveChildren = true;\n const component = changed.component as EventComponent;\n\n if (component.hitArea) {\n this.addHitArea(changed, container, component.hitArea);\n }\n\n container.on('pointertap', (e: FederatedPointerEvent) => {\n component.emit('tap', {\n stopPropagation: () => e.stopPropagation(),\n data: pointerEventData(e, container),\n gameObject: component.gameObject,\n });\n });\n container.on('pointerdown', (e: FederatedPointerEvent) => {\n component.emit('touchstart', {\n stopPropagation: () => e.stopPropagation(),\n data: pointerEventData(e, container),\n gameObject: component.gameObject,\n });\n });\n container.on('pointermove', (e: FederatedPointerEvent) => {\n component.emit('touchmove', {\n stopPropagation: () => e.stopPropagation(),\n data: pointerEventData(e, container),\n gameObject: component.gameObject,\n });\n });\n container.on('pointerup', (e: FederatedPointerEvent) => {\n component.emit('touchend', {\n stopPropagation: () => e.stopPropagation(),\n data: pointerEventData(e, container),\n gameObject: component.gameObject,\n });\n });\n container.on('pointerupoutside', (e: FederatedPointerEvent) => {\n component.emit('touchendoutside', {\n stopPropagation: () => e.stopPropagation(),\n data: pointerEventData(e, container),\n gameObject: component.gameObject,\n });\n });\n container.on('pointercancel', (e: FederatedPointerEvent) => {\n component.emit('touchcancel', {\n stopPropagation: () => e.stopPropagation(),\n data: pointerEventData(e, container),\n gameObject: component.gameObject,\n });\n });\n }\n remove(changed: ComponentChanged) {\n const container = this.containerManager.getContainer(changed.gameObject.id);\n container.interactive = false;\n container.off('tap');\n container.off('pointerdown');\n container.off('pointermove');\n container.off('pointerup');\n container.off('pointerupoutside');\n container.off('pointercancel');\n changed.component.removeAllListeners();\n }\n change(changed: ComponentChanged) {\n const container = this.containerManager.getContainer(changed.gameObject.id);\n container.interactive = true;\n const component = changed.component as EventComponent;\n\n if (component.hitArea) {\n this.addHitArea(changed, container, component.hitArea);\n } else {\n component.hitArea = null;\n }\n }\n addHitArea(changed: ComponentChanged, container, hitArea) {\n const { type, style } = hitArea;\n if (!hitAreaFunc[type]) {\n console.error(`${changed.gameObject.name}'s hitArea type is not defined`);\n return;\n }\n const params = [];\n for (const key of propertyForHitArea[type]) {\n params.push(style[key]);\n }\n const hitAreaShape = new hitAreaFunc[type](...params);\n container.hitArea = hitAreaShape;\n }\n}\n","import { Component } from '@combos-fun/engine';\nimport type { GameObject } from \"@combos-fun/engine\";\n\nexport enum HIT_AREA_TYPE {\n Circle = 'Circle',\n Ellipse = 'Ellipse',\n Polygon = 'Polygon',\n Rect = 'Rect',\n RoundedRect = 'RoundedRect',\n}\n\ninterface HitArea {\n type: HIT_AREA_TYPE;\n style?: {\n x?: number;\n y?: number;\n radius?: number;\n width?: number;\n height?: number;\n paths?: number[];\n };\n}\n\nexport interface EventParams {\n hitArea: HitArea;\n}\n\ntype TouchEventName = 'touchstart' | 'touchmove' | 'touchend' | 'tap' | 'touchendoutside' | 'touchcancel';\ntype EventParam = {\n stopPropagation: () => void,\n data: {\n pointerId: number,\n position: {\n x: number,\n y: number,\n },\n /**\n * The position related to event target gameobject\n */\n localPosition: {\n x: number,\n y: number\n }\n },\n gameObject: GameObject,\n}\n\nexport default class Event extends Component<EventParams> {\n static componentName = 'Event';\n hitArea: HitArea = undefined;\n init(params?: EventParams) {\n params && Object.assign(this, params);\n }\n\n emit(eventName: TouchEventName, ...args: [EventParam]): boolean\n emit<T extends string>(eventName: Exclude<T, TouchEventName>, ...args: any[]): boolean\n emit(en: string, ...args: any[]) {\n return super.emit(en, ...args);\n }\n\n once(eventName: TouchEventName, fn: (arg: EventParam) => void, context?: any): this\n once<T extends string>(eventName: Exclude<T, TouchEventName>, fn: (...args: any[]) => void, context?: any): this\n once(en: string, fn: (...args: any[]) => void, context?: any) {\n return super.once(en, fn, context);\n }\n\n on(eventName: TouchEventName, fn: (arg: EventParam) => void, context?: any): this\n on<T extends string>(eventName: Exclude<T, TouchEventName>, fn: (...args: any[]) => void, context?: any): this\n on(en: string, fn: (...args: any[]) => void, context?: any) {\n return super.on(en, fn, context);\n }\n\n}\n"],"names":["Circle","Ellipse","Polygon","Rectangle","RoundedRectangle","Renderer","RendererSystem","OBSERVER_TYPE","__decorate","decorators","HIT_AREA_TYPE","Component"],"mappings":";;;;;;;AAOA,SAAS,gBAAgB,CAAC,CAAwB,EAAE,SAAwB,EAAA;IAC1E,OAAO;QACL,SAAS,EAAE,CAAC,CAAC,SAAS;AACtB,QAAA,QAAQ,EAAE;AACR,YAAA,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;AACb,YAAA,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;AACd,SAAA;AACD,QAAA,aAAa,EAAE,CAAC,CAAC,gBAAgB,CAAC,SAAS,CAAC;KAC7C;AACH;AAEA,MAAM,WAAW,GAAG;YAClBA,cAAM;aACNC,eAAO;aACPC,eAAO;AACP,IAAA,IAAI,EAAEC,iBAAS;AACf,IAAA,WAAW,EAAEC,wBAAgB;CAC9B;AAED,MAAM,kBAAkB,GAAG;AACzB,IAAA,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC;IAC5B,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC;IACtC,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC;IACnC,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC;IACpD,OAAO,EAAE,CAAC,OAAO,CAAC;CACnB;A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BAnHoB,WAAW;;ACtCpBC;AAAZ,CAAA,UAAY,aAAa,EAAA;AACvB,IAAA,aAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACjB,IAAA,aAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,aAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,aAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,aAAA,CAAA,aAAA,CAAA,GAAA,aAA2B;AAC7B,CAAC,EANWA,qBAAa,KAAbA,qBAAa,GAAA,EAAA,CAAA,CAAA;AA4CX,MAAO,KAAM,SAAQC,gBAAsB,CAAA;AAAzD,IAAA,WAAA,GAAA;;QAEE,IAAA,CAAA,OAAO,GAAY,SAAS;IAuB9B;aAxBS,IAAA,CAAA,aAAa,GAAG,OAAH,CAAW;AAE/B,IAAA,IAAI,CAAC,MAAoB,EAAA;QACvB,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC;IACvC;AAIA,IAAA,IAAI,CAAC,EAAU,EAAE,GAAG,IAAW,EAAA;QAC7B,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC;IAChC;AAIA,IAAA,IAAI,CAAC,EAAU,EAAE,EAA4B,EAAE,OAAa,EAAA;QAC1D,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC;IACpC;AAIA,IAAA,EAAE,CAAC,EAAU,EAAE,EAA4B,EAAE,OAAa,EAAA;QACxD,OAAO,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC;IAClC;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("tslib"),t=require("@combos-fun/plugin-renderer"),o=require("@combos-fun/engine"),n=require("pixi.js");function i(e,t){return{pointerId:e.pointerId,position:{x:e.global.x,y:e.global.y},localPosition:e.getLocalPosition(t)}}const r={Circle:n.Circle,Ellipse:n.Ellipse,Polygon:n.Polygon,Rect:n.Rectangle,RoundedRect:n.RoundedRectangle},a={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]};let s=class extends t.Renderer{constructor(){super(...arguments),this.name="Event"}static{this.systemName="Event"}init({moveWhenInside:e=!1}={}){this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this);const o=this.renderSystem.application?.renderer?.events;o&&(o.features.globalMove=!e)}componentChanged(e){switch(e.type){case o.OBSERVER_TYPE.ADD:this.add(e);break;case o.OBSERVER_TYPE.REMOVE:this.remove(e);break;case o.OBSERVER_TYPE.CHANGE:this.change(e)}}add(e){const t=this.containerManager.getContainer(e.gameObject.id);t.interactive=!0,t.interactiveChildren=!0;const o=e.component;o.hitArea&&this.addHitArea(e,t,o.hitArea),t.on("pointertap",e=>{o.emit("tap",{stopPropagation:()=>e.stopPropagation(),data:i(e,t),gameObject:o.gameObject})}),t.on("pointerdown",e=>{o.emit("touchstart",{stopPropagation:()=>e.stopPropagation(),data:i(e,t),gameObject:o.gameObject})}),t.on("pointermove",e=>{o.emit("touchmove",{stopPropagation:()=>e.stopPropagation(),data:i(e,t),gameObject:o.gameObject})}),t.on("pointerup",e=>{o.emit("touchend",{stopPropagation:()=>e.stopPropagation(),data:i(e,t),gameObject:o.gameObject})}),t.on("pointerupoutside",e=>{o.emit("touchendoutside",{stopPropagation:()=>e.stopPropagation(),data:i(e,t),gameObject:o.gameObject})}),t.on("pointercancel",e=>{o.emit("touchcancel",{stopPropagation:()=>e.stopPropagation(),data:i(e,t),gameObject:o.gameObject})})}remove(e){const t=this.containerManager.getContainer(e.gameObject.id);t.interactive=!1,t.off("tap"),t.off("pointerdown"),t.off("pointermove"),t.off("pointerup"),t.off("pointerupoutside"),t.off("pointercancel"),e.component.removeAllListeners()}change(e){const t=this.containerManager.getContainer(e.gameObject.id);t.interactive=!0;const o=e.component;o.hitArea?this.addHitArea(e,t,o.hitArea):o.hitArea=null}addHitArea(e,t,o){const{type:n,style:i}=o;if(!r[n])return void console.error(`${e.gameObject.name}'s hitArea type is not defined`);const s=[];for(const e of a[n])s.push(i[e]);const c=new r[n](...s);t.hitArea=c}};s=e.__decorate([o.decorators.componentObserver({Event:[{prop:["hitArea"],deep:!0}]})],s);var c,p=s;exports.HIT_AREA_TYPE=void 0,(c=exports.HIT_AREA_TYPE||(exports.HIT_AREA_TYPE={})).Circle="Circle",c.Ellipse="Ellipse",c.Polygon="Polygon",c.Rect="Rect",c.RoundedRect="RoundedRect";class d extends o.Component{constructor(){super(...arguments),this.hitArea=void 0}static{this.componentName="Event"}init(e){e&&Object.assign(this,e)}emit(e,...t){return super.emit(e,...t)}once(e,t,o){return super.once(e,t,o)}on(e,t,o){return super.on(e,t,o)}}exports.Event=d,exports.EventSystem=p;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Renderer, RendererSystem, RendererManager, ContainerManager } from '@combos-fun/plugin-renderer';
|
|
2
|
+
import { ComponentChanged, Component, GameObject } from '@combos-fun/engine';
|
|
3
|
+
|
|
4
|
+
interface EventSystemParams {
|
|
5
|
+
moveWhenInside?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare class EventSystem extends Renderer<EventSystemParams> {
|
|
8
|
+
static systemName: string;
|
|
9
|
+
name: string;
|
|
10
|
+
renderSystem: RendererSystem;
|
|
11
|
+
rendererManager: RendererManager;
|
|
12
|
+
containerManager: ContainerManager;
|
|
13
|
+
init({ moveWhenInside }?: EventSystemParams): void;
|
|
14
|
+
componentChanged(changed: ComponentChanged): void;
|
|
15
|
+
add(changed: ComponentChanged): void;
|
|
16
|
+
remove(changed: ComponentChanged): void;
|
|
17
|
+
change(changed: ComponentChanged): void;
|
|
18
|
+
addHitArea(changed: ComponentChanged, container: any, hitArea: any): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare enum HIT_AREA_TYPE {
|
|
22
|
+
Circle = "Circle",
|
|
23
|
+
Ellipse = "Ellipse",
|
|
24
|
+
Polygon = "Polygon",
|
|
25
|
+
Rect = "Rect",
|
|
26
|
+
RoundedRect = "RoundedRect"
|
|
27
|
+
}
|
|
28
|
+
interface HitArea {
|
|
29
|
+
type: HIT_AREA_TYPE;
|
|
30
|
+
style?: {
|
|
31
|
+
x?: number;
|
|
32
|
+
y?: number;
|
|
33
|
+
radius?: number;
|
|
34
|
+
width?: number;
|
|
35
|
+
height?: number;
|
|
36
|
+
paths?: number[];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
interface EventParams {
|
|
40
|
+
hitArea: HitArea;
|
|
41
|
+
}
|
|
42
|
+
type TouchEventName = 'touchstart' | 'touchmove' | 'touchend' | 'tap' | 'touchendoutside' | 'touchcancel';
|
|
43
|
+
type EventParam = {
|
|
44
|
+
stopPropagation: () => void;
|
|
45
|
+
data: {
|
|
46
|
+
pointerId: number;
|
|
47
|
+
position: {
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The position related to event target gameobject
|
|
53
|
+
*/
|
|
54
|
+
localPosition: {
|
|
55
|
+
x: number;
|
|
56
|
+
y: number;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
gameObject: GameObject;
|
|
60
|
+
};
|
|
61
|
+
declare class Event extends Component<EventParams> {
|
|
62
|
+
static componentName: string;
|
|
63
|
+
hitArea: HitArea;
|
|
64
|
+
init(params?: EventParams): void;
|
|
65
|
+
emit(eventName: TouchEventName, ...args: [EventParam]): boolean;
|
|
66
|
+
emit<T extends string>(eventName: Exclude<T, TouchEventName>, ...args: any[]): boolean;
|
|
67
|
+
once(eventName: TouchEventName, fn: (arg: EventParam) => void, context?: any): this;
|
|
68
|
+
once<T extends string>(eventName: Exclude<T, TouchEventName>, fn: (...args: any[]) => void, context?: any): this;
|
|
69
|
+
on(eventName: TouchEventName, fn: (arg: EventParam) => void, context?: any): this;
|
|
70
|
+
on<T extends string>(eventName: Exclude<T, TouchEventName>, fn: (...args: any[]) => void, context?: any): this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { Event, EventSystem, HIT_AREA_TYPE };
|
|
74
|
+
export type { EventParams, EventSystemParams };
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { Renderer, RendererSystem } from '@combos-fun/plugin-renderer';
|
|
3
|
+
import { OBSERVER_TYPE, decorators, Component } from '@combos-fun/engine';
|
|
4
|
+
import { RoundedRectangle, Rectangle, Polygon, Ellipse, Circle } from 'pixi.js';
|
|
5
|
+
|
|
6
|
+
function pointerEventData(e, container) {
|
|
7
|
+
return {
|
|
8
|
+
pointerId: e.pointerId,
|
|
9
|
+
position: {
|
|
10
|
+
x: e.global.x,
|
|
11
|
+
y: e.global.y,
|
|
12
|
+
},
|
|
13
|
+
localPosition: e.getLocalPosition(container),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const hitAreaFunc = {
|
|
17
|
+
Circle,
|
|
18
|
+
Ellipse,
|
|
19
|
+
Polygon,
|
|
20
|
+
Rect: Rectangle,
|
|
21
|
+
RoundedRect: RoundedRectangle,
|
|
22
|
+
};
|
|
23
|
+
const propertyForHitArea = {
|
|
24
|
+
Circle: ['x', 'y', 'radius'],
|
|
25
|
+
Ellipse: ['x', 'y', 'width', 'height'],
|
|
26
|
+
Rect: ['x', 'y', 'width', 'height'],
|
|
27
|
+
RoundedRect: ['x', 'y', 'width', 'height', 'radius'],
|
|
28
|
+
Polygon: ['paths'],
|
|
29
|
+
};
|
|
30
|
+
let EventSystem = class EventSystem extends Renderer {
|
|
31
|
+
constructor() {
|
|
32
|
+
super(...arguments);
|
|
33
|
+
this.name = 'Event';
|
|
34
|
+
}
|
|
35
|
+
static { this.systemName = 'Event'; }
|
|
36
|
+
init({ moveWhenInside = false } = {}) {
|
|
37
|
+
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
38
|
+
this.renderSystem.rendererManager.register(this);
|
|
39
|
+
const events = this.renderSystem.application?.renderer?.events;
|
|
40
|
+
if (events) {
|
|
41
|
+
events.features.globalMove = !moveWhenInside;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
componentChanged(changed) {
|
|
45
|
+
switch (changed.type) {
|
|
46
|
+
case OBSERVER_TYPE.ADD:
|
|
47
|
+
this.add(changed);
|
|
48
|
+
break;
|
|
49
|
+
case OBSERVER_TYPE.REMOVE:
|
|
50
|
+
this.remove(changed);
|
|
51
|
+
break;
|
|
52
|
+
case OBSERVER_TYPE.CHANGE:
|
|
53
|
+
this.change(changed);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
add(changed) {
|
|
58
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
59
|
+
container.interactive = true;
|
|
60
|
+
container.interactiveChildren = true;
|
|
61
|
+
const component = changed.component;
|
|
62
|
+
if (component.hitArea) {
|
|
63
|
+
this.addHitArea(changed, container, component.hitArea);
|
|
64
|
+
}
|
|
65
|
+
container.on('pointertap', (e) => {
|
|
66
|
+
component.emit('tap', {
|
|
67
|
+
stopPropagation: () => e.stopPropagation(),
|
|
68
|
+
data: pointerEventData(e, container),
|
|
69
|
+
gameObject: component.gameObject,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
container.on('pointerdown', (e) => {
|
|
73
|
+
component.emit('touchstart', {
|
|
74
|
+
stopPropagation: () => e.stopPropagation(),
|
|
75
|
+
data: pointerEventData(e, container),
|
|
76
|
+
gameObject: component.gameObject,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
container.on('pointermove', (e) => {
|
|
80
|
+
component.emit('touchmove', {
|
|
81
|
+
stopPropagation: () => e.stopPropagation(),
|
|
82
|
+
data: pointerEventData(e, container),
|
|
83
|
+
gameObject: component.gameObject,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
container.on('pointerup', (e) => {
|
|
87
|
+
component.emit('touchend', {
|
|
88
|
+
stopPropagation: () => e.stopPropagation(),
|
|
89
|
+
data: pointerEventData(e, container),
|
|
90
|
+
gameObject: component.gameObject,
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
container.on('pointerupoutside', (e) => {
|
|
94
|
+
component.emit('touchendoutside', {
|
|
95
|
+
stopPropagation: () => e.stopPropagation(),
|
|
96
|
+
data: pointerEventData(e, container),
|
|
97
|
+
gameObject: component.gameObject,
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
container.on('pointercancel', (e) => {
|
|
101
|
+
component.emit('touchcancel', {
|
|
102
|
+
stopPropagation: () => e.stopPropagation(),
|
|
103
|
+
data: pointerEventData(e, container),
|
|
104
|
+
gameObject: component.gameObject,
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
remove(changed) {
|
|
109
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
110
|
+
container.interactive = false;
|
|
111
|
+
container.off('tap');
|
|
112
|
+
container.off('pointerdown');
|
|
113
|
+
container.off('pointermove');
|
|
114
|
+
container.off('pointerup');
|
|
115
|
+
container.off('pointerupoutside');
|
|
116
|
+
container.off('pointercancel');
|
|
117
|
+
changed.component.removeAllListeners();
|
|
118
|
+
}
|
|
119
|
+
change(changed) {
|
|
120
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
121
|
+
container.interactive = true;
|
|
122
|
+
const component = changed.component;
|
|
123
|
+
if (component.hitArea) {
|
|
124
|
+
this.addHitArea(changed, container, component.hitArea);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
component.hitArea = null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
addHitArea(changed, container, hitArea) {
|
|
131
|
+
const { type, style } = hitArea;
|
|
132
|
+
if (!hitAreaFunc[type]) {
|
|
133
|
+
console.error(`${changed.gameObject.name}'s hitArea type is not defined`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const params = [];
|
|
137
|
+
for (const key of propertyForHitArea[type]) {
|
|
138
|
+
params.push(style[key]);
|
|
139
|
+
}
|
|
140
|
+
const hitAreaShape = new hitAreaFunc[type](...params);
|
|
141
|
+
container.hitArea = hitAreaShape;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
EventSystem = __decorate([
|
|
145
|
+
decorators.componentObserver({
|
|
146
|
+
Event: [{ prop: ['hitArea'], deep: true }],
|
|
147
|
+
})
|
|
148
|
+
], EventSystem);
|
|
149
|
+
var EventSystem_default = EventSystem;
|
|
150
|
+
|
|
151
|
+
var HIT_AREA_TYPE;
|
|
152
|
+
(function (HIT_AREA_TYPE) {
|
|
153
|
+
HIT_AREA_TYPE["Circle"] = "Circle";
|
|
154
|
+
HIT_AREA_TYPE["Ellipse"] = "Ellipse";
|
|
155
|
+
HIT_AREA_TYPE["Polygon"] = "Polygon";
|
|
156
|
+
HIT_AREA_TYPE["Rect"] = "Rect";
|
|
157
|
+
HIT_AREA_TYPE["RoundedRect"] = "RoundedRect";
|
|
158
|
+
})(HIT_AREA_TYPE || (HIT_AREA_TYPE = {}));
|
|
159
|
+
class Event extends Component {
|
|
160
|
+
constructor() {
|
|
161
|
+
super(...arguments);
|
|
162
|
+
this.hitArea = undefined;
|
|
163
|
+
}
|
|
164
|
+
static { this.componentName = 'Event'; }
|
|
165
|
+
init(params) {
|
|
166
|
+
params && Object.assign(this, params);
|
|
167
|
+
}
|
|
168
|
+
emit(en, ...args) {
|
|
169
|
+
return super.emit(en, ...args);
|
|
170
|
+
}
|
|
171
|
+
once(en, fn, context) {
|
|
172
|
+
return super.once(en, fn, context);
|
|
173
|
+
}
|
|
174
|
+
on(en, fn, context) {
|
|
175
|
+
return super.on(en, fn, context);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { Event, EventSystem_default as EventSystem, HIT_AREA_TYPE };
|
|
180
|
+
//# sourceMappingURL=plugin-renderer-event.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-renderer-event.esm.js","sources":["../lib/system.ts","../lib/component.ts"],"sourcesContent":["import { Renderer, RendererSystem, RendererManager, ContainerManager } from '@combos-fun/plugin-renderer';\nimport { decorators, ComponentChanged, OBSERVER_TYPE } from '@combos-fun/engine';\nimport { Circle, Ellipse, Polygon, RoundedRectangle, Rectangle } from 'pixi.js';\nimport type { Container as PixiContainer } from 'pixi.js';\nimport type { FederatedPointerEvent } from 'pixi.js';\nimport EventComponent from './component';\n\nfunction pointerEventData(e: FederatedPointerEvent, container: PixiContainer) {\n return {\n pointerId: e.pointerId,\n position: {\n x: e.global.x,\n y: e.global.y,\n },\n localPosition: e.getLocalPosition(container),\n };\n}\n\nconst hitAreaFunc = {\n Circle,\n Ellipse,\n Polygon,\n Rect: Rectangle,\n RoundedRect: RoundedRectangle,\n};\n\nconst propertyForHitArea = {\n Circle: ['x', 'y', 'radius'],\n Ellipse: ['x', 'y', 'width', 'height'],\n Rect: ['x', 'y', 'width', 'height'],\n RoundedRect: ['x', 'y', 'width', 'height', 'radius'],\n Polygon: ['paths'],\n};\n\nexport interface EventSystemParams {\n moveWhenInside?: boolean\n}\n\n@decorators.componentObserver({\n Event: [{ prop: ['hitArea'], deep: true }],\n})\nexport default class EventSystem extends Renderer<EventSystemParams> {\n static systemName = 'Event';\n name: string = 'Event';\n renderSystem: RendererSystem;\n rendererManager: RendererManager;\n containerManager: ContainerManager;\n init({ moveWhenInside = false }: EventSystemParams = {}) {\n this.renderSystem = this.game.getSystem(RendererSystem) as RendererSystem;\n this.renderSystem.rendererManager.register(this);\n const events = this.renderSystem.application?.renderer?.events;\n if (events) {\n events.features.globalMove = !moveWhenInside;\n }\n }\n componentChanged(changed: ComponentChanged) {\n switch (changed.type) {\n case OBSERVER_TYPE.ADD:\n this.add(changed);\n break;\n case OBSERVER_TYPE.REMOVE:\n this.remove(changed);\n break;\n case OBSERVER_TYPE.CHANGE:\n this.change(changed);\n break;\n }\n }\n add(changed: ComponentChanged) {\n const container = this.containerManager.getContainer(changed.gameObject.id);\n container.interactive = true;\n container.interactiveChildren = true;\n const component = changed.component as EventComponent;\n\n if (component.hitArea) {\n this.addHitArea(changed, container, component.hitArea);\n }\n\n container.on('pointertap', (e: FederatedPointerEvent) => {\n component.emit('tap', {\n stopPropagation: () => e.stopPropagation(),\n data: pointerEventData(e, container),\n gameObject: component.gameObject,\n });\n });\n container.on('pointerdown', (e: FederatedPointerEvent) => {\n component.emit('touchstart', {\n stopPropagation: () => e.stopPropagation(),\n data: pointerEventData(e, container),\n gameObject: component.gameObject,\n });\n });\n container.on('pointermove', (e: FederatedPointerEvent) => {\n component.emit('touchmove', {\n stopPropagation: () => e.stopPropagation(),\n data: pointerEventData(e, container),\n gameObject: component.gameObject,\n });\n });\n container.on('pointerup', (e: FederatedPointerEvent) => {\n component.emit('touchend', {\n stopPropagation: () => e.stopPropagation(),\n data: pointerEventData(e, container),\n gameObject: component.gameObject,\n });\n });\n container.on('pointerupoutside', (e: FederatedPointerEvent) => {\n component.emit('touchendoutside', {\n stopPropagation: () => e.stopPropagation(),\n data: pointerEventData(e, container),\n gameObject: component.gameObject,\n });\n });\n container.on('pointercancel', (e: FederatedPointerEvent) => {\n component.emit('touchcancel', {\n stopPropagation: () => e.stopPropagation(),\n data: pointerEventData(e, container),\n gameObject: component.gameObject,\n });\n });\n }\n remove(changed: ComponentChanged) {\n const container = this.containerManager.getContainer(changed.gameObject.id);\n container.interactive = false;\n container.off('tap');\n container.off('pointerdown');\n container.off('pointermove');\n container.off('pointerup');\n container.off('pointerupoutside');\n container.off('pointercancel');\n changed.component.removeAllListeners();\n }\n change(changed: ComponentChanged) {\n const container = this.containerManager.getContainer(changed.gameObject.id);\n container.interactive = true;\n const component = changed.component as EventComponent;\n\n if (component.hitArea) {\n this.addHitArea(changed, container, component.hitArea);\n } else {\n component.hitArea = null;\n }\n }\n addHitArea(changed: ComponentChanged, container, hitArea) {\n const { type, style } = hitArea;\n if (!hitAreaFunc[type]) {\n console.error(`${changed.gameObject.name}'s hitArea type is not defined`);\n return;\n }\n const params = [];\n for (const key of propertyForHitArea[type]) {\n params.push(style[key]);\n }\n const hitAreaShape = new hitAreaFunc[type](...params);\n container.hitArea = hitAreaShape;\n }\n}\n","import { Component } from '@combos-fun/engine';\nimport type { GameObject } from \"@combos-fun/engine\";\n\nexport enum HIT_AREA_TYPE {\n Circle = 'Circle',\n Ellipse = 'Ellipse',\n Polygon = 'Polygon',\n Rect = 'Rect',\n RoundedRect = 'RoundedRect',\n}\n\ninterface HitArea {\n type: HIT_AREA_TYPE;\n style?: {\n x?: number;\n y?: number;\n radius?: number;\n width?: number;\n height?: number;\n paths?: number[];\n };\n}\n\nexport interface EventParams {\n hitArea: HitArea;\n}\n\ntype TouchEventName = 'touchstart' | 'touchmove' | 'touchend' | 'tap' | 'touchendoutside' | 'touchcancel';\ntype EventParam = {\n stopPropagation: () => void,\n data: {\n pointerId: number,\n position: {\n x: number,\n y: number,\n },\n /**\n * The position related to event target gameobject\n */\n localPosition: {\n x: number,\n y: number\n }\n },\n gameObject: GameObject,\n}\n\nexport default class Event extends Component<EventParams> {\n static componentName = 'Event';\n hitArea: HitArea = undefined;\n init(params?: EventParams) {\n params && Object.assign(this, params);\n }\n\n emit(eventName: TouchEventName, ...args: [EventParam]): boolean\n emit<T extends string>(eventName: Exclude<T, TouchEventName>, ...args: any[]): boolean\n emit(en: string, ...args: any[]) {\n return super.emit(en, ...args);\n }\n\n once(eventName: TouchEventName, fn: (arg: EventParam) => void, context?: any): this\n once<T extends string>(eventName: Exclude<T, TouchEventName>, fn: (...args: any[]) => void, context?: any): this\n once(en: string, fn: (...args: any[]) => void, context?: any) {\n return super.once(en, fn, context);\n }\n\n on(eventName: TouchEventName, fn: (arg: EventParam) => void, context?: any): this\n on<T extends string>(eventName: Exclude<T, TouchEventName>, fn: (...args: any[]) => void, context?: any): this\n on(en: string, fn: (...args: any[]) => void, context?: any) {\n return super.on(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CAAA;AAAzD,IAAA,WAAA,GAAA;;QAEE,IAAA,CAAA,OAAO,GAAY,SAAS;IAuB9B;aAxBS,IAAA,CAAA,aAAa,GAAG,OAAH,CAAW;AAE/B,IAAA,IAAI,CAAC,MAAoB,EAAA;QACvB,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC;IACvC;AAIA,IAAA,IAAI,CAAC,EAAU,EAAE,GAAG,IAAW,EAAA;QAC7B,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC;IAChC;AAIA,IAAA,IAAI,CAAC,EAAU,EAAE,EAA4B,EAAE,OAAa,EAAA;QAC1D,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC;IACpC;AAIA,IAAA,EAAE,CAAC,EAAU,EAAE,EAA4B,EAAE,OAAa,EAAA;QACxD,OAAO,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC;IAClC;;;;;"}
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@combos-fun/plugin-renderer-event",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "@combos-fun/plugin-renderer-event",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"module": "dist/plugin-renderer-event.esm.js",
|
|
7
|
+
"bundle": "CombosFun.plugin.renderer.event",
|
|
8
|
+
"unpkg": "dist/CombosFun.plugin.renderer.event.min.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js",
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"types": "dist/plugin-renderer-event.d.ts",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"combos-fun",
|
|
16
|
+
"game"
|
|
17
|
+
],
|
|
18
|
+
"author": "sun668 <q947692259@gmail.com>",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"pixi.js": "^8.18.1",
|
|
21
|
+
"@combos-fun/engine": "0.0.1",
|
|
22
|
+
"@combos-fun/plugin-renderer": "0.0.1"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "node ../../scripts/build-package.mjs"
|
|
26
|
+
}
|
|
27
|
+
}
|