@gongxh/bit-core 0.0.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/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # bit-core
2
+ bit-framework库的核心部分
3
+
4
+ #### 版本支持
5
+ - creator 3.7之前的版本理论上也支持,未测试
6
+ - creator 3.7+ 支持
7
+ - creator 3.8+ 支持
8
+
9
+ > 此项目是框架源码,不是creator项目
10
+ >
11
+ > demo见最下方仓库地址
12
+
13
+ ## 安装bit-core
14
+
15
+ 项目已发布到 `npm`, 安装方法如下:
16
+
17
+ ```bash
18
+ npm install bit-core
19
+ ```
20
+
21
+ > 如果连不上npm, 可使用国内镜像 比如: 淘宝、腾讯、华为
22
+
23
+ ```bash
24
+ # 官方
25
+ npm set registry https://registry.npmjs.org
26
+ # 中国镜像站(用这个就行)
27
+ npm set registry https://registry.npmmirror.com/
28
+ #腾讯
29
+ npm set registry https://mirrors.cloud.tencent.com/npm/
30
+ # 华为
31
+ npm set registry https://repo.huaweicloud.com/repository/npm/
32
+ # 阿里
33
+ npm set registry https://npm.aliyun.com
34
+ ```
35
+
36
+ # 集成目录
37
+ 1. [使用教程 (新手必看)](./docs/Noviciate.md)
38
+ 2. [项目配置](./docs/Basic.md)
39
+ 3. [UI模块](./docs/UI.md)
40
+ 4. [全局计时器](./docs/Timer.md)
41
+ 5. [平台工具](./docs/Platform.md)
42
+ 6. [屏幕尺寸](./docs/Screen.md)
43
+ 7. [小工具](./docs/Tools.md)
44
+ 8. [时间](./docs/Time.md)
45
+ 9. [小游戏接口封装](./docs/MiniGame.md)
46
+ 10. [热更新](./docs/HotUpdate.md)
47
+ 11. [条件显示节点 (一般用于UI上的红点)](./docs/Condition.md)
48
+ 12. [数据模块](./docs/Data.md)
49
+
50
+ # 独立模块目录
51
+ 1. [ec模块](https://github.com/Gongxh0901/kunpo-ec)
52
+ 2. [ecs模块](https://github.com/Gongxh0901/kunpo-esc)
53
+ 3. [网络模块 http和socket](https://github.com/Gongxh0901/bit-core-net)
54
+ 4. [四叉树](https://github.com/Gongxh0901/kunpo-quadtree)
55
+ 5. [行为树](https://github.com/Gongxh0901/bit-core-behaviortree)
56
+ 6. [资源管理](https://github.com/Gongxh0901/bit-core-assets)
57
+ 7. [全局事件](https://github.com/Gongxh0901/bit-core-event)
58
+ ## 类型支持
59
+
60
+ 该库完全使用 TypeScript 编写,提供完整的类型定义文件。
61
+
62
+ ## 许可证
63
+
64
+ ISC License
65
+
66
+ ## 作者
67
+
68
+ gongxh
69
+
70
+ ## 联系作者
71
+
72
+ * 邮箱: gong.xinhai@163.com
73
+
74
+ ## 源码仓库
75
+ [bit-core github地址](https://github.com/Gongxh0901/bit-framework)
@@ -0,0 +1,448 @@
1
+ 'use strict';
2
+
3
+ var cc = require('cc');
4
+
5
+ /**
6
+ * @Author: Gongxh
7
+ * @Date: 2024-12-08
8
+ * @Description: 窗口的一些类型配置
9
+ */
10
+ /** 是否开启调试模式 */
11
+ let KUNPO_DEBUG = false;
12
+ /**
13
+ * 启用或禁用调试模式。
14
+ * @param enable - 如果为 true,则启用调试模式;如果为 false,则禁用调试模式。不设置默认不开启
15
+ */
16
+ function enableDebugMode(enable) {
17
+ if (enable == true) {
18
+ KUNPO_DEBUG = true;
19
+ console.warn("调试模式已开启");
20
+ }
21
+ else {
22
+ KUNPO_DEBUG = false;
23
+ }
24
+ }
25
+
26
+ /**
27
+ * @Author: Gongxh
28
+ * @Date: 2024-12-05
29
+ * @Description: log相关的api
30
+ */
31
+ function log(...args) {
32
+ console.log("bit-framework:", ...args);
33
+ }
34
+ /**
35
+ * 开启debug模式后 输出调试信息
36
+ * @param args
37
+ */
38
+ function debug(...args) {
39
+ KUNPO_DEBUG && console.log("bit-framework:", ...args);
40
+ }
41
+ /**
42
+ * 信息性消息 某些浏览器中会带有小图标,但颜色通常与 log 相同
43
+ * @param args
44
+ */
45
+ function info(...args) {
46
+ KUNPO_DEBUG && console.info("bit-framework:", ...args);
47
+ }
48
+ /**
49
+ * 警告信息 黄色背景,通常带有警告图标
50
+ * @param args
51
+ */
52
+ function warn(...args) {
53
+ KUNPO_DEBUG && console.warn("bit-framework:", ...args);
54
+ }
55
+ /**
56
+ * 错误消息 红色背景,通常带有错误图标
57
+ * @param args
58
+ */
59
+ function error(...args) {
60
+ KUNPO_DEBUG && console.error("bit-framework:", ...args);
61
+ }
62
+
63
+ /**
64
+ * @Author: Gongxh
65
+ * @Date: 2024-12-07
66
+ * @Description: 平台相关
67
+ */
68
+ exports.PlatformType = void 0;
69
+ (function (PlatformType) {
70
+ PlatformType[PlatformType["Android"] = 1] = "Android";
71
+ PlatformType[PlatformType["IOS"] = 2] = "IOS";
72
+ PlatformType[PlatformType["HarmonyOS"] = 3] = "HarmonyOS";
73
+ /** 微信小游戏 */
74
+ PlatformType[PlatformType["WX"] = 4] = "WX";
75
+ /** 支付宝小游戏 */
76
+ PlatformType[PlatformType["Alipay"] = 5] = "Alipay";
77
+ /** 字节小游戏 */
78
+ PlatformType[PlatformType["Bytedance"] = 6] = "Bytedance";
79
+ /** 华为快游戏 */
80
+ PlatformType[PlatformType["HuaweiQuick"] = 7] = "HuaweiQuick";
81
+ /** 其他都为Browser */
82
+ PlatformType[PlatformType["Browser"] = 1001] = "Browser";
83
+ })(exports.PlatformType || (exports.PlatformType = {}));
84
+ class Platform {
85
+ }
86
+ /**
87
+ * 是否为原生平台
88
+ * @type {boolean}
89
+ */
90
+ Platform.isNative = false;
91
+ /**
92
+ * 是否为移动平台
93
+ * @type {boolean}
94
+ */
95
+ Platform.isMobile = false;
96
+ /**
97
+ * 是否为原生移动平台
98
+ * @type {boolean}
99
+ */
100
+ Platform.isNativeMobile = false;
101
+ /**
102
+ * 是否为安卓平台
103
+ * @type {boolean}
104
+ */
105
+ Platform.isAndroid = false;
106
+ /**
107
+ * 是否为IOS平台
108
+ * @type {boolean}
109
+ */
110
+ Platform.isIOS = false;
111
+ /**
112
+ * 是否为HarmonyOS平台
113
+ * @type {boolean}
114
+ */
115
+ Platform.isHarmonyOS = false;
116
+ /**
117
+ * 是否为微信小游戏
118
+ * @type {boolean}
119
+ */
120
+ Platform.isWX = false;
121
+ /**
122
+ * 是否为支付宝小游戏
123
+ * @type {boolean}
124
+ */
125
+ Platform.isAlipay = false;
126
+ /**
127
+ * 是否为字节小游戏
128
+ * @type {boolean}
129
+ */
130
+ Platform.isBytedance = false;
131
+ /**
132
+ * 是否是华为快游戏
133
+ * @type {boolean}
134
+ */
135
+ Platform.isHuaweiQuick = false;
136
+ /**
137
+ * 是否为浏览器
138
+ * @type {boolean}
139
+ */
140
+ Platform.isBrowser = false;
141
+ /**
142
+ * 平台初始化器
143
+ * @internal
144
+ */
145
+ class PlatformInitializer {
146
+ constructor() {
147
+ this.initPlatform();
148
+ }
149
+ /**
150
+ * 初始化平台
151
+ * @internal
152
+ */
153
+ initPlatform() {
154
+ // 处理平台判断
155
+ Platform.isNative = cc.sys.isNative;
156
+ Platform.isMobile = cc.sys.isMobile;
157
+ Platform.isNativeMobile = cc.sys.isNative && cc.sys.isMobile;
158
+ switch (cc.sys.os) {
159
+ case cc.sys.OS.ANDROID:
160
+ Platform.isAndroid = true;
161
+ debug("系统类型 Android");
162
+ break;
163
+ case cc.sys.OS.IOS:
164
+ Platform.isIOS = true;
165
+ debug("系统类型 IOS");
166
+ break;
167
+ case cc.sys.OS.OPENHARMONY:
168
+ Platform.isHarmonyOS = true;
169
+ debug("系统类型 HarmonyOS");
170
+ break;
171
+ }
172
+ switch (cc.sys.platform) {
173
+ case cc.sys.Platform.WECHAT_GAME:
174
+ Platform.isWX = true;
175
+ Platform.platform = exports.PlatformType.WX;
176
+ break;
177
+ case cc.sys.Platform.ALIPAY_MINI_GAME:
178
+ Platform.isAlipay = true;
179
+ Platform.platform = exports.PlatformType.Alipay;
180
+ break;
181
+ case cc.sys.Platform.BYTEDANCE_MINI_GAME:
182
+ Platform.isBytedance = true;
183
+ Platform.platform = exports.PlatformType.Bytedance;
184
+ break;
185
+ case cc.sys.Platform.HUAWEI_QUICK_GAME:
186
+ Platform.isHuaweiQuick = true;
187
+ Platform.platform = exports.PlatformType.HuaweiQuick;
188
+ break;
189
+ default:
190
+ // 其他都设置为浏览器
191
+ Platform.isBrowser = true;
192
+ Platform.platform = exports.PlatformType.Browser;
193
+ break;
194
+ }
195
+ debug(`platform: ${exports.PlatformType[Platform.platform]}`);
196
+ }
197
+ }
198
+
199
+ /**
200
+ * @Author: Gongxh
201
+ * @Date: 2024-12-08
202
+ * @Description: 屏幕尺寸信息接口
203
+ */
204
+ class Screen {
205
+ }
206
+
207
+ /******************************************************************************
208
+ Copyright (c) Microsoft Corporation.
209
+
210
+ Permission to use, copy, modify, and/or distribute this software for any
211
+ purpose with or without fee is hereby granted.
212
+
213
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
214
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
215
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
216
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
217
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
218
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
219
+ PERFORMANCE OF THIS SOFTWARE.
220
+ ***************************************************************************** */
221
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
222
+
223
+
224
+ function __decorate(decorators, target, key, desc) {
225
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
226
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
227
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
228
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
229
+ }
230
+
231
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
232
+ var e = new Error(message);
233
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
234
+ };
235
+
236
+ /**
237
+ * @Author: Gongxh
238
+ * @Date: 2024-12-07
239
+ * @Description: 适配用的类
240
+ */
241
+ class Adapter {
242
+ constructor() {
243
+ this.listeners = [];
244
+ }
245
+ /**
246
+ * 外部监听屏幕尺寸发生变化
247
+ * @param listener 监听器
248
+ * @internal
249
+ */
250
+ addResizeListener(listener) {
251
+ this.listeners.push(listener);
252
+ }
253
+ /**
254
+ * 初始化适配器
255
+ * @internal
256
+ */
257
+ init() {
258
+ Adapter.instance = this;
259
+ debug("初始化适配器");
260
+ // 设计尺寸 不会变化
261
+ let designSize = this.getDesignSize();
262
+ Screen.DesignHeight = designSize.height;
263
+ Screen.DesignWidth = designSize.width;
264
+ cc.view.setDesignResolutionSize(Screen.DesignWidth, Screen.DesignHeight, cc.ResolutionPolicy.SHOW_ALL);
265
+ this.resize();
266
+ this.registerListener((...args) => {
267
+ debug("屏幕发生变化", ...args);
268
+ this.resize();
269
+ // 通知所有监听器
270
+ for (const listener of this.listeners) {
271
+ listener(...args);
272
+ }
273
+ });
274
+ }
275
+ /**
276
+ * 调整屏幕尺寸
277
+ * @internal
278
+ */
279
+ resize() {
280
+ Screen.SafeAreaHeight = 60;
281
+ // 屏幕像素尺寸
282
+ const winSize = this.getScreenSize();
283
+ const isDesignLandscape = Screen.DesignWidth > Screen.DesignHeight;
284
+ const isLandscape = winSize.width > winSize.height;
285
+ if (isDesignLandscape == isLandscape) {
286
+ Screen.ScreenWidth = winSize.width;
287
+ Screen.ScreenHeight = winSize.height;
288
+ }
289
+ else {
290
+ Screen.ScreenWidth = winSize.height;
291
+ Screen.ScreenHeight = winSize.width;
292
+ }
293
+ if (isDesignLandscape) {
294
+ // 横屏
295
+ /** 安全区的宽度 */
296
+ Screen.SafeWidth = Screen.ScreenWidth - Screen.SafeAreaHeight * 2;
297
+ /** 安全区的高度 */
298
+ Screen.SafeHeight = Screen.ScreenHeight;
299
+ }
300
+ else {
301
+ // 竖屏
302
+ /** 安全区的宽度 */
303
+ Screen.SafeWidth = Screen.ScreenWidth;
304
+ /** 安全区的高度 */
305
+ Screen.SafeHeight = Screen.ScreenHeight - Screen.SafeAreaHeight * 2;
306
+ }
307
+ this.printScreen();
308
+ }
309
+ /**
310
+ * 打印屏幕信息
311
+ * @internal
312
+ */
313
+ printScreen() {
314
+ debug(`设计分辨率: ${Screen.DesignWidth}x${Screen.DesignHeight}`);
315
+ debug(`屏幕分辨率: ${Screen.ScreenWidth}x${Screen.ScreenHeight}`);
316
+ debug(`安全区域高度: ${Screen.SafeAreaHeight}`);
317
+ debug(`安全区宽高: ${Screen.SafeWidth}x${Screen.SafeHeight}`);
318
+ }
319
+ }
320
+
321
+ /**
322
+ * @Author: Gongxh
323
+ * @Date: 2024-12-08
324
+ * @Description:
325
+ */
326
+ class CocosAdapter extends Adapter {
327
+ /**
328
+ * 获取屏幕像素尺寸
329
+ * @returns {Size}
330
+ * @internal
331
+ */
332
+ getScreenSize() {
333
+ let windowSize = cc.screen.windowSize;
334
+ let width = Math.ceil(windowSize.width / cc.view.getScaleX());
335
+ let height = Math.ceil(windowSize.height / cc.view.getScaleY());
336
+ return { width, height };
337
+ }
338
+ /**
339
+ * 获取设计尺寸
340
+ * @returns {Size}
341
+ * @internal
342
+ */
343
+ getDesignSize() {
344
+ let designSize = cc.view.getDesignResolutionSize();
345
+ return { width: designSize.width, height: designSize.height };
346
+ }
347
+ /**
348
+ * 设置尺寸发生变化的监听
349
+ * @param callback 回调
350
+ * @internal
351
+ */
352
+ registerListener(listener) {
353
+ if (cc.screen && cc.screen.on) {
354
+ cc.screen.on("window-resize", (...args) => {
355
+ debug("window-resize");
356
+ listener(...args);
357
+ }, this);
358
+ cc.screen.on("orientation-change", (...args) => {
359
+ debug("orientation-change");
360
+ listener(...args);
361
+ }, this);
362
+ cc.screen.on("fullscreen-change", (...args) => {
363
+ debug("fullscreen-change");
364
+ listener(...args);
365
+ }, this);
366
+ }
367
+ else {
368
+ // 3.8.0之前的版本
369
+ cc.view.setResizeCallback(listener);
370
+ }
371
+ }
372
+ }
373
+
374
+ /**
375
+ * @Author: Gongxh
376
+ * @Date: 2024-12-07
377
+ * @Description: cocos UI模块
378
+ */
379
+ class Module extends cc.Component {
380
+ /**
381
+ * 模块初始化 (内部使用)
382
+ * @internal
383
+ */
384
+ init() {
385
+ this.onInit();
386
+ }
387
+ }
388
+
389
+ /**
390
+ * @Author: Gongxh
391
+ * @Date: 2024-12-07
392
+ * @Description:cocos游戏入口 定义了游戏启动时的基本配置和初始化流程。
393
+ */
394
+ const { property } = cc._decorator;
395
+ class CocosEntry extends cc.Component {
396
+ constructor() {
397
+ super(...arguments);
398
+ this.fps = 60;
399
+ this.enableDebug = false;
400
+ }
401
+ /**
402
+ * 开始初始化kunpo框架
403
+ * @internal
404
+ */
405
+ start() {
406
+ // 是否开启调试输出
407
+ this.enableDebug && enableDebugMode(true);
408
+ debug("开始初始化【bit-framework】");
409
+ // 设置游戏真帧率
410
+ cc.game.frameRate = this.fps;
411
+ cc.director.addPersistRootNode(this.node);
412
+ this.node.setSiblingIndex(this.node.children.length - 1);
413
+ // 平台信息初始化
414
+ new PlatformInitializer();
415
+ // 适配器
416
+ new CocosAdapter().init();
417
+ this.initModule();
418
+ debug("【bit-framework】初始化完成");
419
+ this.onInit();
420
+ }
421
+ /**
422
+ * 初始化模块
423
+ * @internal
424
+ */
425
+ initModule() {
426
+ const modules = this.getComponentsInChildren(Module);
427
+ for (const module of modules) {
428
+ module.init();
429
+ }
430
+ }
431
+ }
432
+ __decorate([
433
+ property({ displayName: "游戏帧率" })
434
+ ], CocosEntry.prototype, "fps", void 0);
435
+ __decorate([
436
+ property({ displayName: "开启调试输出" })
437
+ ], CocosEntry.prototype, "enableDebug", void 0);
438
+
439
+ exports.CocosEntry = CocosEntry;
440
+ exports.Module = Module;
441
+ exports.Platform = Platform;
442
+ exports.Screen = Screen;
443
+ exports.debug = debug;
444
+ exports.enableDebugMode = enableDebugMode;
445
+ exports.error = error;
446
+ exports.info = info;
447
+ exports.log = log;
448
+ exports.warn = warn;
@@ -0,0 +1,182 @@
1
+ import { Component } from 'cc';
2
+
3
+ /**
4
+ * @Author: Gongxh
5
+ * @Date: 2024-12-07
6
+ * @Description: 平台相关
7
+ */
8
+ declare enum PlatformType {
9
+ Android = 1,
10
+ IOS = 2,
11
+ HarmonyOS = 3,
12
+ /** 微信小游戏 */
13
+ WX = 4,
14
+ /** 支付宝小游戏 */
15
+ Alipay = 5,
16
+ /** 字节小游戏 */
17
+ Bytedance = 6,
18
+ /** 华为快游戏 */
19
+ HuaweiQuick = 7,
20
+ /** 其他都为Browser */
21
+ Browser = 1001
22
+ }
23
+ declare class Platform {
24
+ /**
25
+ * 是否为原生平台
26
+ * @type {boolean}
27
+ */
28
+ static isNative: boolean;
29
+ /**
30
+ * 是否为移动平台
31
+ * @type {boolean}
32
+ */
33
+ static isMobile: boolean;
34
+ /**
35
+ * 是否为原生移动平台
36
+ * @type {boolean}
37
+ */
38
+ static isNativeMobile: boolean;
39
+ /**
40
+ * 是否为安卓平台
41
+ * @type {boolean}
42
+ */
43
+ static isAndroid: boolean;
44
+ /**
45
+ * 是否为IOS平台
46
+ * @type {boolean}
47
+ */
48
+ static isIOS: boolean;
49
+ /**
50
+ * 是否为HarmonyOS平台
51
+ * @type {boolean}
52
+ */
53
+ static isHarmonyOS: boolean;
54
+ /**
55
+ * 是否为微信小游戏
56
+ * @type {boolean}
57
+ */
58
+ static isWX: boolean;
59
+ /**
60
+ * 是否为支付宝小游戏
61
+ * @type {boolean}
62
+ */
63
+ static isAlipay: boolean;
64
+ /**
65
+ * 是否为字节小游戏
66
+ * @type {boolean}
67
+ */
68
+ static isBytedance: boolean;
69
+ /**
70
+ * 是否是华为快游戏
71
+ * @type {boolean}
72
+ */
73
+ static isHuaweiQuick: boolean;
74
+ /**
75
+ * 是否为浏览器
76
+ * @type {boolean}
77
+ */
78
+ static isBrowser: boolean;
79
+ /**
80
+ * 平台类型
81
+ * @type {PlatformType}
82
+ */
83
+ static platform: PlatformType;
84
+ /**
85
+ * 设备ID
86
+ * @type {string}
87
+ */
88
+ static deviceId: string;
89
+ }
90
+
91
+ /**
92
+ * @Author: Gongxh
93
+ * @Date: 2024-12-08
94
+ * @Description: 屏幕尺寸信息接口
95
+ */
96
+ declare class Screen {
97
+ /** 屏幕宽度 */
98
+ static ScreenWidth: number;
99
+ /** 屏幕高度 */
100
+ static ScreenHeight: number;
101
+ /** 设计分辨率宽 */
102
+ static DesignWidth: number;
103
+ /** 设计分辨率高 */
104
+ static DesignHeight: number;
105
+ /** 安全区外一侧的高度 或 宽度 */
106
+ static SafeAreaHeight: number;
107
+ /** 安全区的宽度 */
108
+ static SafeWidth: number;
109
+ /** 安全区的高度 */
110
+ static SafeHeight: number;
111
+ }
112
+
113
+ /**
114
+ * 启用或禁用调试模式。
115
+ * @param enable - 如果为 true,则启用调试模式;如果为 false,则禁用调试模式。不设置默认不开启
116
+ */
117
+ declare function enableDebugMode(enable: boolean): void;
118
+
119
+ /**
120
+ * @Author: Gongxh
121
+ * @Date: 2024-12-05
122
+ * @Description: log相关的api
123
+ */
124
+ declare function log(...args: any[]): void;
125
+ /**
126
+ * 开启debug模式后 输出调试信息
127
+ * @param args
128
+ */
129
+ declare function debug(...args: any[]): void;
130
+ /**
131
+ * 信息性消息 某些浏览器中会带有小图标,但颜色通常与 log 相同
132
+ * @param args
133
+ */
134
+ declare function info(...args: any[]): void;
135
+ /**
136
+ * 警告信息 黄色背景,通常带有警告图标
137
+ * @param args
138
+ */
139
+ declare function warn(...args: any[]): void;
140
+ /**
141
+ * 错误消息 红色背景,通常带有错误图标
142
+ * @param args
143
+ */
144
+ declare function error(...args: any[]): void;
145
+
146
+ /**
147
+ * @Author: Gongxh
148
+ * @Date: 2024-12-07
149
+ * @Description:cocos游戏入口 定义了游戏启动时的基本配置和初始化流程。
150
+ */
151
+
152
+ declare abstract class CocosEntry extends Component {
153
+ fps: number;
154
+ enableDebug: boolean;
155
+ /**
156
+ * 虚函数,子类需要实现
157
+ * kunpo库初始化完成后调用
158
+ */
159
+ abstract onInit(): void;
160
+ }
161
+
162
+ /**
163
+ * @Author: Gongxh
164
+ * @Date: 2024-12-07
165
+ * @Description: cocos UI模块
166
+ */
167
+
168
+ declare abstract class Module extends Component {
169
+ /**
170
+ * 模块名称
171
+ * @type {string}
172
+ */
173
+ readonly moduleName: string;
174
+ /**
175
+ * 虚函数,子类需要实现
176
+ * 模块初始化完成后调用的函数
177
+ * @abstract
178
+ */
179
+ protected abstract onInit(): void;
180
+ }
181
+
182
+ export { CocosEntry, Module, Platform, PlatformType, Screen, debug, enableDebugMode, error, info, log, warn };
@@ -0,0 +1 @@
1
+ "use strict";var e=require("cc");let t=!1;function i(e){1==e?(t=!0,console.warn("调试模式已开启")):t=!1}function s(...e){t&&console.log("bit-framework:",...e)}var r;exports.PlatformType=void 0,(r=exports.PlatformType||(exports.PlatformType={}))[r.Android=1]="Android",r[r.IOS=2]="IOS",r[r.HarmonyOS=3]="HarmonyOS",r[r.WX=4]="WX",r[r.Alipay=5]="Alipay",r[r.Bytedance=6]="Bytedance",r[r.HuaweiQuick=7]="HuaweiQuick",r[r.Browser=1001]="Browser";class o{}o.isNative=!1,o.isMobile=!1,o.isNativeMobile=!1,o.isAndroid=!1,o.isIOS=!1,o.isHarmonyOS=!1,o.isWX=!1,o.isAlipay=!1,o.isBytedance=!1,o.isHuaweiQuick=!1,o.isBrowser=!1;class n{constructor(){this.initPlatform()}initPlatform(){switch(o.isNative=e.sys.isNative,o.isMobile=e.sys.isMobile,o.isNativeMobile=e.sys.isNative&&e.sys.isMobile,e.sys.os){case e.sys.OS.ANDROID:o.isAndroid=!0,s("系统类型 Android");break;case e.sys.OS.IOS:o.isIOS=!0,s("系统类型 IOS");break;case e.sys.OS.OPENHARMONY:o.isHarmonyOS=!0,s("系统类型 HarmonyOS")}switch(e.sys.platform){case e.sys.Platform.WECHAT_GAME:o.isWX=!0,o.platform=exports.PlatformType.WX;break;case e.sys.Platform.ALIPAY_MINI_GAME:o.isAlipay=!0,o.platform=exports.PlatformType.Alipay;break;case e.sys.Platform.BYTEDANCE_MINI_GAME:o.isBytedance=!0,o.platform=exports.PlatformType.Bytedance;break;case e.sys.Platform.HUAWEI_QUICK_GAME:o.isHuaweiQuick=!0,o.platform=exports.PlatformType.HuaweiQuick;break;default:o.isBrowser=!0,o.platform=exports.PlatformType.Browser}s(`platform: ${exports.PlatformType[o.platform]}`)}}class a{}function c(e,t,i,s){var r,o=arguments.length,n=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(o<3?r(n):o>3?r(t,i,n):r(t,i))||n);return o>3&&n&&Object.defineProperty(t,i,n),n}"function"==typeof SuppressedError&&SuppressedError;class l{constructor(){this.listeners=[]}addResizeListener(e){this.listeners.push(e)}init(){l.instance=this,s("初始化适配器");let t=this.getDesignSize();a.DesignHeight=t.height,a.DesignWidth=t.width,e.view.setDesignResolutionSize(a.DesignWidth,a.DesignHeight,e.ResolutionPolicy.SHOW_ALL),this.resize(),this.registerListener((...e)=>{s("屏幕发生变化",...e),this.resize();for(const t of this.listeners)t(...e)})}resize(){a.SafeAreaHeight=60;const e=this.getScreenSize(),t=a.DesignWidth>a.DesignHeight;t==e.width>e.height?(a.ScreenWidth=e.width,a.ScreenHeight=e.height):(a.ScreenWidth=e.height,a.ScreenHeight=e.width),t?(a.SafeWidth=a.ScreenWidth-2*a.SafeAreaHeight,a.SafeHeight=a.ScreenHeight):(a.SafeWidth=a.ScreenWidth,a.SafeHeight=a.ScreenHeight-2*a.SafeAreaHeight),this.printScreen()}printScreen(){s(`设计分辨率: ${a.DesignWidth}x${a.DesignHeight}`),s(`屏幕分辨率: ${a.ScreenWidth}x${a.ScreenHeight}`),s(`安全区域高度: ${a.SafeAreaHeight}`),s(`安全区宽高: ${a.SafeWidth}x${a.SafeHeight}`)}}class h extends l{getScreenSize(){let t=e.screen.windowSize;return{width:Math.ceil(t.width/e.view.getScaleX()),height:Math.ceil(t.height/e.view.getScaleY())}}getDesignSize(){let t=e.view.getDesignResolutionSize();return{width:t.width,height:t.height}}registerListener(t){e.screen&&e.screen.on?(e.screen.on("window-resize",(...e)=>{s("window-resize"),t(...e)},this),e.screen.on("orientation-change",(...e)=>{s("orientation-change"),t(...e)},this),e.screen.on("fullscreen-change",(...e)=>{s("fullscreen-change"),t(...e)},this)):e.view.setResizeCallback(t)}}class f extends e.Component{init(){this.onInit()}}const{property:d}=e._decorator;class p extends e.Component{constructor(){super(...arguments),this.fps=60,this.enableDebug=!1}start(){this.enableDebug&&i(!0),s("开始初始化【bit-framework】"),e.game.frameRate=this.fps,e.director.addPersistRootNode(this.node),this.node.setSiblingIndex(this.node.children.length-1),new n,(new h).init(),this.initModule(),s("【bit-framework】初始化完成"),this.onInit()}initModule(){const e=this.getComponentsInChildren(f);for(const t of e)t.init()}}c([d({displayName:"游戏帧率"})],p.prototype,"fps",void 0),c([d({displayName:"开启调试输出"})],p.prototype,"enableDebug",void 0),exports.CocosEntry=p,exports.Module=f,exports.Platform=o,exports.Screen=a,exports.debug=s,exports.enableDebugMode=i,exports.error=function(...e){t&&console.error("bit-framework:",...e)},exports.info=function(...e){t&&console.info("bit-framework:",...e)},exports.log=function(...e){console.log("bit-framework:",...e)},exports.warn=function(...e){t&&console.warn("bit-framework:",...e)};
@@ -0,0 +1 @@
1
+ import{sys as e,view as i,ResolutionPolicy as t,screen as s,Component as n,_decorator as r,game as o,director as a}from"cc";let c=!1;function h(e){1==e?(c=!0,console.warn("调试模式已开启")):c=!1}function l(...e){console.log("bit-framework:",...e)}function d(...e){c&&console.log("bit-framework:",...e)}function f(...e){c&&console.info("bit-framework:",...e)}function g(...e){c&&console.warn("bit-framework:",...e)}function S(...e){c&&console.error("bit-framework:",...e)}var p;!function(e){e[e.Android=1]="Android",e[e.IOS=2]="IOS",e[e.HarmonyOS=3]="HarmonyOS",e[e.WX=4]="WX",e[e.Alipay=5]="Alipay",e[e.Bytedance=6]="Bytedance",e[e.HuaweiQuick=7]="HuaweiQuick",e[e.Browser=1001]="Browser"}(p||(p={}));class u{}u.isNative=!1,u.isMobile=!1,u.isNativeMobile=!1,u.isAndroid=!1,u.isIOS=!1,u.isHarmonyOS=!1,u.isWX=!1,u.isAlipay=!1,u.isBytedance=!1,u.isHuaweiQuick=!1,u.isBrowser=!1;class w{constructor(){this.initPlatform()}initPlatform(){switch(u.isNative=e.isNative,u.isMobile=e.isMobile,u.isNativeMobile=e.isNative&&e.isMobile,e.os){case e.OS.ANDROID:u.isAndroid=!0,d("系统类型 Android");break;case e.OS.IOS:u.isIOS=!0,d("系统类型 IOS");break;case e.OS.OPENHARMONY:u.isHarmonyOS=!0,d("系统类型 HarmonyOS")}switch(e.platform){case e.Platform.WECHAT_GAME:u.isWX=!0,u.platform=p.WX;break;case e.Platform.ALIPAY_MINI_GAME:u.isAlipay=!0,u.platform=p.Alipay;break;case e.Platform.BYTEDANCE_MINI_GAME:u.isBytedance=!0,u.platform=p.Bytedance;break;case e.Platform.HUAWEI_QUICK_GAME:u.isHuaweiQuick=!0,u.platform=p.HuaweiQuick;break;default:u.isBrowser=!0,u.platform=p.Browser}d(`platform: ${p[u.platform]}`)}}class m{}function b(e,i,t,s){var n,r=arguments.length,o=r<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,t):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,i,t,s);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(o=(r<3?n(o):r>3?n(i,t,o):n(i,t))||o);return r>3&&o&&Object.defineProperty(i,t,o),o}"function"==typeof SuppressedError&&SuppressedError;class H{constructor(){this.listeners=[]}addResizeListener(e){this.listeners.push(e)}init(){H.instance=this,d("初始化适配器");let e=this.getDesignSize();m.DesignHeight=e.height,m.DesignWidth=e.width,i.setDesignResolutionSize(m.DesignWidth,m.DesignHeight,t.SHOW_ALL),this.resize(),this.registerListener((...e)=>{d("屏幕发生变化",...e),this.resize();for(const i of this.listeners)i(...e)})}resize(){m.SafeAreaHeight=60;const e=this.getScreenSize(),i=m.DesignWidth>m.DesignHeight;i==e.width>e.height?(m.ScreenWidth=e.width,m.ScreenHeight=e.height):(m.ScreenWidth=e.height,m.ScreenHeight=e.width),i?(m.SafeWidth=m.ScreenWidth-2*m.SafeAreaHeight,m.SafeHeight=m.ScreenHeight):(m.SafeWidth=m.ScreenWidth,m.SafeHeight=m.ScreenHeight-2*m.SafeAreaHeight),this.printScreen()}printScreen(){d(`设计分辨率: ${m.DesignWidth}x${m.DesignHeight}`),d(`屏幕分辨率: ${m.ScreenWidth}x${m.ScreenHeight}`),d(`安全区域高度: ${m.SafeAreaHeight}`),d(`安全区宽高: ${m.SafeWidth}x${m.SafeHeight}`)}}class A extends H{getScreenSize(){let e=s.windowSize;return{width:Math.ceil(e.width/i.getScaleX()),height:Math.ceil(e.height/i.getScaleY())}}getDesignSize(){let e=i.getDesignResolutionSize();return{width:e.width,height:e.height}}registerListener(e){s&&s.on?(s.on("window-resize",(...i)=>{d("window-resize"),e(...i)},this),s.on("orientation-change",(...i)=>{d("orientation-change"),e(...i)},this),s.on("fullscreen-change",(...i)=>{d("fullscreen-change"),e(...i)},this)):i.setResizeCallback(e)}}class y extends n{init(){this.onInit()}}const{property:O}=r;class W extends n{constructor(){super(...arguments),this.fps=60,this.enableDebug=!1}start(){this.enableDebug&&h(!0),d("开始初始化【bit-framework】"),o.frameRate=this.fps,a.addPersistRootNode(this.node),this.node.setSiblingIndex(this.node.children.length-1),new w,(new A).init(),this.initModule(),d("【bit-framework】初始化完成"),this.onInit()}initModule(){const e=this.getComponentsInChildren(y);for(const i of e)i.init()}}b([O({displayName:"游戏帧率"})],W.prototype,"fps",void 0),b([O({displayName:"开启调试输出"})],W.prototype,"enableDebug",void 0);export{W as CocosEntry,y as Module,u as Platform,p as PlatformType,m as Screen,d as debug,h as enableDebugMode,S as error,f as info,l as log,g as warn};
@@ -0,0 +1,437 @@
1
+ import { sys, view, ResolutionPolicy, screen, Component, _decorator, game, director } from 'cc';
2
+
3
+ /**
4
+ * @Author: Gongxh
5
+ * @Date: 2024-12-08
6
+ * @Description: 窗口的一些类型配置
7
+ */
8
+ /** 是否开启调试模式 */
9
+ let KUNPO_DEBUG = false;
10
+ /**
11
+ * 启用或禁用调试模式。
12
+ * @param enable - 如果为 true,则启用调试模式;如果为 false,则禁用调试模式。不设置默认不开启
13
+ */
14
+ function enableDebugMode(enable) {
15
+ if (enable == true) {
16
+ KUNPO_DEBUG = true;
17
+ console.warn("调试模式已开启");
18
+ }
19
+ else {
20
+ KUNPO_DEBUG = false;
21
+ }
22
+ }
23
+
24
+ /**
25
+ * @Author: Gongxh
26
+ * @Date: 2024-12-05
27
+ * @Description: log相关的api
28
+ */
29
+ function log(...args) {
30
+ console.log("bit-framework:", ...args);
31
+ }
32
+ /**
33
+ * 开启debug模式后 输出调试信息
34
+ * @param args
35
+ */
36
+ function debug(...args) {
37
+ KUNPO_DEBUG && console.log("bit-framework:", ...args);
38
+ }
39
+ /**
40
+ * 信息性消息 某些浏览器中会带有小图标,但颜色通常与 log 相同
41
+ * @param args
42
+ */
43
+ function info(...args) {
44
+ KUNPO_DEBUG && console.info("bit-framework:", ...args);
45
+ }
46
+ /**
47
+ * 警告信息 黄色背景,通常带有警告图标
48
+ * @param args
49
+ */
50
+ function warn(...args) {
51
+ KUNPO_DEBUG && console.warn("bit-framework:", ...args);
52
+ }
53
+ /**
54
+ * 错误消息 红色背景,通常带有错误图标
55
+ * @param args
56
+ */
57
+ function error(...args) {
58
+ KUNPO_DEBUG && console.error("bit-framework:", ...args);
59
+ }
60
+
61
+ /**
62
+ * @Author: Gongxh
63
+ * @Date: 2024-12-07
64
+ * @Description: 平台相关
65
+ */
66
+ var PlatformType;
67
+ (function (PlatformType) {
68
+ PlatformType[PlatformType["Android"] = 1] = "Android";
69
+ PlatformType[PlatformType["IOS"] = 2] = "IOS";
70
+ PlatformType[PlatformType["HarmonyOS"] = 3] = "HarmonyOS";
71
+ /** 微信小游戏 */
72
+ PlatformType[PlatformType["WX"] = 4] = "WX";
73
+ /** 支付宝小游戏 */
74
+ PlatformType[PlatformType["Alipay"] = 5] = "Alipay";
75
+ /** 字节小游戏 */
76
+ PlatformType[PlatformType["Bytedance"] = 6] = "Bytedance";
77
+ /** 华为快游戏 */
78
+ PlatformType[PlatformType["HuaweiQuick"] = 7] = "HuaweiQuick";
79
+ /** 其他都为Browser */
80
+ PlatformType[PlatformType["Browser"] = 1001] = "Browser";
81
+ })(PlatformType || (PlatformType = {}));
82
+ class Platform {
83
+ }
84
+ /**
85
+ * 是否为原生平台
86
+ * @type {boolean}
87
+ */
88
+ Platform.isNative = false;
89
+ /**
90
+ * 是否为移动平台
91
+ * @type {boolean}
92
+ */
93
+ Platform.isMobile = false;
94
+ /**
95
+ * 是否为原生移动平台
96
+ * @type {boolean}
97
+ */
98
+ Platform.isNativeMobile = false;
99
+ /**
100
+ * 是否为安卓平台
101
+ * @type {boolean}
102
+ */
103
+ Platform.isAndroid = false;
104
+ /**
105
+ * 是否为IOS平台
106
+ * @type {boolean}
107
+ */
108
+ Platform.isIOS = false;
109
+ /**
110
+ * 是否为HarmonyOS平台
111
+ * @type {boolean}
112
+ */
113
+ Platform.isHarmonyOS = false;
114
+ /**
115
+ * 是否为微信小游戏
116
+ * @type {boolean}
117
+ */
118
+ Platform.isWX = false;
119
+ /**
120
+ * 是否为支付宝小游戏
121
+ * @type {boolean}
122
+ */
123
+ Platform.isAlipay = false;
124
+ /**
125
+ * 是否为字节小游戏
126
+ * @type {boolean}
127
+ */
128
+ Platform.isBytedance = false;
129
+ /**
130
+ * 是否是华为快游戏
131
+ * @type {boolean}
132
+ */
133
+ Platform.isHuaweiQuick = false;
134
+ /**
135
+ * 是否为浏览器
136
+ * @type {boolean}
137
+ */
138
+ Platform.isBrowser = false;
139
+ /**
140
+ * 平台初始化器
141
+ * @internal
142
+ */
143
+ class PlatformInitializer {
144
+ constructor() {
145
+ this.initPlatform();
146
+ }
147
+ /**
148
+ * 初始化平台
149
+ * @internal
150
+ */
151
+ initPlatform() {
152
+ // 处理平台判断
153
+ Platform.isNative = sys.isNative;
154
+ Platform.isMobile = sys.isMobile;
155
+ Platform.isNativeMobile = sys.isNative && sys.isMobile;
156
+ switch (sys.os) {
157
+ case sys.OS.ANDROID:
158
+ Platform.isAndroid = true;
159
+ debug("系统类型 Android");
160
+ break;
161
+ case sys.OS.IOS:
162
+ Platform.isIOS = true;
163
+ debug("系统类型 IOS");
164
+ break;
165
+ case sys.OS.OPENHARMONY:
166
+ Platform.isHarmonyOS = true;
167
+ debug("系统类型 HarmonyOS");
168
+ break;
169
+ }
170
+ switch (sys.platform) {
171
+ case sys.Platform.WECHAT_GAME:
172
+ Platform.isWX = true;
173
+ Platform.platform = PlatformType.WX;
174
+ break;
175
+ case sys.Platform.ALIPAY_MINI_GAME:
176
+ Platform.isAlipay = true;
177
+ Platform.platform = PlatformType.Alipay;
178
+ break;
179
+ case sys.Platform.BYTEDANCE_MINI_GAME:
180
+ Platform.isBytedance = true;
181
+ Platform.platform = PlatformType.Bytedance;
182
+ break;
183
+ case sys.Platform.HUAWEI_QUICK_GAME:
184
+ Platform.isHuaweiQuick = true;
185
+ Platform.platform = PlatformType.HuaweiQuick;
186
+ break;
187
+ default:
188
+ // 其他都设置为浏览器
189
+ Platform.isBrowser = true;
190
+ Platform.platform = PlatformType.Browser;
191
+ break;
192
+ }
193
+ debug(`platform: ${PlatformType[Platform.platform]}`);
194
+ }
195
+ }
196
+
197
+ /**
198
+ * @Author: Gongxh
199
+ * @Date: 2024-12-08
200
+ * @Description: 屏幕尺寸信息接口
201
+ */
202
+ class Screen {
203
+ }
204
+
205
+ /******************************************************************************
206
+ Copyright (c) Microsoft Corporation.
207
+
208
+ Permission to use, copy, modify, and/or distribute this software for any
209
+ purpose with or without fee is hereby granted.
210
+
211
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
212
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
213
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
214
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
215
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
216
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
217
+ PERFORMANCE OF THIS SOFTWARE.
218
+ ***************************************************************************** */
219
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
220
+
221
+
222
+ function __decorate(decorators, target, key, desc) {
223
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
224
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
225
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
226
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
227
+ }
228
+
229
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
230
+ var e = new Error(message);
231
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
232
+ };
233
+
234
+ /**
235
+ * @Author: Gongxh
236
+ * @Date: 2024-12-07
237
+ * @Description: 适配用的类
238
+ */
239
+ class Adapter {
240
+ constructor() {
241
+ this.listeners = [];
242
+ }
243
+ /**
244
+ * 外部监听屏幕尺寸发生变化
245
+ * @param listener 监听器
246
+ * @internal
247
+ */
248
+ addResizeListener(listener) {
249
+ this.listeners.push(listener);
250
+ }
251
+ /**
252
+ * 初始化适配器
253
+ * @internal
254
+ */
255
+ init() {
256
+ Adapter.instance = this;
257
+ debug("初始化适配器");
258
+ // 设计尺寸 不会变化
259
+ let designSize = this.getDesignSize();
260
+ Screen.DesignHeight = designSize.height;
261
+ Screen.DesignWidth = designSize.width;
262
+ view.setDesignResolutionSize(Screen.DesignWidth, Screen.DesignHeight, ResolutionPolicy.SHOW_ALL);
263
+ this.resize();
264
+ this.registerListener((...args) => {
265
+ debug("屏幕发生变化", ...args);
266
+ this.resize();
267
+ // 通知所有监听器
268
+ for (const listener of this.listeners) {
269
+ listener(...args);
270
+ }
271
+ });
272
+ }
273
+ /**
274
+ * 调整屏幕尺寸
275
+ * @internal
276
+ */
277
+ resize() {
278
+ Screen.SafeAreaHeight = 60;
279
+ // 屏幕像素尺寸
280
+ const winSize = this.getScreenSize();
281
+ const isDesignLandscape = Screen.DesignWidth > Screen.DesignHeight;
282
+ const isLandscape = winSize.width > winSize.height;
283
+ if (isDesignLandscape == isLandscape) {
284
+ Screen.ScreenWidth = winSize.width;
285
+ Screen.ScreenHeight = winSize.height;
286
+ }
287
+ else {
288
+ Screen.ScreenWidth = winSize.height;
289
+ Screen.ScreenHeight = winSize.width;
290
+ }
291
+ if (isDesignLandscape) {
292
+ // 横屏
293
+ /** 安全区的宽度 */
294
+ Screen.SafeWidth = Screen.ScreenWidth - Screen.SafeAreaHeight * 2;
295
+ /** 安全区的高度 */
296
+ Screen.SafeHeight = Screen.ScreenHeight;
297
+ }
298
+ else {
299
+ // 竖屏
300
+ /** 安全区的宽度 */
301
+ Screen.SafeWidth = Screen.ScreenWidth;
302
+ /** 安全区的高度 */
303
+ Screen.SafeHeight = Screen.ScreenHeight - Screen.SafeAreaHeight * 2;
304
+ }
305
+ this.printScreen();
306
+ }
307
+ /**
308
+ * 打印屏幕信息
309
+ * @internal
310
+ */
311
+ printScreen() {
312
+ debug(`设计分辨率: ${Screen.DesignWidth}x${Screen.DesignHeight}`);
313
+ debug(`屏幕分辨率: ${Screen.ScreenWidth}x${Screen.ScreenHeight}`);
314
+ debug(`安全区域高度: ${Screen.SafeAreaHeight}`);
315
+ debug(`安全区宽高: ${Screen.SafeWidth}x${Screen.SafeHeight}`);
316
+ }
317
+ }
318
+
319
+ /**
320
+ * @Author: Gongxh
321
+ * @Date: 2024-12-08
322
+ * @Description:
323
+ */
324
+ class CocosAdapter extends Adapter {
325
+ /**
326
+ * 获取屏幕像素尺寸
327
+ * @returns {Size}
328
+ * @internal
329
+ */
330
+ getScreenSize() {
331
+ let windowSize = screen.windowSize;
332
+ let width = Math.ceil(windowSize.width / view.getScaleX());
333
+ let height = Math.ceil(windowSize.height / view.getScaleY());
334
+ return { width, height };
335
+ }
336
+ /**
337
+ * 获取设计尺寸
338
+ * @returns {Size}
339
+ * @internal
340
+ */
341
+ getDesignSize() {
342
+ let designSize = view.getDesignResolutionSize();
343
+ return { width: designSize.width, height: designSize.height };
344
+ }
345
+ /**
346
+ * 设置尺寸发生变化的监听
347
+ * @param callback 回调
348
+ * @internal
349
+ */
350
+ registerListener(listener) {
351
+ if (screen && screen.on) {
352
+ screen.on("window-resize", (...args) => {
353
+ debug("window-resize");
354
+ listener(...args);
355
+ }, this);
356
+ screen.on("orientation-change", (...args) => {
357
+ debug("orientation-change");
358
+ listener(...args);
359
+ }, this);
360
+ screen.on("fullscreen-change", (...args) => {
361
+ debug("fullscreen-change");
362
+ listener(...args);
363
+ }, this);
364
+ }
365
+ else {
366
+ // 3.8.0之前的版本
367
+ view.setResizeCallback(listener);
368
+ }
369
+ }
370
+ }
371
+
372
+ /**
373
+ * @Author: Gongxh
374
+ * @Date: 2024-12-07
375
+ * @Description: cocos UI模块
376
+ */
377
+ class Module extends Component {
378
+ /**
379
+ * 模块初始化 (内部使用)
380
+ * @internal
381
+ */
382
+ init() {
383
+ this.onInit();
384
+ }
385
+ }
386
+
387
+ /**
388
+ * @Author: Gongxh
389
+ * @Date: 2024-12-07
390
+ * @Description:cocos游戏入口 定义了游戏启动时的基本配置和初始化流程。
391
+ */
392
+ const { property } = _decorator;
393
+ class CocosEntry extends Component {
394
+ constructor() {
395
+ super(...arguments);
396
+ this.fps = 60;
397
+ this.enableDebug = false;
398
+ }
399
+ /**
400
+ * 开始初始化kunpo框架
401
+ * @internal
402
+ */
403
+ start() {
404
+ // 是否开启调试输出
405
+ this.enableDebug && enableDebugMode(true);
406
+ debug("开始初始化【bit-framework】");
407
+ // 设置游戏真帧率
408
+ game.frameRate = this.fps;
409
+ director.addPersistRootNode(this.node);
410
+ this.node.setSiblingIndex(this.node.children.length - 1);
411
+ // 平台信息初始化
412
+ new PlatformInitializer();
413
+ // 适配器
414
+ new CocosAdapter().init();
415
+ this.initModule();
416
+ debug("【bit-framework】初始化完成");
417
+ this.onInit();
418
+ }
419
+ /**
420
+ * 初始化模块
421
+ * @internal
422
+ */
423
+ initModule() {
424
+ const modules = this.getComponentsInChildren(Module);
425
+ for (const module of modules) {
426
+ module.init();
427
+ }
428
+ }
429
+ }
430
+ __decorate([
431
+ property({ displayName: "游戏帧率" })
432
+ ], CocosEntry.prototype, "fps", void 0);
433
+ __decorate([
434
+ property({ displayName: "开启调试输出" })
435
+ ], CocosEntry.prototype, "enableDebug", void 0);
436
+
437
+ export { CocosEntry, Module, Platform, PlatformType, Screen, debug, enableDebugMode, error, info, log, warn };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@gongxh/bit-core",
3
+ "version": "0.0.1",
4
+ "description": "基于creator3.0+的bit-core库",
5
+ "main": "./dist/bit-core.cjs",
6
+ "module": "./dist/bit-core.mjs",
7
+ "types": "./dist/bit-core.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "require": "./dist/bit-core.cjs",
11
+ "import": "./dist/bit-core.mjs",
12
+ "types": "./dist/bit-core.d.ts",
13
+ "default": "./dist/bit-core.cjs"
14
+ },
15
+ "./min": {
16
+ "require": "./dist/bit-core.min.cjs",
17
+ "import": "./dist/bit-core.min.mjs"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "clean": "rm -rf dist",
22
+ "build": "npm run clean && rollup -c rollup.config.mjs",
23
+ "copy": "cp -r dist/* demo/node_modules/bit-core/dist/",
24
+ "build:all": "npm run build && npm run copy"
25
+ },
26
+ "files": [
27
+ "dist/bit-core.cjs",
28
+ "dist/bit-core.mjs",
29
+ "dist/bit-core.min.cjs",
30
+ "dist/bit-core.min.mjs",
31
+ "dist/bit-core.d.ts"
32
+ ],
33
+ "author": "gongxh",
34
+ "license": "ISC",
35
+ "repository": {
36
+ "type": "gitlab",
37
+ "url": "https://github.com/Gongxh0901/bit-core"
38
+ },
39
+ "publishConfig": {
40
+ "registry": "https://registry.npmjs.org/"
41
+ },
42
+ "dependencies": {
43
+ },
44
+ "devDependencies": {
45
+ "@cocos/creator-types": "^3.8.0",
46
+ "@rollup/plugin-terser": "^0.4.4",
47
+ "@rollup/plugin-typescript": "^12.1.2",
48
+ "@types/lodash": "^4.17.13",
49
+ "@types/node": "^22.10.2",
50
+ "rollup": "^4.28.1",
51
+ "rollup-plugin-dts": "^6.1.1",
52
+ "ts-node": "^10.9.2",
53
+ "tslib": "^2.6.2"
54
+ }
55
+ }