dzkcc-mflow 0.0.1 → 0.0.2

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.
Files changed (48) hide show
  1. package/dist/App.d.ts +22 -22
  2. package/dist/App.js +27 -27
  3. package/dist/_virtual/_tslib.js +30 -30
  4. package/dist/core/Api.d.ts +53 -53
  5. package/dist/core/Core.d.ts +18 -18
  6. package/dist/core/Core.js +78 -78
  7. package/dist/core/Decorators.d.ts +7 -7
  8. package/dist/core/Decorators.js +99 -99
  9. package/dist/core/ICocosResManager.d.ts +11 -11
  10. package/dist/core/ServiceLocator.d.ts +7 -7
  11. package/dist/core/ServiceLocator.js +31 -31
  12. package/dist/core/index.d.ts +5 -5
  13. package/dist/libs/BaseView.d.ts +21 -21
  14. package/dist/libs/BaseView.js +78 -78
  15. package/dist/libs/Broadcaster.d.ts +101 -101
  16. package/dist/libs/Broadcaster.js +240 -240
  17. package/dist/libs/CocosCore.d.ts +5 -5
  18. package/dist/libs/CocosCore.js +16 -16
  19. package/dist/libs/ResLoader.d.ts +10 -10
  20. package/dist/libs/ResLoader.js +76 -74
  21. package/dist/libs/UIManager.d.ts +34 -34
  22. package/dist/libs/UIManager.js +251 -251
  23. package/dist/libs/UIRoot.d.ts +4 -4
  24. package/dist/libs/UIRoot.js +4 -4
  25. package/dist/libs/index.d.ts +6 -6
  26. package/dist/mflow-tools.zip +0 -0
  27. package/dist/utils/ArrayExt.d.ts +67 -67
  28. package/dist/utils/ArrayExt.js +298 -298
  29. package/dist/utils/ArrayUtil.d.ts +41 -41
  30. package/dist/utils/ArrayUtil.js +93 -93
  31. package/dist/utils/CameraUtil.d.ts +10 -10
  32. package/dist/utils/CameraUtil.js +23 -23
  33. package/dist/utils/ImageUtil.d.ts +33 -33
  34. package/dist/utils/ImageUtil.js +92 -92
  35. package/dist/utils/MathUtil.d.ts +213 -213
  36. package/dist/utils/MathUtil.js +435 -435
  37. package/dist/utils/ObjectUtil.d.ts +24 -24
  38. package/dist/utils/ObjectUtil.js +58 -58
  39. package/dist/utils/PlatformUtil.d.ts +9 -9
  40. package/dist/utils/PlatformUtil.js +27 -27
  41. package/dist/utils/RotateUtil.d.ts +30 -30
  42. package/dist/utils/RotateUtil.js +63 -63
  43. package/dist/utils/StringUtil.d.ts +107 -107
  44. package/dist/utils/StringUtil.js +249 -249
  45. package/dist/utils/TimeUtil.d.ts +31 -31
  46. package/dist/utils/TimeUtil.js +85 -85
  47. package/dist/utils/index.d.ts +9 -9
  48. package/package.json +1 -1
