webGame.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. var webGame;
  2. (function (webGame) {
  3. class BasePlatform extends core.BasePlatform {
  4. constructor() {
  5. super();
  6. }
  7. /**web版本直接用Laya自带的方法获取保存数据本地缓存*/
  8. getStorageSync(key) {
  9. return Laya.LocalStorage.getJSON(key + core.Manager.baseInfo.game_id);
  10. }
  11. setStorageSync(key, data) {
  12. Laya.LocalStorage.setJSON(key + core.Manager.baseInfo.game_id, data);
  13. }
  14. /** 初始化监听事件 */
  15. initEvent() {
  16. Laya.stage.on(Laya.Event.VISIBILITY_CHANGE, this, this.stageVisibleChange);
  17. // core.Manager.eDispatcher.on(core.Event.ACTIVITYCLOSE, this, this.activityViewClose);
  18. if (!core.Manager.wtsdk.isReady)
  19. core.Manager.eDispatcher.on(core.Event.WTSDK_INIT_COMPLETE, this, this.login); //wtskd加载好并初始化完成后,登陆
  20. else
  21. this.login(); //登陆
  22. }
  23. stageVisibleChange() {
  24. if (Laya.stage.isVisibility) {
  25. this.onShow();
  26. }
  27. else {
  28. this.onHide();
  29. }
  30. }
  31. /**
  32. * 回到前台的事件处理函数
  33. */
  34. onShow(data) {
  35. // Laya.timer.resume();
  36. // Laya.stage.renderingEnabled=true//恢复渲染
  37. // Laya.updateTimer.resume() //恢复onUpdate
  38. // Laya.physicsTimer.resume() //恢复物理
  39. // Laya.systemTimer.resume();
  40. core.SoundManager.muted = this._muted; //还原onHide前的静音状态
  41. // core.Manager.wtsdk.sendStart({ scene: this.startScene });
  42. core.Manager.wtsdk.dotEvent(core.WtsdkEvent.ID_GAME_START);
  43. core.Manager.eDispatcher.event(core.Event.ON_SHOW, data);
  44. }
  45. /**
  46. * 小游戏隐藏到后台事件处理函数。
  47. */
  48. onHide(data) {
  49. // Laya.timer.pause();
  50. // Laya.stage.renderingEnabled=false//停止渲染
  51. // Laya.updateTimer.pause() //停止onUpdate
  52. // Laya.physicsTimer.pause() //停止物理
  53. // Laya.systemTimer.pause();
  54. this._muted = core.SoundManager.muted; //记录onHide前的静音状态
  55. core.SoundManager.muted = false;
  56. // core.Manager.wtsdk.sendExit({ scene: this.startScene });
  57. core.Manager.wtsdk.dotEvent(core.WtsdkEvent.ID_GAME_EXIT);
  58. core.Manager.eDispatcher.event(core.Event.ON_HIDE, data);
  59. }
  60. /**
  61. * 初始化(登陆、获取用户信息、设置默认分享)
  62. */
  63. init() {
  64. this.systemInfo = new webGame.SystemInfo();
  65. core.Manager.baseInfo.app_name = this.systemInfo.appName; //设置应用名
  66. core.Manager.baseInfo.device = this.systemInfo.device; //设置设备
  67. core.Manager.baseInfo.platform_id = core.PlatformType.ID_WEBGAME; //设置平台id(3-web)
  68. this.moneyActivity = new webGame.MoneyActivity();
  69. this.initEvent(); //初始化监听事件
  70. }
  71. /**
  72. * 登陆 - 获取Code
  73. */
  74. login() {
  75. this.gameStarted();
  76. if (core.Manager.wtsdk.isReady) ////wtskd初始化完成才能登陆
  77. {
  78. let locationSearch = decodeURIComponent(window.location.search);
  79. if (locationSearch) //从url取
  80. {
  81. let code = this.jsGetHttpParam("code", locationSearch);
  82. this.loginComplete(code);
  83. }
  84. else { //======================本地测试用的web版本token=======================
  85. this.loginComplete("bcd182bffa0af49c4fe90b69affca5e4");
  86. }
  87. this.ad = new webGame.BaseADManager(); //初始化广告
  88. }
  89. }
  90. jsGetHttpParam(paras, locationSearch) {
  91. let reg = new RegExp("(^|&)" + paras + "=([^&]*)(&|$)", "i");
  92. let r = locationSearch.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
  93. let context = "";
  94. if (r != null)
  95. context = r[2];
  96. reg = null;
  97. r = null;
  98. return context == null || context == "" || context == "undefined" ? "" : context;
  99. }
  100. /**
  101. * 登陆完成回调
  102. */
  103. loginComplete(code) {
  104. // {errMsg: "login:ok", anonymousCode: "535ed5c9f15679e2", code: "6a4bfc20dc513b4e", isLogin: true}
  105. // 登陆失败时,后台要求anonymousCode、code发个空值
  106. let data = {};
  107. data.code = code;
  108. data.app_name = core.Manager.baseInfo.app_name;
  109. data.game_id = core.Manager.baseInfo.game_id;
  110. data.platform_id = core.Manager.baseInfo.platform_id;
  111. data.device = this.systemInfo.device;
  112. data.scene = "0";
  113. data.version = BaseConfig.version;
  114. core.Manager.wtsdk.getUserInfo(data, Laya.Handler.create(this, this.httpUserInfoCallback)); //向后台请求用户信息
  115. }
  116. //向后台请求用户信息
  117. httpUserInfoCallback(data) {
  118. if (data && data.code == 200) {
  119. core.Manager.baseInfo.token = data.result.token; //data.result.id;
  120. core.Manager.selfInfo.updateAll(data.result);
  121. // this.setUserInfo(null);
  122. core.Manager.isLogined = true;
  123. }
  124. else
  125. log(data);
  126. }
  127. // //向后台发送平台用户信息
  128. // private setUserInfo(userInfo: any) {
  129. // //如果能获取到字节个人信息,则发送更新用户信息
  130. // if (userInfo) core.Manager.wtsdk.modifyUserInfo({ userInfo: userInfo, member_id: core.Manager.selfInfo.id }, Laya.Handler.create(this, this.httpModifyUserInfoCallback));
  131. // else {
  132. // core.Manager.selfInfo.isAuthorized = true;//web默认已授权
  133. // this.sendUserInfo(core.Manager.selfInfo);//无需更新信息,则直接发送用户信息到开放域
  134. // }
  135. // }
  136. // private httpModifyUserInfoCallback(data: any) {
  137. // // log(data);
  138. // if (data && data.code == 200) {
  139. // core.Manager.selfInfo.update(data.result);
  140. // core.Manager.selfInfo.isAuthorized = true;//已授权
  141. // this.sendUserInfo(core.Manager.selfInfo);//发送用户信息到开放域
  142. // }
  143. // else log(data);
  144. // }
  145. // /** 传递UserInfo */
  146. // private sendUserInfo(userInfo: any) {
  147. // core.Manager.isLogined = true;
  148. // }
  149. /**震动 */
  150. vibrate(pattern) {
  151. if (core.Manager.wtsdk.isReady)
  152. wtsdk.onVibrator(pattern);
  153. }
  154. /** 创建桌面图标 */
  155. addToDeskIcon(isShow, x = 0, y = 0, parent) {
  156. if (isShow) {
  157. if (core.Manager.config.isOpen(core.FunctionKey.ADD_TO_DESK)) {
  158. return webGame.AddToDeskIcon.show(x, y, parent);
  159. }
  160. }
  161. else
  162. webGame.AddToDeskIcon.hide();
  163. }
  164. /** 保存最高分 */
  165. saveScore(score) {
  166. core.Manager.wtsdk.saveScore({ score: score }, Laya.Handler.create(this, (data) => {
  167. if (data && data.code == 200) {
  168. core.Manager.selfInfo.score = data.result.score;
  169. }
  170. }));
  171. }
  172. /**游戏开始接口 */
  173. gameStarted() {
  174. if (core.Manager.wtsdk.isReady) {
  175. wtsdk.gameStarted({
  176. gameId: core.Manager.baseInfo.game_id,
  177. version: BaseConfig.version
  178. });
  179. }
  180. else {
  181. log('wtsdk is not ready, gameStarted fail');
  182. }
  183. }
  184. //↓↓ 广告类 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
  185. /** 显示或隐藏Banner广告 */
  186. adBanner(isShow, position_id) {
  187. if (core.Manager.wtsdk.isReady) {
  188. try {
  189. if (isShow)
  190. this.ad.showBanner(position_id);
  191. else
  192. this.ad.hideBanner(position_id);
  193. }
  194. catch (e) {
  195. log("adBanner error:", e);
  196. }
  197. }
  198. else {
  199. log('wtsdk is not ready, adBanner fail');
  200. }
  201. }
  202. /** 显示激励式广告 */
  203. // adrewardCding = false
  204. adRewardedVideo(position_id) {
  205. new webGame.LoadADTipsView();
  206. if (core.Manager.wtsdk.isReady) {
  207. try {
  208. this.ad.showRewardedVideoAd(position_id);
  209. }
  210. catch (e) {
  211. log("adBanner error:", e);
  212. }
  213. }
  214. else {
  215. log('wtsdk is not ready, adRewardedVideo fail');
  216. }
  217. }
  218. /** 显示插屏广告 */
  219. adInterstitial(position_id) {
  220. if (core.Manager.wtsdk.isReady) {
  221. try {
  222. this.ad.showInterstitialAd(position_id);
  223. }
  224. catch (e) {
  225. log("adBanner error:", e);
  226. }
  227. }
  228. else {
  229. log('wtsdk is not ready, adInterstitial fail');
  230. }
  231. }
  232. /** 显示全屏广告流广告 */
  233. adFullVideo(position_id) {
  234. if (core.Manager.wtsdk.isReady) {
  235. try {
  236. this.ad.showFullVideoAd(position_id);
  237. }
  238. catch (e) {
  239. log("adBanner error:", e);
  240. }
  241. }
  242. else {
  243. log('wtsdk is not ready, fullVideo fail');
  244. }
  245. }
  246. /** 信息流(可以理解为Banner一样的东西) */
  247. adFeed(isShow, position_id, gravity) {
  248. if (core.Manager.wtsdk.isReady) {
  249. if (isShow) {
  250. try {
  251. if (isShow)
  252. this.ad.showFreeAd(position_id);
  253. else
  254. this.ad.hideFreeAd(position_id);
  255. }
  256. catch (e) {
  257. log("adBanner error:", e);
  258. }
  259. }
  260. else {
  261. wtsdk.closeFeed();
  262. }
  263. }
  264. else {
  265. log('wtsdk is not ready, adInterstitial fail');
  266. }
  267. }
  268. /**
  269. * 更多游戏图标
  270. * @parame isShow 是否显示
  271. */
  272. moreGameBtn(isShow) {
  273. // if (isShow) {
  274. // if (!core.Manager.gameList || core.Manager.gameList.length == 0) return null;
  275. // if (!this._moreGameBtn) this._moreGameBtn = new MoreGameIcon(this.moreGameParams);
  276. // }
  277. // else if (this._moreGameBtn) {
  278. // this._moreGameBtn.destroy();
  279. // this._moreGameBtn = null;
  280. // }
  281. // return this._moreGameBtn;
  282. return;
  283. }
  284. /** 更多游戏按钮参数 */
  285. get moreGameParams() {
  286. return { x: 0, y: 0, w: 60, h: 60, appLaunchOptions: [] };
  287. }
  288. //↓↓ 网赚 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
  289. openMoneyActiviyView(type, data) {
  290. if (core.Manager.wtsdk.isReady) {
  291. this.moneyActivity.ActivityView(type, data);
  292. }
  293. else {
  294. log('wtsdk is not ready, openMoneyActiviyView fail');
  295. }
  296. }
  297. /**账户的金币信息接口 */
  298. operateCoin(callback) {
  299. if (core.Manager.wtsdk.isReady) {
  300. this.moneyActivity.operateCoin(callback);
  301. }
  302. else {
  303. log('wtsdk is not ready, operateCoin fail');
  304. }
  305. }
  306. /**账户的积分信息接口 */
  307. getUserCoinInfo(Type, callback) {
  308. if (core.Manager.wtsdk.isReady) {
  309. this.moneyActivity.getUserCoinInfo(Type, callback);
  310. }
  311. else {
  312. log('wtsdk is not ready, getUserCoinInfo fail');
  313. }
  314. }
  315. /**小迈--神策 --自定义事件上报 */
  316. // event: "game_pass", // game_pass 是事件的标识,策划定的
  317. // data: { // data 里面需要的数据,策划定的
  318. // game_level: 8, // 通关的关卡
  319. // game_state: 'succeed' // 是否通过
  320. // },
  321. // public Event_track(eventName: string, eventdata: any) {
  322. // if (core.Manager.wtsdk.isReady) {
  323. // wtsdk.track({
  324. // event: eventName,
  325. // data: eventdata,
  326. // });
  327. // } else {
  328. // // alert('wtsdk is not ready');
  329. // }
  330. // }
  331. //↓↓ 网赚view客户端接口 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
  332. // 领取奖励
  333. wzFinishReward(sceneType, Level, moneyType = 2) {
  334. if (core.Manager.wtsdk.isReady) {
  335. wtsdk.wzFinishReward({
  336. params: {
  337. type: moneyType,
  338. scene: sceneType,
  339. level: Level
  340. },
  341. onSuccess: function (res) {
  342. core.Manager.eDispatcher.event(core.Event.GET_ACTIVITY_REWARD, { type: sceneType, value: res.data.coin_add });
  343. },
  344. onFail: function (res) {
  345. // core.FloatTips.addTips(res.msg)
  346. }
  347. });
  348. }
  349. else {
  350. // alert('wtsdk is not ready');
  351. }
  352. }
  353. // 如果需要预加载,先提前调用loadRewardVideo去加载广告
  354. loadRewardVideo(postionID) {
  355. if (core.Manager.wtsdk.isReady) {
  356. this.ad.LoadRewardedVideoAd(postionID);
  357. }
  358. else {
  359. // alert('wtsdk is not ready');
  360. }
  361. }
  362. /**签到初始化 */
  363. loginSignInit(SuccessCallBack) {
  364. if (core.Manager.wtsdk.isReady) {
  365. wtsdk.loginSignInit({
  366. onSuccess: function (res) {
  367. if (SuccessCallBack)
  368. SuccessCallBack.runWith(res.data);
  369. },
  370. onFail: function (res) {
  371. // core.FloatTips.addTips("初始化失败,请稍后重试")
  372. }
  373. });
  374. }
  375. else {
  376. // alert('wtsdk is not ready');
  377. }
  378. }
  379. /**签到一次,保存用户当天签到记录 */
  380. loginSignLog(onSuccess) {
  381. if (core.Manager.wtsdk.isReady) {
  382. wtsdk.loginSignLog({
  383. onSuccess: function (res) {
  384. if (res && res.code == 1) {
  385. onSuccess.run();
  386. }
  387. },
  388. onFail: function (res) {
  389. // core.FloatTips.addTips(res.msg)
  390. }
  391. });
  392. }
  393. else {
  394. // alert('wtsdk is not ready');
  395. }
  396. }
  397. /**签到提现 */
  398. loginSignWithdraw(day, amount, Rank, SuccessCallBack) {
  399. if (core.Manager.wtsdk.isReady) {
  400. wtsdk.loginSignWithdraw({
  401. params: {
  402. days: day,
  403. amount: amount,
  404. rank: Rank // 提现的档位
  405. },
  406. onSuccess: function (res) {
  407. if (SuccessCallBack)
  408. SuccessCallBack.runWith(1);
  409. },
  410. onFail: function (res) {
  411. if (SuccessCallBack)
  412. SuccessCallBack.runWith(0);
  413. }
  414. });
  415. }
  416. else {
  417. // alert('wtsdk is not ready');
  418. }
  419. }
  420. /**
  421. * 进度值
  422. * @param data percent进度值,1-100
  423. */
  424. progress(data) {
  425. // log("to sdk progress",data.percent)
  426. if (core.Manager.wtsdk.isReady) {
  427. return wtsdk.progress(data);
  428. }
  429. }
  430. }
  431. webGame.BasePlatform = BasePlatform;
  432. })(webGame || (webGame = {}));
  433. /// <reference path="./base/BasePlatform.ts" />
  434. var webGame;
  435. /// <reference path="./base/BasePlatform.ts" />
  436. (function (webGame) {
  437. class Platform extends webGame.BasePlatform {
  438. constructor() {
  439. super();
  440. // if(BaseConfig.needResServer) Laya.URL.basePath = core.Manager.baseResPath + "game/gameResName/tt/v1.0.0";//"/gameResName/tt/v" + BaseConfig.version;
  441. }
  442. showTitle(score) {
  443. throw new Error("Method not implemented.");
  444. }
  445. sendLoginCheck() {
  446. throw new Error("Method not implemented.");
  447. }
  448. // public showSurpass(score:number):void{}
  449. /** 更多游戏按钮参数 */
  450. get moreGameParams() {
  451. return { x: 0, y: 0, w: 60, h: 60,
  452. appLaunchOptions: [
  453. {
  454. appId: "ttXXXXXX",
  455. query: "",
  456. extraData: {},
  457. }
  458. ]
  459. };
  460. }
  461. }
  462. webGame.Platform = Platform;
  463. })(webGame || (webGame = {}));
  464. window.webGame = webGame;
  465. //首次加载时,初始化
  466. window.platform = new webGame.Platform();
  467. /**
  468. * 广告
  469. */
  470. var webGame;
  471. /**
  472. * 广告
  473. */
  474. (function (webGame) {
  475. class BaseADManager {
  476. constructor() {
  477. this.createAD();
  478. }
  479. createAD() {
  480. this.createBannerAd();
  481. this.createInterstitialAd();
  482. this.createRewardedVideoAd();
  483. this.createFreeAd();
  484. this.createFullVideoAd();
  485. }
  486. //↓↓ Banner广告 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
  487. /** 创建Banner广告 */
  488. createBannerAd() {
  489. if (!core.Manager.wtsdk.isReady || this._bannerAd)
  490. return;
  491. // 创建 Banner 广告实例,提前初始化
  492. let ad = wtsdk.createBannerAd();
  493. if (!ad)
  494. return;
  495. ad.onError(this.onBannerError.bind(this));
  496. this._bannerAd = ad;
  497. }
  498. /** banner报错 */
  499. onBannerError(err) {
  500. }
  501. /** 显示 banner 广告 */
  502. showBanner(posid) {
  503. if (this._bannerAd)
  504. this._bannerAd.show(posid);
  505. }
  506. /** 隐藏 banner 广告 */
  507. hideBanner(posid) {
  508. if (this._bannerAd)
  509. this._bannerAd.close(posid);
  510. }
  511. //↑↑ Banner广告 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
  512. //↓↓ 插屏广告 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
  513. /** 创建插屏广告 */
  514. createInterstitialAd() {
  515. // 创建插屏广告实例,提前初始化
  516. if (!core.Manager.wtsdk.isReady || this._interstitialAd)
  517. return;
  518. this._interstitialAd = wtsdk.createInterstitialAd();
  519. if (!this._interstitialAd)
  520. return;
  521. this._interstitialAd.onError(this.onInterstitialAdError.bind(this));
  522. this._interstitialAd.onClose(this.onInterstitialAdClosed.bind(this));
  523. this._interstitialAd.onLoad(this.onInterstitialAdLoaded.bind(this));
  524. //默认load一个视频出来
  525. this.LoadInterstitialAd(40000);
  526. }
  527. /** 插屏广告报错 */
  528. onInterstitialAdError(err) {
  529. core.Manager.eDispatcher.event(core.Event.INTERSTITIAL_AD_ERROR, err);
  530. }
  531. /** 插屏广告关闭 */
  532. onInterstitialAdClosed(res) {
  533. core.Manager.eDispatcher.event(core.Event.INTERSTITIAL_AD_CLOSE, res);
  534. }
  535. /** 插屏广告加载完成 */
  536. onInterstitialAdLoaded(res) {
  537. if (!this._interstitialAd)
  538. return;
  539. core.Manager.eDispatcher.event(core.Event.INTERSTITIAL_AD_ONLOAD, res);
  540. }
  541. /** 插屏广告预加载 */
  542. LoadInterstitialAd(posId) {
  543. if (!this._interstitialAd)
  544. return;
  545. this._interstitialAd.load(posId);
  546. }
  547. /**
  548. * 显示插屏广告
  549. */
  550. showInterstitialAd(posid) {
  551. // 在适合的场景显示插屏广告
  552. if (!this._interstitialAd)
  553. return;
  554. this._interstitialAd.show(posid); //skd在show里加了load,不再需要load
  555. // this._interstitialAd.load(posid);
  556. // this._interstitialAd.onLoad((function(result){
  557. // this._interstitialAd.show(posid);
  558. // }).bind(this));
  559. }
  560. //↑↑ 插屏广告 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
  561. //↓↓ 激励视频广告 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
  562. /** 创建激励视频广告 */
  563. createRewardedVideoAd() {
  564. if (!core.Manager.wtsdk.isReady || this._rewardedVideoAd)
  565. return;
  566. this._rewardedVideoAd = wtsdk.createRewardVideoAd();
  567. if (!this._rewardedVideoAd)
  568. return;
  569. this._rewardedVideoAd.onError(this.onRewardedVideoAdError.bind(this));
  570. this._rewardedVideoAd.onClose(this.onRewardedVideoAdClosed.bind(this));
  571. this._rewardedVideoAd.onLoad(this.onRewardedVideoAdLoaded.bind(this));
  572. //默认load一个视频出来
  573. this.LoadRewardedVideoAd(30000);
  574. //this._rewardedVideoAd.onReward(this.onRewardedVideoAdReward.bind(this));
  575. }
  576. /** 激励视频广告报错 */
  577. onRewardedVideoAdError(err) {
  578. core.Manager.eDispatcher.event(core.Event.REWARDED_AD_ERROR, false);
  579. }
  580. /** 激励视频广告关闭 */
  581. onRewardedVideoAdClosed(res) {
  582. let result = res && res.data ? res.data.isReward : false;
  583. core.Manager.eDispatcher.event(core.Event.REWARDED_AD_CLOSE, result);
  584. }
  585. /** 激励视频广告加载完成 */
  586. onRewardedVideoAdLoaded(res) {
  587. core.Manager.eDispatcher.event(core.Event.REWARDED_AD_ONLOAD, res);
  588. }
  589. // /**激励播放成功 */
  590. // protected onRewardedVideoAdReward(){
  591. // }
  592. /** 激励视频广告预加载 */
  593. LoadRewardedVideoAd(posId) {
  594. if (!this._rewardedVideoAd)
  595. return;
  596. this._rewardedVideoAd.load(posId);
  597. }
  598. /** 显示激励广告 */
  599. showRewardedVideoAd(posId) {
  600. if (!this._rewardedVideoAd)
  601. return;
  602. this._rewardedVideoAd.show(posId);
  603. }
  604. //↑↑ 激励视频广告 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
  605. //↓↓ 信息流广告 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
  606. createFreeAd() {
  607. if (!core.Manager.wtsdk.isReady || this._FreeAD)
  608. return;
  609. // 创建 FreeAd 广告实例,提前初始化
  610. let ad = wtsdk.createFeedAd();
  611. if (!ad)
  612. return;
  613. ad.onError(this.onFreeAdError.bind(this));
  614. this._FreeAD = ad;
  615. }
  616. /** FreeAd报错 */
  617. onFreeAdError(err) {
  618. }
  619. /** 显示 FreeAd 广告 */
  620. showFreeAd(posid) {
  621. if (this._FreeAD)
  622. this._FreeAD.show(posid);
  623. }
  624. /** 隐藏 FreeAd 广告 */
  625. hideFreeAd(posid) {
  626. if (this._FreeAD)
  627. this._FreeAD.close(posid);
  628. }
  629. //↑↑ 信息流广告 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
  630. //↓↓ 全屏视频广告 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
  631. createFullVideoAd() {
  632. if (!core.Manager.wtsdk.isReady || this._FullVideoAd)
  633. return;
  634. this._FullVideoAd = wtsdk.createFullVideoAd();
  635. if (!this._FullVideoAd)
  636. return;
  637. this._FullVideoAd.onError(this.onFullVideoAdError.bind(this));
  638. this._FullVideoAd.onClose(this.onFullVideoAdClosed.bind(this));
  639. this._FullVideoAd.onLoad(this.onFullVideoAdLoaded.bind(this));
  640. }
  641. /** 全屏广告广告报错 */
  642. onFullVideoAdError(err) {
  643. core.Manager.eDispatcher.event(core.Event.FULL_AD_ERROR, false);
  644. }
  645. /** 全屏广告广告关闭 */
  646. onFullVideoAdClosed(res) {
  647. core.Manager.eDispatcher.event(core.Event.FULL_AD_CLOSE, res);
  648. }
  649. /** 全屏广告广告加载完成 */
  650. onFullVideoAdLoaded(res) {
  651. core.Manager.eDispatcher.event(core.Event.FULL_AD_ONLOAD, res);
  652. }
  653. /** 全屏广告广告预加载 */
  654. LoadFullVideoAd(posId) {
  655. if (!this._FullVideoAd)
  656. return;
  657. this._FullVideoAd.load(posId);
  658. }
  659. /** 显示激励广告 */
  660. showFullVideoAd(posId) {
  661. if (!this._FullVideoAd)
  662. return;
  663. this._FullVideoAd.show(posId);
  664. }
  665. }
  666. webGame.BaseADManager = BaseADManager;
  667. })(webGame || (webGame = {}));
  668. var webGame;
  669. (function (webGame) {
  670. class MoneyActivity {
  671. constructor() { }
  672. /**账户的金币信息接口 */
  673. operateCoin(callback) {
  674. if (core.Manager.wtsdk.isReady) {
  675. wtsdk.operateCoin({
  676. userState: function (result) {
  677. log(result);
  678. if (callback)
  679. callback.runWith(result.data);
  680. }
  681. });
  682. }
  683. }
  684. /**
  685. * 账户的积分信息接口
  686. * @param Type 货币类型
  687. * @param callback
  688. */
  689. getUserCoinInfo(Type, callback) {
  690. if (core.Manager.wtsdk.isReady) {
  691. wtsdk.getUserCoinInfo({
  692. params: {
  693. type: Type
  694. },
  695. success: function (result) {
  696. log("getUserCoinInfo success...");
  697. if (callback)
  698. callback.runWith(result.data);
  699. },
  700. error: function (result) {
  701. log("getUserCoinInfo error", result);
  702. if (callback)
  703. callback.runWith({});
  704. },
  705. });
  706. }
  707. else {
  708. log('wtsdk is not ready');
  709. }
  710. }
  711. /******************以下维特部分网赚接口是独立工程调起网赚页接口************************************************************************ */
  712. ActivityView(type, data) {
  713. if (!core.Manager.wtsdk.isReady)
  714. return;
  715. switch (type) {
  716. case core.MoneyActivityType.withdraw: /** 提现页 */
  717. log("提现");
  718. // wtsdk.withdraw(data)
  719. break;
  720. case core.MoneyActivityType.wheel: /** 大转盘 */
  721. wtsdk.wheel(data);
  722. break;
  723. case core.MoneyActivityType.fruitMachine: /** 水果机 */
  724. wtsdk.fruitMachine(data);
  725. break;
  726. case core.MoneyActivityType.idiom: /** 成语游戏 */
  727. wtsdk.idiom(data);
  728. break;
  729. case core.MoneyActivityType.newIdiom: /**成语答题 */
  730. wtsdk.newIdiom(data);
  731. break;
  732. case core.MoneyActivityType.scratchCard: /**刮刮卡 */
  733. wtsdk.scratchCard(data);
  734. break;
  735. case core.MoneyActivityType.userFeedBack: /**用户反馈 */
  736. wtsdk.userFeedBack(data);
  737. break;
  738. case core.MoneyActivityType.policyPage: /**隐私政策 */
  739. wtsdk.policyPage(data);
  740. break;
  741. case core.MoneyActivityType.agreementPage: /**用户协议 */
  742. wtsdk.agreementPage(data);
  743. break;
  744. case core.MoneyActivityType.withdrawIntegral: /**积分提现页 */
  745. wtsdk.withdrawIntegral(data);
  746. break;
  747. // case core.MoneyActivityType.loginSignWithdraw:/**签到提现页 */
  748. // wtsdk.loginSignWithdraw(data)
  749. // break
  750. case core.MoneyActivityType.loginOut: /** 小迈 注销页 */
  751. wtsdk.logout(data);
  752. break;
  753. // case core.MoneyActivityType.triggerBehavior: /** 小迈 自定义激活回传 */
  754. // wtsdk.triggerBehavior({
  755. // level: data
  756. // })
  757. // break
  758. // case core.MoneyActivityType.keyBehavior: /** 小迈 关键行为回传 */
  759. // wtsdk.keyBehavior(data)
  760. // break
  761. case core.MoneyActivityType.debugPage:
  762. wtsdk.debugPage(data);
  763. break;
  764. case core.MoneyActivityType.loadWZRewardAd:
  765. wtsdk.loadWZRewardAd({
  766. type: 'level_pass' // 过关红包
  767. });
  768. break;
  769. /**维特接口 */
  770. case core.MoneyActivityType.SevenLogin: /**七日登录 */
  771. wtsdk.showSevenLogin(this.WeiTeSdkParame(type, data));
  772. break;
  773. case core.MoneyActivityType.LoginSign: /**登录签到 */
  774. wtsdk.showLoginSign(this.WeiTeSdkParame(type, data));
  775. break;
  776. case core.MoneyActivityType.Achievement: /**成就红包 */
  777. wtsdk.showAchievement(this.WeiTeSdkParame(type, data));
  778. break;
  779. case core.MoneyActivityType.AchievementBig: /**成就红包 */
  780. wtsdk.showAchievementBig(this.WeiTeSdkParame(type, data));
  781. break;
  782. case core.MoneyActivityType.Bubbles: /**泡泡红包 */
  783. wtsdk.showBubbles(this.WeiTeSdkParame(type, data));
  784. break;
  785. case core.MoneyActivityType.LevelPass: /**过关红包 */
  786. wtsdk.showLevelPass(this.WeiTeSdkParame(type, data));
  787. break;
  788. case core.MoneyActivityType.NewPlayer: /**新人红包 */
  789. wtsdk.showNewUser(this.WeiTeSdkParame(type, data));
  790. break;
  791. case core.MoneyActivityType.AchievementNewC: /**新成就红包(积分C) */
  792. wtsdk.showAchievementNewC(this.WeiTeSdkParame(type, data));
  793. break;
  794. }
  795. }
  796. WeiTeSdkParame(type, data) {
  797. let wtActivityParame = {
  798. params: {
  799. xx: data ? data : 'guide=0'
  800. },
  801. open: function (res) {
  802. log("开启通知");
  803. // core.Manager.eDispatcher.event(core.Event.ACTIVITYOPEN, {
  804. // activityType: type,
  805. // res: res.data
  806. // });
  807. },
  808. close: function (res) {
  809. log("关闭通知", res);
  810. // core.Manager.eDispatcher.event(core.Event.ACTIVITYCLOSE, {
  811. // activityType: type,
  812. // res: res.data
  813. // });
  814. }
  815. };
  816. log("请求网赚:", type, " 参数:", data, wtActivityParame);
  817. return wtActivityParame;
  818. }
  819. }
  820. webGame.MoneyActivity = MoneyActivity;
  821. })(webGame || (webGame = {}));
  822. var webGame;
  823. (function (webGame) {
  824. class SystemInfo {
  825. constructor() {
  826. this.info = { appName: "wtyx", platform: "" };
  827. this.info.platform = Laya.Browser.onIOS ? "ios" : (Laya.Browser.onAndroid ? "android" : "computer");
  828. }
  829. /** 设备:android,ios */
  830. get device() {
  831. return this.info.platform;
  832. }
  833. /** app名字 */
  834. get appName() {
  835. return this.info.appName;
  836. }
  837. }
  838. webGame.SystemInfo = SystemInfo;
  839. })(webGame || (webGame = {}));
  840. var webGame;
  841. (function (webGame) {
  842. class AddToDeskIcon extends Laya.Image {
  843. //↑↑ static ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
  844. constructor() {
  845. super(core.Manager.commonResPath + "atTodesk/icon.png");
  846. }
  847. static show(x = 0, y = 0, parent) {
  848. if (!this._instance)
  849. this._instance = new AddToDeskIcon();
  850. this._instance.pos(x, y);
  851. if (!parent)
  852. parent = Laya.stage;
  853. parent.addChild(this._instance);
  854. return this._instance;
  855. }
  856. static hide() {
  857. if (this._instance) {
  858. this._instance.destroy();
  859. this._instance = null;
  860. }
  861. }
  862. onEnable() {
  863. super.onEnable();
  864. this.on(Laya.Event.CLICK, this, this.onClick);
  865. }
  866. onDisable() {
  867. super.onDisable();
  868. this.off(Laya.Event.CLICK, this, this.onClick);
  869. }
  870. onClick(e) {
  871. if (core.Manager.wtsdk.isReady)
  872. wtsdk.onShortcut();
  873. }
  874. destroy() {
  875. Laya.timer.clearAll(this);
  876. super.destroy();
  877. }
  878. }
  879. webGame.AddToDeskIcon = AddToDeskIcon;
  880. })(webGame || (webGame = {}));
  881. var webGame;
  882. (function (webGame) {
  883. class LoadADTipsView extends Laya.Box {
  884. constructor() {
  885. super();
  886. this.zOrder = 1000;
  887. this.mouseEnabled = true;
  888. this.blackBg = new Laya.Sprite();
  889. this.blackBg.alpha = 0.5;
  890. this.addChild(this.blackBg);
  891. Laya.stage.addChild(this);
  892. }
  893. onAwake() {
  894. this.timeNum = 3;
  895. this.str = "等待广告中...";
  896. let size = Laya.stage.width > 600 ? 38 : (Laya.stage.width <= 400 ? 24 : 30);
  897. this.lable = core.FloatTips.createLable(`${this.str}`, 0, (78 - size) / 2, size, Laya.stage.width, '#ffffff', "center");
  898. this.lable.text = this.str + "\n" + this.timeNum;
  899. this.lable.leading = 10;
  900. this.lable.centerX = 0;
  901. this.lable.centerY = 0;
  902. this.addChild(this.lable);
  903. }
  904. onEnable() {
  905. super.onEnable();
  906. core.Manager.eDispatcher.on(core.Event.REWARDED_AD_CLOSE, this, this.destroy);
  907. core.Manager.eDispatcher.on(core.Event.REWARDED_AD_ERROR, this, this.destroy);
  908. Laya.stage.on(Laya.Event.RESIZE, this, this.onResize);
  909. this.onResize();
  910. Laya.timer.loop(1000, this, this.timeCount, null, false);
  911. }
  912. onResize(e) {
  913. this.blackBg.graphics.clear();
  914. this.blackBg.graphics.drawRect(0, 0, Laya.stage.width, Laya.stage.height, '#000000');
  915. this.blackBg.size(Laya.stage.width, Laya.stage.height);
  916. }
  917. timeCount() {
  918. this.timeNum--;
  919. this.lable.text = this.str + "\n" + this.timeNum;
  920. if (this.timeNum <= 0) {
  921. // core.FloatTips.addTips("激励视频加载失败");
  922. Laya.timer.clearAll(this);
  923. this.destroy();
  924. }
  925. }
  926. onDisable() {
  927. core.Manager.eDispatcher.off(core.Event.REWARDED_AD_CLOSE, this, this.destroy);
  928. core.Manager.eDispatcher.off(core.Event.REWARDED_AD_ERROR, this, this.destroy);
  929. Laya.stage.off(Laya.Event.RESIZE, this, this.onResize);
  930. }
  931. destroy() {
  932. Laya.timer.clearAll(this);
  933. super.destroy();
  934. }
  935. }
  936. webGame.LoadADTipsView = LoadADTipsView;
  937. })(webGame || (webGame = {}));
  938. var webGame;
  939. (function (webGame) {
  940. class MoreGameIcon extends Laya.Box {
  941. constructor(params) {
  942. super();
  943. this.ICON_SIZE = 120; //游戏图标的始尺寸
  944. this.zOrder = core.ZOrder.POPUP;
  945. this._appLaunchOptions = params.appLaunchOptions;
  946. this.pos(params.x, params.y);
  947. // this.size(params.w, params.h);
  948. this.scale(params.w / this.ICON_SIZE, params.h / this.ICON_SIZE);
  949. Laya.stage.addChild(this);
  950. }
  951. onAwake() {
  952. this._index = 0;
  953. this._icon = new Laya.Image();
  954. this._icon.anchorX = 0.5;
  955. this._icon.anchorY = 0.5;
  956. this.addChild(this._icon);
  957. this._label = new Laya.Image(this.getRes("gdhw")); //
  958. this._label.anchorX = 0.5;
  959. this._label.anchorY = 0.5;
  960. this._label.y = 86;
  961. this.addChild(this._label);
  962. this._iconUrls = [];
  963. let gameList = core.Manager.gameList;
  964. for (let i = gameList.length - 1; i >= 0; i--) {
  965. if (gameList[i].rec_degree == 1)
  966. this._iconUrls.push(gameList[i].icon); //取热门游戏
  967. }
  968. if (this._iconUrls.length == 0)
  969. this._iconUrls.push(gameList[0].icon); //无热门游戏,推第一个进去,保证起码有一个游戏
  970. this._tweentimeLite = new core.TweenTimeLine(0);
  971. this._tweentimeLite.addToTween(this, { scaleX: this.scaleX * 0.8, scaleY: this.scaleX * 0.8 }, 600, Laya.Ease.backOut);
  972. this._tweentimeLite.addToTween(this, { scaleX: this.scaleX, scaleY: this.scaleX }, 600, Laya.Ease.backIn);
  973. }
  974. getRes(name) {
  975. return core.Manager.commonResPath + "gameIcon/" + name + ".png"; //指定取资源图片
  976. }
  977. onEnable() {
  978. super.onEnable();
  979. this.timerLoop(5000, this, this.changeSkin);
  980. this.changeSkin();
  981. this._tweentimeLite.start();
  982. this.on(Laya.Event.CLICK, this, this.onClick);
  983. this._icon.on(Laya.Event.LOADED, this, this.iconLoaded);
  984. }
  985. changeSkin() {
  986. if (this._index >= this._iconUrls.length)
  987. this._index = 0;
  988. this._icon.skin = this._iconUrls[this._index];
  989. this._index++;
  990. }
  991. iconLoaded() {
  992. this._icon.size(this.ICON_SIZE, this.ICON_SIZE); //每个图片大小可能不一样,加载完成重新设置一下
  993. }
  994. onClick(e) {
  995. // // // 监听弹窗关闭
  996. // // tt.onMoreGamesModalClose(function (res) {
  997. // // log("modal closed", res);
  998. // // });
  999. // // // 监听小游戏盒子跳转
  1000. // // tt.onNavigateToMiniGameBox(function (res) {
  1001. // // log(res.errCode);
  1002. // // log(res.errMsg);
  1003. // // });
  1004. // const systemInfo = tt.getSystemInfoSync();
  1005. // // iOS 不支持,建议先检测再使用
  1006. // if (systemInfo.platform !== "ios") {
  1007. // // 打开小游戏盒子
  1008. // tt.showMoreGamesModal({
  1009. // appLaunchOptions: this._appLaunchOptions,
  1010. // // success(res) { log("success", res.errMsg); },
  1011. // // fail(res) { log("fail", res.errMsg); },
  1012. // });
  1013. // }
  1014. }
  1015. onDisable() {
  1016. super.onDisable();
  1017. this.clearTimer(this, this.changeSkin);
  1018. this._tweentimeLite.pause();
  1019. this.off(Laya.Event.CLICK, this, this.onClick);
  1020. this._icon.off(Laya.Event.LOADED, this, this.iconLoaded);
  1021. }
  1022. destroy() {
  1023. super.destroy();
  1024. this._tweentimeLite.destroy();
  1025. this._tweentimeLite = null;
  1026. this._appLaunchOptions = null;
  1027. this._iconUrls = null;
  1028. }
  1029. }
  1030. webGame.MoreGameIcon = MoreGameIcon;
  1031. })(webGame || (webGame = {}));
  1032. //# sourceMappingURL=webGame.js.map