@safe-engine/cocos 2.4.1 → 2.4.3
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/dist/chipmunk/PhysicsSystem.js +1 -1
- package/dist/core/EnhancedComponent.d.ts.map +1 -1
- package/dist/core/EnhancedComponent.js +1 -1
- package/dist/core/Scene.d.ts.map +1 -1
- package/dist/core/Scene.js +1 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/dragonbones/PixiDragonBonesSprite.d.ts +19 -0
- package/dist/dragonbones/PixiDragonBonesSprite.d.ts.map +1 -0
- package/dist/dragonbones/PixiDragonBonesSprite.js +75 -0
- package/dist/gworld/EnhancedComponent.d.ts +22 -0
- package/dist/gworld/EnhancedComponent.d.ts.map +1 -0
- package/dist/gworld/EnhancedComponent.js +44 -0
- package/dist/gworld/NodeComp.d.ts +153 -0
- package/dist/gworld/NodeComp.d.ts.map +1 -0
- package/dist/gworld/NodeComp.js +337 -0
- package/dist/gworld/NodePool.d.ts +9 -0
- package/dist/gworld/NodePool.d.ts.map +1 -0
- package/dist/gworld/NodePool.js +23 -0
- package/dist/gworld/Scene.d.ts +5 -0
- package/dist/gworld/Scene.d.ts.map +1 -0
- package/dist/gworld/Scene.js +14 -0
- package/dist/gworld/decorator.d.ts +8 -0
- package/dist/gworld/decorator.d.ts.map +1 -0
- package/dist/gworld/decorator.js +12 -0
- package/dist/gworld/index.d.ts +8 -0
- package/dist/gworld/index.d.ts.map +1 -0
- package/dist/gworld/index.js +14 -0
- package/dist/render/RenderSystem.d.ts.map +1 -1
- package/dist/render/RenderSystem.js +1 -35
- package/dist/render/TiledSprite.d.ts +12 -0
- package/dist/render/TiledSprite.d.ts.map +1 -0
- package/dist/render/TiledSprite.js +83 -0
- package/dist/render/shader.d.ts +3 -0
- package/dist/render/shader.d.ts.map +1 -0
- package/dist/render/shader.js +52 -0
- package/dist/safex.d.ts +10 -0
- package/dist/safex.d.ts.map +1 -0
- package/dist/safex.js +1 -0
- package/dist/spine/CCSkeleton.d.ts +189 -0
- package/dist/spine/CCSkeleton.d.ts.map +1 -0
- package/dist/spine/CCSkeleton.js +320 -0
- package/dist/spine/CCSkeletonAnimation.d.ts +146 -0
- package/dist/spine/CCSkeletonAnimation.d.ts.map +1 -0
- package/dist/spine/CCSkeletonAnimation.js +311 -0
- package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts +2 -0
- package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts.map +1 -0
- package/dist/spine/CCSkeletonCanvasRenderCmd.js +228 -0
- package/dist/spine/CCSkeletonTexture.d.ts +25 -0
- package/dist/spine/CCSkeletonTexture.d.ts.map +1 -0
- package/dist/spine/CCSkeletonTexture.js +60 -0
- package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts +28 -0
- package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts.map +1 -0
- package/dist/spine/CCSkeletonWebGLRenderCmd.js +277 -0
- package/dist/spine/PixiSpineSprite.d.ts +19 -0
- package/dist/spine/PixiSpineSprite.d.ts.map +1 -0
- package/dist/spine/PixiSpineSprite.js +72 -0
- package/dist/spine/spine-cocos/CCSkeleton.d.ts +0 -1
- package/dist/spine/spine-cocos/CCSkeleton.d.ts.map +1 -1
- package/dist/spine/spine-cocos/CCSkeleton.js +0 -1
- package/package.json +3 -3
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { instantiate } from '../helper/utils';
|
|
2
|
+
import { ExtraDataComp } from '../norender';
|
|
3
|
+
import { Vec2 } from '../polyfills';
|
|
4
|
+
export class NodeComp {
|
|
5
|
+
entity;
|
|
6
|
+
instance;
|
|
7
|
+
parent;
|
|
8
|
+
children = [];
|
|
9
|
+
name;
|
|
10
|
+
_group;
|
|
11
|
+
_active = true;
|
|
12
|
+
constructor(instance, entity) {
|
|
13
|
+
this.entity = entity;
|
|
14
|
+
this.instance = instance;
|
|
15
|
+
}
|
|
16
|
+
get uuid() {
|
|
17
|
+
return this.entity.id;
|
|
18
|
+
}
|
|
19
|
+
get position() {
|
|
20
|
+
return Vec2(this.instance.getPosition());
|
|
21
|
+
}
|
|
22
|
+
set position(val) {
|
|
23
|
+
this.instance.setPosition(val.x, val.y);
|
|
24
|
+
}
|
|
25
|
+
set xy(val) {
|
|
26
|
+
this.instance.setPosition(val[0], val[1]);
|
|
27
|
+
}
|
|
28
|
+
get posX() {
|
|
29
|
+
return this.instance.getPositionX();
|
|
30
|
+
}
|
|
31
|
+
set posX(val) {
|
|
32
|
+
this.instance.setPositionX(val);
|
|
33
|
+
}
|
|
34
|
+
get posY() {
|
|
35
|
+
return this.instance.getPositionY();
|
|
36
|
+
}
|
|
37
|
+
set posY(val) {
|
|
38
|
+
this.instance.setPositionY(val);
|
|
39
|
+
}
|
|
40
|
+
get scale() {
|
|
41
|
+
return this.instance.getScale();
|
|
42
|
+
}
|
|
43
|
+
set scale(val) {
|
|
44
|
+
this.instance.setScale(val, val);
|
|
45
|
+
}
|
|
46
|
+
get scaleX() {
|
|
47
|
+
return this.instance.getScaleX();
|
|
48
|
+
}
|
|
49
|
+
set scaleX(val) {
|
|
50
|
+
this.instance.setScaleX(val);
|
|
51
|
+
}
|
|
52
|
+
get scaleY() {
|
|
53
|
+
return this.instance.getScaleY();
|
|
54
|
+
}
|
|
55
|
+
set scaleY(val) {
|
|
56
|
+
this.instance.setScaleY(val);
|
|
57
|
+
}
|
|
58
|
+
get anchorX() {
|
|
59
|
+
return this.instance.anchorX;
|
|
60
|
+
}
|
|
61
|
+
set anchorX(val) {
|
|
62
|
+
this.instance.anchorX = val;
|
|
63
|
+
}
|
|
64
|
+
get anchorY() {
|
|
65
|
+
return this.instance.anchorY;
|
|
66
|
+
}
|
|
67
|
+
set anchorY(val) {
|
|
68
|
+
this.instance.anchorY = val;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns the angle of the node in degrees. 0 is the default rotation angle. Positive values rotate node clockwise.
|
|
72
|
+
* @function
|
|
73
|
+
* @return {Number} The rotation of the node in degrees.
|
|
74
|
+
*/
|
|
75
|
+
get rotation() {
|
|
76
|
+
return this.instance.getRotation();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* Sets the X angle of the node in degrees which performs a horizontal rotational skew.
|
|
81
|
+
* (support only in WebGL rendering mode)
|
|
82
|
+
* 0 is the default rotation angle.
|
|
83
|
+
* Positive values rotate node clockwise, and negative values for anti-clockwise.
|
|
84
|
+
*
|
|
85
|
+
* @param {Number} degrees The X rotation in degrees which performs a horizontal rotational skew.
|
|
86
|
+
*/
|
|
87
|
+
set rotation(val) {
|
|
88
|
+
this.instance.setRotation(val);
|
|
89
|
+
}
|
|
90
|
+
get color() {
|
|
91
|
+
return this.instance.getColor();
|
|
92
|
+
}
|
|
93
|
+
set color(val) {
|
|
94
|
+
this.instance.setColor(val);
|
|
95
|
+
}
|
|
96
|
+
get opacity() {
|
|
97
|
+
return this.instance.getOpacity();
|
|
98
|
+
}
|
|
99
|
+
set opacity(val) {
|
|
100
|
+
this.instance.setOpacity(val);
|
|
101
|
+
}
|
|
102
|
+
get active() {
|
|
103
|
+
if (!cc.sys.isObjectValid(this.instance) || !this._active)
|
|
104
|
+
return false;
|
|
105
|
+
let p = this.parent;
|
|
106
|
+
while (p) {
|
|
107
|
+
if (!p.active)
|
|
108
|
+
return false;
|
|
109
|
+
p = p.parent;
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
set active(val) {
|
|
114
|
+
if (!cc.sys.isObjectValid(this.instance)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this._active = val;
|
|
118
|
+
if (this.instance instanceof ccui.Widget) {
|
|
119
|
+
this.instance.setEnabled(val);
|
|
120
|
+
}
|
|
121
|
+
this.instance.setVisible(val);
|
|
122
|
+
}
|
|
123
|
+
get group() {
|
|
124
|
+
return this._group;
|
|
125
|
+
}
|
|
126
|
+
set group(val) {
|
|
127
|
+
this._group = val;
|
|
128
|
+
}
|
|
129
|
+
get width() {
|
|
130
|
+
return this.instance.width;
|
|
131
|
+
}
|
|
132
|
+
set width(val) {
|
|
133
|
+
this.instance.setContentSize(val, this.height);
|
|
134
|
+
}
|
|
135
|
+
get height() {
|
|
136
|
+
return this.instance.height;
|
|
137
|
+
}
|
|
138
|
+
set height(val) {
|
|
139
|
+
this.instance.setContentSize(val, this.width);
|
|
140
|
+
}
|
|
141
|
+
get zIndex() {
|
|
142
|
+
return this.instance.zIndex;
|
|
143
|
+
}
|
|
144
|
+
set zIndex(val) {
|
|
145
|
+
this.instance.zIndex = val;
|
|
146
|
+
}
|
|
147
|
+
get childrenCount() {
|
|
148
|
+
return this.children.length;
|
|
149
|
+
}
|
|
150
|
+
destroy() {
|
|
151
|
+
this.removeFromParent(true);
|
|
152
|
+
}
|
|
153
|
+
addComponent(instance) {
|
|
154
|
+
return this.entity.assign(instance);
|
|
155
|
+
}
|
|
156
|
+
getComponent(component) {
|
|
157
|
+
return this.entity.getComponent(component);
|
|
158
|
+
}
|
|
159
|
+
getComponentsInChildren(component) {
|
|
160
|
+
if (!this.children.length) {
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
const listHave = this.children.filter((child) => {
|
|
164
|
+
return child.getComponent(component);
|
|
165
|
+
});
|
|
166
|
+
return listHave.map((node) => node.getComponent(component));
|
|
167
|
+
}
|
|
168
|
+
getComponentInChildren(component) {
|
|
169
|
+
return this.getComponentsInChildren(component)[0];
|
|
170
|
+
}
|
|
171
|
+
hasComponentInChildren(component) {
|
|
172
|
+
if (!this.children.length) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return this.children.some((child) => {
|
|
176
|
+
return child.getComponent(component);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
getPercent() {
|
|
180
|
+
if (this.instance instanceof ccui.LoadingBar) {
|
|
181
|
+
return this.instance.getPercent();
|
|
182
|
+
}
|
|
183
|
+
return 0;
|
|
184
|
+
}
|
|
185
|
+
setPercent(val) {
|
|
186
|
+
if (this.instance instanceof ccui.LoadingBar) {
|
|
187
|
+
return this.instance.setPercent(val);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
setTouchEnabled(enabled) {
|
|
191
|
+
if (!cc.sys.isObjectValid(this.instance)) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (this.instance instanceof ccui.Widget) {
|
|
195
|
+
this.instance.setTouchEnabled(enabled);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
addTouchEventListener(cb) {
|
|
199
|
+
if (!cc.sys.isObjectValid(this.instance)) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (this.instance instanceof ccui.Widget) {
|
|
203
|
+
this.instance.addTouchEventListener(cb);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
convertToNodeSpace(point) {
|
|
207
|
+
const { x, y } = this.instance.convertToNodeSpace(point);
|
|
208
|
+
return Vec2(x, y);
|
|
209
|
+
}
|
|
210
|
+
convertToNodeSpaceAR(point) {
|
|
211
|
+
const { x, y } = this.instance.convertToNodeSpaceAR(point);
|
|
212
|
+
return Vec2(x, y);
|
|
213
|
+
}
|
|
214
|
+
convertToWorldSpaceAR(point) {
|
|
215
|
+
const { x, y } = this.instance.convertToWorldSpaceAR(point);
|
|
216
|
+
return Vec2(x, y);
|
|
217
|
+
}
|
|
218
|
+
getPosition() {
|
|
219
|
+
return this.instance.getPosition();
|
|
220
|
+
}
|
|
221
|
+
setPosition(x, y) {
|
|
222
|
+
this.instance.setPosition(x, y);
|
|
223
|
+
}
|
|
224
|
+
setRotation(deg) {
|
|
225
|
+
this.instance.setRotation(deg);
|
|
226
|
+
}
|
|
227
|
+
getRotation() {
|
|
228
|
+
return this.instance.getRotation();
|
|
229
|
+
}
|
|
230
|
+
setAnchorPoint(point, y) {
|
|
231
|
+
this.instance.setAnchorPoint(point, y);
|
|
232
|
+
}
|
|
233
|
+
getAnchorPoint() {
|
|
234
|
+
return this.instance.getAnchorPoint();
|
|
235
|
+
}
|
|
236
|
+
getBoundingBox() {
|
|
237
|
+
const box = this.instance.getBoundingBox();
|
|
238
|
+
box.contains = function (point) {
|
|
239
|
+
return this.x <= point.x && this.x + this.width >= point.x && this.y <= point.y && this.y + this.height >= point.y;
|
|
240
|
+
};
|
|
241
|
+
return box;
|
|
242
|
+
}
|
|
243
|
+
getContentSize() {
|
|
244
|
+
return this.instance.getContentSize();
|
|
245
|
+
}
|
|
246
|
+
setContentSize(size, height) {
|
|
247
|
+
this.instance.setContentSize(size, height);
|
|
248
|
+
if (this.instance instanceof cc.ClippingNode) {
|
|
249
|
+
const hw = (size.width || size) * 0.5;
|
|
250
|
+
const hh = (size.height || height) * 0.5;
|
|
251
|
+
const stencil = new cc.DrawNode();
|
|
252
|
+
const rectangle = [cc.p(-hw, -hh), cc.p(hw, -hh), cc.p(hw, hh), cc.p(-hw, hh)];
|
|
253
|
+
stencil.drawPoly(rectangle, cc.Color.WHITE, 0, cc.Color.WHITE);
|
|
254
|
+
// stencil.drawDot(cc.p(-height * 0.5, -height * 0.5), height, cc.Color.WHITE);
|
|
255
|
+
this.instance.stencil = stencil;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
setColor(color) {
|
|
259
|
+
this.instance.setColor(color);
|
|
260
|
+
}
|
|
261
|
+
setScale(scaleX, scaleY) {
|
|
262
|
+
this.instance.setScale(scaleX, scaleY || scaleX);
|
|
263
|
+
}
|
|
264
|
+
runAction(atc) {
|
|
265
|
+
this.instance.runAction(atc);
|
|
266
|
+
}
|
|
267
|
+
stopAllActions() {
|
|
268
|
+
this.instance.stopAllActions();
|
|
269
|
+
}
|
|
270
|
+
pauseAllActionsAndSchedule() {
|
|
271
|
+
this.instance.pause();
|
|
272
|
+
this.instance.unscheduleUpdate();
|
|
273
|
+
}
|
|
274
|
+
resumeAllActionsAndSchedule() {
|
|
275
|
+
this.instance.resume();
|
|
276
|
+
this.instance.scheduleUpdate();
|
|
277
|
+
}
|
|
278
|
+
removeFromParent(cleanup) {
|
|
279
|
+
this.active = false;
|
|
280
|
+
if (this.parent) {
|
|
281
|
+
this.parent.children = this.parent.children.filter(({ entity }) => entity.id !== this.entity.id);
|
|
282
|
+
}
|
|
283
|
+
if (cleanup) {
|
|
284
|
+
this.children.forEach((child) => {
|
|
285
|
+
child.destroy();
|
|
286
|
+
});
|
|
287
|
+
this.parent = null;
|
|
288
|
+
this.entity.destroy();
|
|
289
|
+
this.stopAllActions();
|
|
290
|
+
this.instance.removeFromParent(cleanup);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
this.stopAllActions();
|
|
294
|
+
this.instance.removeFromParent();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
addChild(child) {
|
|
298
|
+
child._active = true;
|
|
299
|
+
child.parent = this;
|
|
300
|
+
this.children.push(child);
|
|
301
|
+
this.instance.addChild(child.instance);
|
|
302
|
+
}
|
|
303
|
+
removeAllChildren(cleanup) {
|
|
304
|
+
this.children.forEach((child) => {
|
|
305
|
+
child.removeFromParent(cleanup);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
getData(key) {
|
|
309
|
+
const data = this.getComponent(ExtraDataComp);
|
|
310
|
+
if (!data)
|
|
311
|
+
throw Error('need add ExtraDataComp to Node');
|
|
312
|
+
return data.getData(key);
|
|
313
|
+
}
|
|
314
|
+
setData(key, value) {
|
|
315
|
+
const data = this.getComponent(ExtraDataComp);
|
|
316
|
+
if (!data) {
|
|
317
|
+
this.addComponent(instantiate(ExtraDataComp, { key, value }));
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
data.setData(key, value);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
removeData(key) {
|
|
324
|
+
const data = this.getComponent(ExtraDataComp);
|
|
325
|
+
if (data) {
|
|
326
|
+
data.removeData(key);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
resolveComponent(component) {
|
|
330
|
+
if (component.constructor.hasRender) {
|
|
331
|
+
this.addChild(component.node);
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
this.addComponent(component);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodePool.d.ts","sourceRoot":"","sources":["../../src/gworld/NodePool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,qBAAa,QAAQ;IACnB,KAAK,EAAE,QAAQ,EAAE,CAAK;IAEtB,GAAG,CAAC,IAAI,EAAE,QAAQ;IAQlB,GAAG,IAAI,QAAQ;IAOf,IAAI;IAIJ,KAAK;CAIN"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class NodePool {
|
|
2
|
+
items = [];
|
|
3
|
+
put(node) {
|
|
4
|
+
if (node) {
|
|
5
|
+
node.removeFromParent();
|
|
6
|
+
node.entity.immortal = true;
|
|
7
|
+
this.items.push(node);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
get() {
|
|
11
|
+
const node = this.items.pop();
|
|
12
|
+
node.entity.immortal = false;
|
|
13
|
+
node.active = true;
|
|
14
|
+
return node;
|
|
15
|
+
}
|
|
16
|
+
size() {
|
|
17
|
+
return this.items.length;
|
|
18
|
+
}
|
|
19
|
+
clear() {
|
|
20
|
+
this.items.forEach((node) => node.destroy());
|
|
21
|
+
this.items.length = 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Scene.d.ts","sourceRoot":"","sources":["../../src/gworld/Scene.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAGvD,qBAAa,cAAe,SAAQ,iBAAiB;IACnD,MAAM;CASP"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GameWorld } from '.';
|
|
2
|
+
import { EnhancedComponent } from './EnhancedComponent';
|
|
3
|
+
import { NodeComp } from './NodeComp';
|
|
4
|
+
export class SceneComponent extends EnhancedComponent {
|
|
5
|
+
render() {
|
|
6
|
+
const world = GameWorld.Instance;
|
|
7
|
+
world.entities.reset();
|
|
8
|
+
const root = world.entities.create();
|
|
9
|
+
const node = root.assign(new NodeComp(cc.director.getRunningScene(), root));
|
|
10
|
+
const sceneComponent = root.assign(this);
|
|
11
|
+
sceneComponent.node = node;
|
|
12
|
+
return sceneComponent;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EnhancedComponent, NodeComp } from '.';
|
|
2
|
+
export declare class NoRenderComponentX<Props = object, C extends cc.Node = cc.Node> extends EnhancedComponent<Props, NodeComp<C>> {
|
|
3
|
+
static hasRender: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare class ComponentX<Props = object, C extends cc.Node = cc.Node> extends EnhancedComponent<Props, NodeComp<C>> {
|
|
6
|
+
render?(): this;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.d.ts","sourceRoot":"","sources":["../../src/gworld/decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAa,QAAQ,EAAE,MAAM,GAAG,CAAA;AAE1D,qBAAa,kBAAkB,CAAC,KAAK,GAAG,MAAM,EAAE,CAAC,SAAS,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAE,SAAQ,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACxH,MAAM,CAAC,SAAS,UAAQ;CACzB;AAED,qBAAa,UAAU,CAAC,KAAK,GAAG,MAAM,EAAE,CAAC,SAAS,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAE,SAAQ,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAChH,MAAM,CAAC;CAMR"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EnhancedComponent, GameWorld } from '.';
|
|
2
|
+
export class NoRenderComponentX extends EnhancedComponent {
|
|
3
|
+
static hasRender = false;
|
|
4
|
+
}
|
|
5
|
+
export class ComponentX extends EnhancedComponent {
|
|
6
|
+
render() {
|
|
7
|
+
const world = GameWorld.Instance;
|
|
8
|
+
const root = world.entities.create();
|
|
9
|
+
const comp = root.assign(this);
|
|
10
|
+
return comp;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Constructor, System, World } from 'entityx-ts';
|
|
2
|
+
export declare class GameWorld extends World {
|
|
3
|
+
listUpdate: (System | Constructor<System>)[];
|
|
4
|
+
update(dt: number): void;
|
|
5
|
+
private static _instance;
|
|
6
|
+
static get Instance(): GameWorld;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gworld/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvD,qBAAa,SAAU,SAAQ,KAAK;IAClC,UAAU,EAAE,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,CAAK;IACjD,MAAM,CAAC,EAAE,EAAE,MAAM;IAMjB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAW;IAEnC,WAAkB,QAAQ,cAGzB;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { World } from 'entityx-ts';
|
|
2
|
+
export class GameWorld extends World {
|
|
3
|
+
listUpdate = [];
|
|
4
|
+
update(dt) {
|
|
5
|
+
this.listUpdate.forEach((system) => {
|
|
6
|
+
this.systems.update(system, dt);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
static _instance;
|
|
10
|
+
static get Instance() {
|
|
11
|
+
// Do you need arguments? Make it a regular static method instead.
|
|
12
|
+
return this._instance || (this._instance = new this());
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderSystem.d.ts","sourceRoot":"","sources":["../../src/render/RenderSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"RenderSystem.d.ts","sourceRoot":"","sources":["../../src/render/RenderSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;AAMnF,oBAAY,WAAW;IACrB,MAAM,IAAA;IACN,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,IAAI,IAAA;IACJ,SAAS,IAAA;CACV;AAED,qBAAa,YAAa,YAAW,MAAM;IACzC,SAAS,CAAC,aAAa,EAAE,YAAY;IAWrC,OAAO,CAAC,eAAe,CAKtB;IAED,OAAO,CAAC,iBAAiB,CAgBxB;IAED,OAAO,CAAC,eAAe,CAatB;IAED,OAAO,CAAC,mBAAmB,CAQ1B;IAED,OAAO,CAAC,iBAAiB,CAKxB;IAED,OAAO,CAAC,aAAa,CAKpB;IAED,OAAO,CAAC,iBAAiB,CAUxB;IAED,OAAO,CAAC,iBAAiB,CAKxB;CAKF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventTypes } from 'entityx-ts';
|
|
2
2
|
import { NodeComp } from '../core/NodeComp';
|
|
3
3
|
import { GraphicsRender, MaskRender, MotionStreakComp, NodeRender, ParticleComp, SpriteRender, TiledMap } from './RenderComponent';
|
|
4
|
+
import { createTiledSprite } from './TiledSprite';
|
|
4
5
|
export var SpriteTypes;
|
|
5
6
|
(function (SpriteTypes) {
|
|
6
7
|
SpriteTypes[SpriteTypes["SIMPLE"] = 0] = "SIMPLE";
|
|
@@ -10,41 +11,6 @@ export var SpriteTypes;
|
|
|
10
11
|
SpriteTypes[SpriteTypes["MESH"] = 4] = "MESH";
|
|
11
12
|
SpriteTypes[SpriteTypes["ANIMATION"] = 5] = "ANIMATION";
|
|
12
13
|
})(SpriteTypes || (SpriteTypes = {}));
|
|
13
|
-
function createTiledSprite(src, totalW, totalH) {
|
|
14
|
-
// tạo sprite từ input
|
|
15
|
-
const tileSprite = new cc.Sprite(src);
|
|
16
|
-
// lấy kích thước gốc của texture
|
|
17
|
-
const frame = tileSprite.getSpriteFrame();
|
|
18
|
-
const tileW = frame ? frame.getRect().width : tileSprite.getContentSize().width;
|
|
19
|
-
const tileH = frame ? frame.getRect().height : tileSprite.getContentSize().height;
|
|
20
|
-
// tạo renderTexture với kích thước cần phủ
|
|
21
|
-
const { width, height } = cc.winSize;
|
|
22
|
-
const rt = new cc.RenderTexture(width, height);
|
|
23
|
-
rt.beginWithClear(0, 0, 0, 0);
|
|
24
|
-
const drawSprite = new cc.Sprite(tileSprite.getTexture());
|
|
25
|
-
// if (frame) {
|
|
26
|
-
// drawSprite.setSpriteFrame(frame)
|
|
27
|
-
// }
|
|
28
|
-
drawSprite.setAnchorPoint(0, 0);
|
|
29
|
-
// số tile theo trục x,y
|
|
30
|
-
const cols = Math.ceil(totalW / tileW);
|
|
31
|
-
const rows = Math.ceil(totalH / tileH);
|
|
32
|
-
for (let r = 0; r < rows; r++) {
|
|
33
|
-
for (let c = 0; c < cols; c++) {
|
|
34
|
-
const s = new cc.Sprite(frame);
|
|
35
|
-
s.setFlippedY(true);
|
|
36
|
-
s.setAnchorPoint(0, 0);
|
|
37
|
-
s.setPosition(c * tileW, r * tileH);
|
|
38
|
-
s.visit(rt);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
rt.end();
|
|
42
|
-
const finalSprite = rt.sprite;
|
|
43
|
-
// finalSprite.setFlippedY(true) // RenderTexture bị lật
|
|
44
|
-
finalSprite.setAnchorPoint(0, 0);
|
|
45
|
-
finalSprite.setContentSize(cc.size(totalW, totalH));
|
|
46
|
-
return new cc.Sprite(finalSprite.texture);
|
|
47
|
-
}
|
|
48
14
|
export class RenderSystem {
|
|
49
15
|
configure(event_manager) {
|
|
50
16
|
event_manager.subscribe(EventTypes.ComponentAdded, NodeRender, this.onAddNodeRender);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class TiledSpriteNode extends cc.Sprite {
|
|
2
|
+
_program: cc.GLProgram;
|
|
3
|
+
_tileScaleLoc: WebGLUniformLocation;
|
|
4
|
+
_texSizeLoc: WebGLUniformLocation;
|
|
5
|
+
_texLoc: WebGLUniformLocation;
|
|
6
|
+
constructor(file: any);
|
|
7
|
+
initShader(): void;
|
|
8
|
+
updateShaderUniforms(): void;
|
|
9
|
+
setContentSize(w: any, h: any): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function createTiledSprite(src: string, totalW: number, totalH: number): cc.Sprite;
|
|
12
|
+
//# sourceMappingURL=TiledSprite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TiledSprite.d.ts","sourceRoot":"","sources":["../../src/render/TiledSprite.ts"],"names":[],"mappings":"AAEA,qBAAa,eAAgB,SAAQ,EAAE,CAAC,MAAM;IAC5C,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAA;IACtB,aAAa,EAAE,oBAAoB,CAAA;IACnC,WAAW,EAAE,oBAAoB,CAAA;IACjC,OAAO,EAAE,oBAAoB,CAAA;gBAEjB,IAAI,KAAA;IAMhB,UAAU;IAqBV,oBAAoB;IAgBpB,cAAc,CAAC,CAAC,KAAA,EAAE,CAAC,KAAA;CAIpB;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAmC5E"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { tieldFsh, tiledVsh } from './shader';
|
|
2
|
+
export class TiledSpriteNode extends cc.Sprite {
|
|
3
|
+
_program;
|
|
4
|
+
_tileScaleLoc;
|
|
5
|
+
_texSizeLoc;
|
|
6
|
+
_texLoc;
|
|
7
|
+
constructor(file) {
|
|
8
|
+
super(file);
|
|
9
|
+
this.ctor();
|
|
10
|
+
this.initShader();
|
|
11
|
+
}
|
|
12
|
+
initShader() {
|
|
13
|
+
const program = new cc.GLProgram();
|
|
14
|
+
program.initWithVertexShaderByteArray(tiledVsh, tieldFsh);
|
|
15
|
+
program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION);
|
|
16
|
+
program.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR);
|
|
17
|
+
program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS);
|
|
18
|
+
program.link();
|
|
19
|
+
program.updateUniforms();
|
|
20
|
+
program.use();
|
|
21
|
+
this._program = program;
|
|
22
|
+
this.setShaderProgram(program);
|
|
23
|
+
// Lưu lại uniform location để update nhanh
|
|
24
|
+
this._tileScaleLoc = program.getUniformLocationForName('u_tileScale');
|
|
25
|
+
this._texSizeLoc = program.getUniformLocationForName('u_texSize');
|
|
26
|
+
this._texLoc = program.getUniformLocationForName('u_texture');
|
|
27
|
+
this.scheduleUpdate();
|
|
28
|
+
}
|
|
29
|
+
updateShaderUniforms() {
|
|
30
|
+
if (!this._program || !this.texture || !this.texture.isLoaded())
|
|
31
|
+
return;
|
|
32
|
+
const texW = this.texture.width;
|
|
33
|
+
const texH = this.texture.height;
|
|
34
|
+
const size = this.getContentSize();
|
|
35
|
+
const scaleX = size.width / texW;
|
|
36
|
+
const scaleY = size.height / texH;
|
|
37
|
+
this._program.use();
|
|
38
|
+
this._program.setUniformLocationWith2f(this._tileScaleLoc, scaleX, scaleY);
|
|
39
|
+
this._program.setUniformLocationWith2f(this._texSizeLoc, texW, texH);
|
|
40
|
+
this._program.setUniformLocationWith1i(this._texLoc, 0);
|
|
41
|
+
}
|
|
42
|
+
setContentSize(w, h) {
|
|
43
|
+
super.setContentSize(w, h);
|
|
44
|
+
this.updateShaderUniforms();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function createTiledSprite(src, totalW, totalH) {
|
|
48
|
+
// tạo sprite từ input
|
|
49
|
+
const tileSprite = new cc.Sprite(src);
|
|
50
|
+
// lấy kích thước gốc của texture
|
|
51
|
+
const tileW = tileSprite.texture.width;
|
|
52
|
+
const tileH = tileSprite.texture.height;
|
|
53
|
+
const program = new cc.GLProgram();
|
|
54
|
+
program.initWithString(tiledVsh, tieldFsh);
|
|
55
|
+
// program.initWithVertexShaderByteArray(vert, frag);
|
|
56
|
+
program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION);
|
|
57
|
+
program.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR);
|
|
58
|
+
program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS);
|
|
59
|
+
if (!program.link()) {
|
|
60
|
+
console.error('Failed to link shader program');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
program.updateUniforms();
|
|
64
|
+
program.setUniformLocationWith1i(program.getUniformLocationForName('u_texture'), 0);
|
|
65
|
+
const tileScaleLoc = program.getUniformLocationForName('u_tileScale');
|
|
66
|
+
const texSizeLoc = program.getUniformLocationForName('u_texSize');
|
|
67
|
+
const scaleX = totalW / tileW;
|
|
68
|
+
const scaleY = totalH / tileH;
|
|
69
|
+
if (tileSprite.texture._textureLoaded)
|
|
70
|
+
afterLoaded();
|
|
71
|
+
else
|
|
72
|
+
tileSprite.texture.addLoadedEventListener(afterLoaded);
|
|
73
|
+
function afterLoaded() {
|
|
74
|
+
// program.use()
|
|
75
|
+
program.setUniformLocationWith2f(texSizeLoc, tileW, tileH);
|
|
76
|
+
program.setUniformLocationWith2f(tileScaleLoc, scaleX, scaleY);
|
|
77
|
+
tileSprite.setShaderProgram(program);
|
|
78
|
+
// nếu dùng batch node hoặc spriteframe atlas, đảm bảo texture unit đúng
|
|
79
|
+
}
|
|
80
|
+
// tileSprite.setContentSize(totalW, totalH)
|
|
81
|
+
tileSprite.setScale(scaleX, scaleY);
|
|
82
|
+
return tileSprite;
|
|
83
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const tieldFsh = "\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\nvarying vec2 v_texCoord;\nvarying vec4 v_fragmentColor;\n\nuniform sampler2D u_texture;\nuniform vec2 u_tileScale;\nuniform vec2 u_texSize;\n\nvoid main()\n{\n // scale UV to tile space\n vec2 uv = v_texCoord * u_tileScale;\n\n // wrap using fract\n vec2 uvw = fract(uv);\n\n // avoid linear-filter seams: push UVs slightly away from exact 0.0/1.0 edges\n // compute texel size in uv-space\n vec2 texel = 1.0 / u_texSize;\n\n // shrink usable range slightly to avoid sampling border when linear filter is used\n // the factor 1.0 - 2.0*texel moves the uv into [texel, 1-texel]\n uvw = uvw * (1.0 - 2.0 * texel) + texel;\n\n vec4 color = texture2D(u_texture, uvw);\n\n gl_FragColor = color * v_fragmentColor;\n}\n";
|
|
2
|
+
export declare const tiledVsh = "\nattribute vec4 a_position;\nattribute vec2 a_texCoord;\nattribute vec4 a_color;\n\n#ifdef GL_ES\nvarying mediump vec2 v_texCoord;\nvarying lowp vec4 v_fragmentColor;\n#else\nvarying vec2 v_texCoord;\nvarying vec4 v_fragmentColor;\n#endif\n\nvoid main() {\n gl_Position = CC_PMatrix * a_position;\n v_texCoord = a_texCoord;\n v_fragmentColor = a_color;\n}\n";
|
|
3
|
+
//# sourceMappingURL=shader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shader.d.ts","sourceRoot":"","sources":["../../src/render/shader.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,qyBAgCpB,CAAA;AACD,eAAO,MAAM,QAAQ,oXAkBpB,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const tieldFsh = `
|
|
2
|
+
#ifdef GL_ES
|
|
3
|
+
precision mediump float;
|
|
4
|
+
#endif
|
|
5
|
+
|
|
6
|
+
varying vec2 v_texCoord;
|
|
7
|
+
varying vec4 v_fragmentColor;
|
|
8
|
+
|
|
9
|
+
uniform sampler2D u_texture;
|
|
10
|
+
uniform vec2 u_tileScale;
|
|
11
|
+
uniform vec2 u_texSize;
|
|
12
|
+
|
|
13
|
+
void main()
|
|
14
|
+
{
|
|
15
|
+
// scale UV to tile space
|
|
16
|
+
vec2 uv = v_texCoord * u_tileScale;
|
|
17
|
+
|
|
18
|
+
// wrap using fract
|
|
19
|
+
vec2 uvw = fract(uv);
|
|
20
|
+
|
|
21
|
+
// avoid linear-filter seams: push UVs slightly away from exact 0.0/1.0 edges
|
|
22
|
+
// compute texel size in uv-space
|
|
23
|
+
vec2 texel = 1.0 / u_texSize;
|
|
24
|
+
|
|
25
|
+
// shrink usable range slightly to avoid sampling border when linear filter is used
|
|
26
|
+
// the factor 1.0 - 2.0*texel moves the uv into [texel, 1-texel]
|
|
27
|
+
uvw = uvw * (1.0 - 2.0 * texel) + texel;
|
|
28
|
+
|
|
29
|
+
vec4 color = texture2D(u_texture, uvw);
|
|
30
|
+
|
|
31
|
+
gl_FragColor = color * v_fragmentColor;
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
export const tiledVsh = `
|
|
35
|
+
attribute vec4 a_position;
|
|
36
|
+
attribute vec2 a_texCoord;
|
|
37
|
+
attribute vec4 a_color;
|
|
38
|
+
|
|
39
|
+
#ifdef GL_ES
|
|
40
|
+
varying mediump vec2 v_texCoord;
|
|
41
|
+
varying lowp vec4 v_fragmentColor;
|
|
42
|
+
#else
|
|
43
|
+
varying vec2 v_texCoord;
|
|
44
|
+
varying vec4 v_fragmentColor;
|
|
45
|
+
#endif
|
|
46
|
+
|
|
47
|
+
void main() {
|
|
48
|
+
gl_Position = CC_PMatrix * a_position;
|
|
49
|
+
v_texCoord = a_texCoord;
|
|
50
|
+
v_fragmentColor = a_color;
|
|
51
|
+
}
|
|
52
|
+
`;
|