light-h5-core-lib 2.8.3 → 2.9.0
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/LightCore.js +4 -1
- package/common/util/CollisionDetectionUtil.js +310 -0
- package/common/util/StringUtil.js +38 -0
- package/package.json +1 -1
- package/type/index.d.ts +94 -0
- package/common/util/CryptUtil.js +0 -43
package/LightCore.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SelfDecrypt = exports.NumberUtil = exports.BooleanUtil = exports.Crc32Util = exports.PromiseUtil = exports.BeizerUtil = exports.UniqueIDUtil = exports.StringUtil = exports.RandomNumUtil = exports.FloatDigitUtil = exports.DateUtil = exports.BitUtil = exports.MD5 = exports.BaseSingleton = exports.PoolObj = void 0;
|
|
6
|
+
exports.CollisionDetectionUtil = exports.SelfDecrypt = exports.NumberUtil = exports.BooleanUtil = exports.Crc32Util = exports.PromiseUtil = exports.BeizerUtil = exports.UniqueIDUtil = exports.StringUtil = exports.RandomNumUtil = exports.FloatDigitUtil = exports.DateUtil = exports.BitUtil = exports.MD5 = exports.BaseSingleton = exports.PoolObj = void 0;
|
|
7
7
|
var PoolObj_1 = require("./pool/PoolObj");
|
|
8
8
|
Object.defineProperty(exports, "PoolObj", { enumerable: true, get: function () { return PoolObj_1.PoolObj; } });
|
|
9
9
|
var BaseSingleton_1 = require("./common/base/BaseSingleton");
|
|
@@ -34,6 +34,8 @@ var NumberUtil_1 = require("./common/util/NumberUtil");
|
|
|
34
34
|
Object.defineProperty(exports, "NumberUtil", { enumerable: true, get: function () { return NumberUtil_1.NumberUtil; } });
|
|
35
35
|
var SelfDecrypt_1 = require("./common/util/SelfDecrypt");
|
|
36
36
|
Object.defineProperty(exports, "SelfDecrypt", { enumerable: true, get: function () { return SelfDecrypt_1.SelfDecrypt; } });
|
|
37
|
+
var CollisionDetectionUtil_1 = require("./common/util/CollisionDetectionUtil");
|
|
38
|
+
Object.defineProperty(exports, "CollisionDetectionUtil", { enumerable: true, get: function () { return CollisionDetectionUtil_1.CollisionDetectionUtil; } });
|
|
37
39
|
module.exports = {
|
|
38
40
|
PoolObj: PoolObj_1.PoolObj,
|
|
39
41
|
BaseSingleton: BaseSingleton_1.BaseSingleton,
|
|
@@ -50,4 +52,5 @@ module.exports = {
|
|
|
50
52
|
BooleanUtil: BooleanUtil_1.BooleanUtil,
|
|
51
53
|
NumberUtil: NumberUtil_1.NumberUtil,
|
|
52
54
|
SelfDecrypt: SelfDecrypt_1.SelfDecrypt,
|
|
55
|
+
CollisionDetectionUtil: CollisionDetectionUtil_1.CollisionDetectionUtil,
|
|
53
56
|
};
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
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.CollisionDetectionUtil = void 0;
|
|
19
|
+
/**
|
|
20
|
+
* 碰撞检测工具
|
|
21
|
+
* @author Aonaufly
|
|
22
|
+
*/
|
|
23
|
+
var CollisionDetectionUtil = /** @class */ (function () {
|
|
24
|
+
function CollisionDetectionUtil() {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* AABB检测
|
|
28
|
+
* @param aAnchor A的锚点(0~1)
|
|
29
|
+
* @param bAnchor B的描点(0~1)
|
|
30
|
+
* @param aBox
|
|
31
|
+
* @param bBox
|
|
32
|
+
*/
|
|
33
|
+
CollisionDetectionUtil.aABB = function (aAnchor, bAnchor, aBox, bBox) {
|
|
34
|
+
if (!CollisionDetectionUtil._aabb) {
|
|
35
|
+
CollisionDetectionUtil._aabb = new AABB();
|
|
36
|
+
}
|
|
37
|
+
var result = CollisionDetectionUtil._aabb.conllision(aAnchor, bAnchor, aBox, bBox);
|
|
38
|
+
CollisionDetectionUtil._aabb.clear();
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* OBB检测
|
|
43
|
+
* @param aCenter A的中心位置
|
|
44
|
+
* @param bCenter B的中心位置
|
|
45
|
+
* @param aOBB
|
|
46
|
+
* @param bOBB
|
|
47
|
+
*/
|
|
48
|
+
CollisionDetectionUtil.oBB = function (aCenter, bCenter, aOBB, bOBB) {
|
|
49
|
+
if (!CollisionDetectionUtil._obb) {
|
|
50
|
+
CollisionDetectionUtil._obb = new OBB();
|
|
51
|
+
}
|
|
52
|
+
var result = CollisionDetectionUtil._obb.conllision(aCenter, bCenter, aOBB, bOBB);
|
|
53
|
+
CollisionDetectionUtil._obb.clear();
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* 多边形检测
|
|
58
|
+
* @param aVertices A的每个点的位置
|
|
59
|
+
* @param bVertices B的每个点的位置
|
|
60
|
+
*/
|
|
61
|
+
CollisionDetectionUtil.polygon = function (aVertices, bVertices) {
|
|
62
|
+
if (!CollisionDetectionUtil._polygon) {
|
|
63
|
+
CollisionDetectionUtil._polygon = new Polygon();
|
|
64
|
+
}
|
|
65
|
+
var result = CollisionDetectionUtil._polygon.conllision(null, null, aVertices, bVertices);
|
|
66
|
+
CollisionDetectionUtil._polygon.clear();
|
|
67
|
+
return result;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* 检测旋转矩形和圆形是否相交<br>
|
|
71
|
+
* <div style="color: #FF0000;">锚点都为0.5</div>
|
|
72
|
+
* @param circle 圆形
|
|
73
|
+
* @param rect 矩形
|
|
74
|
+
*/
|
|
75
|
+
CollisionDetectionUtil.circle2Rect = function (circle, rect) {
|
|
76
|
+
var angle = rect.angle / Math.PI * 180;
|
|
77
|
+
var rectMidPointX = rect.position.x;
|
|
78
|
+
var rectMidPointY = rect.position.y;
|
|
79
|
+
var rectLeftBottomX = rect.position.x - rect.width / 2;
|
|
80
|
+
var rectLeftBottomY = rect.position.y - rect.height / 2;
|
|
81
|
+
var unrotatedCircleX = Math.cos(-angle) * (circle.position.x - rectMidPointX) - Math.sin(-angle) * (circle.position.y - rectMidPointY) + rectMidPointX;
|
|
82
|
+
var unrotatedCircleY = Math.sin(-angle) * (circle.position.x - rectMidPointX) + Math.cos(-angle) * (circle.position.y - rectMidPointY) + rectMidPointY;
|
|
83
|
+
var closestX = 0, closestY = 0;
|
|
84
|
+
if (unrotatedCircleX < rectLeftBottomX)
|
|
85
|
+
closestX = rectLeftBottomX;
|
|
86
|
+
else if (unrotatedCircleX > rectLeftBottomX + rect.width)
|
|
87
|
+
closestX = rectLeftBottomX + rect.width;
|
|
88
|
+
else
|
|
89
|
+
closestX = unrotatedCircleX;
|
|
90
|
+
if (unrotatedCircleY < rectLeftBottomY)
|
|
91
|
+
closestY = rectLeftBottomY;
|
|
92
|
+
else if (unrotatedCircleY > rectLeftBottomY + rect.height)
|
|
93
|
+
closestY = rectLeftBottomY + rect.height;
|
|
94
|
+
else
|
|
95
|
+
closestY = unrotatedCircleY;
|
|
96
|
+
var findDistance = function (fromX, fromY, toX, toY) {
|
|
97
|
+
var a = Math.abs(fromX - toX);
|
|
98
|
+
var b = Math.abs(fromY - toY);
|
|
99
|
+
return Math.sqrt((a * a) + (b * b));
|
|
100
|
+
};
|
|
101
|
+
var distance = findDistance(unrotatedCircleX, unrotatedCircleY, closestX, closestY);
|
|
102
|
+
return distance < circle.radius;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* 2个圆形是否碰撞
|
|
106
|
+
*/
|
|
107
|
+
CollisionDetectionUtil.circle2Circle = function (aCircle, bCircle) {
|
|
108
|
+
var distance = Math.sqrt(Math.pow((aCircle.position.x - bCircle.position.x), 2) + Math.pow((aCircle.position.y - bCircle.position.y), 2));
|
|
109
|
+
return distance <= aCircle.radius + bCircle.radius;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* 判断某个点的位置是否位于椭圆内
|
|
113
|
+
* @param pos 点的位置
|
|
114
|
+
* @param centerPos 椭圆中心点
|
|
115
|
+
* @param ellipseAxis 椭圆轴
|
|
116
|
+
* @returns
|
|
117
|
+
*/
|
|
118
|
+
CollisionDetectionUtil.IsInEllipse = function (pos, centerPos, ellipseAxis) {
|
|
119
|
+
var diffX = pos.x - centerPos.x;
|
|
120
|
+
var diffY = pos.y - centerPos.y;
|
|
121
|
+
return ((diffX * diffX) / (ellipseAxis.x * ellipseAxis.x) + (diffY * diffY) / (ellipseAxis.y * ellipseAxis.y)) <= 1;
|
|
122
|
+
};
|
|
123
|
+
return CollisionDetectionUtil;
|
|
124
|
+
}());
|
|
125
|
+
exports.CollisionDetectionUtil = CollisionDetectionUtil;
|
|
126
|
+
//#region 碰撞检测基类
|
|
127
|
+
var CollisionBase = /** @class */ (function () {
|
|
128
|
+
function CollisionBase() {
|
|
129
|
+
}
|
|
130
|
+
CollisionBase.prototype.clear = function () {
|
|
131
|
+
this._aAnchor = null;
|
|
132
|
+
this._bAnchor = null;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* 碰撞检测处理
|
|
136
|
+
*/
|
|
137
|
+
CollisionBase.prototype.conllision = function (aAnchor, bAnchor) {
|
|
138
|
+
var args = [];
|
|
139
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
140
|
+
args[_i - 2] = arguments[_i];
|
|
141
|
+
}
|
|
142
|
+
this._aAnchor = aAnchor;
|
|
143
|
+
this._bAnchor = bAnchor;
|
|
144
|
+
return this.check();
|
|
145
|
+
};
|
|
146
|
+
CollisionBase.prototype.destroy = function () {
|
|
147
|
+
this.clear();
|
|
148
|
+
};
|
|
149
|
+
return CollisionBase;
|
|
150
|
+
}());
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region AABB碰撞(2个矩形的简单碰撞)
|
|
153
|
+
var AABB = /** @class */ (function (_super) {
|
|
154
|
+
__extends(AABB, _super);
|
|
155
|
+
function AABB() {
|
|
156
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
157
|
+
}
|
|
158
|
+
AABB.prototype.conllision = function (aAnchor, bAnchor, aBox, bBox) {
|
|
159
|
+
this._aBox = aBox;
|
|
160
|
+
this._bBox = bBox;
|
|
161
|
+
return _super.prototype.conllision.call(this, aAnchor, bAnchor);
|
|
162
|
+
};
|
|
163
|
+
AABB.prototype.check = function () {
|
|
164
|
+
var aX = this._aBox.x - this._aAnchor.x * this._aBox.width;
|
|
165
|
+
var aY = this._aBox.y - this._aAnchor.y * this._aBox.height;
|
|
166
|
+
var bX = this._bBox.x - this._bAnchor.x * this._bBox.width;
|
|
167
|
+
var bY = this._bBox.y - this._bAnchor.y * this._bBox.height;
|
|
168
|
+
return aX < bX + this._bBox.width &&
|
|
169
|
+
aX + this._aBox.width > bX &&
|
|
170
|
+
aY < bY + this._bBox.height &&
|
|
171
|
+
aY + this._aBox.height > bY;
|
|
172
|
+
};
|
|
173
|
+
AABB.prototype.clear = function () {
|
|
174
|
+
this._aBox = null;
|
|
175
|
+
this._bBox = null;
|
|
176
|
+
_super.prototype.clear.call(this);
|
|
177
|
+
};
|
|
178
|
+
return AABB;
|
|
179
|
+
}(CollisionBase));
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region OBB适用于旋转的矩形,需要使用分离轴定理(SAT)进行检测
|
|
182
|
+
var OBB = /** @class */ (function (_super) {
|
|
183
|
+
__extends(OBB, _super);
|
|
184
|
+
function OBB() {
|
|
185
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
186
|
+
}
|
|
187
|
+
OBB.prototype.clear = function () {
|
|
188
|
+
this._aOBB = null;
|
|
189
|
+
this._bOBB = null;
|
|
190
|
+
_super.prototype.clear.call(this);
|
|
191
|
+
};
|
|
192
|
+
OBB.prototype.conllision = function (aAnchor, bAnchor, aOBB, bOBB) {
|
|
193
|
+
this._aOBB = aOBB;
|
|
194
|
+
this._bOBB = bOBB;
|
|
195
|
+
return _super.prototype.conllision.call(this, aAnchor, bAnchor);
|
|
196
|
+
};
|
|
197
|
+
OBB.prototype.getVertices = function (isA) {
|
|
198
|
+
var obbInfo = isA ? this._aOBB : this._bOBB;
|
|
199
|
+
var center = isA ? this._aAnchor : this._bAnchor;
|
|
200
|
+
var rad = obbInfo.angle * Math.PI / 180;
|
|
201
|
+
var cos = Math.cos(rad);
|
|
202
|
+
var sin = Math.sin(rad);
|
|
203
|
+
var halfWidth = obbInfo.width / 2;
|
|
204
|
+
var halfHeight = obbInfo.height / 2;
|
|
205
|
+
return [
|
|
206
|
+
{
|
|
207
|
+
x: center.x + cos * halfWidth - sin * halfHeight,
|
|
208
|
+
y: center.y + sin * halfWidth + cos * halfHeight
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
x: center.x - cos * halfWidth - sin * halfHeight,
|
|
212
|
+
y: center.y - sin * halfWidth + cos * halfHeight
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
x: center.x - cos * halfWidth + sin * halfHeight,
|
|
216
|
+
y: center.y - sin * halfWidth - cos * halfHeight
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
x: center.x + cos * halfWidth + sin * halfHeight,
|
|
220
|
+
y: center.y + sin * halfWidth - cos * halfHeight
|
|
221
|
+
}
|
|
222
|
+
];
|
|
223
|
+
};
|
|
224
|
+
OBB.prototype.getAxes = function (isA) {
|
|
225
|
+
var vertices = this.getVertices(isA);
|
|
226
|
+
return [
|
|
227
|
+
{ x: vertices[1].x - vertices[0].x, y: vertices[1].y - vertices[0].y },
|
|
228
|
+
{ x: vertices[2].x - vertices[1].x, y: vertices[2].y - vertices[1].y }
|
|
229
|
+
];
|
|
230
|
+
};
|
|
231
|
+
OBB.prototype.project = function (axis, isA) {
|
|
232
|
+
var vertices = this.getVertices(isA);
|
|
233
|
+
var min = Infinity;
|
|
234
|
+
var max = -Infinity;
|
|
235
|
+
vertices.forEach(function (vertex) {
|
|
236
|
+
var dot = vertex.x * axis.x + vertex.y * axis.y;
|
|
237
|
+
min = Math.min(min, dot);
|
|
238
|
+
max = Math.max(max, dot);
|
|
239
|
+
});
|
|
240
|
+
return { min: min, max: max };
|
|
241
|
+
};
|
|
242
|
+
OBB.prototype.check = function () {
|
|
243
|
+
var axes = this.getAxes(true).concat(this.getAxes(false));
|
|
244
|
+
for (var _i = 0, axes_1 = axes; _i < axes_1.length; _i++) {
|
|
245
|
+
var axis = axes_1[_i];
|
|
246
|
+
var proj1 = this.project(axis, true);
|
|
247
|
+
var proj2 = this.project(axis, false);
|
|
248
|
+
if (proj1.max < proj2.min || proj2.max < proj1.min) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return true;
|
|
253
|
+
};
|
|
254
|
+
return OBB;
|
|
255
|
+
}(CollisionBase));
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region 多边形
|
|
258
|
+
var Polygon = /** @class */ (function (_super) {
|
|
259
|
+
__extends(Polygon, _super);
|
|
260
|
+
function Polygon() {
|
|
261
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
262
|
+
}
|
|
263
|
+
Polygon.prototype.conllision = function (aAnchor, bAnchor, aVertices, bVertices) {
|
|
264
|
+
this._aVertices = aVertices;
|
|
265
|
+
this._bVertices = bVertices;
|
|
266
|
+
return _super.prototype.conllision.call(this, null, null);
|
|
267
|
+
};
|
|
268
|
+
Polygon.prototype.getAxes = function (isA) {
|
|
269
|
+
var vertices = isA ? this._aVertices : this._bVertices;
|
|
270
|
+
var axes = [];
|
|
271
|
+
for (var i = 0; i < vertices.length; i++) {
|
|
272
|
+
var p1 = vertices[i];
|
|
273
|
+
var p2 = vertices[(i + 1) % vertices.length];
|
|
274
|
+
var edge = { x: p2.x - p1.x, y: p2.y - p1.y };
|
|
275
|
+
var normal = { x: -edge.y, y: edge.x };
|
|
276
|
+
axes.push(normal);
|
|
277
|
+
}
|
|
278
|
+
return axes;
|
|
279
|
+
};
|
|
280
|
+
Polygon.prototype.project = function (axis, isA) {
|
|
281
|
+
var min = Infinity;
|
|
282
|
+
var max = -Infinity;
|
|
283
|
+
var vertices = isA ? this._aVertices : this._bVertices;
|
|
284
|
+
vertices.forEach(function (vertex) {
|
|
285
|
+
var dot = vertex.x * axis.x + vertex.y * axis.y;
|
|
286
|
+
min = Math.min(min, dot);
|
|
287
|
+
max = Math.max(max, dot);
|
|
288
|
+
});
|
|
289
|
+
return { min: min, max: max };
|
|
290
|
+
};
|
|
291
|
+
Polygon.prototype.clear = function () {
|
|
292
|
+
this._aVertices = null;
|
|
293
|
+
this._bVertices = null;
|
|
294
|
+
_super.prototype.clear.call(this);
|
|
295
|
+
};
|
|
296
|
+
Polygon.prototype.check = function () {
|
|
297
|
+
var axes = this.getAxes(true).concat(this.getAxes(false));
|
|
298
|
+
for (var _i = 0, axes_2 = axes; _i < axes_2.length; _i++) {
|
|
299
|
+
var axis = axes_2[_i];
|
|
300
|
+
var proj1 = this.project(axis, true);
|
|
301
|
+
var proj2 = this.project(axis, false);
|
|
302
|
+
if (proj1.max < proj2.min || proj2.max < proj1.min) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return true;
|
|
307
|
+
};
|
|
308
|
+
return Polygon;
|
|
309
|
+
}(CollisionBase));
|
|
310
|
+
//#endregion
|
|
@@ -25,6 +25,44 @@ var StringUtil = /** @class */ (function () {
|
|
|
25
25
|
}
|
|
26
26
|
return str;
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* 字符串的格式化 , 从1开始
|
|
30
|
+
* @param str 源字符串
|
|
31
|
+
* @param args 填充参数
|
|
32
|
+
*/
|
|
33
|
+
StringUtil.formatWithStart1 = function (str) {
|
|
34
|
+
var args = [];
|
|
35
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
36
|
+
args[_i - 1] = arguments[_i];
|
|
37
|
+
}
|
|
38
|
+
if (!args || args.length == 0)
|
|
39
|
+
return str;
|
|
40
|
+
for (var i = 1, j = args.length; i <= j; i++) {
|
|
41
|
+
str = str.replace("{".concat(i, "}"), args[i - 1]);
|
|
42
|
+
}
|
|
43
|
+
return str;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* 单个替换
|
|
47
|
+
*/
|
|
48
|
+
StringUtil.replace = function (text, searchValue, replaceValue, ignoreCase) {
|
|
49
|
+
if (ignoreCase === void 0) { ignoreCase = false; }
|
|
50
|
+
var flags = ignoreCase ? 'gi' : 'g';
|
|
51
|
+
var esc = searchValue.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
52
|
+
return text.replace(new RegExp(esc, flags), replaceValue);
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* 批量替换
|
|
56
|
+
*/
|
|
57
|
+
StringUtil.replaceBatch = function (text, map, ignoreCase) {
|
|
58
|
+
if (ignoreCase === void 0) { ignoreCase = false; }
|
|
59
|
+
if (!Object.keys(map).length)
|
|
60
|
+
return text;
|
|
61
|
+
var flags = ignoreCase ? 'gi' : 'g';
|
|
62
|
+
var keys = Object.keys(map).sort(function (a, b) { return b.length - a.length; }); // 长优先
|
|
63
|
+
var pattern = keys.map(function (k) { return k.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }).join('|');
|
|
64
|
+
return text.replace(new RegExp(pattern, flags), function (m) { var _a; return (_a = map[m]) !== null && _a !== void 0 ? _a : m; });
|
|
65
|
+
};
|
|
28
66
|
/**
|
|
29
67
|
* 将字符串中所有的\/替换成/
|
|
30
68
|
*/
|
package/package.json
CHANGED
package/type/index.d.ts
CHANGED
|
@@ -191,6 +191,20 @@ export declare class StringUtil {
|
|
|
191
191
|
* @param args 填充参数
|
|
192
192
|
*/
|
|
193
193
|
static format(str: string, ...args: any): string;
|
|
194
|
+
/**
|
|
195
|
+
* 字符串的格式化 , 从1开始
|
|
196
|
+
* @param str 源字符串
|
|
197
|
+
* @param args 填充参数
|
|
198
|
+
*/
|
|
199
|
+
static formatWithStart1(str: string, ...args: any): string;
|
|
200
|
+
/**
|
|
201
|
+
* 单个替换
|
|
202
|
+
*/
|
|
203
|
+
static replace(text: string, searchValue: string, replaceValue: string, ignoreCase?: boolean): string;
|
|
204
|
+
/**
|
|
205
|
+
* 批量替换
|
|
206
|
+
*/
|
|
207
|
+
static replaceBatch(text: string, map: ReplacerMap, ignoreCase?: boolean): string;
|
|
194
208
|
/**
|
|
195
209
|
* 将字符串中所有的\/替换成/
|
|
196
210
|
*/
|
|
@@ -203,6 +217,7 @@ export declare class StringUtil {
|
|
|
203
217
|
static string2UTF8Buffer(str: string): ArrayBuffer;
|
|
204
218
|
static buffer2UTF8String: (buffer: ArrayBuffer) => string;
|
|
205
219
|
}
|
|
220
|
+
export type ReplacerMap = Record<string, string>;
|
|
206
221
|
/**
|
|
207
222
|
* 唯一ID生成器
|
|
208
223
|
* @author Aonaufly
|
|
@@ -331,5 +346,84 @@ export declare class SelfDecrypt {
|
|
|
331
346
|
*/
|
|
332
347
|
static decryptBase64(b64: string, key: string): string;
|
|
333
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* 碰撞检测工具
|
|
351
|
+
* @author Aonaufly
|
|
352
|
+
*/
|
|
353
|
+
export declare class CollisionDetectionUtil {
|
|
354
|
+
private static _aabb;
|
|
355
|
+
private static _obb;
|
|
356
|
+
private static _polygon;
|
|
357
|
+
/**
|
|
358
|
+
* AABB检测
|
|
359
|
+
* @param aAnchor A的锚点(0~1)
|
|
360
|
+
* @param bAnchor B的描点(0~1)
|
|
361
|
+
* @param aBox
|
|
362
|
+
* @param bBox
|
|
363
|
+
*/
|
|
364
|
+
static aABB(aAnchor: Vec2, bAnchor: Vec2, aBox: IBoxInfo, bBox: IBoxInfo): boolean;
|
|
365
|
+
/**
|
|
366
|
+
* OBB检测
|
|
367
|
+
* @param aCenter A的中心位置
|
|
368
|
+
* @param bCenter B的中心位置
|
|
369
|
+
* @param aOBB
|
|
370
|
+
* @param bOBB
|
|
371
|
+
*/
|
|
372
|
+
static oBB(aCenter: Vec2, bCenter: Vec2, aOBB: IOBBInfo, bOBB: IOBBInfo): boolean;
|
|
373
|
+
/**
|
|
374
|
+
* 多边形检测
|
|
375
|
+
* @param aVertices A的每个点的位置
|
|
376
|
+
* @param bVertices B的每个点的位置
|
|
377
|
+
*/
|
|
378
|
+
static polygon(aVertices: Vec2[], bVertices: Vec2[]): boolean;
|
|
379
|
+
/**
|
|
380
|
+
* 检测旋转矩形和圆形是否相交<br>
|
|
381
|
+
* <div style="color: #FF0000;">锚点都为0.5</div>
|
|
382
|
+
* @param circle 圆形
|
|
383
|
+
* @param rect 矩形
|
|
384
|
+
*/
|
|
385
|
+
static circle2Rect(circle: {
|
|
386
|
+
position: Vec2;
|
|
387
|
+
radius: number;
|
|
388
|
+
}, rect: {
|
|
389
|
+
position: Vec2;
|
|
390
|
+
width: number;
|
|
391
|
+
height: number;
|
|
392
|
+
angle: number;
|
|
393
|
+
}): boolean;
|
|
394
|
+
/**
|
|
395
|
+
* 2个圆形是否碰撞
|
|
396
|
+
*/
|
|
397
|
+
static circle2Circle(aCircle: {
|
|
398
|
+
position: Vec2;
|
|
399
|
+
radius: number;
|
|
400
|
+
}, bCircle: {
|
|
401
|
+
position: Vec2;
|
|
402
|
+
radius: number;
|
|
403
|
+
}): boolean;
|
|
404
|
+
/**
|
|
405
|
+
* 判断某个点的位置是否位于椭圆内
|
|
406
|
+
* @param pos 点的位置
|
|
407
|
+
* @param centerPos 椭圆中心点
|
|
408
|
+
* @param ellipseAxis 椭圆轴
|
|
409
|
+
* @returns
|
|
410
|
+
*/
|
|
411
|
+
static IsInEllipse(pos: Vec2, centerPos: Vec2, ellipseAxis: Vec2): boolean;
|
|
412
|
+
}
|
|
413
|
+
export interface IBoxInfo {
|
|
414
|
+
x: number;
|
|
415
|
+
y: number;
|
|
416
|
+
width: number;
|
|
417
|
+
height: number;
|
|
418
|
+
}
|
|
419
|
+
export interface Vec2 {
|
|
420
|
+
x: number;
|
|
421
|
+
y: number;
|
|
422
|
+
}
|
|
423
|
+
export interface IOBBInfo {
|
|
424
|
+
width: number;
|
|
425
|
+
height: number;
|
|
426
|
+
angle: number;
|
|
427
|
+
}
|
|
334
428
|
|
|
335
429
|
export {};
|
package/common/util/CryptUtil.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CryptUtil = void 0;
|
|
7
|
-
var crypto_es_1 = __importDefault(require("crypto-es"));
|
|
8
|
-
/**
|
|
9
|
-
* 加解密工具
|
|
10
|
-
* @author Aonaufly
|
|
11
|
-
*/
|
|
12
|
-
var CryptUtil = /** @class */ (function () {
|
|
13
|
-
function CryptUtil() {
|
|
14
|
-
}
|
|
15
|
-
//#region AES-256 ECB
|
|
16
|
-
/** 加密函数AES-256 ECB */
|
|
17
|
-
CryptUtil.encryptAes = function (plainText, key) {
|
|
18
|
-
var keyBytes = crypto_es_1.default.enc.Utf8.parse(key);
|
|
19
|
-
var encrypted = crypto_es_1.default.AES.encrypt(crypto_es_1.default.enc.Utf8.parse(plainText), keyBytes, {
|
|
20
|
-
mode: crypto_es_1.default.mode.ECB,
|
|
21
|
-
padding: crypto_es_1.default.pad.Pkcs7,
|
|
22
|
-
});
|
|
23
|
-
return encrypted.toString();
|
|
24
|
-
};
|
|
25
|
-
/**解密函数AES-256 ECB*/
|
|
26
|
-
CryptUtil.decryptAes = function (cipherText, key) {
|
|
27
|
-
var keyBytes = crypto_es_1.default.enc.Utf8.parse(key);
|
|
28
|
-
var decrypted = crypto_es_1.default.AES.decrypt(cipherText, keyBytes, {
|
|
29
|
-
mode: crypto_es_1.default.mode.ECB,
|
|
30
|
-
padding: crypto_es_1.default.pad.Pkcs7,
|
|
31
|
-
});
|
|
32
|
-
return crypto_es_1.default.enc.Utf8.stringify(decrypted);
|
|
33
|
-
};
|
|
34
|
-
//#endregion
|
|
35
|
-
/**
|
|
36
|
-
* MD5
|
|
37
|
-
*/
|
|
38
|
-
CryptUtil.md5 = function (text) {
|
|
39
|
-
return crypto_es_1.default.MD5(text).toString();
|
|
40
|
-
};
|
|
41
|
-
return CryptUtil;
|
|
42
|
-
}());
|
|
43
|
-
exports.CryptUtil = CryptUtil;
|