drgame-cc 1.0.37 → 1.0.38

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.
@@ -7,16 +7,19 @@ import { showRewardVideo } from "./Info";
7
7
  import { Loader } from "./Loader";
8
8
  import ToastManager from "./toast/ToastManager";
9
9
  import { InternalUitl } from "./InternalUitl";
10
+ import { WebBridge } from "./WebBridge";
10
11
  /** 平台适配器,名字有点长防止和Platform,Adapter冲突 */
11
12
  export class PlatformAdapter {
12
13
  private static readonly version = "1.0.36";
13
14
  private static readonly designWidth = 1920;
14
15
  private static readonly designHeight = 1080;
16
+ private static webBridge: WebBridge;
15
17
  /** 初始化
16
18
  * @param cnName 中文名称
17
19
  * @param minigameID 小游戏ID,文档地址:https://doc.weixin.qq.com/sheet/e3_AcEAlgaLALsCNiuHzH2NOQGCjVc3a?scode=AOcA0AdfAAoSqmh5BfAQIA6AYEAB4&tab=BB08J2
18
20
  */
19
21
  public static async init(cnName: string, minigameID: number) {
22
+ this.webBridge = new WebBridge();
20
23
  var platform = GameAnalyticsPlatform.XiaomiTv;//平台由sdk后续处理
21
24
  var appItem = GameAnalytics.getAppItem(platform);
22
25
  var contentId = minigameID.toString();//InternalUitl.getChineseInitials(cnName);
@@ -226,7 +229,12 @@ export class PlatformAdapter {
226
229
 
227
230
  /** 退出游戏 */
228
231
  public static exitGame() {
229
- let bridge: ILobbyBridge = cc.director.getScene().getComponentInChildren('LobbyBridge');
232
+ if (this.webBridge.isAvailable()) {
233
+ this.webBridge.callHandler("router/navigateBack", {}, (a) => { cc.log(a); });
234
+ return;
235
+ }
236
+ var GRoot = window['GRoot'];
237
+ let bridge: ILobbyBridge = GRoot && GRoot.inst.node.getComponentInChildren('LobbyBridge');
230
238
  bridge && bridge.exitGame();
231
239
  }
232
240
  }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Web 桥接
3
+ * 封装 window.callHandler 的调用逻辑
4
+ * 构造时一次性检测可用性,避免每次调用重复判断
5
+ */
6
+ export class WebBridge {
7
+
8
+ /** 缓存:callHandler 是否可用 */
9
+ private _available: boolean;
10
+
11
+ constructor() {
12
+ this._available = cc.sys.isBrowser && typeof (window as any).callHandler === 'function';
13
+ }
14
+
15
+ /** 检测浏览器环境中是否存在 callHandler */
16
+ isAvailable(): boolean {
17
+ return this._available;
18
+ }
19
+
20
+ callHandler(message: string, param: any, success?: Function, fail?: Function): void {
21
+ if (this._available) {
22
+ (window as any).callHandler(message, param, success);
23
+ } else {
24
+ fail && fail({ code: -1, message: 'callHandler 未找到,非基座环境' });
25
+ }
26
+ }
27
+
28
+ async getSystemInfo(): Promise<any> {
29
+ return new Promise<any>((resolve, reject) => {
30
+ this.callHandler("system/getSystemInfo", {}, resolve,
31
+ (err: any) => reject(err || new Error('非基座环境:callHandler 不存在'))
32
+ );
33
+ });
34
+ }
35
+ }
@@ -11,13 +11,13 @@ export enum TvRemoteKey {
11
11
 
12
12
  export default class KeyCodeAdapter {
13
13
  public static toRemoteKey(keyCode: number): TvRemoteKey {
14
- if ([0, 4, 8, 27, 10009].indexOf(keyCode) >= 0) return TvRemoteKey.Back;
15
- if ([13, 23, 66].indexOf(keyCode) >= 0) return TvRemoteKey.Ok;
14
+ if ([0, 4, 6, 8, 27, 10009].indexOf(keyCode) >= 0) return TvRemoteKey.Back;
15
+ if ([13, 23, 66, 1005].indexOf(keyCode) >= 0) return TvRemoteKey.Ok;
16
16
  if ([80].indexOf(keyCode) >= 0) return TvRemoteKey.Pause;
17
- if ([21, 37].indexOf(keyCode) >= 0) return TvRemoteKey.Left;
18
- if ([19, 38].indexOf(keyCode) >= 0) return TvRemoteKey.Up;
19
- if ([22, 39].indexOf(keyCode) >= 0) return TvRemoteKey.Right;
20
- if ([20, 40].indexOf(keyCode) >= 0) return TvRemoteKey.Down;
17
+ if ([21, 37, 1000].indexOf(keyCode) >= 0) return TvRemoteKey.Left;
18
+ if ([19, 38, 1003].indexOf(keyCode) >= 0) return TvRemoteKey.Up;
19
+ if ([22, 39, 1001].indexOf(keyCode) >= 0) return TvRemoteKey.Right;
20
+ if ([20, 40, 1004].indexOf(keyCode) >= 0) return TvRemoteKey.Down;
21
21
  return TvRemoteKey.Unknown;
22
22
  }
23
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drgame-cc",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "description": "道然游戏适配包",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",