2a5c63ac12d75132c52c8f7691451f27e85f9a6e.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, PlatformTT, _crd, TT_CONFIG, globalTT, delayTime;
  4. return {
  5. setters: [function (_cc) {
  6. _cclegacy = _cc.cclegacy;
  7. __checkObsolete__ = _cc.__checkObsolete__;
  8. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  9. }],
  10. execute: function () {
  11. _crd = true;
  12. _cclegacy._RF.push({}, "c097aDI7bFCML/d7lEO/gd8", "PlatformTT", undefined);
  13. __checkObsolete__(['Vec2', '_decorator']);
  14. TT_CONFIG = {
  15. AD_ID: {
  16. /** banner广告 */
  17. banner: '30a3ll993k15aakgla',
  18. /** 视频广告 */
  19. video: 'o1h5n7r8fnp31df3g1',
  20. /** 插屏广告 */
  21. interstitial: '4687fak66i8aklc5hd'
  22. }
  23. };
  24. delayTime = 1900;
  25. PlatformTT = class PlatformTT {
  26. constructor() {
  27. this._onHideTime = Infinity;
  28. this._shareTimes = 0;
  29. this._rewardVideo = void 0;
  30. this._bannerAd = void 0;
  31. this._interstitialAd = void 0;
  32. this._shareSuccessHandler = null;
  33. this._videoSuccessHandler = null;
  34. this._showInterstitialAdTime = null;
  35. this._shareModalIsActive = false;
  36. this._shareStr = "东北F4来到美国西部拓荒时代,保卫城镇,完成自我救赎。";
  37. }
  38. initialize() {
  39. //@ts-ignore
  40. globalTT = tt;
  41. console.log("初始化抖音框架"); //监听游戏生命周期回调
  42. globalTT.onShow(function (res) {
  43. //判断是否是从侧边栏复访
  44. if (res.scene == 1104) {
  45. console.log('从侧边栏复访');
  46. }
  47. });
  48. globalTT.showShareMenu({
  49. withShareTicket: true,
  50. menus: ['shareAppMessage', 'shareTimeline'],
  51. success: () => {},
  52. fail: () => {},
  53. complete: () => {}
  54. }); //发送给朋友
  55. globalTT.onShareAppMessage(function () {
  56. globalTT.shareAppMessage({
  57. title: this._shareStr,
  58. query: 'shareMsg=' + 'a=1'
  59. });
  60. }.bind(this));
  61. globalTT.onShow(res => {
  62. if (this._shareSuccessHandler == null) return;
  63. if (this._shareModalIsActive) return;
  64. if (Date.now() - this._onHideTime >= delayTime) {
  65. if (this._shareSuccessHandler) this._shareSuccessHandler(true);
  66. } else {
  67. globalTT.showModal({
  68. title: '分享提示',
  69. content: '成功分享到群即可获得奖励',
  70. success: res => {
  71. if (res.confirm) {
  72. this.shareShowReward(this._shareSuccessHandler(false));
  73. } else if (res.cancel) {
  74. this._shareSuccessHandler = null;
  75. }
  76. this._shareModalIsActive = false;
  77. }
  78. });
  79. this._shareModalIsActive = true;
  80. }
  81. this._onHideTime = Infinity;
  82. }); //this.__createBannerAd();
  83. this.__createVideoAd(); //this.__createInterstitialAd();
  84. } //检查当前宿主是否支持跳转到侧边栏
  85. isCheckScene(handler) {
  86. if (handler === void 0) {
  87. handler = null;
  88. }
  89. globalTT.checkScene({
  90. scene: 'sidebar',
  91. success(res) {
  92. if (handler) {
  93. if (res.isExist) {
  94. //支持
  95. if (true) {
  96. handler(false);
  97. } else {
  98. handler(true);
  99. }
  100. } else {
  101. //不支持
  102. handler(false);
  103. }
  104. }
  105. },
  106. fail(err) {
  107. console.error('检查侧边栏支持失败', err); // 可以选择默认操作,例如不展示奖励入口
  108. if (handler) {
  109. handler(false);
  110. }
  111. }
  112. });
  113. } //添加测边栏功能
  114. openSideBar(handler) {
  115. if (handler === void 0) {
  116. handler = null;
  117. }
  118. globalTT.navigateToScene({
  119. scene: 'sidebar',
  120. success() {
  121. handler == null || handler('成功打开侧边栏', true);
  122. },
  123. fail(err) {
  124. handler == null || handler('打开侧边栏失败', false);
  125. }
  126. });
  127. }
  128. /**
  129. * 是否支持添加桌面
  130. * @returns
  131. */
  132. isSupportDesk() {
  133. return true;
  134. } //添加到桌面
  135. addDesk(handler) {
  136. if (handler === void 0) {
  137. handler = null;
  138. }
  139. // 调用创建桌面快捷方式 API
  140. globalTT.addShortcut({
  141. success() {
  142. globalTT.showToast({
  143. title: '创建桌面快捷方式成功'
  144. });
  145. },
  146. fail(err) {
  147. globalTT.showToast({
  148. title: '创建桌面快捷方式失败',
  149. err
  150. });
  151. }
  152. });
  153. }
  154. showToast(param) {
  155. var finalParam = {
  156. title: '',
  157. icon: 'none',
  158. duration: 2000
  159. };
  160. Object.assign(finalParam, param);
  161. globalTT.showToast(finalParam);
  162. }
  163. shareAppMessage(param) {
  164. if (param === void 0) {
  165. param = {};
  166. }
  167. globalTT.shareAppMessage(param);
  168. }
  169. vibrateShort(param) {
  170. if (param === void 0) {
  171. param = {};
  172. }
  173. globalTT.vibrateShort(param);
  174. }
  175. vibrateLong(param) {
  176. if (param === void 0) {
  177. param = {};
  178. }
  179. globalTT.vibrateLong(param);
  180. }
  181. showCustomAd(close) {}
  182. hideCustomAd() {}
  183. showSigleCustomAd() {}
  184. hideSigleCustomAd() {} //分享
  185. shareShowReward(handler) {
  186. if (handler === void 0) {
  187. handler = null;
  188. }
  189. if (handler) {
  190. this._shareSuccessHandler = handler;
  191. }
  192. this._onHideTime = Date.now();
  193. this.shareAppMessage({
  194. title: this._shareStr,
  195. query: 'shareMsg=' + 'a=1'
  196. });
  197. }
  198. showRewardVideo(handler) {
  199. if (handler === void 0) {
  200. handler = null;
  201. }
  202. //console.log('当日视频次数: ', ArchiveSystem.localData.videoRewardTimesToday);
  203. /*if (ArchiveSystem.localData.videoRewardTimesToday % 2 === 1) {
  204. cc.log(ArchiveSystem.localData.videoRewardTimesToday, '转为分享');
  205. this.__turnVideoToShare(handler);
  206. return;
  207. }*/
  208. if (!this._rewardVideo) {
  209. this.__turnVideoToShare(handler);
  210. return;
  211. }
  212. this._videoSuccessHandler = handler;
  213. this._rewardVideo.show().then(() => {
  214. console.log("视频播放成功");
  215. }).catch(err => {
  216. this._rewardVideo.load().then(() => {
  217. this._rewardVideo.show().then(() => {
  218. console.log("视频重新加载,播放成功");
  219. });
  220. }).catch(err2 => {
  221. var _this$_videoSuccessHa;
  222. (_this$_videoSuccessHa = this._videoSuccessHandler) == null || _this$_videoSuccessHa.call(this, false);
  223. this.shareShowReward(handler);
  224. this._videoSuccessHandler = null;
  225. });
  226. });
  227. }
  228. showBannerAd() {
  229. if (!this._bannerAd) return;
  230. var {
  231. screenWidth,
  232. screenHeight
  233. } = globalTT.getSystemInfoSync();
  234. this._bannerAd.show().then(() => {
  235. this._bannerAd.style.left = (screenWidth - this._bannerAd.style.realWidth) / 2;
  236. this._bannerAd.style.top = screenHeight - this._bannerAd.style.realHeight;
  237. }).catch(e => {
  238. console.log('banner广告显示出错', e);
  239. });
  240. }
  241. hideBannerAd(recreate) {
  242. if (recreate === void 0) {
  243. recreate = false;
  244. }
  245. if (!this._bannerAd) return;
  246. this._bannerAd.hide();
  247. if (recreate) {
  248. this.refreshBannerAd();
  249. }
  250. }
  251. refreshBannerAd() {
  252. if (!this._bannerAd) return;
  253. this._bannerAd.destroy();
  254. this.__createBannerAd();
  255. }
  256. showInterstitialAd(force) {
  257. if (force === void 0) {
  258. force = false;
  259. }
  260. if (force) {
  261. if (!this._interstitialAd) return;
  262. this._interstitialAd.show();
  263. } else {
  264. if (!this._interstitialAd) return;
  265. var timeNow = Date.now();
  266. if (this._showInterstitialAdTime == null) {
  267. this._showInterstitialAdTime = timeNow;
  268. return;
  269. }
  270. if (timeNow - this._showInterstitialAdTime > 120 * 1000) {
  271. this._interstitialAd.show();
  272. this._showInterstitialAdTime = timeNow;
  273. }
  274. }
  275. }
  276. exitGame() {
  277. wx.exitMiniProgram({});
  278. }
  279. __createVideoAd() {
  280. if (!TT_CONFIG.AD_ID.video) return;
  281. this._rewardVideo = globalTT.createRewardedVideoAd({
  282. adUnitId: TT_CONFIG.AD_ID.video
  283. }); // 注册视频的onClose事件
  284. this._rewardVideo.onClose(res => {
  285. if (res && res.isEnded || res === undefined) {
  286. var _this$_videoSuccessHa2;
  287. (_this$_videoSuccessHa2 = this._videoSuccessHandler) == null || _this$_videoSuccessHa2.call(this, true);
  288. } else {
  289. var _this$_videoSuccessHa3;
  290. this.showToast({
  291. title: "完整观看视频才有奖励哦"
  292. });
  293. (_this$_videoSuccessHa3 = this._videoSuccessHandler) == null || _this$_videoSuccessHa3.call(this, false);
  294. }
  295. this._videoSuccessHandler = null;
  296. }); // 注册视频的onError事件
  297. this._rewardVideo.onError(res => {
  298. var _this$_videoSuccessHa4;
  299. (_this$_videoSuccessHa4 = this._videoSuccessHandler) == null || _this$_videoSuccessHa4.call(this, false);
  300. this.showToast({
  301. title: "暂时没有可观看的视频"
  302. });
  303. this.shareShowReward(this._videoSuccessHandler);
  304. this._videoSuccessHandler = null;
  305. });
  306. }
  307. __createBannerAd() {
  308. if (!TT_CONFIG.AD_ID.banner) return;
  309. var {
  310. screenWidth,
  311. screenHeight
  312. } = globalTT.getSystemInfoSync();
  313. var w = screenWidth * 0.85;
  314. var left = (screenWidth - w) / 2.0;
  315. this._bannerAd = globalTT.createBannerAd({
  316. adUnitId: TT_CONFIG.AD_ID.banner,
  317. adIntervals: 48,
  318. style: {
  319. left: left,
  320. top: screenHeight - 70,
  321. width: w,
  322. height: 70
  323. }
  324. });
  325. this._bannerAd.onError(err => {
  326. switch (err.errCode) {
  327. case 1001:
  328. {
  329. break;
  330. }
  331. case 1004:
  332. {
  333. break;
  334. }
  335. }
  336. });
  337. this._bannerAd.onResize(() => {});
  338. }
  339. __createInterstitialAd() {
  340. if (!TT_CONFIG.AD_ID.interstitial) return;
  341. this._interstitialAd = globalTT.createInterstitialAd({
  342. adUnitId: TT_CONFIG.AD_ID.interstitial
  343. });
  344. }
  345. __turnVideoToShare(handler) {
  346. this.shareShowReward(handler);
  347. this._videoSuccessHandler = null;
  348. }
  349. };
  350. _export("default", new PlatformTT());
  351. _cclegacy._RF.pop();
  352. _crd = false;
  353. }
  354. };
  355. });
  356. //# sourceMappingURL=2a5c63ac12d75132c52c8f7691451f27e85f9a6e.js.map