@gongxh/bit-core 0.0.2 → 0.0.4
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/dist/bit-core.cjs +104 -93
- package/dist/bit-core.d.ts +21 -1
- package/dist/bit-core.min.cjs +1 -1
- package/dist/bit-core.min.mjs +1 -1
- package/dist/bit-core.mjs +105 -95
- package/package.json +1 -1
package/dist/bit-core.cjs
CHANGED
|
@@ -60,6 +60,109 @@ function error(...args) {
|
|
|
60
60
|
KUNPO_DEBUG && console.error("bit-framework:", ...args);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* @Author: Gongxh
|
|
65
|
+
* @Date: 2024-12-08
|
|
66
|
+
* @Description: 屏幕尺寸信息接口
|
|
67
|
+
*/
|
|
68
|
+
class Screen {
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @Author: Gongxh
|
|
73
|
+
* @Date: 2024-12-07
|
|
74
|
+
* @Description: 适配用的类
|
|
75
|
+
*/
|
|
76
|
+
class Adapter {
|
|
77
|
+
constructor() {
|
|
78
|
+
/**
|
|
79
|
+
* 监听器
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
this.listeners = [];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 添加屏幕尺寸发生变化的监听
|
|
86
|
+
* @param listener 监听器
|
|
87
|
+
*/
|
|
88
|
+
addResizeListener(listener) {
|
|
89
|
+
this.listeners.push(listener);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 移除屏幕尺寸发生变化的监听
|
|
93
|
+
* @param listener 监听器
|
|
94
|
+
*/
|
|
95
|
+
removeResizeListener(listener) {
|
|
96
|
+
this.listeners = this.listeners.filter(l => l !== listener);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 初始化适配器
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
init() {
|
|
103
|
+
Adapter.instance = this;
|
|
104
|
+
debug("初始化适配器");
|
|
105
|
+
// 设计尺寸 不会变化
|
|
106
|
+
let designSize = this.getDesignSize();
|
|
107
|
+
Screen.DesignHeight = designSize.height;
|
|
108
|
+
Screen.DesignWidth = designSize.width;
|
|
109
|
+
cc.view.setDesignResolutionSize(Screen.DesignWidth, Screen.DesignHeight, cc.ResolutionPolicy.SHOW_ALL);
|
|
110
|
+
this.resize();
|
|
111
|
+
this.registerListener((...args) => {
|
|
112
|
+
debug("屏幕发生变化", ...args);
|
|
113
|
+
this.resize();
|
|
114
|
+
// 通知所有监听器
|
|
115
|
+
for (const listener of this.listeners) {
|
|
116
|
+
listener(...args);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 调整屏幕尺寸
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
resize() {
|
|
125
|
+
Screen.SafeAreaHeight = 60;
|
|
126
|
+
// 屏幕像素尺寸
|
|
127
|
+
const winSize = this.getScreenSize();
|
|
128
|
+
const isDesignLandscape = Screen.DesignWidth > Screen.DesignHeight;
|
|
129
|
+
const isLandscape = winSize.width > winSize.height;
|
|
130
|
+
if (isDesignLandscape == isLandscape) {
|
|
131
|
+
Screen.ScreenWidth = winSize.width;
|
|
132
|
+
Screen.ScreenHeight = winSize.height;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
Screen.ScreenWidth = winSize.height;
|
|
136
|
+
Screen.ScreenHeight = winSize.width;
|
|
137
|
+
}
|
|
138
|
+
if (isDesignLandscape) {
|
|
139
|
+
// 横屏
|
|
140
|
+
/** 安全区的宽度 */
|
|
141
|
+
Screen.SafeWidth = Screen.ScreenWidth - Screen.SafeAreaHeight * 2;
|
|
142
|
+
/** 安全区的高度 */
|
|
143
|
+
Screen.SafeHeight = Screen.ScreenHeight;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
// 竖屏
|
|
147
|
+
/** 安全区的宽度 */
|
|
148
|
+
Screen.SafeWidth = Screen.ScreenWidth;
|
|
149
|
+
/** 安全区的高度 */
|
|
150
|
+
Screen.SafeHeight = Screen.ScreenHeight - Screen.SafeAreaHeight * 2;
|
|
151
|
+
}
|
|
152
|
+
this.printScreen();
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 打印屏幕信息
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
printScreen() {
|
|
159
|
+
debug(`设计分辨率: ${Screen.DesignWidth}x${Screen.DesignHeight}`);
|
|
160
|
+
debug(`屏幕分辨率: ${Screen.ScreenWidth}x${Screen.ScreenHeight}`);
|
|
161
|
+
debug(`安全区域高度: ${Screen.SafeAreaHeight}`);
|
|
162
|
+
debug(`安全区宽高: ${Screen.SafeWidth}x${Screen.SafeHeight}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
63
166
|
/**
|
|
64
167
|
* @Author: Gongxh
|
|
65
168
|
* @Date: 2024-12-07
|
|
@@ -196,14 +299,6 @@ class PlatformInitializer {
|
|
|
196
299
|
}
|
|
197
300
|
}
|
|
198
301
|
|
|
199
|
-
/**
|
|
200
|
-
* @Author: Gongxh
|
|
201
|
-
* @Date: 2024-12-08
|
|
202
|
-
* @Description: 屏幕尺寸信息接口
|
|
203
|
-
*/
|
|
204
|
-
class Screen {
|
|
205
|
-
}
|
|
206
|
-
|
|
207
302
|
/******************************************************************************
|
|
208
303
|
Copyright (c) Microsoft Corporation.
|
|
209
304
|
|
|
@@ -233,91 +328,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
233
328
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
234
329
|
};
|
|
235
330
|
|
|
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
331
|
/**
|
|
322
332
|
* @Author: Gongxh
|
|
323
333
|
* @Date: 2024-12-08
|
|
@@ -436,6 +446,7 @@ __decorate([
|
|
|
436
446
|
property({ displayName: "开启调试输出" })
|
|
437
447
|
], CocosEntry.prototype, "enableDebug", void 0);
|
|
438
448
|
|
|
449
|
+
exports.Adapter = Adapter;
|
|
439
450
|
exports.CocosEntry = CocosEntry;
|
|
440
451
|
exports.Module = Module;
|
|
441
452
|
exports.Platform = Platform;
|
package/dist/bit-core.d.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import { Component } from 'cc';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @Author: Gongxh
|
|
5
|
+
* @Date: 2024-12-07
|
|
6
|
+
* @Description: 适配用的类
|
|
7
|
+
*/
|
|
8
|
+
declare abstract class Adapter {
|
|
9
|
+
/** 适配器实例 */
|
|
10
|
+
static instance: Adapter;
|
|
11
|
+
/**
|
|
12
|
+
* 添加屏幕尺寸发生变化的监听
|
|
13
|
+
* @param listener 监听器
|
|
14
|
+
*/
|
|
15
|
+
addResizeListener(listener: (...args: any) => void): void;
|
|
16
|
+
/**
|
|
17
|
+
* 移除屏幕尺寸发生变化的监听
|
|
18
|
+
* @param listener 监听器
|
|
19
|
+
*/
|
|
20
|
+
removeResizeListener(listener: (...args: any) => void): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
3
23
|
/**
|
|
4
24
|
* @Author: Gongxh
|
|
5
25
|
* @Date: 2024-12-07
|
|
@@ -179,4 +199,4 @@ declare abstract class Module extends Component {
|
|
|
179
199
|
protected abstract onInit(): void;
|
|
180
200
|
}
|
|
181
201
|
|
|
182
|
-
export { CocosEntry, Module, Platform, PlatformType, Screen, debug, enableDebugMode, error, info, log, warn };
|
|
202
|
+
export { Adapter, CocosEntry, Module, Platform, PlatformType, Screen, debug, enableDebugMode, error, info, log, warn };
|
package/dist/bit-core.min.cjs
CHANGED
|
@@ -1 +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)}
|
|
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)}class r{}class o{constructor(){this.listeners=[]}addResizeListener(e){this.listeners.push(e)}removeResizeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}init(){o.instance=this,s("初始化适配器");let t=this.getDesignSize();r.DesignHeight=t.height,r.DesignWidth=t.width,e.view.setDesignResolutionSize(r.DesignWidth,r.DesignHeight,e.ResolutionPolicy.SHOW_ALL),this.resize(),this.registerListener((...e)=>{s("屏幕发生变化",...e),this.resize();for(const t of this.listeners)t(...e)})}resize(){r.SafeAreaHeight=60;const e=this.getScreenSize(),t=r.DesignWidth>r.DesignHeight;t==e.width>e.height?(r.ScreenWidth=e.width,r.ScreenHeight=e.height):(r.ScreenWidth=e.height,r.ScreenHeight=e.width),t?(r.SafeWidth=r.ScreenWidth-2*r.SafeAreaHeight,r.SafeHeight=r.ScreenHeight):(r.SafeWidth=r.ScreenWidth,r.SafeHeight=r.ScreenHeight-2*r.SafeAreaHeight),this.printScreen()}printScreen(){s(`设计分辨率: ${r.DesignWidth}x${r.DesignHeight}`),s(`屏幕分辨率: ${r.ScreenWidth}x${r.ScreenHeight}`),s(`安全区域高度: ${r.SafeAreaHeight}`),s(`安全区宽高: ${r.SafeWidth}x${r.SafeHeight}`)}}var n;exports.PlatformType=void 0,(n=exports.PlatformType||(exports.PlatformType={}))[n.Android=1]="Android",n[n.IOS=2]="IOS",n[n.HarmonyOS=3]="HarmonyOS",n[n.WX=4]="WX",n[n.Alipay=5]="Alipay",n[n.Bytedance=6]="Bytedance",n[n.HuaweiQuick=7]="HuaweiQuick",n[n.Browser=1001]="Browser";class a{}a.isNative=!1,a.isMobile=!1,a.isNativeMobile=!1,a.isAndroid=!1,a.isIOS=!1,a.isHarmonyOS=!1,a.isWX=!1,a.isAlipay=!1,a.isBytedance=!1,a.isHuaweiQuick=!1,a.isBrowser=!1;class c{constructor(){this.initPlatform()}initPlatform(){switch(a.isNative=e.sys.isNative,a.isMobile=e.sys.isMobile,a.isNativeMobile=e.sys.isNative&&e.sys.isMobile,e.sys.os){case e.sys.OS.ANDROID:a.isAndroid=!0,s("系统类型 Android");break;case e.sys.OS.IOS:a.isIOS=!0,s("系统类型 IOS");break;case e.sys.OS.OPENHARMONY:a.isHarmonyOS=!0,s("系统类型 HarmonyOS")}switch(e.sys.platform){case e.sys.Platform.WECHAT_GAME:a.isWX=!0,a.platform=exports.PlatformType.WX;break;case e.sys.Platform.ALIPAY_MINI_GAME:a.isAlipay=!0,a.platform=exports.PlatformType.Alipay;break;case e.sys.Platform.BYTEDANCE_MINI_GAME:a.isBytedance=!0,a.platform=exports.PlatformType.Bytedance;break;case e.sys.Platform.HUAWEI_QUICK_GAME:a.isHuaweiQuick=!0,a.platform=exports.PlatformType.HuaweiQuick;break;default:a.isBrowser=!0,a.platform=exports.PlatformType.Browser}s(`platform: ${exports.PlatformType[a.platform]}`)}}function l(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 h extends o{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 c,(new h).init(),this.initModule(),s("【bit-framework】初始化完成"),this.onInit()}initModule(){const e=this.getComponentsInChildren(f);for(const t of e)t.init()}}l([d({displayName:"游戏帧率"})],p.prototype,"fps",void 0),l([d({displayName:"开启调试输出"})],p.prototype,"enableDebug",void 0),exports.Adapter=o,exports.CocosEntry=p,exports.Module=f,exports.Platform=a,exports.Screen=r,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)};
|
package/dist/bit-core.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{view as e,ResolutionPolicy as i,sys as t,screen as s,Component as r,_decorator as n,game as o,director as a}from"cc";let h=!1;function c(e){1==e?(h=!0,console.warn("调试模式已开启")):h=!1}function l(...e){console.log("bit-framework:",...e)}function d(...e){h&&console.log("bit-framework:",...e)}function f(...e){h&&console.info("bit-framework:",...e)}function g(...e){h&&console.warn("bit-framework:",...e)}function S(...e){h&&console.error("bit-framework:",...e)}class p{}class u{constructor(){this.listeners=[]}addResizeListener(e){this.listeners.push(e)}removeResizeListener(e){this.listeners=this.listeners.filter(i=>i!==e)}init(){u.instance=this,d("初始化适配器");let t=this.getDesignSize();p.DesignHeight=t.height,p.DesignWidth=t.width,e.setDesignResolutionSize(p.DesignWidth,p.DesignHeight,i.SHOW_ALL),this.resize(),this.registerListener((...e)=>{d("屏幕发生变化",...e),this.resize();for(const i of this.listeners)i(...e)})}resize(){p.SafeAreaHeight=60;const e=this.getScreenSize(),i=p.DesignWidth>p.DesignHeight;i==e.width>e.height?(p.ScreenWidth=e.width,p.ScreenHeight=e.height):(p.ScreenWidth=e.height,p.ScreenHeight=e.width),i?(p.SafeWidth=p.ScreenWidth-2*p.SafeAreaHeight,p.SafeHeight=p.ScreenHeight):(p.SafeWidth=p.ScreenWidth,p.SafeHeight=p.ScreenHeight-2*p.SafeAreaHeight),this.printScreen()}printScreen(){d(`设计分辨率: ${p.DesignWidth}x${p.DesignHeight}`),d(`屏幕分辨率: ${p.ScreenWidth}x${p.ScreenHeight}`),d(`安全区域高度: ${p.SafeAreaHeight}`),d(`安全区宽高: ${p.SafeWidth}x${p.SafeHeight}`)}}var w;!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"}(w||(w={}));class m{}m.isNative=!1,m.isMobile=!1,m.isNativeMobile=!1,m.isAndroid=!1,m.isIOS=!1,m.isHarmonyOS=!1,m.isWX=!1,m.isAlipay=!1,m.isBytedance=!1,m.isHuaweiQuick=!1,m.isBrowser=!1;class b{constructor(){this.initPlatform()}initPlatform(){switch(m.isNative=t.isNative,m.isMobile=t.isMobile,m.isNativeMobile=t.isNative&&t.isMobile,t.os){case t.OS.ANDROID:m.isAndroid=!0,d("系统类型 Android");break;case t.OS.IOS:m.isIOS=!0,d("系统类型 IOS");break;case t.OS.OPENHARMONY:m.isHarmonyOS=!0,d("系统类型 HarmonyOS")}switch(t.platform){case t.Platform.WECHAT_GAME:m.isWX=!0,m.platform=w.WX;break;case t.Platform.ALIPAY_MINI_GAME:m.isAlipay=!0,m.platform=w.Alipay;break;case t.Platform.BYTEDANCE_MINI_GAME:m.isBytedance=!0,m.platform=w.Bytedance;break;case t.Platform.HUAWEI_QUICK_GAME:m.isHuaweiQuick=!0,m.platform=w.HuaweiQuick;break;default:m.isBrowser=!0,m.platform=w.Browser}d(`platform: ${w[m.platform]}`)}}function H(e,i,t,s){var r,n=arguments.length,o=n<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--)(r=e[a])&&(o=(n<3?r(o):n>3?r(i,t,o):r(i,t))||o);return n>3&&o&&Object.defineProperty(i,t,o),o}"function"==typeof SuppressedError&&SuppressedError;class A extends u{getScreenSize(){let i=s.windowSize;return{width:Math.ceil(i.width/e.getScaleX()),height:Math.ceil(i.height/e.getScaleY())}}getDesignSize(){let i=e.getDesignResolutionSize();return{width:i.width,height:i.height}}registerListener(i){s&&s.on?(s.on("window-resize",(...e)=>{d("window-resize"),i(...e)},this),s.on("orientation-change",(...e)=>{d("orientation-change"),i(...e)},this),s.on("fullscreen-change",(...e)=>{d("fullscreen-change"),i(...e)},this)):e.setResizeCallback(i)}}class y extends r{init(){this.onInit()}}const{property:O}=n;class W extends r{constructor(){super(...arguments),this.fps=60,this.enableDebug=!1}start(){this.enableDebug&&c(!0),d("开始初始化【bit-framework】"),o.frameRate=this.fps,a.addPersistRootNode(this.node),this.node.setSiblingIndex(this.node.children.length-1),new b,(new A).init(),this.initModule(),d("【bit-framework】初始化完成"),this.onInit()}initModule(){const e=this.getComponentsInChildren(y);for(const i of e)i.init()}}H([O({displayName:"游戏帧率"})],W.prototype,"fps",void 0),H([O({displayName:"开启调试输出"})],W.prototype,"enableDebug",void 0);export{u as Adapter,W as CocosEntry,y as Module,m as Platform,w as PlatformType,p as Screen,d as debug,c as enableDebugMode,S as error,f as info,l as log,g as warn};
|
package/dist/bit-core.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { view, ResolutionPolicy, sys, screen, Component, _decorator, game, director } from 'cc';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @Author: Gongxh
|
|
@@ -58,6 +58,109 @@ function error(...args) {
|
|
|
58
58
|
KUNPO_DEBUG && console.error("bit-framework:", ...args);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
* @Author: Gongxh
|
|
63
|
+
* @Date: 2024-12-08
|
|
64
|
+
* @Description: 屏幕尺寸信息接口
|
|
65
|
+
*/
|
|
66
|
+
class Screen {
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @Author: Gongxh
|
|
71
|
+
* @Date: 2024-12-07
|
|
72
|
+
* @Description: 适配用的类
|
|
73
|
+
*/
|
|
74
|
+
class Adapter {
|
|
75
|
+
constructor() {
|
|
76
|
+
/**
|
|
77
|
+
* 监听器
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
this.listeners = [];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 添加屏幕尺寸发生变化的监听
|
|
84
|
+
* @param listener 监听器
|
|
85
|
+
*/
|
|
86
|
+
addResizeListener(listener) {
|
|
87
|
+
this.listeners.push(listener);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 移除屏幕尺寸发生变化的监听
|
|
91
|
+
* @param listener 监听器
|
|
92
|
+
*/
|
|
93
|
+
removeResizeListener(listener) {
|
|
94
|
+
this.listeners = this.listeners.filter(l => l !== listener);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 初始化适配器
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
init() {
|
|
101
|
+
Adapter.instance = this;
|
|
102
|
+
debug("初始化适配器");
|
|
103
|
+
// 设计尺寸 不会变化
|
|
104
|
+
let designSize = this.getDesignSize();
|
|
105
|
+
Screen.DesignHeight = designSize.height;
|
|
106
|
+
Screen.DesignWidth = designSize.width;
|
|
107
|
+
view.setDesignResolutionSize(Screen.DesignWidth, Screen.DesignHeight, ResolutionPolicy.SHOW_ALL);
|
|
108
|
+
this.resize();
|
|
109
|
+
this.registerListener((...args) => {
|
|
110
|
+
debug("屏幕发生变化", ...args);
|
|
111
|
+
this.resize();
|
|
112
|
+
// 通知所有监听器
|
|
113
|
+
for (const listener of this.listeners) {
|
|
114
|
+
listener(...args);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 调整屏幕尺寸
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
resize() {
|
|
123
|
+
Screen.SafeAreaHeight = 60;
|
|
124
|
+
// 屏幕像素尺寸
|
|
125
|
+
const winSize = this.getScreenSize();
|
|
126
|
+
const isDesignLandscape = Screen.DesignWidth > Screen.DesignHeight;
|
|
127
|
+
const isLandscape = winSize.width > winSize.height;
|
|
128
|
+
if (isDesignLandscape == isLandscape) {
|
|
129
|
+
Screen.ScreenWidth = winSize.width;
|
|
130
|
+
Screen.ScreenHeight = winSize.height;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
Screen.ScreenWidth = winSize.height;
|
|
134
|
+
Screen.ScreenHeight = winSize.width;
|
|
135
|
+
}
|
|
136
|
+
if (isDesignLandscape) {
|
|
137
|
+
// 横屏
|
|
138
|
+
/** 安全区的宽度 */
|
|
139
|
+
Screen.SafeWidth = Screen.ScreenWidth - Screen.SafeAreaHeight * 2;
|
|
140
|
+
/** 安全区的高度 */
|
|
141
|
+
Screen.SafeHeight = Screen.ScreenHeight;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// 竖屏
|
|
145
|
+
/** 安全区的宽度 */
|
|
146
|
+
Screen.SafeWidth = Screen.ScreenWidth;
|
|
147
|
+
/** 安全区的高度 */
|
|
148
|
+
Screen.SafeHeight = Screen.ScreenHeight - Screen.SafeAreaHeight * 2;
|
|
149
|
+
}
|
|
150
|
+
this.printScreen();
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 打印屏幕信息
|
|
154
|
+
* @internal
|
|
155
|
+
*/
|
|
156
|
+
printScreen() {
|
|
157
|
+
debug(`设计分辨率: ${Screen.DesignWidth}x${Screen.DesignHeight}`);
|
|
158
|
+
debug(`屏幕分辨率: ${Screen.ScreenWidth}x${Screen.ScreenHeight}`);
|
|
159
|
+
debug(`安全区域高度: ${Screen.SafeAreaHeight}`);
|
|
160
|
+
debug(`安全区宽高: ${Screen.SafeWidth}x${Screen.SafeHeight}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
61
164
|
/**
|
|
62
165
|
* @Author: Gongxh
|
|
63
166
|
* @Date: 2024-12-07
|
|
@@ -194,14 +297,6 @@ class PlatformInitializer {
|
|
|
194
297
|
}
|
|
195
298
|
}
|
|
196
299
|
|
|
197
|
-
/**
|
|
198
|
-
* @Author: Gongxh
|
|
199
|
-
* @Date: 2024-12-08
|
|
200
|
-
* @Description: 屏幕尺寸信息接口
|
|
201
|
-
*/
|
|
202
|
-
class Screen {
|
|
203
|
-
}
|
|
204
|
-
|
|
205
300
|
/******************************************************************************
|
|
206
301
|
Copyright (c) Microsoft Corporation.
|
|
207
302
|
|
|
@@ -231,91 +326,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
231
326
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
232
327
|
};
|
|
233
328
|
|
|
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
329
|
/**
|
|
320
330
|
* @Author: Gongxh
|
|
321
331
|
* @Date: 2024-12-08
|
|
@@ -434,4 +444,4 @@ __decorate([
|
|
|
434
444
|
property({ displayName: "开启调试输出" })
|
|
435
445
|
], CocosEntry.prototype, "enableDebug", void 0);
|
|
436
446
|
|
|
437
|
-
export { CocosEntry, Module, Platform, PlatformType, Screen, debug, enableDebugMode, error, info, log, warn };
|
|
447
|
+
export { Adapter, CocosEntry, Module, Platform, PlatformType, Screen, debug, enableDebugMode, error, info, log, warn };
|