@cc-component/cc-ex-component 1.1.0 → 1.1.2
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/assets/ex/BaseEx.ts +1 -10
- package/assets/platform/Interface.ts +73 -0
- package/assets/platform/Interface.ts.meta +9 -0
- package/assets/platform/android/AndroidSDK.ts +176 -0
- package/assets/platform/android/AndroidSDK.ts.meta +1 -0
- package/assets/platform/android/AnyThinkAds/ATBanner.ts +266 -0
- package/assets/platform/android/AnyThinkAds/ATBanner.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/ATInterstitial.ts +185 -0
- package/assets/platform/android/AnyThinkAds/ATInterstitial.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/ATInterstitialAuto.ts +180 -0
- package/assets/platform/android/AnyThinkAds/ATInterstitialAuto.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/ATNative.ts +256 -0
- package/assets/platform/android/AnyThinkAds/ATNative.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/ATRewardedAutoVideo.ts +175 -0
- package/assets/platform/android/AnyThinkAds/ATRewardedAutoVideo.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/ATRewardedVideo.ts +243 -0
- package/assets/platform/android/AnyThinkAds/ATRewardedVideo.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/ATSDK.ts +222 -0
- package/assets/platform/android/AnyThinkAds/ATSDK.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/ATSplash.ts +155 -0
- package/assets/platform/android/AnyThinkAds/ATSplash.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidBannerTS.ts +71 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidBannerTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidInterstitialAutoTS.ts +52 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidInterstitialAutoTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidInterstitialTS.ts +41 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidInterstitialTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidNativeTS.ts +47 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidNativeTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidRewardedVideoAutoTS.ts +52 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidRewardedVideoAutoTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidRewardedVideoTS.ts +41 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidRewardedVideoTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidSplashTS.ts +42 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidSplashTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidTS.ts +73 -0
- package/assets/platform/android/AnyThinkAds/Android/ATAndroidTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/Android.meta +9 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSBannerTS.ts +66 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSBannerTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSInterstitiaAutolTS.ts +54 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSInterstitiaAutolTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSInterstitialTS.ts +43 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSInterstitialTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSNativeTS.ts +47 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSNativeTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSRewardedAutoVideoTS.ts +55 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSRewardedAutoVideoTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSRewardedVideoTS.ts +43 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSRewardedVideoTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSSplashTS.ts +47 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSSplashTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSTS.ts +76 -0
- package/assets/platform/android/AnyThinkAds/iOS/ATiOSTS.ts.meta +9 -0
- package/assets/platform/android/AnyThinkAds/iOS.meta +9 -0
- package/assets/platform/android/AnyThinkAds.meta +9 -0
- package/assets/platform/android/iOSSDK.ts +14 -0
- package/assets/platform/android/iOSSDK.ts.meta +1 -0
- package/assets/platform/android.meta +11 -0
- package/assets/platform/base/EditorSDK.ts +29 -0
- package/assets/platform/base/EditorSDK.ts.meta +1 -0
- package/assets/platform/base/PlatfprmModule.ts +138 -0
- package/assets/platform/base/PlatfprmModule.ts.meta +9 -0
- package/assets/platform/base/SDKBase.ts +59 -0
- package/assets/platform/base/SDKBase.ts.meta +9 -0
- package/assets/platform/base/SDKEnum.ts +127 -0
- package/assets/platform/base/SDKEnum.ts.meta +9 -0
- package/assets/platform/base/TTSDK.ts +355 -0
- package/assets/platform/base/TTSDK.ts.meta +9 -0
- package/assets/platform/base/WXSDK.ts +150 -0
- package/assets/platform/base/WXSDK.ts.meta +1 -0
- package/assets/platform/base.meta +9 -0
- package/assets/platform/wx/MiniSDK.ts +1001 -0
- package/assets/platform/wx/MiniSDK.ts.meta +9 -0
- package/assets/platform/wx/lib.douyin.d.ts +168 -0
- package/assets/platform/wx/lib.douyin.d.ts.meta +9 -0
- package/assets/platform/wx/wxmini.d.ts +2452 -0
- package/assets/platform/wx/wxmini.d.ts.meta +9 -0
- package/assets/platform/wx.meta +9 -0
- package/assets/platform.meta +9 -0
- package/assets/video/IVideo.ts +2 -2
- package/assets/video/Interface.ts +0 -1
- package/assets/video/VideoComponent.ts +1 -1
- package/assets/video/VideoManager.ts +5 -1
- package/assets/video/VideoModule.ts +30 -7
- package/assets/video/VideoPlayTT.ts +22 -3
- package/assets/video/VideoPlayWX.ts +34 -6
- package/assets/video/VideoPlayWeb.ts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { _decorator, Component, Node } from 'cc';
|
|
2
|
+
import { SDKBase } from './SDKBase';
|
|
3
|
+
import { AdsCall, AdsData, PositonData, SDKLoginData, SDKStatus, TTData } from './SDKEnum';
|
|
4
|
+
const { ccclass, property } = _decorator;
|
|
5
|
+
|
|
6
|
+
@ccclass('TTSDK')
|
|
7
|
+
export class TTSDK extends SDKBase {
|
|
8
|
+
videoAds: any;
|
|
9
|
+
videoAdsLoadResolve: any = null
|
|
10
|
+
adsCall: AdsCall;
|
|
11
|
+
sidebarCall: Function;
|
|
12
|
+
init(): Promise<void> {
|
|
13
|
+
const windowInfo = tt.getSystemInfoSync();
|
|
14
|
+
var options = tt.getLaunchOptionsSync();
|
|
15
|
+
const scene: string = options.scene;
|
|
16
|
+
const query: any = options.query;
|
|
17
|
+
const self = this
|
|
18
|
+
let enter_game = false;
|
|
19
|
+
//直播伴侣进入小游戏
|
|
20
|
+
if (scene === '029003') {
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
//用于判断是否为推荐流直出场景(xx为可变的数字,判断后四位是 3041 即可确认为推荐流直出)
|
|
24
|
+
if (scene.includes("3041")) {
|
|
25
|
+
//console.log("1启动参数:", options)
|
|
26
|
+
const feed_game_scene = options.query.feed_game_scene
|
|
27
|
+
const feed_game_channel = options.query.feed_game_channel//1.复访用户,2.获客用户
|
|
28
|
+
const feed_game_extra = options.query.feed_game_extra//开发者自定义字段,可通过 推荐流直出能力 OpenAPI 接入文档 接口的 extra 字段进行赋值
|
|
29
|
+
if (feed_game_extra === "1" || feed_game_extra === "2" || feed_game_channel === 2) {
|
|
30
|
+
enter_game = true
|
|
31
|
+
}
|
|
32
|
+
tt.onFeedStatusChange(({ type }) => {
|
|
33
|
+
if (type === 'feedEnter') {
|
|
34
|
+
console.log('触发从Feed流进入小游戏事件回调')
|
|
35
|
+
}
|
|
36
|
+
if (type === 'feedExit') {
|
|
37
|
+
console.log('触发从小游戏退回到Feed流事件回调')
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
//console.log("1启动参数:", options)
|
|
42
|
+
tt.onShow((res) => {
|
|
43
|
+
//从侧边栏进入小游戏
|
|
44
|
+
if (res.scene == "021036" && res.launch_from == "homepage" && res.location == "sidebar_card") {
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
self.sidebarCall?.()
|
|
47
|
+
self.sidebarCall = null;
|
|
48
|
+
}, 200);
|
|
49
|
+
}
|
|
50
|
+
// console.log("启动参数:", res.query);
|
|
51
|
+
// console.log("来源信息:", res.refererInfo);
|
|
52
|
+
// console.log("场景值:", res.scene);
|
|
53
|
+
// console.log("启动场景字段:", res.launch_from, ", ", res.location);
|
|
54
|
+
});
|
|
55
|
+
tt.onHide(() => { });
|
|
56
|
+
this.bindTouchEnd();
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public login(data?: string): Promise<SDKLoginData> {
|
|
61
|
+
return new Promise<SDKLoginData>((resolve, reject) => {
|
|
62
|
+
tt.login({
|
|
63
|
+
success: function (res: any) {
|
|
64
|
+
resolve({ success: true, code: res.code })
|
|
65
|
+
},
|
|
66
|
+
fail: function (err) {
|
|
67
|
+
console.log(`获取code失败`, err);
|
|
68
|
+
resolve({ success: false, code: "" })
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
public logout(): Promise<SDKStatus> {
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
public initRewardedVideo(param: AdsData) {
|
|
79
|
+
//广告
|
|
80
|
+
this.videoAds = tt.createRewardedVideoAd({
|
|
81
|
+
adUnitId: param.adUnitId,
|
|
82
|
+
});
|
|
83
|
+
this.videoAds.offError(this.onError)
|
|
84
|
+
this.videoAds.offClose(this.onClose); //这里监听广告的close 事件
|
|
85
|
+
this.videoAds.onError(this.onError)
|
|
86
|
+
this.videoAds.onClose(this.onClose); //这里监听广告的close 事件
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public showRewardedVideo(param: AdsCall) {
|
|
90
|
+
this.adsCall = param;
|
|
91
|
+
this.videoAds.show().then(() => {
|
|
92
|
+
console.log("视频广告展示");
|
|
93
|
+
this.adsCall.show?.();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
initTTScene() {
|
|
98
|
+
this.reportScene()
|
|
99
|
+
// setInterval(() => {
|
|
100
|
+
// SDKManager.instance.getFeedData("CONTENT13014381058", 1)
|
|
101
|
+
// }, 1000);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
reportScene() {
|
|
105
|
+
tt.reportScene({
|
|
106
|
+
sceneId: 7001,
|
|
107
|
+
costTime: 350,
|
|
108
|
+
dimension: {
|
|
109
|
+
d1: '2.1.0', // value仅支持传入String类型。若value表示Boolean,请将值处理为'0'、'1'进行上报;若value为Number,请转换为String进行上报
|
|
110
|
+
},
|
|
111
|
+
metric: {
|
|
112
|
+
m1: '546', // value仅支持传入数值且需要转换为String类型进行上报
|
|
113
|
+
},
|
|
114
|
+
success(res) {
|
|
115
|
+
// 上报接口执行完成后的回调,用于检查上报数据是否符合预期
|
|
116
|
+
//console.log('成功', res)
|
|
117
|
+
},
|
|
118
|
+
fail(res) {
|
|
119
|
+
// 上报报错时的回调,用于查看上报错误的原因:如参数类型错误等
|
|
120
|
+
console.log('失败', res)
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ttOther(data: TTData) {
|
|
126
|
+
// this.storeFeedData("CONTENT12694320898", 2, "2", 1000 * 60 * 10)
|
|
127
|
+
// }
|
|
128
|
+
|
|
129
|
+
// ttOffline(data: TTData) {
|
|
130
|
+
// this.storeFeedData("CONTENT13014381058", 1, "1", 1000 * 60 * 1)
|
|
131
|
+
// }
|
|
132
|
+
|
|
133
|
+
storeFeedData(data: TTData) {
|
|
134
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
135
|
+
tt.storeFeedData({
|
|
136
|
+
scene: data.scene,
|
|
137
|
+
contentID: data.contentID,
|
|
138
|
+
leftValue: 'timeStampMs',
|
|
139
|
+
operator: '>=',
|
|
140
|
+
rightValue: ((new Date().getTime()) + data.time).toString(),
|
|
141
|
+
status: 1,
|
|
142
|
+
extra: data.ext,
|
|
143
|
+
success(res) {
|
|
144
|
+
resolve(true)
|
|
145
|
+
},
|
|
146
|
+
fail(res) {
|
|
147
|
+
console.error('视频流失败:', res)
|
|
148
|
+
resolve(false)
|
|
149
|
+
},
|
|
150
|
+
})
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
getFeedData(contentID: string, scene: number) {
|
|
155
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
156
|
+
tt.getFeedData({
|
|
157
|
+
scene: scene, // 体力恢复
|
|
158
|
+
contentID: contentID,
|
|
159
|
+
success(res) {
|
|
160
|
+
console.log('getFeedData success', res, res.status, res.extra);
|
|
161
|
+
resolve(true)
|
|
162
|
+
},
|
|
163
|
+
fail(res) {
|
|
164
|
+
console.log('getFeedData fail', res)
|
|
165
|
+
resolve(false)
|
|
166
|
+
},
|
|
167
|
+
})
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
public checkFeedSubscribeStatus() {
|
|
173
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
174
|
+
if (tt.canIUse("checkFeedSubscribeStatus.object.allScene")) {
|
|
175
|
+
tt.checkFeedSubscribeStatus({
|
|
176
|
+
type: "play",
|
|
177
|
+
allScene: true,
|
|
178
|
+
success(res) {
|
|
179
|
+
// 若返回字段 status = true,表示已订阅,不展示订阅引导入口
|
|
180
|
+
// 若返回字段 status = false,表示未订阅,展示订阅引导入口
|
|
181
|
+
console.log(res.status)
|
|
182
|
+
resolve(res.status);
|
|
183
|
+
},
|
|
184
|
+
fail(res) {
|
|
185
|
+
console.log("订阅报错了:", res.errMsg)
|
|
186
|
+
resolve(false)
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
} else {
|
|
190
|
+
console.log("订阅失败了")
|
|
191
|
+
resolve(false)
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
addShortcut() {
|
|
198
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
199
|
+
tt.addShortcut({
|
|
200
|
+
success() {
|
|
201
|
+
resolve(true)
|
|
202
|
+
},
|
|
203
|
+
fail(err) {
|
|
204
|
+
console.log("添加桌面失败", err);
|
|
205
|
+
resolve(false)
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
onError(res: any) {
|
|
213
|
+
this.adsCall.error?.(res)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
onClose(res: any): void {
|
|
217
|
+
if (res.isEnded) {
|
|
218
|
+
this.adsCall.success?.()
|
|
219
|
+
|
|
220
|
+
} else {
|
|
221
|
+
this.adsCall.fail?.('未完整观看视频')
|
|
222
|
+
}
|
|
223
|
+
// console.log("视频广告关闭:", res, res.isEnded);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
bindTouchEnd() {
|
|
228
|
+
PlatfprmModule.buttonTouch.tt_button = false
|
|
229
|
+
PlatfprmModule.buttonTouch.tt_button_subscribe = null
|
|
230
|
+
PlatfprmModule.buttonTouch.tt_button_feedsubscribe = false
|
|
231
|
+
|
|
232
|
+
tt.offTouchEnd(this.onTouchEnd)
|
|
233
|
+
tt.onTouchEnd(this.onTouchEnd)
|
|
234
|
+
// tt.showModal({
|
|
235
|
+
// title: "订阅完成",
|
|
236
|
+
// content: '',
|
|
237
|
+
// });
|
|
238
|
+
}
|
|
239
|
+
onTouchEnd() {
|
|
240
|
+
const self = this;
|
|
241
|
+
if (PlatfprmModule.buttonTouch.tt_button) {
|
|
242
|
+
PlatfprmModule.buttonTouch.tt_button = false
|
|
243
|
+
tt.addShortcut({
|
|
244
|
+
success() {
|
|
245
|
+
console.log("添加桌面成功");
|
|
246
|
+
},
|
|
247
|
+
fail(err) {
|
|
248
|
+
console.log("添加桌面失败", err);
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
else if (PlatfprmModule.buttonTouch.tt_button_subscribe) {
|
|
253
|
+
const msg = PlatfprmModule.buttonTouch.tt_button_subscribe//'MSG1738838137157339868090924108072'
|
|
254
|
+
PlatfprmModule.buttonTouch.tt_button_subscribe = null
|
|
255
|
+
const tmplIds = [msg];
|
|
256
|
+
tt.requestSubscribeMessage({
|
|
257
|
+
tmplIds: tmplIds,
|
|
258
|
+
complete: (res) => {
|
|
259
|
+
if (res[msg] === "accept") {
|
|
260
|
+
|
|
261
|
+
} else {
|
|
262
|
+
}
|
|
263
|
+
console.log('订阅', JSON.stringify(res))
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
else if (PlatfprmModule.buttonTouch.tt_button_feedsubscribe) {
|
|
268
|
+
PlatfprmModule.buttonTouch.tt_button_feedsubscribe = false
|
|
269
|
+
tt.requestFeedSubscribe({
|
|
270
|
+
type: "play",
|
|
271
|
+
allScene: true,
|
|
272
|
+
success(res) {
|
|
273
|
+
console.log(res.success)
|
|
274
|
+
self.requestFeedSubscribe?.(res.success)
|
|
275
|
+
},
|
|
276
|
+
fail(res) {
|
|
277
|
+
console.log(res)
|
|
278
|
+
self.requestFeedSubscribe?.(false)
|
|
279
|
+
},
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
// console.log('没有点击');
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
public navigateToScene(param?: { scene?: string; callBack?: () => void }) {
|
|
289
|
+
this.sidebarCall = param?.callBack;
|
|
290
|
+
tt.navigateToScene({
|
|
291
|
+
scene: "sidebar",
|
|
292
|
+
success: () => {
|
|
293
|
+
},
|
|
294
|
+
fail: () => {
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
toPosition(node: Node) {
|
|
300
|
+
const pos: PositonData = { x: 0, y: 0, width: 0, height: 0 }
|
|
301
|
+
return pos
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
//开放数据域
|
|
305
|
+
public initOpenDataLayout(params: { x: number, y: number, width: number, height: number }) {
|
|
306
|
+
let data = {
|
|
307
|
+
type: "engine",
|
|
308
|
+
event: "viewport",
|
|
309
|
+
...params
|
|
310
|
+
}
|
|
311
|
+
this.sendMessageToOpenData(data)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
public sendMessageToOpenData(params: { type: string, event: string }) {
|
|
315
|
+
let openDataContext = tt.getOpenDataContext();
|
|
316
|
+
openDataContext.postMessage(params)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** 更新微信开放数据榜单数据 */
|
|
320
|
+
public updateCloudRank(key: string, score: number) {
|
|
321
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
322
|
+
let data = {
|
|
323
|
+
ttgame: {
|
|
324
|
+
score: score,
|
|
325
|
+
update_time: Math.floor(Date.now() / 1000)
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
tt.setUserCloudStorage({
|
|
329
|
+
KVDataList: [{
|
|
330
|
+
key: key,
|
|
331
|
+
value: JSON.stringify(data)
|
|
332
|
+
}],
|
|
333
|
+
success: () => {
|
|
334
|
+
resolve(true)
|
|
335
|
+
},
|
|
336
|
+
fail: (res) => {
|
|
337
|
+
console.error('开放数据更新失败', res)
|
|
338
|
+
resolve(false)
|
|
339
|
+
}
|
|
340
|
+
})
|
|
341
|
+
})
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
public showRank(keyList: string[], openId?: string) {
|
|
345
|
+
let data = {
|
|
346
|
+
type: "game",
|
|
347
|
+
event: "showRank",
|
|
348
|
+
keyList: keyList,
|
|
349
|
+
openId: openId
|
|
350
|
+
}
|
|
351
|
+
this.sendMessageToOpenData(data)
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { _decorator, Component, Node } from 'cc';
|
|
2
|
+
import { SDKBase } from './SDKBase';
|
|
3
|
+
import { AdsCall, AdsData, PositonData, SDKLoginData, SDKStatus, UserInfoData } from './SDKEnum';
|
|
4
|
+
import { ICreateUserInfoButton, miniSDK } from '../wx/MiniSDK';
|
|
5
|
+
const { ccclass, property } = _decorator;
|
|
6
|
+
|
|
7
|
+
@ccclass('WXSDK')
|
|
8
|
+
export class WXSDK extends SDKBase {
|
|
9
|
+
adsCall: AdsCall;
|
|
10
|
+
|
|
11
|
+
init(): Promise<void> {
|
|
12
|
+
wx.onShow((res: any) => {
|
|
13
|
+
|
|
14
|
+
});
|
|
15
|
+
wx.onHide(() => {
|
|
16
|
+
|
|
17
|
+
});
|
|
18
|
+
this.bindTouchEnd()
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
public login(data?: string): Promise<SDKLoginData> {
|
|
22
|
+
throw new Error('Method not implemented.');
|
|
23
|
+
}
|
|
24
|
+
public logout(): Promise<SDKStatus> {
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
27
|
+
public initRewardedVideo(param: AdsData) {
|
|
28
|
+
return miniSDK.init({ videoID: param.adUnitId })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public showRewardedVideo(param: AdsCall) {
|
|
32
|
+
this.adsCall = param;
|
|
33
|
+
miniSDK.showRewardedVideoAd({
|
|
34
|
+
onShow: () => {
|
|
35
|
+
this.adsCall.show?.()
|
|
36
|
+
},
|
|
37
|
+
onClose: (success: boolean) => {
|
|
38
|
+
if (success)
|
|
39
|
+
this.adsCall.success?.()
|
|
40
|
+
else
|
|
41
|
+
this.adsCall.close?.()
|
|
42
|
+
},
|
|
43
|
+
onError: (res) => {
|
|
44
|
+
this.adsCall.error?.(res)
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
bindTouchEnd() {
|
|
52
|
+
PlatfprmModule.buttonTouch.wx_button_subscribe = false
|
|
53
|
+
wx.offTouchEnd(this.onTouchEnd)
|
|
54
|
+
wx.onTouchEnd(this.onTouchEnd)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
onTouchEnd() {
|
|
58
|
+
const self = this;
|
|
59
|
+
if (PlatfprmModule.buttonTouch.wx_button_subscribe) {
|
|
60
|
+
PlatfprmModule.buttonTouch.wx_button_subscribe = false
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// console.log('没有点击');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
createUserInfoButton(param: ICreateUserInfoButton, callBack: (userInfo: UserInfoData) => void) {
|
|
68
|
+
return miniSDK.createUserInfoButton(param, callBack)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
createGameClubButton(node: Node) {
|
|
72
|
+
return miniSDK.createGameClubButton(node)
|
|
73
|
+
}
|
|
74
|
+
toPosition(node: Node) {
|
|
75
|
+
return miniSDK.toPosition(node)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
//开放数据域
|
|
80
|
+
public initOpenDataLayout(params: { x: number, y: number, width: number, height: number }) {
|
|
81
|
+
let data = {
|
|
82
|
+
type: "engine",
|
|
83
|
+
event: "viewport",
|
|
84
|
+
...params
|
|
85
|
+
}
|
|
86
|
+
this.sendMessageToOpenData(data)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public sendMessageToOpenData(params: { type: string, event: string }) {
|
|
90
|
+
let openDataContext = wx.getOpenDataContext();
|
|
91
|
+
openDataContext.postMessage(params)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 更新微信开放数据榜单数据 */
|
|
95
|
+
public updateCloudRank(key: string, score: number) {
|
|
96
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
97
|
+
let data = {
|
|
98
|
+
ttgame: {
|
|
99
|
+
score: score,
|
|
100
|
+
update_time: Math.floor(Date.now() / 1000)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
wx.setUserCloudStorage({
|
|
104
|
+
KVDataList: [{
|
|
105
|
+
key: key,
|
|
106
|
+
value: JSON.stringify(data)
|
|
107
|
+
}],
|
|
108
|
+
success: () => {
|
|
109
|
+
resolve(true)
|
|
110
|
+
},
|
|
111
|
+
fail: (res) => {
|
|
112
|
+
console.error('开放数据更新失败', res)
|
|
113
|
+
resolve(false)
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public showRank(keyList: string[], openId?: string) {
|
|
120
|
+
let data = {
|
|
121
|
+
type: "game",
|
|
122
|
+
event: "showRank",
|
|
123
|
+
keyList: keyList,
|
|
124
|
+
openId: openId
|
|
125
|
+
}
|
|
126
|
+
this.sendMessageToOpenData(data)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
/**检查是否显示隐私条约 */
|
|
132
|
+
public static checkShowPrivacy(): Promise<boolean> {
|
|
133
|
+
return new Promise(resovle => {
|
|
134
|
+
wx.getPrivacySetting({
|
|
135
|
+
success: res => {
|
|
136
|
+
resovle(res.needAuthorization)
|
|
137
|
+
},
|
|
138
|
+
fail: () => {
|
|
139
|
+
resovle(false)
|
|
140
|
+
},
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
public static openPrivacyCUrl(): void {
|
|
145
|
+
wx.openPrivacyContract({})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"ver":"4.0.24","importer":"typescript","imported":true,"uuid":"5bd8cee7-3af1-41fd-8ef6-0a8b8ef53945","files":[],"subMetas":{},"userData":{}}
|