light-h5-core-lib 2.10.11 → 2.11.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 +4 -1
- package/common/util/BeizerPositionsLerpUtil.js +80 -0
- package/common/util/BeizerUtil.js +23 -0
- package/common/util/DateUtil.js +47 -5
- package/package.json +1 -1
- package/type/index.d.ts +50 -9
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.MapUtil = exports.CollisionDetectionUtil = exports.SelfDecrypt = exports.GetDecorateUtils = 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.SetterGetterBase = exports.ClassNameUtil = exports.PoolObj = exports.PoolObjPutStatus = void 0;
|
|
6
|
+
exports.MapUtil = exports.CollisionDetectionUtil = exports.SelfDecrypt = exports.GetDecorateUtils = 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.SetterGetterBase = exports.ClassNameUtil = exports.PoolObj = exports.PoolObjPutStatus = exports.BeizerPositionsLerpUtil = void 0;
|
|
7
7
|
const PoolObj_1 = require("./pool/PoolObj");
|
|
8
8
|
Object.defineProperty(exports, "PoolObj", { enumerable: true, get: function () { return PoolObj_1.PoolObj; } });
|
|
9
9
|
const BaseSingleton_1 = require("./common/base/BaseSingleton");
|
|
@@ -46,7 +46,10 @@ const MapUtil_1 = require("./common/util/MapUtil");
|
|
|
46
46
|
Object.defineProperty(exports, "MapUtil", { enumerable: true, get: function () { return MapUtil_1.MapUtil; } });
|
|
47
47
|
const PoolObjPutStatus_1 = require("./pool/PoolObjPutStatus");
|
|
48
48
|
Object.defineProperty(exports, "PoolObjPutStatus", { enumerable: true, get: function () { return PoolObjPutStatus_1.PoolObjPutStatus; } });
|
|
49
|
+
const BeizerPositionsLerpUtil_1 = require("./common/util/BeizerPositionsLerpUtil");
|
|
50
|
+
Object.defineProperty(exports, "BeizerPositionsLerpUtil", { enumerable: true, get: function () { return BeizerPositionsLerpUtil_1.BeizerPositionsLerpUtil; } });
|
|
49
51
|
module.exports = {
|
|
52
|
+
BeizerPositionsLerpUtil: BeizerPositionsLerpUtil_1.BeizerPositionsLerpUtil,
|
|
50
53
|
PoolObjPutStatus: PoolObjPutStatus_1.PoolObjPutStatus,
|
|
51
54
|
PoolObj: PoolObj_1.PoolObj,
|
|
52
55
|
ClassNameUtil: ClassNameUtil_1.ClassNameUtil,
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BeizerPositionsLerpUtil = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 贝塞尔曲线坐标点插值算法
|
|
6
|
+
* @author Aonaufly
|
|
7
|
+
*/
|
|
8
|
+
class BeizerPositionsLerpUtil {
|
|
9
|
+
/**
|
|
10
|
+
* 根据开始坐标和结束坐标计算整个贝塞尔曲线的坐标点集合
|
|
11
|
+
* @param startPosition 开始坐标
|
|
12
|
+
* @param endPosition 结束坐标
|
|
13
|
+
* @param addCount 再添加的坐标点数(startPosition + addCount + endPosition) default 1
|
|
14
|
+
* @param amplitude 幅度(1: 最大为开始坐标与结束坐标的距离的一半)default 0.4
|
|
15
|
+
* @param distanceMultiple 距离倍数(1=线段内, >1则控制点可向两端外延,如1.5=两端各外延0.25倍线段长度)default 1.0
|
|
16
|
+
* @returns 控制点集合
|
|
17
|
+
*/
|
|
18
|
+
static generateControlPoints(startPosition, endPosition, addCount = 1, amplitude = 0.4, distanceMultiple = 1.0) {
|
|
19
|
+
const result = [{ x: startPosition.x, y: startPosition.y }];
|
|
20
|
+
if (addCount <= 0) {
|
|
21
|
+
result.push({ x: endPosition.x, y: endPosition.y });
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
// 连接线方向向量
|
|
25
|
+
const dx = endPosition.x - startPosition.x;
|
|
26
|
+
const dy = endPosition.y - startPosition.y;
|
|
27
|
+
const len = Math.sqrt(dx * dx + dy * dy);
|
|
28
|
+
if (len < 0.000001) {
|
|
29
|
+
// 起点与终点重合,直接返回
|
|
30
|
+
for (let i = 0; i < addCount; i++) {
|
|
31
|
+
result.push({ x: startPosition.x, y: startPosition.y });
|
|
32
|
+
}
|
|
33
|
+
result.push({ x: endPosition.x, y: endPosition.y });
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
// 单位方向向量
|
|
37
|
+
const ux = dx / len;
|
|
38
|
+
const uy = dy / len;
|
|
39
|
+
// 垂直方向向量(法向量),旋转90度
|
|
40
|
+
const nx = -uy;
|
|
41
|
+
const ny = ux;
|
|
42
|
+
// 添加点到连接线的最大距离:amplitude * 0.5 * 连接线长度
|
|
43
|
+
const maxDistance = amplitude * 0.5 * len;
|
|
44
|
+
// 投影延伸:distanceMultiple=1时投影范围在[0,1]内,>1时向两端外延
|
|
45
|
+
const extension = (distanceMultiple - 1) * 0.5;
|
|
46
|
+
// 上一个添加点所在的侧(1 或 -1),用于交替偏向
|
|
47
|
+
let prevSide = 0;
|
|
48
|
+
for (let i = 0; i < addCount; i++) {
|
|
49
|
+
// 在连接线上的投影比例 t ∈ (0, 1),均匀分布
|
|
50
|
+
const t = (i + 1) / (addCount + 1);
|
|
51
|
+
// 映射到实际投影比例:t=0时映射到-extension(起点外侧),t=1时映射到1+extension(终点外侧)
|
|
52
|
+
const effectiveT = t * distanceMultiple - extension;
|
|
53
|
+
// 投影点坐标
|
|
54
|
+
const px = startPosition.x + dx * effectiveT;
|
|
55
|
+
const py = startPosition.y + dy * effectiveT;
|
|
56
|
+
// 随机距离 ∈ (0, maxDistance],确保不在连接线上
|
|
57
|
+
const randomFactor = 0.1 + Math.random() * 0.9;
|
|
58
|
+
const distance = randomFactor * maxDistance;
|
|
59
|
+
// 选择连接线的一侧
|
|
60
|
+
// 若有上一个点,偏向另一侧的概率为 75%(基础50%增加50%)
|
|
61
|
+
// 若无上一个点(第一个添加点),各侧50%
|
|
62
|
+
let side;
|
|
63
|
+
if (prevSide === 0) {
|
|
64
|
+
side = Math.random() > 0.5 ? 1 : -1;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
side = Math.random() < 0.75 ? -prevSide : prevSide;
|
|
68
|
+
}
|
|
69
|
+
// 沿法向量偏移得到最终坐标
|
|
70
|
+
result.push({
|
|
71
|
+
x: px + nx * distance * side,
|
|
72
|
+
y: py + ny * distance * side,
|
|
73
|
+
});
|
|
74
|
+
prevSide = side;
|
|
75
|
+
}
|
|
76
|
+
result.push({ x: endPosition.x, y: endPosition.y });
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.BeizerPositionsLerpUtil = BeizerPositionsLerpUtil;
|
|
@@ -24,6 +24,29 @@ class BeizerUtil {
|
|
|
24
24
|
}
|
|
25
25
|
return { x, y };
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* 获得当前时间的切线(运动方向)(慎用: 耗性能)
|
|
29
|
+
* @param timer 时间[0,1]
|
|
30
|
+
* @returns 切线
|
|
31
|
+
*/
|
|
32
|
+
static getTangent(points, timer) {
|
|
33
|
+
if (points.length < 2) {
|
|
34
|
+
return { x: 0, y: 0 };
|
|
35
|
+
}
|
|
36
|
+
// 导数控制点: Q_i = P_{i+1} - P_i
|
|
37
|
+
const derivativePoints = [];
|
|
38
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
39
|
+
derivativePoints.push({
|
|
40
|
+
x: points[i + 1].x - points[i].x,
|
|
41
|
+
y: points[i + 1].y - points[i].y,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
// 在导数控制点上计算 n-2 阶贝塞尔值
|
|
45
|
+
const pos = BeizerUtil.getPosition(derivativePoints, timer);
|
|
46
|
+
// 乘以 (n-1) 得到最终切线
|
|
47
|
+
const n = points.length;
|
|
48
|
+
return { x: pos.x * (n - 1), y: pos.y * (n - 1) };
|
|
49
|
+
}
|
|
27
50
|
//#endregion
|
|
28
51
|
//region 获得路线的长度
|
|
29
52
|
static distance(p1, p2) {
|
package/common/util/DateUtil.js
CHANGED
|
@@ -34,11 +34,19 @@ class DateUtil {
|
|
|
34
34
|
}
|
|
35
35
|
const m = Math.floor((s - h * 3600) / 60);
|
|
36
36
|
s = s - h * 3600 - m * 60;
|
|
37
|
-
let result = isSingle0
|
|
37
|
+
let result = isSingle0
|
|
38
|
+
? h < 10
|
|
39
|
+
? `0${h}`
|
|
40
|
+
: h.toString()
|
|
41
|
+
: h.toString();
|
|
38
42
|
result += separator;
|
|
39
|
-
result =
|
|
43
|
+
result =
|
|
44
|
+
result +
|
|
45
|
+
(isSingle0 ? (m < 10 ? `0${m}` : m.toString()) : m.toString());
|
|
40
46
|
result += separator;
|
|
41
|
-
result =
|
|
47
|
+
result =
|
|
48
|
+
result +
|
|
49
|
+
(isSingle0 ? (s < 10 ? `0${s}` : s.toString()) : s.toString());
|
|
42
50
|
return result;
|
|
43
51
|
}
|
|
44
52
|
/**
|
|
@@ -50,11 +58,45 @@ class DateUtil {
|
|
|
50
58
|
static format_MS(s, separator = ":", isSingle0 = true) {
|
|
51
59
|
const m = Math.floor(s / 60);
|
|
52
60
|
s = s - m * 60;
|
|
53
|
-
let result = isSingle0
|
|
61
|
+
let result = isSingle0
|
|
62
|
+
? m < 10
|
|
63
|
+
? `0${m}`
|
|
64
|
+
: m.toString()
|
|
65
|
+
: m.toString();
|
|
54
66
|
result += separator;
|
|
55
|
-
result =
|
|
67
|
+
result =
|
|
68
|
+
result +
|
|
69
|
+
(isSingle0 ? (s < 10 ? `0${s}` : s.toString()) : s.toString());
|
|
56
70
|
return result;
|
|
57
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* 秒级时间戳转日期字符串
|
|
74
|
+
* @param seconds 秒级时间戳
|
|
75
|
+
* @param separator 分隔符,默认 "/"
|
|
76
|
+
* @returns 如 "2026/2/1"
|
|
77
|
+
*/
|
|
78
|
+
static formatDate(seconds, separator = "/") {
|
|
79
|
+
const date = new Date(seconds * 1000);
|
|
80
|
+
const year = date.getFullYear();
|
|
81
|
+
const month = date.getMonth() + 1;
|
|
82
|
+
const day = date.getDate();
|
|
83
|
+
return `${year}${separator}${month}${separator}${day}`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 秒级时间戳转日期时间字符串
|
|
87
|
+
* @param seconds 秒级时间戳
|
|
88
|
+
* @returns 如 "2026/2/1 14:30:00"
|
|
89
|
+
*/
|
|
90
|
+
static formatDateTime(seconds) {
|
|
91
|
+
const date = new Date(seconds * 1000);
|
|
92
|
+
const y = date.getFullYear();
|
|
93
|
+
const m = date.getMonth() + 1;
|
|
94
|
+
const d = date.getDate();
|
|
95
|
+
const h = date.getHours().toString().padStart(2, "0");
|
|
96
|
+
const min = date.getMinutes().toString().padStart(2, "0");
|
|
97
|
+
const s = date.getSeconds().toString().padStart(2, "0");
|
|
98
|
+
return `${y}/${m}/${d} ${h}:${min}:${s}`;
|
|
99
|
+
}
|
|
58
100
|
/**
|
|
59
101
|
* 获取下一天的时间(凌晨)秒 存在1ms误差可以忽略不计<b style="color:red">当天时间24:00</b>
|
|
60
102
|
* @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
|
package/package.json
CHANGED
package/type/index.d.ts
CHANGED
|
@@ -159,6 +159,19 @@ export declare class DateUtil {
|
|
|
159
159
|
* @param isSingle0 是否补0(default:true)
|
|
160
160
|
*/
|
|
161
161
|
static format_MS(s: number, separator?: string, isSingle0?: boolean): string;
|
|
162
|
+
/**
|
|
163
|
+
* 秒级时间戳转日期字符串
|
|
164
|
+
* @param seconds 秒级时间戳
|
|
165
|
+
* @param separator 分隔符,默认 "/"
|
|
166
|
+
* @returns 如 "2026/2/1"
|
|
167
|
+
*/
|
|
168
|
+
static formatDate(seconds: number, separator?: string): string;
|
|
169
|
+
/**
|
|
170
|
+
* 秒级时间戳转日期时间字符串
|
|
171
|
+
* @param seconds 秒级时间戳
|
|
172
|
+
* @returns 如 "2026/2/1 14:30:00"
|
|
173
|
+
*/
|
|
174
|
+
static formatDateTime(seconds: number): string;
|
|
162
175
|
/**
|
|
163
176
|
* 获取下一天的时间(凌晨)秒 存在1ms误差可以忽略不计<b style="color:red">当天时间24:00</b>
|
|
164
177
|
* @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
|
|
@@ -309,6 +322,18 @@ export declare class BeizerUtil {
|
|
|
309
322
|
x: number;
|
|
310
323
|
y: number;
|
|
311
324
|
};
|
|
325
|
+
/**
|
|
326
|
+
* 获得当前时间的切线(运动方向)(慎用: 耗性能)
|
|
327
|
+
* @param timer 时间[0,1]
|
|
328
|
+
* @returns 切线
|
|
329
|
+
*/
|
|
330
|
+
static getTangent(points: {
|
|
331
|
+
x: number;
|
|
332
|
+
y: number;
|
|
333
|
+
}[], timer: number): {
|
|
334
|
+
x: number;
|
|
335
|
+
y: number;
|
|
336
|
+
};
|
|
312
337
|
private static calculationC;
|
|
313
338
|
private static factorial;
|
|
314
339
|
private static distance;
|
|
@@ -442,7 +467,7 @@ export declare class CollisionDetectionUtil {
|
|
|
442
467
|
* @param aBox
|
|
443
468
|
* @param bBox
|
|
444
469
|
*/
|
|
445
|
-
static aABB(aAnchor:
|
|
470
|
+
static aABB(aAnchor: CoreVec2, bAnchor: CoreVec2, aBox: IBoxInfo, bBox: IBoxInfo): boolean;
|
|
446
471
|
/**
|
|
447
472
|
* OBB检测
|
|
448
473
|
* @param aCenter A的中心位置
|
|
@@ -450,13 +475,13 @@ export declare class CollisionDetectionUtil {
|
|
|
450
475
|
* @param aOBB
|
|
451
476
|
* @param bOBB
|
|
452
477
|
*/
|
|
453
|
-
static oBB(aCenter:
|
|
478
|
+
static oBB(aCenter: CoreVec2, bCenter: CoreVec2, aOBB: IOBBInfo, bOBB: IOBBInfo): boolean;
|
|
454
479
|
/**
|
|
455
480
|
* 多边形检测
|
|
456
481
|
* @param aVertices A的每个点的位置
|
|
457
482
|
* @param bVertices B的每个点的位置
|
|
458
483
|
*/
|
|
459
|
-
static polygon(aVertices:
|
|
484
|
+
static polygon(aVertices: CoreVec2[], bVertices: CoreVec2[]): boolean;
|
|
460
485
|
/**
|
|
461
486
|
* 检测旋转矩形和圆形是否相交<br>
|
|
462
487
|
* <div style="color: #FF0000;">锚点都为0.5</div>
|
|
@@ -464,10 +489,10 @@ export declare class CollisionDetectionUtil {
|
|
|
464
489
|
* @param rect 矩形
|
|
465
490
|
*/
|
|
466
491
|
static circle2Rect(circle: {
|
|
467
|
-
position:
|
|
492
|
+
position: CoreVec2;
|
|
468
493
|
radius: number;
|
|
469
494
|
}, rect: {
|
|
470
|
-
position:
|
|
495
|
+
position: CoreVec2;
|
|
471
496
|
width: number;
|
|
472
497
|
height: number;
|
|
473
498
|
angle: number;
|
|
@@ -476,10 +501,10 @@ export declare class CollisionDetectionUtil {
|
|
|
476
501
|
* 2个圆形是否碰撞
|
|
477
502
|
*/
|
|
478
503
|
static circle2Circle(aCircle: {
|
|
479
|
-
position:
|
|
504
|
+
position: CoreVec2;
|
|
480
505
|
radius: number;
|
|
481
506
|
}, bCircle: {
|
|
482
|
-
position:
|
|
507
|
+
position: CoreVec2;
|
|
483
508
|
radius: number;
|
|
484
509
|
}): boolean;
|
|
485
510
|
/**
|
|
@@ -489,7 +514,7 @@ export declare class CollisionDetectionUtil {
|
|
|
489
514
|
* @param ellipseAxis 椭圆轴
|
|
490
515
|
* @returns
|
|
491
516
|
*/
|
|
492
|
-
static IsInEllipse(pos:
|
|
517
|
+
static IsInEllipse(pos: CoreVec2, centerPos: CoreVec2, ellipseAxis: CoreVec2): boolean;
|
|
493
518
|
}
|
|
494
519
|
export interface IBoxInfo {
|
|
495
520
|
x: number;
|
|
@@ -497,7 +522,7 @@ export interface IBoxInfo {
|
|
|
497
522
|
width: number;
|
|
498
523
|
height: number;
|
|
499
524
|
}
|
|
500
|
-
export interface
|
|
525
|
+
export interface CoreVec2 {
|
|
501
526
|
x: number;
|
|
502
527
|
y: number;
|
|
503
528
|
}
|
|
@@ -594,5 +619,21 @@ export declare class MapUtil {
|
|
|
594
619
|
*/
|
|
595
620
|
static clearEmptyValue<KEY, VALUE>(targetMap: Map<KEY, VALUE>, isNeedClearCallback?: (item: VALUE) => boolean): void;
|
|
596
621
|
}
|
|
622
|
+
/**
|
|
623
|
+
* 贝塞尔曲线坐标点插值算法
|
|
624
|
+
* @author Aonaufly
|
|
625
|
+
*/
|
|
626
|
+
export declare class BeizerPositionsLerpUtil {
|
|
627
|
+
/**
|
|
628
|
+
* 根据开始坐标和结束坐标计算整个贝塞尔曲线的坐标点集合
|
|
629
|
+
* @param startPosition 开始坐标
|
|
630
|
+
* @param endPosition 结束坐标
|
|
631
|
+
* @param addCount 再添加的坐标点数(startPosition + addCount + endPosition) default 1
|
|
632
|
+
* @param amplitude 幅度(1: 最大为开始坐标与结束坐标的距离的一半)default 0.4
|
|
633
|
+
* @param distanceMultiple 距离倍数(1=线段内, >1则控制点可向两端外延,如1.5=两端各外延0.25倍线段长度)default 1.0
|
|
634
|
+
* @returns 控制点集合
|
|
635
|
+
*/
|
|
636
|
+
static generateControlPoints(startPosition: CoreVec2, endPosition: CoreVec2, addCount?: number, amplitude?: number, distanceMultiple?: number): CoreVec2[];
|
|
637
|
+
}
|
|
597
638
|
|
|
598
639
|
export {};
|