@@ -1,96 +1,96 @@
1
- /** 数组工具 */
2
- class ArrayUtil {
3
- /**
4
- * 数组去重,并创建一个新数组返回
5
- * @param arr 源数组
6
- */
7
- static noRepeated(arr) {
8
- var res = [arr[0]];
9
- for (var i = 1; i < arr.length; i++) {
10
- var repeat = false;
11
- for (var j = 0; j < res.length; j++) {
12
- if (arr[i] == res[j]) {
13
- repeat = true;
14
- break;
15
- }
16
- }
17
- if (!repeat) {
18
- res.push(arr[i]);
19
- }
20
- }
21
- return res;
22
- }
23
- /**
24
- * 复制二维数组
25
- * @param array 目标数组
26
- */
27
- static copy2DArray(array) {
28
- let newArray = [];
29
- for (let i = 0; i < array.length; i++) {
30
- newArray.push(array[i].concat());
31
- }
32
- return newArray;
33
- }
34
- /**
35
- * Fisher-Yates Shuffle 随机置乱算法
36
- * @param array 目标数组
37
- */
38
- static fisherYatesShuffle(array) {
39
- let count = array.length;
40
- while (count) {
41
- let index = Math.floor(Math.random() * count--);
42
- let temp = array[count];
43
- array[count] = array[index];
44
- array[index] = temp;
45
- }
46
- return array;
47
- }
48
- /**
49
- * 混淆数组
50
- * @param array 目标数组
51
- */
52
- static confound(array) {
53
- let result = array.slice().sort(() => Math.random() - .5);
54
- return result;
55
- }
56
- /**
57
- * 数组扁平化
58
- * @param array 目标数组
59
- */
60
- static flattening(array) {
61
- for (; array.some(v => Array.isArray(v));) { // 判断 array 中是否有数组
62
- array = [].concat.apply([], array); // 压扁数组
63
- }
64
- return array;
65
- }
66
- /** 删除数组中指定项 */
67
- static removeItem(array, item) {
68
- var temp = array.concat();
69
- for (let i = 0; i < temp.length; i++) {
70
- const value = temp[i];
71
- if (item == value) {
72
- array.splice(i, 1);
73
- break;
74
- }
75
- }
76
- }
77
- /**
78
- * 合并数组
79
- * @param array1 目标数组1
80
- * @param array2 目标数组2
81
- */
82
- static combineArrays(array1, array2) {
83
- let newArray = [...array1, ...array2];
84
- return newArray;
85
- }
86
- /**
87
- * 获取随机数组成员
88
- * @param array 目标数组
89
- */
90
- static getRandomValueInArray(array) {
91
- let newArray = array[Math.floor(Math.random() * array.length)];
92
- return newArray;
93
- }
1
+ /** 数组工具 */
2
+ class ArrayUtil {
3
+ /**
4
+ * 数组去重,并创建一个新数组返回
5
+ * @param arr 源数组
6
+ */
7
+ static noRepeated(arr) {
8
+ var res = [arr[0]];
9
+ for (var i = 1; i < arr.length; i++) {
10
+ var repeat = false;
11
+ for (var j = 0; j < res.length; j++) {
12
+ if (arr[i] == res[j]) {
13
+ repeat = true;
14
+ break;
15
+ }
16
+ }
17
+ if (!repeat) {
18
+ res.push(arr[i]);
19
+ }
20
+ }
21
+ return res;
22
+ }
23
+ /**
24
+ * 复制二维数组
25
+ * @param array 目标数组
26
+ */
27
+ static copy2DArray(array) {
28
+ let newArray = [];
29
+ for (let i = 0; i < array.length; i++) {
30
+ newArray.push(array[i].concat());
31
+ }
32
+ return newArray;
33
+ }
34
+ /**
35
+ * Fisher-Yates Shuffle 随机置乱算法
36
+ * @param array 目标数组
37
+ */
38
+ static fisherYatesShuffle(array) {
39
+ let count = array.length;
40
+ while (count) {
41
+ let index = Math.floor(Math.random() * count--);
42
+ let temp = array[count];
43
+ array[count] = array[index];
44
+ array[index] = temp;
45
+ }
46
+ return array;
47
+ }
48
+ /**
49
+ * 混淆数组
50
+ * @param array 目标数组
51
+ */
52
+ static confound(array) {
53
+ let result = array.slice().sort(() => Math.random() - .5);
54
+ return result;
55
+ }
56
+ /**
57
+ * 数组扁平化
58
+ * @param array 目标数组
59
+ */
60
+ static flattening(array) {
61
+ for (; array.some(v => Array.isArray(v));) { // 判断 array 中是否有数组
62
+ array = [].concat.apply([], array); // 压扁数组
63
+ }
64
+ return array;
65
+ }
66
+ /** 删除数组中指定项 */
67
+ static removeItem(array, item) {
68
+ var temp = array.concat();
69
+ for (let i = 0; i < temp.length; i++) {
70
+ const value = temp[i];
71
+ if (item == value) {
72
+ array.splice(i, 1);
73
+ break;
74
+ }
75
+ }
76
+ }
77
+ /**
78
+ * 合并数组
79
+ * @param array1 目标数组1
80
+ * @param array2 目标数组2
81
+ */
82
+ static combineArrays(array1, array2) {
83
+ let newArray = [...array1, ...array2];
84
+ return newArray;
85
+ }
86
+ /**
87
+ * 获取随机数组成员
88
+ * @param array 目标数组
89
+ */
90
+ static getRandomValueInArray(array) {
91
+ let newArray = array[Math.floor(Math.random() * array.length)];
92
+ return newArray;
93
+ }
94
94
  }
95
95
 
96
96
  export { ArrayUtil };
@@ -1,10 +1,10 @@
1
- import { Camera, Vec3 } from "cc";
2
- /** 摄像机工具 */
3
- export declare class CameraUtil {
4
- /**
5
- * 当前世界坐标是否在摄像机显示范围内
6
- * @param camera 摄像机
7
- * @param worldPos 坐标
8
- */
9
- static isInView(camera: Camera, worldPos: Vec3): boolean;
10
- }
1
+ import { Camera, Vec3 } from "cc";
2
+ /** 摄像机工具 */
3
+ export declare class CameraUtil {
4
+ /**
5
+ * 当前世界坐标是否在摄像机显示范围内
6
+ * @param camera 摄像机
7
+ * @param worldPos 坐标
8
+ */
9
+ static isInView(camera: Camera, worldPos: Vec3): boolean;
10
+ }
@@ -1,28 +1,28 @@
1
1
  import { Vec3, view } from 'cc';
2
2
 
3
- /** 摄像机工具 */
4
- class CameraUtil {
5
- /**
6
- * 当前世界坐标是否在摄像机显示范围内
7
- * @param camera 摄像机
8
- * @param worldPos 坐标
9
- */
10
- static isInView(camera, worldPos) {
11
- var cameraPos = camera.node.getWorldPosition();
12
- var viewPos = camera.worldToScreen(worldPos);
13
- var dir = Vec3.normalize(new Vec3(), worldPos.subtract(cameraPos));
14
- var forward = camera.node.forward;
15
- var dot = Vec3.dot(forward, dir);
16
- const viewportRect = view.getViewportRect();
17
- // 判断物体是否在相机前面
18
- if (dot > 0
19
- // 判断物体是否在视窗内
20
- && (viewPos.x <= viewportRect.width) && (viewPos.x >= 0)
21
- && (viewPos.y <= viewportRect.height) && (viewPos.y >= 0))
22
- return true;
23
- else
24
- return false;
25
- }
3
+ /** 摄像机工具 */
4
+ class CameraUtil {
5
+ /**
6
+ * 当前世界坐标是否在摄像机显示范围内
7
+ * @param camera 摄像机
8
+ * @param worldPos 坐标
9
+ */
10
+ static isInView(camera, worldPos) {
11
+ var cameraPos = camera.node.getWorldPosition();
12
+ var viewPos = camera.worldToScreen(worldPos);
13
+ var dir = Vec3.normalize(new Vec3(), worldPos.subtract(cameraPos));
14
+ var forward = camera.node.forward;
15
+ var dot = Vec3.dot(forward, dir);
16
+ const viewportRect = view.getViewportRect();
17
+ // 判断物体是否在相机前面
18
+ if (dot > 0
19
+ // 判断物体是否在视窗内
20
+ && (viewPos.x <= viewportRect.width) && (viewPos.x >= 0)
21
+ && (viewPos.y <= viewportRect.height) && (viewPos.y >= 0))
22
+ return true;
23
+ else
24
+ return false;
25
+ }
26
26
  }
27
27
 
28
28
  export { CameraUtil };
@@ -1,33 +1,33 @@
1
- import { Color, Texture2D } from "cc";
2
- /**
3
- * 图像工具
4
- */
5
- export declare class ImageUtil {
6
- /**
7
- * 获取纹理中指定像素的颜色,原点为左上角,从像素 (1, 1) 开始。
8
- * @param texture 纹理
9
- * @param x x 坐标
10
- * @param y y 坐标
11
- * @example
12
- // 获取纹理左上角第一个像素的颜色
13
- const color = ImageUtil.getPixelColor(texture, 1, 1);
14
- cc.color(50, 100, 123, 255);
15
- */
16
- static getPixelColor(texture: Texture2D, x: number, y: number): Color;
17
- /**
18
- * 将图像转为 Base64 字符(仅 png、jpg 或 jpeg 格式资源)(有问题)
19
- * @param url 图像地址
20
- * @param callback 完成回调
21
- */
22
- static imageToBase64(url: string, callback?: (dataURL: string) => void): Promise<string>;
23
- /**
24
- * 将 Base64 字符转为 cc.Texture2D 资源(有问题)
25
- * @param base64 Base64 字符
26
- */
27
- static base64ToTexture(base64: string): Texture2D;
28
- /**
29
- * 将 Base64 字符转为二进制数据(有问题)
30
- * @param base64 Base64 字符
31
- */
32
- static base64ToBlob(base64: string): Blob;
33
- }
1
+ import { Color, Texture2D } from "cc";
2
+ /**
3
+ * 图像工具
4
+ */
5
+ export declare class ImageUtil {
6
+ /**
7
+ * 获取纹理中指定像素的颜色,原点为左上角,从像素 (1, 1) 开始。
8
+ * @param texture 纹理
9
+ * @param x x 坐标
10
+ * @param y y 坐标
11
+ * @example
12
+ // 获取纹理左上角第一个像素的颜色
13
+ const color = ImageUtil.getPixelColor(texture, 1, 1);
14
+ cc.color(50, 100, 123, 255);
15
+ */
16
+ static getPixelColor(texture: Texture2D, x: number, y: number): Color;
17
+ /**
18
+ * 将图像转为 Base64 字符(仅 png、jpg 或 jpeg 格式资源)(有问题)
19
+ * @param url 图像地址
20
+ * @param callback 完成回调
21
+ */
22
+ static imageToBase64(url: string, callback?: (dataURL: string) => void): Promise<string>;
23
+ /**
24
+ * 将 Base64 字符转为 cc.Texture2D 资源(有问题)
25
+ * @param base64 Base64 字符
26
+ */
27
+ static base64ToTexture(base64: string): Texture2D;
28
+ /**
29
+ * 将 Base64 字符转为二进制数据(有问题)
30
+ * @param base64 Base64 字符
31
+ */
32
+ static base64ToBlob(base64: string): Blob;
33
+ }
@@ -1,97 +1,97 @@
1
1
  import { Color, Texture2D } from 'cc';
2
2
 
3
- /**
4
- * 图像工具
5
- */
6
- class ImageUtil {
7
- /**
8
- * 获取纹理中指定像素的颜色,原点为左上角,从像素 (1, 1) 开始。
9
- * @param texture 纹理
10
- * @param x x 坐标
11
- * @param y y 坐标
12
- * @example
13
- // 获取纹理左上角第一个像素的颜色
14
- const color = ImageUtil.getPixelColor(texture, 1, 1);
15
- cc.color(50, 100, 123, 255);
16
- */
17
- static getPixelColor(texture, x, y) {
18
- const canvas = document.createElement('canvas');
19
- const ctx = canvas.getContext('2d');
20
- canvas.width = texture.width;
21
- canvas.height = texture.height;
22
- const image = texture.getHtmlElementObj();
23
- ctx.drawImage(image, 0, 0, texture.width, texture.height);
24
- const imageData = ctx.getImageData(0, 0, texture.width, texture.height);
25
- const pixelIndex = ((y - 1) * texture.width * 4) + (x - 1) * 4;
26
- const pixelData = imageData.data.slice(pixelIndex, pixelIndex + 4);
27
- const color = new Color(pixelData[0], pixelData[1], pixelData[2], pixelData[3]);
28
- image.remove();
29
- canvas.remove();
30
- return color;
31
- }
32
- /**
33
- * 将图像转为 Base64 字符(仅 png、jpg 或 jpeg 格式资源)(有问题)
34
- * @param url 图像地址
35
- * @param callback 完成回调
36
- */
37
- static imageToBase64(url, callback) {
38
- return new Promise(res => {
39
- var _a;
40
- let extname = (_a = /\.png|\.jpg|\.jpeg/.exec(url)) === null || _a === void 0 ? void 0 : _a[0];
41
- //@ts-ignore
42
- if (['.png', '.jpg', '.jpeg'].includes(extname)) {
43
- const canvas = document.createElement('canvas');
44
- const ctx = canvas.getContext('2d');
45
- const image = new Image();
46
- image.src = url;
47
- image.onload = () => {
48
- canvas.height = image.height;
49
- canvas.width = image.width;
50
- ctx.drawImage(image, 0, 0);
51
- extname = extname === '.jpg' ? 'jpeg' : extname.replace('.', '');
52
- const dataURL = canvas.toDataURL(`image/${extname}`);
53
- callback && callback(dataURL);
54
- res(dataURL);
55
- image.remove();
56
- canvas.remove();
57
- };
58
- }
59
- else {
60
- console.warn('Not a jpg/jpeg or png resource!');
61
- callback && callback("");
62
- res("");
63
- }
64
- });
65
- }
66
- /**
67
- * 将 Base64 字符转为 cc.Texture2D 资源(有问题)
68
- * @param base64 Base64 字符
69
- */
70
- static base64ToTexture(base64) {
71
- const image = document.createElement('img');
72
- image.src = base64;
73
- const texture = new Texture2D();
74
- //@ts-ignore
75
- texture.initWithElement(image);
76
- image.remove();
77
- return texture;
78
- }
79
- /**
80
- * 将 Base64 字符转为二进制数据(有问题)
81
- * @param base64 Base64 字符
82
- */
83
- static base64ToBlob(base64) {
84
- const strings = base64.split(',');
85
- //@ts-ignore
86
- const type = /image\/\w+|;/.exec(strings[0])[0];
87
- const data = window.atob(strings[1]);
88
- const arrayBuffer = new ArrayBuffer(data.length);
89
- const uint8Array = new Uint8Array(arrayBuffer);
90
- for (let i = 0; i < data.length; i++) {
91
- uint8Array[i] = data.charCodeAt(i) & 0xff;
92
- }
93
- return new Blob([uint8Array], { type: type });
94
- }
3
+ /**
4
+ * 图像工具
5
+ */
6
+ class ImageUtil {
7
+ /**
8
+ * 获取纹理中指定像素的颜色,原点为左上角,从像素 (1, 1) 开始。
9
+ * @param texture 纹理
10
+ * @param x x 坐标
11
+ * @param y y 坐标
12
+ * @example
13
+ // 获取纹理左上角第一个像素的颜色
14
+ const color = ImageUtil.getPixelColor(texture, 1, 1);
15
+ cc.color(50, 100, 123, 255);
16
+ */
17
+ static getPixelColor(texture, x, y) {
18
+ const canvas = document.createElement('canvas');
19
+ const ctx = canvas.getContext('2d');
20
+ canvas.width = texture.width;
21
+ canvas.height = texture.height;
22
+ const image = texture.getHtmlElementObj();
23
+ ctx.drawImage(image, 0, 0, texture.width, texture.height);
24
+ const imageData = ctx.getImageData(0, 0, texture.width, texture.height);
25
+ const pixelIndex = ((y - 1) * texture.width * 4) + (x - 1) * 4;
26
+ const pixelData = imageData.data.slice(pixelIndex, pixelIndex + 4);
27
+ const color = new Color(pixelData[0], pixelData[1], pixelData[2], pixelData[3]);
28
+ image.remove();
29
+ canvas.remove();
30
+ return color;
31
+ }
32
+ /**
33
+ * 将图像转为 Base64 字符(仅 png、jpg 或 jpeg 格式资源)(有问题)
34
+ * @param url 图像地址
35
+ * @param callback 完成回调
36
+ */
37
+ static imageToBase64(url, callback) {
38
+ return new Promise(res => {
39
+ var _a;
40
+ let extname = (_a = /\.png|\.jpg|\.jpeg/.exec(url)) === null || _a === void 0 ? void 0 : _a[0];
41
+ //@ts-ignore
42
+ if (['.png', '.jpg', '.jpeg'].includes(extname)) {
43
+ const canvas = document.createElement('canvas');
44
+ const ctx = canvas.getContext('2d');
45
+ const image = new Image();
46
+ image.src = url;
47
+ image.onload = () => {
48
+ canvas.height = image.height;
49
+ canvas.width = image.width;
50
+ ctx.drawImage(image, 0, 0);
51
+ extname = extname === '.jpg' ? 'jpeg' : extname.replace('.', '');
52
+ const dataURL = canvas.toDataURL(`image/${extname}`);
53
+ callback && callback(dataURL);
54
+ res(dataURL);
55
+ image.remove();
56
+ canvas.remove();
57
+ };
58
+ }
59
+ else {
60
+ console.warn('Not a jpg/jpeg or png resource!');
61
+ callback && callback("");
62
+ res("");
63
+ }
64
+ });
65
+ }
66
+ /**
67
+ * 将 Base64 字符转为 cc.Texture2D 资源(有问题)
68
+ * @param base64 Base64 字符
69
+ */
70
+ static base64ToTexture(base64) {
71
+ const image = document.createElement('img');
72
+ image.src = base64;
73
+ const texture = new Texture2D();
74
+ //@ts-ignore
75
+ texture.initWithElement(image);
76
+ image.remove();
77
+ return texture;
78
+ }
79
+ /**
80
+ * 将 Base64 字符转为二进制数据(有问题)
81
+ * @param base64 Base64 字符
82
+ */
83
+ static base64ToBlob(base64) {
84
+ const strings = base64.split(',');
85
+ //@ts-ignore
86
+ const type = /image\/\w+|;/.exec(strings[0])[0];
87
+ const data = window.atob(strings[1]);
88
+ const arrayBuffer = new ArrayBuffer(data.length);
89
+ const uint8Array = new Uint8Array(arrayBuffer);
90
+ for (let i = 0; i < data.length; i++) {
91
+ uint8Array[i] = data.charCodeAt(i) & 0xff;
92
+ }
93
+ return new Blob([uint8Array], { type: type });
94
+ }
95
95
  }
96
96
 
97
97
  export { ImageUtil };