drgame-cc 1.0.38 → 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++;
@@ -8,17 +8,23 @@ import { Loader } from "./Loader";
8
8
  import ToastManager from "./toast/ToastManager";
9
9
  import { InternalUitl } from "./InternalUitl";
10
10
  import { WebBridge } from "./WebBridge";
11
+ import { AdPlatform, AdSdk } from "./ad-sdk/ad-sdk";
12
+ import HelperWin from "./HelperWin";
11
13
  /** 平台适配器,名字有点长防止和Platform,Adapter冲突 */
12
14
  export class PlatformAdapter {
13
15
  private static readonly version = "1.0.36";
14
16
  private static readonly designWidth = 1920;
15
17
  private static readonly designHeight = 1080;
16
18
  private static webBridge: WebBridge;
19
+ private static _canWatchVideo: boolean;
20
+ private static _isVIP: boolean;
21
+ private static _zhName: string;
17
22
  /** 初始化
18
23
  * @param cnName 中文名称
19
24
  * @param minigameID 小游戏ID,文档地址:https://doc.weixin.qq.com/sheet/e3_AcEAlgaLALsCNiuHzH2NOQGCjVc3a?scode=AOcA0AdfAAoSqmh5BfAQIA6AYEAB4&tab=BB08J2
20
25
  */
21
26
  public static async init(cnName: string, minigameID: number) {
27
+ this._zhName = cnName;
22
28
  this.webBridge = new WebBridge();
23
29
  var platform = GameAnalyticsPlatform.XiaomiTv;//平台由sdk后续处理
24
30
  var appItem = GameAnalytics.getAppItem(platform);
@@ -75,6 +81,14 @@ export class PlatformAdapter {
75
81
  });
76
82
  if (this.isCocos)
77
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));
78
92
  }
79
93
 
80
94
  /**
@@ -177,7 +191,7 @@ export class PlatformAdapter {
177
191
  }
178
192
 
179
193
  public static async showExitWin() {
180
- let exitPfb = await Loader.loadRes<cc.Prefab>('drres/prefab/ExitWin');
194
+ let exitPfb = await Loader.loadRes('drres/prefab/ExitWin', cc.Prefab);
181
195
  let exitWin = cc.instantiate(exitPfb);
182
196
  exitWin.parent = cc.director.getScene();
183
197
  exitWin.setPosition(cc.v2(cc.winSize.width / 2, cc.winSize.height / 2));
@@ -227,9 +241,24 @@ export class PlatformAdapter {
227
241
  return window['cc'] != undefined;
228
242
  }
229
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
+
230
259
  /** 退出游戏 */
231
260
  public static exitGame() {
232
- if (this.webBridge.isAvailable()) {
261
+ if (this.isWebBridge) {
233
262
  this.webBridge.callHandler("router/navigateBack", {}, (a) => { cc.log(a); });
234
263
  return;
235
264
  }
@@ -237,4 +266,20 @@ export class PlatformAdapter {
237
266
  let bridge: ILobbyBridge = GRoot && GRoot.inst.node.getComponentInChildren('LobbyBridge');
238
267
  bridge && bridge.exitGame();
239
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
+ }
240
285
  }
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drgame-cc",
3
- "version": "1.0.38",
3
+ "version": "1.0.39",
4
4
  "description": "道然游戏适配包",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",