drgame-cc 1.0.37 → 1.0.39

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.
@@ -0,0 +1,202 @@
1
+ [
2
+ {
3
+ "__type__": "cc.Prefab",
4
+ "_name": "",
5
+ "_objFlags": 0,
6
+ "_native": "",
7
+ "data": {
8
+ "__id__": 1
9
+ },
10
+ "optimizationPolicy": 0,
11
+ "asyncLoadAssets": false,
12
+ "readonly": false
13
+ },
14
+ {
15
+ "__type__": "cc.Node",
16
+ "_name": "HelperWin",
17
+ "_objFlags": 0,
18
+ "_parent": null,
19
+ "_children": [
20
+ {
21
+ "__id__": 2
22
+ }
23
+ ],
24
+ "_active": true,
25
+ "_components": [],
26
+ "_prefab": {
27
+ "__id__": 5
28
+ },
29
+ "_opacity": 255,
30
+ "_color": {
31
+ "__type__": "cc.Color",
32
+ "r": 255,
33
+ "g": 255,
34
+ "b": 255,
35
+ "a": 255
36
+ },
37
+ "_contentSize": {
38
+ "__type__": "cc.Size",
39
+ "width": 0,
40
+ "height": 0
41
+ },
42
+ "_anchorPoint": {
43
+ "__type__": "cc.Vec2",
44
+ "x": 0.5,
45
+ "y": 0.5
46
+ },
47
+ "_trs": {
48
+ "__type__": "TypedArray",
49
+ "ctor": "Float64Array",
50
+ "array": [
51
+ 0,
52
+ 0,
53
+ 0,
54
+ 0,
55
+ 0,
56
+ 0,
57
+ 1,
58
+ 1,
59
+ 1,
60
+ 1
61
+ ]
62
+ },
63
+ "_eulerAngles": {
64
+ "__type__": "cc.Vec3",
65
+ "x": 0,
66
+ "y": 0,
67
+ "z": 0
68
+ },
69
+ "_skewX": 0,
70
+ "_skewY": 0,
71
+ "_is3DNode": false,
72
+ "_groupIndex": 0,
73
+ "groupIndex": 0,
74
+ "_id": ""
75
+ },
76
+ {
77
+ "__type__": "cc.Node",
78
+ "_name": "skeleton",
79
+ "_objFlags": 0,
80
+ "_parent": {
81
+ "__id__": 1
82
+ },
83
+ "_children": [],
84
+ "_active": true,
85
+ "_components": [
86
+ {
87
+ "__id__": 3
88
+ }
89
+ ],
90
+ "_prefab": {
91
+ "__id__": 4
92
+ },
93
+ "_opacity": 255,
94
+ "_color": {
95
+ "__type__": "cc.Color",
96
+ "r": 255,
97
+ "g": 255,
98
+ "b": 255,
99
+ "a": 255
100
+ },
101
+ "_contentSize": {
102
+ "__type__": "cc.Size",
103
+ "width": 1388.91,
104
+ "height": 923.54
105
+ },
106
+ "_anchorPoint": {
107
+ "__type__": "cc.Vec2",
108
+ "x": 0.5,
109
+ "y": 0.5
110
+ },
111
+ "_trs": {
112
+ "__type__": "TypedArray",
113
+ "ctor": "Float64Array",
114
+ "array": [
115
+ 0,
116
+ 0,
117
+ 0,
118
+ 0,
119
+ 0,
120
+ 0,
121
+ 1,
122
+ 1,
123
+ 1,
124
+ 1
125
+ ]
126
+ },
127
+ "_eulerAngles": {
128
+ "__type__": "cc.Vec3",
129
+ "x": 0,
130
+ "y": 0,
131
+ "z": 0
132
+ },
133
+ "_skewX": 0,
134
+ "_skewY": 0,
135
+ "_is3DNode": false,
136
+ "_groupIndex": 0,
137
+ "groupIndex": 0,
138
+ "_id": ""
139
+ },
140
+ {
141
+ "__type__": "sp.Skeleton",
142
+ "_name": "",
143
+ "_objFlags": 0,
144
+ "node": {
145
+ "__id__": 2
146
+ },
147
+ "_enabled": true,
148
+ "_materials": [
149
+ {
150
+ "__uuid__": "7afd064b-113f-480e-b793-8817d19f63c3"
151
+ }
152
+ ],
153
+ "paused": false,
154
+ "defaultSkin": "default",
155
+ "defaultAnimation": "animation",
156
+ "_preCacheMode": 0,
157
+ "_cacheMode": 0,
158
+ "loop": false,
159
+ "premultipliedAlpha": true,
160
+ "timeScale": 1,
161
+ "_accTime": 0,
162
+ "_playCount": 0,
163
+ "_frameCache": null,
164
+ "_curFrame": null,
165
+ "_skeletonCache": null,
166
+ "_animationName": "animation",
167
+ "_animationQueue": [],
168
+ "_headAniInfo": null,
169
+ "_playTimes": 1,
170
+ "_isAniComplete": true,
171
+ "_N$skeletonData": null,
172
+ "_N$_defaultCacheMode": 0,
173
+ "_N$debugSlots": false,
174
+ "_N$debugBones": false,
175
+ "_N$debugMesh": false,
176
+ "_N$useTint": false,
177
+ "_N$enableBatch": false,
178
+ "_id": ""
179
+ },
180
+ {
181
+ "__type__": "cc.PrefabInfo",
182
+ "root": {
183
+ "__id__": 1
184
+ },
185
+ "asset": {
186
+ "__id__": 0
187
+ },
188
+ "fileId": "773nu47W9KRIk2SeNjYEqp",
189
+ "sync": false
190
+ },
191
+ {
192
+ "__type__": "cc.PrefabInfo",
193
+ "root": {
194
+ "__id__": 1
195
+ },
196
+ "asset": {
197
+ "__id__": 0
198
+ },
199
+ "fileId": "",
200
+ "sync": false
201
+ }
202
+ ]
@@ -0,0 +1,55 @@
1
+ import { AdSdk, KeyAction, KeyCode } from "./ad-sdk/ad-sdk";
2
+ import TvUi from "./core/TvUi";
3
+ import { Loader } from "./Loader";
4
+ import { PlatformAdapter } from "./PlatformAdapter";
5
+
6
+ const { ccclass, property } = cc._decorator;
7
+
8
+ @ccclass
9
+ export default class HelperWin extends cc.Component {
10
+ @property(sp.Skeleton)
11
+ spine: sp.Skeleton = null;
12
+
13
+ private nativeBackHandler: () => boolean = null;
14
+
15
+ start() {
16
+ }
17
+
18
+ public async setBackHandler(url: string, cb: () => void) {
19
+ let spData = await Loader.loadRes(`spine/${url}`, sp.SkeletonData);
20
+ if (!spData) {
21
+ console.log(`[PlatformAdapter] HelperWin setBackHandler failed, url: ${url}`);
22
+ return;
23
+ }
24
+ this.spine = this.node.getChildByName("skeleton").getComponent(sp.Skeleton);
25
+ this.spine.skeletonData = spData;
26
+ this.spine.setAnimation(0, 'animation', false);
27
+ AdSdk.onKeyEvent((e) => {
28
+ var isDown = e.action === KeyAction.Down;
29
+
30
+ if (isDown) {
31
+ switch (e.key) {
32
+ case KeyCode.Back:
33
+ this.node.active = false;
34
+ cb && cb();
35
+ break;
36
+ }
37
+ }
38
+ });
39
+ this.nativeBackHandler = () => {
40
+ this.node.destroy();
41
+ cb && cb();
42
+ return true;
43
+ };
44
+ TvUi.back.push(this.nativeBackHandler);
45
+ }
46
+
47
+ onEnable() {
48
+ PlatformAdapter.showWindow(this.node);
49
+ }
50
+
51
+ onDisable() {
52
+ TvUi.back.remove(this.nativeBackHandler);
53
+ PlatformAdapter.hideWindow(this.node);
54
+ }
55
+ }
@@ -8,14 +8,15 @@ export class Loader {
8
8
  */
9
9
  public static async loadRes<T extends cc.Asset>(
10
10
  path: string,
11
+ type: new () => T,
11
12
  progressCallback?: (progress: number) => void
12
13
  ): Promise<T> {
13
14
  return new Promise<T>((resolve, reject) => {
14
- cc.loader.loadRes(path, (completedCount: number, totalCount: number, item: any) => {
15
+ cc.loader.loadRes(path, type as any, (completedCount: number, totalCount: number, item: any) => {
15
16
  if (progressCallback) {
16
17
  progressCallback(completedCount / totalCount);
17
18
  }
18
- }, (error: Error, asset: cc.Asset) => {
19
+ }, (error: Error, asset: T) => {
19
20
  if (error) {
20
21
  reject(error);
21
22
  } else {
@@ -57,7 +58,7 @@ export class Loader {
57
58
  * @returns Promise<Map<string, any>>
58
59
  */
59
60
  public static async loadBatch(
60
- resources: Array<{ path: string; key?: string }>,
61
+ resources: Array<{ path: string; type: new () => cc.Asset; key?: string }>,
61
62
  progressCallback?: (progress: number, completedCount: number, totalCount: number) => void
62
63
  ): Promise<Map<string, any>> {
63
64
  const results = new Map<string, any>();
@@ -66,7 +67,7 @@ export class Loader {
66
67
 
67
68
  const loadPromises = resources.map((res, index) => {
68
69
  const key = res.key || res.path;
69
- return this.loadRes(res.path)
70
+ return this.loadRes(res.path, res.type)
70
71
  .then((asset) => {
71
72
  results.set(key, asset);
72
73
  completedCount++;
@@ -7,16 +7,25 @@ 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";
11
+ import { AdPlatform, AdSdk } from "./ad-sdk/ad-sdk";
12
+ import HelperWin from "./HelperWin";
10
13
  /** 平台适配器,名字有点长防止和Platform,Adapter冲突 */
11
14
  export class PlatformAdapter {
12
15
  private static readonly version = "1.0.36";
13
16
  private static readonly designWidth = 1920;
14
17
  private static readonly designHeight = 1080;
18
+ private static webBridge: WebBridge;
19
+ private static _canWatchVideo: boolean;
20
+ private static _isVIP: boolean;
21
+ private static _zhName: string;
15
22
  /** 初始化
16
23
  * @param cnName 中文名称
17
24
  * @param minigameID 小游戏ID,文档地址:https://doc.weixin.qq.com/sheet/e3_AcEAlgaLALsCNiuHzH2NOQGCjVc3a?scode=AOcA0AdfAAoSqmh5BfAQIA6AYEAB4&tab=BB08J2
18
25
  */
19
26
  public static async init(cnName: string, minigameID: number) {
27
+ this._zhName = cnName;
28
+ this.webBridge = new WebBridge();
20
29
  var platform = GameAnalyticsPlatform.XiaomiTv;//平台由sdk后续处理
21
30
  var appItem = GameAnalytics.getAppItem(platform);
22
31
  var contentId = minigameID.toString();//InternalUitl.getChineseInitials(cnName);
@@ -72,6 +81,14 @@ export class PlatformAdapter {
72
81
  });
73
82
  if (this.isCocos)
74
83
  await ToastManager.Inst.init();
84
+ let adapters: any = {};
85
+ adapters[platform] = { cpId: contentId };
86
+ await AdSdk.init({
87
+ platform: AdPlatform.Xiaomi,
88
+ adapters: adapters
89
+ });
90
+ AdSdk.onGameReady(this.version);
91
+ // AdSdk.onKeyEvent(this.onKeyEvent.bind(this));
75
92
  }
76
93
 
77
94
  /**
@@ -174,7 +191,7 @@ export class PlatformAdapter {
174
191
  }
175
192
 
176
193
  public static async showExitWin() {
177
- let exitPfb = await Loader.loadRes<cc.Prefab>('drres/prefab/ExitWin');
194
+ let exitPfb = await Loader.loadRes('drres/prefab/ExitWin', cc.Prefab);
178
195
  let exitWin = cc.instantiate(exitPfb);
179
196
  exitWin.parent = cc.director.getScene();
180
197
  exitWin.setPosition(cc.v2(cc.winSize.width / 2, cc.winSize.height / 2));
@@ -224,9 +241,45 @@ export class PlatformAdapter {
224
241
  return window['cc'] != undefined;
225
242
  }
226
243
 
244
+ /** 是否是基座环境 */
245
+ public static get isWebBridge() {
246
+ return this.webBridge.isAvailable();
247
+ }
248
+
249
+ /** 是否可以观看视频 */
250
+ public static get canWatchVideo() {
251
+ return !this._canWatchVideo;
252
+ }
253
+
254
+ /** 是否是VIP用户 */
255
+ public static get isVIP() {
256
+ return this._isVIP;
257
+ }
258
+
227
259
  /** 退出游戏 */
228
260
  public static exitGame() {
229
- let bridge: ILobbyBridge = cc.director.getScene().getComponentInChildren('LobbyBridge');
261
+ if (this.isWebBridge) {
262
+ this.webBridge.callHandler("router/navigateBack", {}, (a) => { cc.log(a); });
263
+ return;
264
+ }
265
+ var GRoot = window['GRoot'];
266
+ let bridge: ILobbyBridge = GRoot && GRoot.inst.node.getComponentInChildren('LobbyBridge');
230
267
  bridge && bridge.exitGame();
231
268
  }
269
+
270
+ public static async showHelper(url: string, cb: () => void) {
271
+ var key = `${this._zhName}-isFirst`;
272
+ var isFirst = cc.sys.localStorage.getItem(key);
273
+ if (!isFirst) {
274
+ cc.sys.localStorage.setItem(key, false);
275
+ let helperPfb = await Loader.loadRes('drres/prefab/HelperWin', cc.Prefab);
276
+ let helperWin = cc.instantiate(helperPfb);
277
+ helperWin.parent = cc.director.getScene();
278
+ helperWin.setPosition(cc.v2(cc.winSize.width / 2, cc.winSize.height / 2));
279
+ var comp = helperWin.addComponent(HelperWin);
280
+ comp.setBackHandler(url, cb);
281
+ } else {
282
+ cb && cb();
283
+ }
284
+ }
232
285
  }
@@ -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
+ }
@@ -66,7 +66,7 @@ export default class AdManager {
66
66
 
67
67
  public static showPopup(options: AdShowOptions): Promise<boolean> {
68
68
  options = this.mergeOptions(options, { mode: "popup" });
69
- return this.showSlot((options && options.slotId) || (options && options.trigger_scene) || "popup", options);
69
+ return this.showSlot((options && options.slotId) || (options && options.scene) || "popup", options);
70
70
  }
71
71
 
72
72
  public static hidePopup(scene?: string) {
@@ -14,14 +14,12 @@ export default class BackManager {
14
14
  }
15
15
 
16
16
  public static push(handler: BackHandler) {
17
- return;
18
17
  if (!handler) return;
19
18
  this.remove(handler);
20
19
  this.handlers.push(handler);
21
20
  }
22
21
 
23
22
  public static remove(handler: BackHandler) {
24
- return;
25
23
  for (let i = this.handlers.length - 1; i >= 0; i--) {
26
24
  if (this.handlers[i] == handler) this.handlers.splice(i, 1);
27
25
  }
@@ -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.39",
4
4
  "description": "道然游戏适配包",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",