@safe-engine/cocos 1.5.2 → 1.5.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/dist/animation/AnimationComponent.d.ts +63 -0
- package/dist/animation/AnimationComponent.d.ts.map +1 -0
- package/dist/animation/AnimationComponent.js +119 -0
- package/dist/animation/AnimationSystem.d.ts +6 -0
- package/dist/animation/AnimationSystem.d.ts.map +1 -0
- package/dist/animation/AnimationSystem.js +22 -0
- package/dist/animation/index.d.ts +2 -0
- package/dist/animation/index.d.ts.map +1 -0
- package/dist/animation/index.js +7 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +40 -65
- package/dist/box2d-wasm/ContactListener.d.ts +12 -0
- package/dist/box2d-wasm/ContactListener.d.ts.map +1 -0
- package/dist/box2d-wasm/ContactListener.js +64 -0
- package/dist/box2d-wasm/PhysicsComponent.d.ts +50 -0
- package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -0
- package/dist/box2d-wasm/PhysicsComponent.js +16 -0
- package/dist/box2d-wasm/PhysicsSprite.d.ts +12 -0
- package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -0
- package/dist/box2d-wasm/PhysicsSprite.js +51 -0
- package/dist/box2d-wasm/PhysicsSystem.d.ts +15 -0
- package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -0
- package/dist/box2d-wasm/PhysicsSystem.js +139 -0
- package/dist/box2d-wasm/debugDraw.d.ts +66 -0
- package/dist/box2d-wasm/debugDraw.d.ts.map +1 -0
- package/dist/box2d-wasm/debugDraw.js +210 -0
- package/dist/box2d-wasm/index.d.ts +6 -0
- package/dist/box2d-wasm/index.d.ts.map +1 -0
- package/dist/box2d-wasm/index.js +10 -0
- package/dist/collider/CollideComponent.js +98 -159
- package/dist/collider/CollideSystem.js +63 -79
- package/dist/collider/index.d.ts +1 -1
- package/dist/collider/index.d.ts.map +1 -1
- package/dist/collider/index.js +11 -9
- package/dist/dragonbones/PixiDragonBonesSprite.js +15 -19
- package/dist/dragonbones/index.js +38 -68
- package/dist/gworld/components/AnimationComponent.d.ts +2 -2
- package/dist/gworld/components/CollideComponent.d.ts +3 -3
- package/dist/gworld/components/EnhancedComponent.js +29 -36
- package/dist/gworld/components/GUIComponent.js +50 -118
- package/dist/gworld/components/NoRenderComponent.js +25 -65
- package/dist/gworld/components/NodeComp.d.ts.map +1 -1
- package/dist/gworld/components/NodeComp.js +237 -317
- package/dist/gworld/components/RenderComponent.js +46 -104
- package/dist/gworld/core/NodePool.js +13 -20
- package/dist/gworld/core/Scene.js +11 -35
- package/dist/gworld/core/decorator.js +12 -42
- package/dist/gworld/index.js +13 -42
- package/dist/gworld/systems/CollideSystem.d.ts +1 -2
- package/dist/gworld/systems/CollideSystem.d.ts.map +1 -1
- package/dist/gworld/systems/CollideSystem.js +2 -12
- package/dist/gworld/systems/GUISystem.js +105 -120
- package/dist/gworld/systems/NoRenderSystem.d.ts.map +1 -1
- package/dist/gworld/systems/NoRenderSystem.js +70 -80
- package/dist/gworld/systems/RenderSystem.js +64 -78
- package/dist/helper/Intersection.js +33 -40
- package/dist/helper/action.js +8 -21
- package/dist/helper/director.js +2 -6
- package/dist/helper/math.js +9 -15
- package/dist/helper/utils.js +28 -37
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -31
- package/dist/polyfills.js +69 -97
- package/dist/richtext/RichTextComp.js +27 -55
- package/dist/richtext/RichTextSystem.js +17 -25
- package/dist/richtext/html-text-parser.js +36 -40
- package/dist/richtext/index.js +5 -8
- package/dist/safex.js +1 -2
- package/dist/spine/CCSkeleton.d.ts.map +1 -1
- package/dist/spine/CCSkeleton.js +25 -61
- package/dist/spine/CCSkeletonAnimation.js +18 -54
- package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts +1 -1
- package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts.map +1 -1
- package/dist/spine/CCSkeletonCanvasRenderCmd.js +39 -43
- package/dist/spine/CCSkeletonTexture.js +4 -40
- package/dist/spine/CCSkeletonWebGLRenderCmd.js +56 -92
- package/dist/spine/index.js +37 -63
- package/package.json +4 -1
- package/dist/dragonbones/cocos/CocosArmatureDisplay.d.ts +0 -77
- package/dist/dragonbones/cocos/CocosArmatureDisplay.d.ts.map +0 -1
- package/dist/dragonbones/cocos/CocosArmatureDisplay.js +0 -227
- package/dist/dragonbones/cocos/CocosFactory.d.ts +0 -128
- package/dist/dragonbones/cocos/CocosFactory.d.ts.map +0 -1
- package/dist/dragonbones/cocos/CocosFactory.js +0 -231
- package/dist/dragonbones/cocos/CocosSlot.d.ts +0 -49
- package/dist/dragonbones/cocos/CocosSlot.d.ts.map +0 -1
- package/dist/dragonbones/cocos/CocosSlot.js +0 -385
- package/dist/dragonbones/cocos/CocosTextureAtlasData.d.ts +0 -53
- package/dist/dragonbones/cocos/CocosTextureAtlasData.d.ts.map +0 -1
- package/dist/dragonbones/cocos/CocosTextureAtlasData.js +0 -158
- package/dist/dragonbones/dragonBones.d.ts +0 -3
- package/dist/dragonbones/dragonBones.d.ts.map +0 -1
- package/dist/dragonbones/dragonBones.js +0 -4788
- package/dist/helper/NodePool.d.ts +0 -9
- package/dist/helper/NodePool.d.ts.map +0 -1
- package/dist/helper/NodePool.js +0 -29
|
@@ -1,125 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.Contract = exports.CollisionType = exports.PolygonCollider = exports.CircleCollider = exports.BoxCollider = exports.Collider = void 0;
|
|
19
|
-
var decorator_1 = require("../gworld/core/decorator");
|
|
20
|
-
var math_1 = require("../helper/math");
|
|
21
|
-
var polyfills_1 = require("../polyfills");
|
|
1
|
+
import { NoRenderComponentX } from '../gworld/core/decorator';
|
|
2
|
+
import { getMax, getMin } from '../helper/math';
|
|
3
|
+
import { Vec2 } from '../polyfills';
|
|
22
4
|
function getNodeToWorldTransformAR(node) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
const t = node.instance.getNodeToWorldTransform();
|
|
6
|
+
const anchorPointSize = node.instance.getAnchorPointInPoints();
|
|
7
|
+
const transform = cc.affineTransformTranslate(t, anchorPointSize.x, anchorPointSize.y);
|
|
26
8
|
return transform;
|
|
27
9
|
}
|
|
28
10
|
function cloneRect(origin) {
|
|
29
11
|
return cc.rect(origin.x, origin.y, origin.width, origin.height);
|
|
30
12
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
_this._preAabb = cc.rect(0, 0, 0, 0);
|
|
38
|
-
return _this;
|
|
39
|
-
}
|
|
13
|
+
export class Collider extends NoRenderComponentX {
|
|
14
|
+
_worldPoints = [];
|
|
15
|
+
_worldPosition;
|
|
16
|
+
_worldRadius;
|
|
17
|
+
_AABB = cc.rect(0, 0, 0, 0);
|
|
18
|
+
_preAabb = cc.rect(0, 0, 0, 0);
|
|
40
19
|
// update(dt: number, draw?: cc.DrawNode) {}
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
getAABB() {
|
|
21
|
+
const collider = this.getComponent(Collider);
|
|
43
22
|
if (collider)
|
|
44
23
|
return collider._AABB;
|
|
45
24
|
return this._AABB;
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(Collider.prototype, "world", {
|
|
48
|
-
get: function () {
|
|
49
|
-
return {
|
|
50
|
-
points: this._worldPoints,
|
|
51
|
-
preAabb: this._preAabb,
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
enumerable: false,
|
|
55
|
-
configurable: true
|
|
56
|
-
});
|
|
57
|
-
return Collider;
|
|
58
|
-
}(decorator_1.NoRenderComponentX));
|
|
59
|
-
exports.Collider = Collider;
|
|
60
|
-
var BoxCollider = /** @class */ (function (_super) {
|
|
61
|
-
__extends(BoxCollider, _super);
|
|
62
|
-
function BoxCollider() {
|
|
63
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
64
25
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
26
|
+
get world() {
|
|
27
|
+
return {
|
|
28
|
+
points: this._worldPoints,
|
|
29
|
+
preAabb: this._preAabb,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class BoxCollider extends Collider {
|
|
34
|
+
get size() {
|
|
35
|
+
return cc.size(this.props.width, this.props.height);
|
|
36
|
+
}
|
|
37
|
+
set size(s) {
|
|
38
|
+
this.props.width = s.width;
|
|
39
|
+
this.props.height = s.height;
|
|
40
|
+
}
|
|
41
|
+
update(dt, draw) {
|
|
77
42
|
if (!this.node) {
|
|
78
43
|
return;
|
|
79
44
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
45
|
+
const collider = this.getComponent(Collider);
|
|
46
|
+
const { x, y } = collider.props.offset || Vec2(0, 0);
|
|
47
|
+
const hw = this.props.width * 0.5;
|
|
48
|
+
const hh = this.props.height * 0.5;
|
|
49
|
+
const transform = getNodeToWorldTransformAR(this.node);
|
|
50
|
+
const rect = cc.rect(x - hw, y - hh, this.props.width, this.props.height);
|
|
51
|
+
const rectTrs = cc.rectApplyAffineTransform(rect, transform);
|
|
87
52
|
// cc.log(rectTrs);
|
|
88
|
-
collider._worldPoints[0] =
|
|
89
|
-
collider._worldPoints[1] =
|
|
90
|
-
collider._worldPoints[2] =
|
|
91
|
-
collider._worldPoints[3] =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return x;
|
|
95
|
-
});
|
|
96
|
-
var listY = collider._worldPoints.map(function (_a) {
|
|
97
|
-
var y = _a.y;
|
|
98
|
-
return y;
|
|
99
|
-
});
|
|
53
|
+
collider._worldPoints[0] = Vec2(rectTrs.x, rectTrs.y);
|
|
54
|
+
collider._worldPoints[1] = Vec2(rectTrs.x, rectTrs.y + rectTrs.height);
|
|
55
|
+
collider._worldPoints[2] = Vec2(rectTrs.x + rectTrs.width, rectTrs.y + rectTrs.height);
|
|
56
|
+
collider._worldPoints[3] = Vec2(rectTrs.x + rectTrs.width, rectTrs.y);
|
|
57
|
+
const listX = collider._worldPoints.map(({ x }) => x);
|
|
58
|
+
const listY = collider._worldPoints.map(({ y }) => y);
|
|
100
59
|
collider._preAabb = cloneRect(collider._AABB);
|
|
101
|
-
collider._AABB.x =
|
|
102
|
-
collider._AABB.y =
|
|
103
|
-
collider._AABB.width =
|
|
104
|
-
collider._AABB.height =
|
|
60
|
+
collider._AABB.x = getMin(listX);
|
|
61
|
+
collider._AABB.y = getMin(listY);
|
|
62
|
+
collider._AABB.width = getMax(listX) - collider._AABB.x;
|
|
63
|
+
collider._AABB.height = getMax(listY) - collider._AABB.y;
|
|
105
64
|
if (draw) {
|
|
106
65
|
draw.drawPoly(collider._worldPoints, null, 3, cc.Color.DEBUG_BORDER_COLOR);
|
|
107
66
|
}
|
|
108
|
-
};
|
|
109
|
-
return BoxCollider;
|
|
110
|
-
}(Collider));
|
|
111
|
-
exports.BoxCollider = BoxCollider;
|
|
112
|
-
var CircleCollider = /** @class */ (function (_super) {
|
|
113
|
-
__extends(CircleCollider, _super);
|
|
114
|
-
function CircleCollider() {
|
|
115
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
116
67
|
}
|
|
117
|
-
|
|
68
|
+
}
|
|
69
|
+
export class CircleCollider extends Collider {
|
|
70
|
+
update(dt, draw) {
|
|
118
71
|
if (!this.node) {
|
|
119
72
|
return;
|
|
120
73
|
}
|
|
121
|
-
|
|
122
|
-
|
|
74
|
+
const transform = getNodeToWorldTransformAR(this.node);
|
|
75
|
+
const collider = this.getComponent(Collider);
|
|
123
76
|
collider._worldRadius = this.props.radius * this.node.scaleX;
|
|
124
77
|
collider._worldPosition = cc.pointApplyAffineTransform(collider.props.offset, transform);
|
|
125
78
|
if (draw) {
|
|
@@ -134,78 +87,66 @@ var CircleCollider = /** @class */ (function (_super) {
|
|
|
134
87
|
// draw.drawRect(cc.p(this._AABB.x, this._AABB.y),
|
|
135
88
|
// cc.p(this._worldPosition.x + this._worldRadius, this._worldPosition.y + this._worldRadius),
|
|
136
89
|
// cc.Color.WHITE, 3, cc.Color.DEBUG_BORDER_COLOR);
|
|
137
|
-
};
|
|
138
|
-
return CircleCollider;
|
|
139
|
-
}(Collider));
|
|
140
|
-
exports.CircleCollider = CircleCollider;
|
|
141
|
-
var PolygonCollider = /** @class */ (function (_super) {
|
|
142
|
-
__extends(PolygonCollider, _super);
|
|
143
|
-
function PolygonCollider() {
|
|
144
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
145
90
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
});
|
|
158
|
-
PolygonCollider.prototype.update = function (dt, draw) {
|
|
91
|
+
}
|
|
92
|
+
export class PolygonCollider extends Collider {
|
|
93
|
+
get points() {
|
|
94
|
+
const { x, y } = this.props.offset;
|
|
95
|
+
const pointsList = this.props.points.map((p) => Vec2(p.x + x, p.y + y));
|
|
96
|
+
return pointsList;
|
|
97
|
+
}
|
|
98
|
+
set points(points) {
|
|
99
|
+
this.props.points = points;
|
|
100
|
+
}
|
|
101
|
+
update(dt, draw) {
|
|
159
102
|
if (!this.node) {
|
|
160
103
|
return;
|
|
161
104
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
collider._worldPoints = this.points.map(
|
|
105
|
+
const transform = getNodeToWorldTransformAR(this.node);
|
|
106
|
+
const collider = this.getComponent(Collider);
|
|
107
|
+
collider._worldPoints = this.points.map((p) => cc.pointApplyAffineTransform(p, transform));
|
|
165
108
|
// cc.log(polyPoints);
|
|
166
109
|
if (draw) {
|
|
167
110
|
draw.drawPoly(collider._worldPoints, cc.Color.DEBUG_FILL_COLOR, 3, cc.Color.DEBUG_BORDER_COLOR);
|
|
168
111
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return x;
|
|
172
|
-
});
|
|
173
|
-
var listY = collider._worldPoints.map(function (_a) {
|
|
174
|
-
var y = _a.y;
|
|
175
|
-
return y;
|
|
176
|
-
});
|
|
112
|
+
const listX = collider._worldPoints.map(({ x }) => x);
|
|
113
|
+
const listY = collider._worldPoints.map(({ y }) => y);
|
|
177
114
|
collider._preAabb = cloneRect(collider._AABB);
|
|
178
|
-
collider._AABB.x =
|
|
179
|
-
collider._AABB.y =
|
|
180
|
-
collider._AABB.width =
|
|
181
|
-
collider._AABB.height =
|
|
115
|
+
collider._AABB.x = getMin(listX);
|
|
116
|
+
collider._AABB.y = getMin(listY);
|
|
117
|
+
collider._AABB.width = getMax(listX) - collider._AABB.x;
|
|
118
|
+
collider._AABB.height = getMax(listY) - collider._AABB.y;
|
|
182
119
|
// draw.drawRect(cc.p(this._AABB.x, this._AABB.y), cc.p(max(listX), max(listY)),
|
|
183
120
|
// cc.Color.WHITE, 3, cc.Color.DEBUG_BORDER_COLOR);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
exports.PolygonCollider = PolygonCollider;
|
|
188
|
-
var CollisionType;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export var CollisionType;
|
|
189
124
|
(function (CollisionType) {
|
|
190
125
|
CollisionType[CollisionType["NONE"] = 0] = "NONE";
|
|
191
126
|
CollisionType[CollisionType["ENTER"] = 1] = "ENTER";
|
|
192
127
|
CollisionType[CollisionType["STAY"] = 2] = "STAY";
|
|
193
128
|
CollisionType[CollisionType["EXIT"] = 3] = "EXIT";
|
|
194
|
-
})(CollisionType || (
|
|
129
|
+
})(CollisionType || (CollisionType = {}));
|
|
195
130
|
function isPolygonCollider(col) {
|
|
196
131
|
return col.getComponent(PolygonCollider) || col.getComponent(BoxCollider);
|
|
197
132
|
}
|
|
198
133
|
function isCircleCollider(col) {
|
|
199
134
|
return col.getComponent(CircleCollider);
|
|
200
135
|
}
|
|
201
|
-
|
|
202
|
-
|
|
136
|
+
export class Contract {
|
|
137
|
+
_collider1;
|
|
138
|
+
_collider2;
|
|
139
|
+
_touching;
|
|
140
|
+
_isPolygonPolygon;
|
|
141
|
+
_isCircleCircle;
|
|
142
|
+
_isPolygonCircle;
|
|
143
|
+
constructor(collider1, collider2) {
|
|
203
144
|
this._collider1 = collider1;
|
|
204
145
|
this._collider2 = collider2;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
146
|
+
const isCollider1Polygon = isPolygonCollider(collider1);
|
|
147
|
+
const isCollider2Polygon = isPolygonCollider(collider2);
|
|
148
|
+
const isCollider1Circle = isCircleCollider(collider1);
|
|
149
|
+
const isCollider2Circle = isCircleCollider(collider2);
|
|
209
150
|
if (isCollider1Polygon && isCollider2Polygon) {
|
|
210
151
|
this._isPolygonPolygon = true;
|
|
211
152
|
}
|
|
@@ -222,9 +163,9 @@ var Contract = /** @class */ (function () {
|
|
|
222
163
|
}
|
|
223
164
|
// cc.log(this._isPolygonPolygon);
|
|
224
165
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
166
|
+
updateState() {
|
|
167
|
+
const result = this.test();
|
|
168
|
+
let type = CollisionType.NONE;
|
|
228
169
|
if (result && !this._touching) {
|
|
229
170
|
this._touching = true;
|
|
230
171
|
type = CollisionType.ENTER;
|
|
@@ -237,8 +178,8 @@ var Contract = /** @class */ (function () {
|
|
|
237
178
|
type = CollisionType.EXIT;
|
|
238
179
|
}
|
|
239
180
|
return type;
|
|
240
|
-
}
|
|
241
|
-
|
|
181
|
+
}
|
|
182
|
+
test() {
|
|
242
183
|
// if (!shouldCollider(this._collider1, this._collider2)) {
|
|
243
184
|
// return false;
|
|
244
185
|
// }
|
|
@@ -250,16 +191,14 @@ var Contract = /** @class */ (function () {
|
|
|
250
191
|
return cc.Intersection.polygonPolygon(this._collider1._worldPoints, this._collider2._worldPoints);
|
|
251
192
|
}
|
|
252
193
|
if (this._isCircleCircle) {
|
|
253
|
-
|
|
254
|
-
|
|
194
|
+
const p1 = this._collider1;
|
|
195
|
+
const p2 = this._collider2;
|
|
255
196
|
return cc.Intersection.circleCircle(p1._worldPosition, p1._worldRadius, p2._worldPosition, p2._worldRadius);
|
|
256
197
|
}
|
|
257
198
|
if (this._isPolygonCircle) {
|
|
258
|
-
|
|
199
|
+
const p2 = this._collider2;
|
|
259
200
|
return cc.Intersection.polygonCircle(this._collider1._worldPoints, p2._worldPosition, p2._worldRadius);
|
|
260
201
|
}
|
|
261
202
|
return false;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
}());
|
|
265
|
-
exports.Contract = Contract;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -1,59 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var CollideComponent_1 = require("./CollideComponent");
|
|
9
|
-
function shouldCollider(colA, colB) {
|
|
10
|
-
var groupA = colA.node.group;
|
|
11
|
-
var groupB = colB.node.group;
|
|
1
|
+
import { EventTypes } from 'entityx-ts';
|
|
2
|
+
import { GameWorld } from '../gworld';
|
|
3
|
+
import { NodeComp } from '../gworld/components/NodeComp';
|
|
4
|
+
import { BoxCollider, CircleCollider, Collider, CollisionType, Contract, PolygonCollider } from './CollideComponent';
|
|
5
|
+
export function shouldCollider(colA, colB) {
|
|
6
|
+
const groupA = colA.node.group;
|
|
7
|
+
const groupB = colB.node.group;
|
|
12
8
|
if (groupA === undefined || groupB === undefined) {
|
|
13
9
|
return true;
|
|
14
10
|
}
|
|
15
|
-
|
|
11
|
+
const { colliderMatrix } = GameWorld.Instance.systems.get(CollideSystem);
|
|
16
12
|
return colliderMatrix[groupA][groupB];
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.onAddCollider
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
component.node = entity.getComponent(NodeComp_1.NodeComp);
|
|
34
|
-
_this.addCollider(collider);
|
|
35
|
-
};
|
|
36
|
-
this.onRemoveCollider = function (_a) {
|
|
37
|
-
var component = _a.component;
|
|
38
|
-
_this.removeColliders.push(component.getComponent(CollideComponent_1.Collider));
|
|
39
|
-
};
|
|
14
|
+
export class CollideSystem {
|
|
15
|
+
listColliders = [];
|
|
16
|
+
_contracts = [];
|
|
17
|
+
removeColliders = [];
|
|
18
|
+
debugGraphics;
|
|
19
|
+
enabledDebugDraw = false;
|
|
20
|
+
enabled = true;
|
|
21
|
+
colliderMatrix = [[true]];
|
|
22
|
+
configure(event_manager) {
|
|
23
|
+
event_manager.subscribe(EventTypes.ComponentAdded, BoxCollider, this.onAddCollider.bind(this));
|
|
24
|
+
event_manager.subscribe(EventTypes.ComponentAdded, CircleCollider, this.onAddCollider.bind(this));
|
|
25
|
+
event_manager.subscribe(EventTypes.ComponentAdded, PolygonCollider, this.onAddCollider.bind(this));
|
|
26
|
+
event_manager.subscribe(EventTypes.ComponentRemoved, BoxCollider, this.onRemoveCollider.bind(this));
|
|
27
|
+
event_manager.subscribe(EventTypes.ComponentRemoved, CircleCollider, this.onRemoveCollider.bind(this));
|
|
28
|
+
event_manager.subscribe(EventTypes.ComponentRemoved, PolygonCollider, this.onRemoveCollider.bind(this));
|
|
40
29
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
onAddCollider = ({ entity, component }) => {
|
|
31
|
+
const collider = entity.assign(new Collider(component));
|
|
32
|
+
collider.node = entity.getComponent(NodeComp);
|
|
33
|
+
collider.props = component.props;
|
|
34
|
+
// collider.props.enable = true
|
|
35
|
+
component.node = entity.getComponent(NodeComp);
|
|
36
|
+
this.addCollider(collider);
|
|
37
|
+
};
|
|
38
|
+
onRemoveCollider = ({ component }) => {
|
|
39
|
+
this.removeColliders.push(component.getComponent(Collider));
|
|
48
40
|
};
|
|
49
|
-
|
|
50
|
-
var _this = this;
|
|
41
|
+
update(entities, events, dt) {
|
|
51
42
|
if (!this.enabled) {
|
|
52
43
|
return;
|
|
53
44
|
}
|
|
54
|
-
this.listColliders.forEach(
|
|
45
|
+
this.listColliders.forEach((collider) => {
|
|
55
46
|
if (!cc.sys.isObjectValid(collider.node.instance)) {
|
|
56
|
-
|
|
47
|
+
this.removeColliders.push(collider);
|
|
57
48
|
}
|
|
58
49
|
});
|
|
59
50
|
// this.removeColliders.forEach(comp => {
|
|
@@ -79,8 +70,8 @@ var CollideSystem = /** @class */ (function () {
|
|
|
79
70
|
// );
|
|
80
71
|
// });
|
|
81
72
|
this.removeColliders = [];
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
let draw;
|
|
74
|
+
const { enabledDebugDraw, debugGraphics } = this;
|
|
84
75
|
if (enabledDebugDraw) {
|
|
85
76
|
draw = debugGraphics;
|
|
86
77
|
draw.clear();
|
|
@@ -96,24 +87,21 @@ var CollideSystem = /** @class */ (function () {
|
|
|
96
87
|
// }
|
|
97
88
|
// });
|
|
98
89
|
}
|
|
99
|
-
for (
|
|
100
|
-
|
|
101
|
-
var comp = entt.getComponent(CollideComponent_1.BoxCollider);
|
|
90
|
+
for (const entt of entities.entities_with_components(BoxCollider)) {
|
|
91
|
+
const comp = entt.getComponent(BoxCollider);
|
|
102
92
|
comp.update(dt, draw);
|
|
103
93
|
}
|
|
104
|
-
for (
|
|
105
|
-
|
|
106
|
-
var comp = entt.getComponent(CollideComponent_1.CircleCollider);
|
|
94
|
+
for (const entt of entities.entities_with_components(CircleCollider)) {
|
|
95
|
+
const comp = entt.getComponent(CircleCollider);
|
|
107
96
|
comp.update(dt, draw);
|
|
108
97
|
}
|
|
109
|
-
for (
|
|
110
|
-
|
|
111
|
-
var comp = entt.getComponent(CollideComponent_1.PolygonCollider);
|
|
98
|
+
for (const entt of entities.entities_with_components(PolygonCollider)) {
|
|
99
|
+
const comp = entt.getComponent(PolygonCollider);
|
|
112
100
|
comp.update(dt, draw);
|
|
113
101
|
}
|
|
114
|
-
this._contracts.forEach(
|
|
115
|
-
|
|
116
|
-
|
|
102
|
+
this._contracts.forEach((contract) => {
|
|
103
|
+
const col1 = contract._collider1;
|
|
104
|
+
const col2 = contract._collider2;
|
|
117
105
|
if (!cc.sys.isObjectValid(col1.node.instance) ||
|
|
118
106
|
!cc.sys.isObjectValid(col2.node.instance) ||
|
|
119
107
|
!col1.node ||
|
|
@@ -122,9 +110,9 @@ var CollideSystem = /** @class */ (function () {
|
|
|
122
110
|
!col2.node.active) {
|
|
123
111
|
return;
|
|
124
112
|
}
|
|
125
|
-
|
|
113
|
+
const type = contract.updateState();
|
|
126
114
|
switch (type) {
|
|
127
|
-
case
|
|
115
|
+
case CollisionType.ENTER: {
|
|
128
116
|
if (col1.props.onCollisionEnter) {
|
|
129
117
|
col1.props.onCollisionEnter(col2);
|
|
130
118
|
}
|
|
@@ -133,7 +121,7 @@ var CollideSystem = /** @class */ (function () {
|
|
|
133
121
|
}
|
|
134
122
|
break;
|
|
135
123
|
}
|
|
136
|
-
case
|
|
124
|
+
case CollisionType.STAY:
|
|
137
125
|
if (col1.props.onCollisionStay) {
|
|
138
126
|
col1.props.onCollisionStay(col2);
|
|
139
127
|
}
|
|
@@ -141,7 +129,7 @@ var CollideSystem = /** @class */ (function () {
|
|
|
141
129
|
col2.props.onCollisionStay(col1);
|
|
142
130
|
}
|
|
143
131
|
break;
|
|
144
|
-
case
|
|
132
|
+
case CollisionType.EXIT:
|
|
145
133
|
if (col1.props.onCollisionExit) {
|
|
146
134
|
col1.props.onCollisionExit(col2);
|
|
147
135
|
}
|
|
@@ -153,29 +141,25 @@ var CollideSystem = /** @class */ (function () {
|
|
|
153
141
|
break;
|
|
154
142
|
}
|
|
155
143
|
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
this.listColliders.forEach(function (col) {
|
|
144
|
+
}
|
|
145
|
+
addCollider(collider) {
|
|
146
|
+
this.listColliders.forEach((col) => {
|
|
160
147
|
if (shouldCollider(col, collider)) {
|
|
161
|
-
|
|
148
|
+
this._contracts.push(new Contract(col, collider));
|
|
162
149
|
}
|
|
163
150
|
});
|
|
164
151
|
this.listColliders.push(collider);
|
|
165
|
-
}
|
|
166
|
-
|
|
152
|
+
}
|
|
153
|
+
removeCollider(collider) {
|
|
167
154
|
this.removeColliders.push(collider);
|
|
168
|
-
}
|
|
169
|
-
|
|
155
|
+
}
|
|
156
|
+
addDebugNode(root) {
|
|
170
157
|
this.debugGraphics = new cc.DrawNode();
|
|
171
158
|
this.debugGraphics.zIndex = 1000;
|
|
172
159
|
root.addChild(this.debugGraphics);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (enable === void 0) { enable = true; }
|
|
160
|
+
}
|
|
161
|
+
toggleDebugDraw(enable = true) {
|
|
176
162
|
this.enabledDebugDraw = enable;
|
|
177
163
|
this.addDebugNode(cc.director.getRunningScene());
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
}());
|
|
181
|
-
exports.CollideSystem = CollideSystem;
|
|
164
|
+
}
|
|
165
|
+
}
|
package/dist/collider/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function setupCollider(): void;
|
|
1
|
+
export declare function setupCollider(colliderMatrix?: any, debug?: boolean): void;
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/collider/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/collider/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,CAAC,cAAc,CAAC,KAAA,EAAE,KAAK,UAAQ,QAS3D"}
|
package/dist/collider/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { GameWorld } from '../gworld';
|
|
2
|
+
import { CollideSystem } from './CollideSystem';
|
|
3
|
+
export function setupCollider(colliderMatrix, debug = false) {
|
|
4
|
+
GameWorld.Instance.systems.add(CollideSystem);
|
|
5
|
+
GameWorld.Instance.listUpdate.push(CollideSystem);
|
|
6
|
+
GameWorld.Instance.systems.configureOnce(CollideSystem);
|
|
7
|
+
const collideSystem = GameWorld.Instance.systems.get(CollideSystem);
|
|
8
|
+
if (colliderMatrix) {
|
|
9
|
+
collideSystem.colliderMatrix = colliderMatrix;
|
|
10
|
+
}
|
|
11
|
+
collideSystem.toggleDebugDraw(debug);
|
|
10
12
|
}
|
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PixiDragonBonesSprite = exports.SharedDragonBonesManager = void 0;
|
|
4
|
-
exports.SharedDragonBonesManager = {
|
|
1
|
+
export const SharedDragonBonesManager = {
|
|
5
2
|
isLoaded: false,
|
|
6
3
|
factory: dragonBones.PixiFactory.factory,
|
|
7
4
|
assets: {},
|
|
8
5
|
loadAssetsOnce: function (key, texJsonUrl, texPngUrl) {
|
|
9
|
-
var _this = this;
|
|
10
6
|
if (this.assets[key]) {
|
|
11
7
|
return;
|
|
12
8
|
}
|
|
13
|
-
|
|
9
|
+
const loader = new PIXI.Loader();
|
|
14
10
|
loader
|
|
15
|
-
.add(
|
|
16
|
-
.add(
|
|
17
|
-
.add(
|
|
18
|
-
.load(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
dragonData
|
|
23
|
-
texture: resources[
|
|
11
|
+
.add(`ske${key}`, key)
|
|
12
|
+
.add(`texJson${key}`, texJsonUrl)
|
|
13
|
+
.add(`texPng${key}`, texPngUrl)
|
|
14
|
+
.load((loader, resources) => {
|
|
15
|
+
const dragonData = this.factory.parseDragonBonesData(resources[`ske${key}`].data, key);
|
|
16
|
+
this.factory.parseTextureAtlasData(resources[`texJson${key}`].data, resources[`texPng${key}`].texture, key);
|
|
17
|
+
this.assets[key] = {
|
|
18
|
+
dragonData,
|
|
19
|
+
texture: resources[`texPng${key}`].texture,
|
|
24
20
|
};
|
|
25
21
|
});
|
|
26
22
|
},
|
|
27
23
|
buildArmatureDisplay: function (key) {
|
|
28
24
|
// console.log(this.assets[key])
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
const { armatureNames } = this.assets[key].dragonData;
|
|
26
|
+
const armatureName = armatureNames[0];
|
|
31
27
|
return this.factory.buildArmatureDisplay(armatureName, key);
|
|
32
28
|
},
|
|
33
29
|
};
|
|
34
|
-
|
|
30
|
+
export const PixiDragonBonesSprite = cc.Sprite.extend({
|
|
35
31
|
ctor: function (config) {
|
|
36
32
|
this._super();
|
|
37
33
|
this._canvas = document.createElement('canvas');
|
|
@@ -57,7 +53,7 @@ exports.PixiDragonBonesSprite = cc.Sprite.extend({
|
|
|
57
53
|
// this.schedule(this.updateTexture, 1 / 30);
|
|
58
54
|
},
|
|
59
55
|
_setupArmature: function () {
|
|
60
|
-
|
|
56
|
+
const display = SharedDragonBonesManager.buildArmatureDisplay(this._config.ske);
|
|
61
57
|
if (!display) {
|
|
62
58
|
console.error('Không thể build armature:', this._config.armatureName);
|
|
63
59
|
return;
|