light-h5-core-lib 2.8.3 → 2.9.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/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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "light-h5-core-lib",
3
- "version": "2.8.3",
3
+ "version": "2.9.1",
4
4
  "description": "light core lib",
5
5
  "main": "./LightCore.js",
6
6
  "types": "./type/index.d.ts",
package/pool/PoolObj.js CHANGED
@@ -8,23 +8,95 @@ exports.PoolObj = void 0;
8
8
  var PoolObj = /** @class */ (function () {
9
9
  /**
10
10
  * @param cap 容量(容积)
11
+ * @param initCreateNum 初始化创建的数量 (createCallback != null 有效)
12
+ * @param createCallback Item创建函数
13
+ * @param clearCallback Item清理函数
14
+ * @param destroyCallback Item销毁函数
11
15
  */
12
- function PoolObj(cap) {
16
+ function PoolObj(cap, initCreateNum, createCallback, clearCallback, destroyCallback) {
13
17
  if (cap === void 0) { cap = 5; }
18
+ if (initCreateNum === void 0) { initCreateNum = 0; }
19
+ if (createCallback === void 0) { createCallback = null; }
20
+ if (clearCallback === void 0) { clearCallback = null; }
21
+ if (destroyCallback === void 0) { destroyCallback = null; }
14
22
  this._cap = cap;
23
+ this._createCallback = createCallback;
24
+ this._clearCallback = clearCallback;
25
+ this._destroyCallback = destroyCallback;
15
26
  this._pool = [];
27
+ this.initCreate(initCreateNum);
16
28
  }
29
+ /**
30
+ * 初始化一些数量的item
31
+ */
32
+ PoolObj.prototype.initCreate = function (initCreateNum) {
33
+ if (initCreateNum <= 0)
34
+ return;
35
+ if (!this._createCallback)
36
+ return;
37
+ var maxNum = Math.min(this._cap, initCreateNum);
38
+ for (var i = 0; i < maxNum; i++) {
39
+ this._pool.push(this._createCallback());
40
+ }
41
+ };
42
+ /**
43
+ * 放入到对象池
44
+ * @return 放入到对象池是否成功
45
+ */
17
46
  PoolObj.prototype.put = function (obj) {
18
- if (!obj || this._pool.length >= this._cap)
47
+ if (!obj)
48
+ return false;
49
+ if (this._pool.length >= this._cap) {
50
+ this._destroyCallback && this._destroyCallback(obj);
19
51
  return false;
52
+ }
53
+ this._clearCallback && this._clearCallback(obj);
20
54
  this._pool.push(obj);
21
55
  return true;
22
56
  };
57
+ /**
58
+ * 获得一个Item<br>
59
+ * <b style="color:green">如果size==0,则自动使用createCallback创建</b><br>
60
+ * <b style="color:red">⚠️如果size==0 && createCallback==null,则返回null</b>
61
+ */
23
62
  PoolObj.prototype.one = function () {
24
- if (this._pool.length == 0)
25
- return null;
63
+ if (this._pool.length == 0) {
64
+ if (!this._createCallback)
65
+ return null;
66
+ return this._createCallback();
67
+ }
26
68
  return this._pool.shift();
27
69
  };
70
+ Object.defineProperty(PoolObj.prototype, "isExistCreateCallback", {
71
+ /**
72
+ * 是否存在Item创建方法
73
+ */
74
+ get: function () {
75
+ return this._createCallback != null;
76
+ },
77
+ enumerable: false,
78
+ configurable: true
79
+ });
80
+ Object.defineProperty(PoolObj.prototype, "isExistClearCallback", {
81
+ /**
82
+ * 是否存在Item的清理函数
83
+ */
84
+ get: function () {
85
+ return this._clearCallback != null;
86
+ },
87
+ enumerable: false,
88
+ configurable: true
89
+ });
90
+ Object.defineProperty(PoolObj.prototype, "isExistDestroyCallback", {
91
+ /**
92
+ * 是否存在Item的销毁函数
93
+ */
94
+ get: function () {
95
+ return this._destroyCallback != null;
96
+ },
97
+ enumerable: false,
98
+ configurable: true
99
+ });
28
100
  Object.defineProperty(PoolObj.prototype, "cap", {
29
101
  /**
30
102
  * 获取容量(容积)
@@ -58,13 +130,10 @@ var PoolObj = /** @class */ (function () {
58
130
  var obj;
59
131
  for (var i = 0, j = this._pool.length; i < j; i++) {
60
132
  obj = this._pool[i];
61
- if (obj.destroy) {
62
- obj.destroy();
63
- }
64
- else if (obj.onDestroy) {
65
- obj.onDestroy();
133
+ if (obj) {
134
+ this._destroyCallback && this._destroyCallback(obj);
135
+ obj = null;
66
136
  }
67
- obj = null;
68
137
  }
69
138
  this._pool.length = 0;
70
139
  };
@@ -72,6 +141,9 @@ var PoolObj = /** @class */ (function () {
72
141
  if (!isCleared) {
73
142
  this.clear();
74
143
  }
144
+ this._createCallback = null;
145
+ this._clearCallback = null;
146
+ this._destroyCallback = null;
75
147
  this._pool && (this._pool = null);
76
148
  };
77
149
  return PoolObj;
package/type/index.d.ts CHANGED
@@ -13,12 +13,44 @@ export interface IClear extends IDestroy {
13
13
  export declare class PoolObj<T> implements IClear {
14
14
  private _pool;
15
15
  private _cap;
16
+ private _createCallback;
17
+ private _clearCallback;
18
+ private _destroyCallback;
16
19
  /**
17
20
  * @param cap 容量(容积)
21
+ * @param initCreateNum 初始化创建的数量 (createCallback != null 有效)
22
+ * @param createCallback Item创建函数
23
+ * @param clearCallback Item清理函数
24
+ * @param destroyCallback Item销毁函数
25
+ */
26
+ constructor(cap?: number, initCreateNum?: number, createCallback?: () => T, clearCallback?: (item: T) => void, destroyCallback?: (item: T) => void);
27
+ /**
28
+ * 初始化一些数量的item
29
+ */
30
+ private initCreate;
31
+ /**
32
+ * 放入到对象池
33
+ * @return 放入到对象池是否成功
18
34
  */
19
- constructor(cap?: number);
20
35
  put(obj: T): boolean;
36
+ /**
37
+ * 获得一个Item<br>
38
+ * <b style="color:green">如果size==0,则自动使用createCallback创建</b><br>
39
+ * <b style="color:red">⚠️如果size==0 && createCallback==null,则返回null</b>
40
+ */
21
41
  one(): T;
42
+ /**
43
+ * 是否存在Item创建方法
44
+ */
45
+ get isExistCreateCallback(): boolean;
46
+ /**
47
+ * 是否存在Item的清理函数
48
+ */
49
+ get isExistClearCallback(): boolean;
50
+ /**
51
+ * 是否存在Item的销毁函数
52
+ */
53
+ get isExistDestroyCallback(): boolean;
22
54
  /**
23
55
  * 获取容量(容积)
24
56
  */
@@ -191,6 +223,20 @@ export declare class StringUtil {
191
223
  * @param args 填充参数
192
224
  */
193
225
  static format(str: string, ...args: any): string;
226
+ /**
227
+ * 字符串的格式化 , 从1开始
228
+ * @param str 源字符串
229
+ * @param args 填充参数
230
+ */
231
+ static formatWithStart1(str: string, ...args: any): string;
232
+ /**
233
+ * 单个替换
234
+ */
235
+ static replace(text: string, searchValue: string, replaceValue: string, ignoreCase?: boolean): string;
236
+ /**
237
+ * 批量替换
238
+ */
239
+ static replaceBatch(text: string, map: ReplacerMap, ignoreCase?: boolean): string;
194
240
  /**
195
241
  * 将字符串中所有的\/替换成/
196
242
  */
@@ -203,6 +249,7 @@ export declare class StringUtil {
203
249
  static string2UTF8Buffer(str: string): ArrayBuffer;
204
250
  static buffer2UTF8String: (buffer: ArrayBuffer) => string;
205
251
  }
252
+ export type ReplacerMap = Record<string, string>;
206
253
  /**
207
254
  * 唯一ID生成器
208
255
  * @author Aonaufly
@@ -331,5 +378,84 @@ export declare class SelfDecrypt {
331
378
  */
332
379
  static decryptBase64(b64: string, key: string): string;
333
380
  }
381
+ /**
382
+ * 碰撞检测工具
383
+ * @author Aonaufly
384
+ */
385
+ export declare class CollisionDetectionUtil {
386
+ private static _aabb;
387
+ private static _obb;
388
+ private static _polygon;
389
+ /**
390
+ * AABB检测
391
+ * @param aAnchor A的锚点(0~1)
392
+ * @param bAnchor B的描点(0~1)
393
+ * @param aBox
394
+ * @param bBox
395
+ */
396
+ static aABB(aAnchor: Vec2, bAnchor: Vec2, aBox: IBoxInfo, bBox: IBoxInfo): boolean;
397
+ /**
398
+ * OBB检测
399
+ * @param aCenter A的中心位置
400
+ * @param bCenter B的中心位置
401
+ * @param aOBB
402
+ * @param bOBB
403
+ */
404
+ static oBB(aCenter: Vec2, bCenter: Vec2, aOBB: IOBBInfo, bOBB: IOBBInfo): boolean;
405
+ /**
406
+ * 多边形检测
407
+ * @param aVertices A的每个点的位置
408
+ * @param bVertices B的每个点的位置
409
+ */
410
+ static polygon(aVertices: Vec2[], bVertices: Vec2[]): boolean;
411
+ /**
412
+ * 检测旋转矩形和圆形是否相交<br>
413
+ * <div style="color: #FF0000;">锚点都为0.5</div>
414
+ * @param circle 圆形
415
+ * @param rect 矩形
416
+ */
417
+ static circle2Rect(circle: {
418
+ position: Vec2;
419
+ radius: number;
420
+ }, rect: {
421
+ position: Vec2;
422
+ width: number;
423
+ height: number;
424
+ angle: number;
425
+ }): boolean;
426
+ /**
427
+ * 2个圆形是否碰撞
428
+ */
429
+ static circle2Circle(aCircle: {
430
+ position: Vec2;
431
+ radius: number;
432
+ }, bCircle: {
433
+ position: Vec2;
434
+ radius: number;
435
+ }): boolean;
436
+ /**
437
+ * 判断某个点的位置是否位于椭圆内
438
+ * @param pos 点的位置
439
+ * @param centerPos 椭圆中心点
440
+ * @param ellipseAxis 椭圆轴
441
+ * @returns
442
+ */
443
+ static IsInEllipse(pos: Vec2, centerPos: Vec2, ellipseAxis: Vec2): boolean;
444
+ }
445
+ export interface IBoxInfo {
446
+ x: number;
447
+ y: number;
448
+ width: number;
449
+ height: number;
450
+ }
451
+ export interface Vec2 {
452
+ x: number;
453
+ y: number;
454
+ }
455
+ export interface IOBBInfo {
456
+ width: number;
457
+ height: number;
458
+ angle: number;
459
+ }
334
460
 
335
461
  export {};
@@ -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;