54a8b719-008d-4a30-9763-43908c251a9d.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. "use strict";
  2. cc._RF.push(module, '54a8bcZAI1KMJdjQ5CMJRqd', 'CocosZ');
  3. // scripts/Framework/CocosZ.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. exports.cocosz = void 0;
  26. var GameMgr_1 = require("./GameMgr");
  27. var DataMgr_1 = require("./DataMgr");
  28. var UIMgr_1 = require("./UIMgr");
  29. var ResMgr_1 = require("./ResMgr");
  30. var Constant_1 = require("./Constant");
  31. var SceneMgr_1 = require("./SceneMgr");
  32. var AudioMgr_1 = require("./AudioMgr");
  33. var Utils_1 = require("../../common-plugin/Scripts/Utils");
  34. var Msg_1 = require("./Msg");
  35. var PlatUtils_1 = require("../../common-plugin/Scripts/PlatUtils");
  36. var ATRewardedVideoJSSDK_1 = require("../AnyThinkAds/ATRewardedVideoJSSDK");
  37. var ATAndroidJS2_1 = require("../ATAndroidJS2");
  38. // @ts-ignore
  39. var i18n = require('LanguageData');
  40. /**
  41. * sp.Skeleton动画
  42. */
  43. if (CC_EDITOR) {
  44. // 重写update方法 达到在编辑模式下 自动播放动画的功能
  45. sp.Skeleton.prototype['lateUpdate'] = function (dt) {
  46. if (CC_EDITOR) {
  47. cc['engine']._animatingInEditMode = 1;
  48. cc['engine'].animatingInEditMode = 1;
  49. }
  50. if (this.paused)
  51. return;
  52. dt *= this.timeScale * sp['timeScale'];
  53. if (this.isAnimationCached()) {
  54. // Cache mode and has animation queue.
  55. if (this._isAniComplete) {
  56. if (this._animationQueue.length === 0 && !this._headAniInfo) {
  57. var frameCache = this._frameCache;
  58. if (frameCache && frameCache.isInvalid()) {
  59. frameCache.updateToFrame();
  60. var frames = frameCache.frames;
  61. this._curFrame = frames[frames.length - 1];
  62. }
  63. return;
  64. }
  65. if (!this._headAniInfo) {
  66. this._headAniInfo = this._animationQueue.shift();
  67. }
  68. this._accTime += dt;
  69. if (this._accTime > this._headAniInfo.delay) {
  70. var aniInfo = this._headAniInfo;
  71. this._headAniInfo = null;
  72. this.setAnimation(0, aniInfo.animationName, aniInfo.loop);
  73. }
  74. return;
  75. }
  76. this._updateCache(dt);
  77. }
  78. else {
  79. this._updateRealtime(dt);
  80. }
  81. };
  82. }
  83. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  84. var Languages;
  85. (function (Languages) {
  86. Languages[Languages["zh"] = 0] = "zh";
  87. Languages[Languages["en"] = 1] = "en";
  88. })(Languages || (Languages = {}));
  89. exports.cocosz = null;
  90. var CocosZ = /** @class */ (function (_super) {
  91. __extends(CocosZ, _super);
  92. function CocosZ() {
  93. var _this = _super !== null && _super.apply(this, arguments) || this;
  94. _this._gameMgr = null;
  95. _this._dataMgr = null;
  96. _this._uiMgr = null;
  97. _this._resMgr = null;
  98. _this._audioMgr = null;
  99. _this._sceneMgr = null;
  100. _this.btnDebug = false; //zh:diy default false;
  101. _this._languagesArr = ["zh", "en"];
  102. _this.curLanguage = "zh";
  103. _this._curLang = Languages.zh;
  104. _this.audioList = [];
  105. _this._useCJTimes = 0;
  106. _this._totalCJTimes = 0;
  107. _this.curLevel = 0;
  108. /** 暂停计数 */
  109. _this._pauseCount = 0;
  110. /** 最大分享数量 */
  111. _this.serverConfig_shareMaxNum = 0;
  112. /** 是否启用调试 zh:diy default false */
  113. _this.isDeBug = false;
  114. /** 是否显示视频按钮 */
  115. _this.isADON = true;
  116. /** 游戏模式 */
  117. _this.gameMode = 6;
  118. _this._dtBack = 1 / 60;
  119. _this.isOk = false;
  120. _this.bundleConfig = {
  121. "ui/UILoadingPage": "bundleLoad"
  122. };
  123. _this.serverConfig = {
  124. ////////////////// 分享 ///////////////////
  125. // 分享最大次数(平台不能分享不要配置)
  126. "shareMaxNum": 5,
  127. // 分享成功的时间(秒)
  128. "shareTime": 2,
  129. ////////////////// 视频 ///////////////////
  130. // 视频点_游戏界面_高级武器(默认显示)
  131. "isVideoAd_advanced_weapon": "true",
  132. // 视频点_游戏界面_全屏轰炸(默认显示)
  133. "isVideoAd_Qpbz": "true",
  134. // 视频点_游戏界面_磁铁(默认显示)
  135. "isVideoAd_Citie": "true",
  136. // 视频点_游戏界面_隐藏banner(默认隐藏)
  137. "isVideoAd_hideBanner": "true",
  138. // 视频点_技能弹窗_视频解锁数量(默认0)
  139. "skillLockNum": 2,
  140. ////////////////// banner ///////////////////
  141. // 是否显示游戏界面banner(默认显示)
  142. "isBanner_game": true,
  143. ////////////////// 插屏 ///////////////////
  144. // 首页
  145. "isInterstitial_UIHomePage": "true",
  146. // 签到
  147. "isInterstitial_UISignPanel": "true",
  148. // 转盘
  149. "isInterstitial_UITurntablePanel": "true",
  150. // 在线奖励
  151. "isInterstitial_UITimePanel": "true",
  152. // 游戏
  153. "isInterstitial_UIGamePage": "true",
  154. // 复活
  155. "isInterstitial_UIRevivePanel": "true",
  156. // 暂停
  157. "isInterstitial_UIPausePanel": "true",
  158. // 技能
  159. "isInterstitial_UIUpgradePanel": "true",
  160. // 皮肤试用间隔(组件自带)
  161. "try_skin_level_count": 1,
  162. // 皮肤试用插屏间隔(组件自带)
  163. "try_skin_show_ad_interval": 1,
  164. };
  165. // 分享所需的时间(单位/秒)
  166. _this.serverConfig_shareTime = 2;
  167. return _this;
  168. }
  169. Object.defineProperty(CocosZ.prototype, "gameMgr", {
  170. get: function () {
  171. return this._gameMgr;
  172. },
  173. enumerable: false,
  174. configurable: true
  175. });
  176. Object.defineProperty(CocosZ.prototype, "dataMgr", {
  177. get: function () {
  178. return this._dataMgr;
  179. },
  180. enumerable: false,
  181. configurable: true
  182. });
  183. Object.defineProperty(CocosZ.prototype, "uiMgr", {
  184. get: function () {
  185. return this._uiMgr;
  186. },
  187. enumerable: false,
  188. configurable: true
  189. });
  190. Object.defineProperty(CocosZ.prototype, "resMgr", {
  191. get: function () {
  192. return this._resMgr;
  193. },
  194. enumerable: false,
  195. configurable: true
  196. });
  197. Object.defineProperty(CocosZ.prototype, "audioMgr", {
  198. get: function () {
  199. return this._audioMgr;
  200. },
  201. enumerable: false,
  202. configurable: true
  203. });
  204. Object.defineProperty(CocosZ.prototype, "sceneMgr", {
  205. get: function () {
  206. return this._sceneMgr;
  207. },
  208. enumerable: false,
  209. configurable: true
  210. });
  211. Object.defineProperty(CocosZ.prototype, "curLang", {
  212. get: function () { return this._curLang; },
  213. set: function (v) {
  214. this._curLang = v;
  215. this.curLanguage = this._languagesArr[v];
  216. cc.log("当前语言: ", this.curLanguage);
  217. },
  218. enumerable: false,
  219. configurable: true
  220. });
  221. Object.defineProperty(CocosZ.prototype, "useCJTimes", {
  222. get: function () {
  223. return this._useCJTimes;
  224. },
  225. set: function (num) {
  226. this._useCJTimes = num;
  227. localStorage.setItem(Constant_1.default.ST_GameData + "useCJTimes_dmm", this._useCJTimes.toString());
  228. },
  229. enumerable: false,
  230. configurable: true
  231. });
  232. Object.defineProperty(CocosZ.prototype, "totalCJTimes", {
  233. get: function () {
  234. return this._totalCJTimes;
  235. },
  236. set: function (num) {
  237. this._totalCJTimes = num;
  238. localStorage.setItem(Constant_1.default.ST_GameData + "totalCJTimes_dmm", this._totalCJTimes.toString());
  239. },
  240. enumerable: false,
  241. configurable: true
  242. });
  243. /** 事件上报的关卡id */
  244. CocosZ.prototype.getLevelId = function (id) {
  245. return exports.cocosz.dataMgr.TotoalCount_6;
  246. };
  247. Object.defineProperty(CocosZ.prototype, "pauseCount", {
  248. get: function () {
  249. return this._pauseCount;
  250. },
  251. set: function (v) {
  252. if (v < 0) {
  253. v = 0;
  254. }
  255. this._pauseCount = v;
  256. cc.log("pauseCount:", this._pauseCount);
  257. },
  258. enumerable: false,
  259. configurable: true
  260. });
  261. Object.defineProperty(CocosZ.prototype, "isPause", {
  262. get: function () {
  263. return (this.pauseCount > 0);
  264. },
  265. set: function (v) { },
  266. enumerable: false,
  267. configurable: true
  268. });
  269. Object.defineProperty(CocosZ.prototype, "canShare", {
  270. /** 能否显示分享 */
  271. get: function () {
  272. var r = false;
  273. if ((CC_DEBUG && this.isDeBug) || PlatUtils_1.default.IsWechat) {
  274. if (exports.cocosz.dataMgr.shareNum < exports.cocosz.serverConfig_shareMaxNum) {
  275. r = true;
  276. }
  277. }
  278. return r;
  279. },
  280. enumerable: false,
  281. configurable: true
  282. });
  283. CocosZ.prototype.onLoad = function () {
  284. var _this = this;
  285. exports.cocosz = this;
  286. this._gameMgr = GameMgr_1.default.inst;
  287. this._dataMgr = DataMgr_1.default.inst;
  288. this._resMgr = ResMgr_1.default.inst;
  289. this._uiMgr = UIMgr_1.default.inst;
  290. this._audioMgr = AudioMgr_1.default.inst;
  291. this._sceneMgr = SceneMgr_1.default.inst;
  292. // 常驻节点
  293. cc.game.addPersistRootNode(this.node);
  294. ////////////////////////////// 初始化语言 //////////////////////////////
  295. if (cc.sys.languageCode) {
  296. if (cc.sys.languageCode.toLowerCase().indexOf("zh") > -1) {
  297. this.curLanguage = 'zh';
  298. }
  299. else {
  300. this.curLanguage = 'en';
  301. }
  302. }
  303. this.curLanguage = 'en'; //zh:diy
  304. i18n.init(this.curLanguage);
  305. ////////////////////////////// 测试模式 //////////////////////////////
  306. this.isDeBug = this.btnDebug;
  307. console.log('zh:is debug =' + this.btnDebug);
  308. ////////////////////////////// 服务器配置 //////////////////////////////
  309. this._initConfigKey();
  310. ////////////////////////////// 游戏配置 //////////////////////////////
  311. cc.director.getCollisionManager().enabled = true;
  312. // cc.director.getCollisionManager().enabledDebugDraw = true;
  313. var manager = cc.director.getPhysicsManager();
  314. manager.enabled = true;
  315. manager.gravity = cc.v2();
  316. // manager.debugDrawFlags = 1;
  317. // cc.game.setFrameRate(30);
  318. //保持微信屏幕长亮不熄屏
  319. if (PlatUtils_1.default.IsWechat) {
  320. //@ts-ignore
  321. wx.setKeepScreenOn({ keepScreenOn: true });
  322. }
  323. else if (PlatUtils_1.default.IsOPPO) {
  324. //@ts-ignore
  325. qg.setKeepScreenOn({
  326. keepScreenOn: true,
  327. success: function (res) { },
  328. fail: function (res) { },
  329. complete: function (res) { }
  330. });
  331. }
  332. else if (PlatUtils_1.default.IsVIVO) {
  333. //@ts-ignore
  334. qg.setKeepScreenOn({
  335. keepScreenOn: true,
  336. success: function () { console.log('handling success'); },
  337. fail: function (data, code) { console.log("handling fail, code = " + code); }
  338. });
  339. }
  340. ////////////////////////////// 加载bundle //////////////////////////////
  341. cc.assetManager.loadBundle("bundleLoad", null, function (err, bundle) {
  342. if (!err) {
  343. _this._initLoadingPage();
  344. }
  345. else {
  346. cc.log("加载分包bundleLoad出错");
  347. }
  348. });
  349. };
  350. CocosZ.prototype.initAdForPage = function () {
  351. if (cc.sys.os === cc.sys.OS_ANDROID) {
  352. var deviceId = ATAndroidJS2_1.default.getDeviceUserId();
  353. console.log("zh:checkstatus:", ATRewardedVideoJSSDK_1.default.checkAdStatus(ATAndroidJS2_1.default.getPlacementId()));
  354. var setting = {};
  355. setting[ATRewardedVideoJSSDK_1.default.userIdKey] = deviceId;
  356. ATRewardedVideoJSSDK_1.default.loadRewardedVideo(ATAndroidJS2_1.default.getPlacementId(), setting);
  357. }
  358. };
  359. CocosZ.prototype.update = function (dt) {
  360. var manager = cc.director.getPhysicsManager();
  361. manager.enabledAccumulator = true;
  362. // @ts-ignore
  363. manager.FIXED_TIME_STEP = cc.misc.lerp(this._dtBack, dt, 0.01);
  364. this._dtBack = dt;
  365. };
  366. CocosZ.prototype._initLoadingPage = function () {
  367. var _this = this;
  368. var url = "ui/UILoadingPage";
  369. this.resMgr.loadAndCacheRes(url, cc.Prefab, null, function () {
  370. _this._uiMgr.openPage(Constant_1.PageName.UILoadingPage);
  371. /** 登录认证 */
  372. Utils_1.utils.login(function () {
  373. ////////////////////////////// 缓存初始化 //////////////////////////////
  374. _this._initCache();
  375. ////////////////////////////// 加载bundleRes ///////////////////////////
  376. _this._loadBundleRes();
  377. ////////////////////////////// 华为隐私->插屏 ///////////////////////////
  378. if (PlatUtils_1.default.IsHuaWei) {
  379. Utils_1.utils.showYzRealNameAuthPanel();
  380. Utils_1.utils.showPrivacyPanel();
  381. _this.scheduleOnce(function () {
  382. Utils_1.utils.registerServerInitEvent(function () {
  383. Utils_1.utils.adManager.showNativeSplashView(function () { _this.isOk = true; });
  384. }, _this);
  385. }, 3);
  386. }
  387. else {
  388. _this.isOk = true;
  389. }
  390. });
  391. });
  392. };
  393. CocosZ.prototype._loadBundleRes = function () {
  394. var _this = this;
  395. cc.assetManager.loadBundle("bundleRes", function (err, bundle) {
  396. if (!err) {
  397. // 初始化bundle配置
  398. _this._initBundleConfig();
  399. // 加载资源
  400. _this._loadRes();
  401. }
  402. else {
  403. cc.log("zh:加载分包bundleRes出错");
  404. }
  405. });
  406. };
  407. CocosZ.prototype._loadRes = function () {
  408. var _this = this;
  409. var totalCount = 0;
  410. var compCount = 0;
  411. // UI
  412. var mess1 = [];
  413. exports.cocosz.getDirWithPath("UI/", cc.Prefab, mess1);
  414. exports.cocosz.resMgr.loadAndCacheResArray(mess1, cc.Prefab, null, function () { compCount++; });
  415. // 图片_name
  416. var mess2 = [];
  417. exports.cocosz.getDirWithPath("i18n/tex_name/" + exports.cocosz.curLanguage, cc.SpriteAtlas, mess2);
  418. exports.cocosz.resMgr.loadAndCacheResArray(mess2, cc.SpriteAtlas, null, function () { compCount++; });
  419. // 图片_icon
  420. var mess3 = [];
  421. exports.cocosz.getDirWithPath("tex_common", cc.SpriteAtlas, mess3);
  422. exports.cocosz.resMgr.loadAndCacheResArray(mess3, cc.SpriteAtlas, null, function () { compCount++; });
  423. // 头像
  424. var mess4 = [];
  425. exports.cocosz.getDirWithPath("prefab_heads", cc.Prefab, mess4);
  426. exports.cocosz.resMgr.loadAndCacheResArray(mess4, cc.Prefab, null, function () { compCount++; });
  427. // 武器
  428. var mess5 = [];
  429. exports.cocosz.getDirWithPath("prefab_weapon", cc.Prefab, mess5);
  430. exports.cocosz.resMgr.loadAndCacheResArray(mess5, cc.Prefab, null, function () { compCount++; });
  431. // 皮肤
  432. var mess6 = [];
  433. exports.cocosz.getDirWithPath("prefab_skin", cc.Prefab, mess6);
  434. exports.cocosz.resMgr.loadAndCacheResArray(mess6, cc.Prefab, null, function () { compCount++; });
  435. // 音效
  436. var mess7 = [];
  437. exports.cocosz.getDirWithPath("audio_common", cc.AudioClip, mess7);
  438. exports.cocosz.resMgr.loadAndCacheResArray(mess7, cc.AudioClip, null, function () { compCount++; });
  439. // 总资源数量
  440. totalCount = mess1.length + mess2.length + mess3.length + mess4.length + mess5.length + mess6.length + mess7.length;
  441. // 挂载音效
  442. this.resMgr.cacheCocoszAudio();
  443. var percent = 0;
  444. this.schedule(function () {
  445. percent = compCount / totalCount;
  446. cc.game.emit(Constant_1.default.E_GAME_LOGIC, { type: Constant_1.default.E_UPDATE_PROGRESS, data: percent });
  447. if (compCount >= totalCount && _this.isOk) {
  448. _this.unscheduleAllCallbacks();
  449. // 计时插屏
  450. Utils_1.utils.registerServerInitEvent(function () {
  451. var t = exports.cocosz.getConfigByKey("interval_time_show_cp");
  452. if (Number.isInteger(t) && t > 0) {
  453. _this.schedule(function () { Utils_1.utils.adManager.ShowInterstitial(); }, t);
  454. }
  455. }, _this);
  456. // 开始在线计时
  457. setInterval(function () { exports.cocosz.dataMgr.OnlineToday++; }, 1000);
  458. // 跳转首页
  459. _this._sceneMgr.loadScene("Home", function () {
  460. _this._uiMgr.openPage(Constant_1.PageName.UIHomePage);
  461. });
  462. }
  463. }, 0);
  464. };
  465. CocosZ.prototype._initBundleConfig = function () {
  466. var arr = ["resources", "bundleRes", "bundleLoad"];
  467. for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
  468. var bundleKey = arr_1[_i];
  469. var bundle = cc.assetManager.bundles.get(bundleKey);
  470. if (bundle) {
  471. var info = bundle["_config"]["paths"]["_map"];
  472. if (info) {
  473. for (var key in info) {
  474. this.bundleConfig[key] = bundleKey;
  475. }
  476. }
  477. }
  478. }
  479. // cc.log("bundleConfig:", JSON.stringify(this.bundleConfig))
  480. };
  481. CocosZ.prototype.getBundleWithPath = function (path) {
  482. if (this.bundleConfig[path]) {
  483. return cc.assetManager.bundles.get(this.bundleConfig[path]);
  484. }
  485. else {
  486. for (var key in this.bundleConfig) {
  487. if (key[0] === path[0]) {
  488. if (key.includes(path, 0)) {
  489. return cc.assetManager.bundles.get(this.bundleConfig[key]);
  490. }
  491. }
  492. }
  493. }
  494. cc.log("查找budle失败:", path);
  495. return null;
  496. };
  497. CocosZ.prototype.getDirWithPath = function (path, type, out) {
  498. var bundle = this.getBundleWithPath(path);
  499. if (bundle) {
  500. return bundle.getDirWithPath(path, type, out);
  501. }
  502. else {
  503. return null;
  504. }
  505. };
  506. CocosZ.prototype.getConfigByKey = function (key) {
  507. if (CC_DEBUG && exports.cocosz.isDeBug) {
  508. return this.serverConfig ? this.serverConfig[key] : null;
  509. }
  510. else {
  511. return Utils_1.utils.getConfigByKey(key);
  512. }
  513. };
  514. CocosZ.prototype._initConfigKey = function () {
  515. var callback = function () {
  516. // 0 测试模式
  517. if (exports.cocosz.getConfigByKey("game_debug") == "true") {
  518. exports.cocosz.isDeBug = true;
  519. }
  520. // 1 分享最大数量
  521. var shareMaxNum = exports.cocosz.getConfigByKey("shareMaxNum");
  522. if (Number.isInteger(shareMaxNum) && shareMaxNum >= 0) {
  523. exports.cocosz.serverConfig_shareMaxNum = shareMaxNum;
  524. }
  525. // 2 分享所需的时间
  526. var shareTime = exports.cocosz.getConfigByKey("shareTime");
  527. if (Number.isInteger(shareTime) && shareTime >= 0) {
  528. exports.cocosz.serverConfig_shareTime = shareTime;
  529. }
  530. };
  531. if (CC_DEBUG && this.isDeBug) {
  532. callback && callback();
  533. }
  534. else {
  535. // 注册服务器回调
  536. Utils_1.utils.registerServerInitEvent(callback, this);
  537. }
  538. };
  539. CocosZ.prototype._initCache = function () {
  540. // 缓存
  541. exports.cocosz.dataMgr && exports.cocosz.dataMgr.init();
  542. if (exports.cocosz.dataMgr.LastLoadDate != (new Date()).toDateString()) {
  543. exports.cocosz.dataMgr.LastLoadDate = (new Date()).toDateString();
  544. exports.cocosz.dataMgr.shareNum = 0;
  545. }
  546. if (localStorage.getItem(Constant_1.default.ST_GameData + "totalCJTimes_dmm")) {
  547. this._totalCJTimes = Number(localStorage.getItem(Constant_1.default.ST_GameData + "totalCJTimes_dmm"));
  548. }
  549. if (localStorage.getItem(Constant_1.default.ST_GameData + "useCJTimes_dmm")) {
  550. this._useCJTimes = Number(localStorage.getItem(Constant_1.default.ST_GameData + "useCJTimes_dmm"));
  551. }
  552. if (new Date().toDateString() != exports.cocosz.dataMgr.LastLoadDate) {
  553. this.useCJTimes = 0;
  554. exports.cocosz.dataMgr.OnlineToday = 0;
  555. exports.cocosz.dataMgr.receiveToday = [0, 0, 0, 0, 0];
  556. exports.cocosz.dataMgr.LastLoadDate = new Date().toDateString();
  557. }
  558. };
  559. Object.defineProperty(CocosZ.prototype, "isShowAd", {
  560. /** 是否显示广告 */
  561. get: function () {
  562. return true;
  563. },
  564. enumerable: false,
  565. configurable: true
  566. });
  567. Object.defineProperty(CocosZ.prototype, "isShowGameBanner", {
  568. /** 是否显示游戏banner */
  569. get: function () {
  570. if (exports.cocosz.getConfigByKey("gameBanner") == "false") {
  571. return false;
  572. }
  573. else {
  574. return true;
  575. }
  576. },
  577. enumerable: false,
  578. configurable: true
  579. });
  580. /** 秒转换时分秒 */
  581. CocosZ.prototype.StoHMS = function (s) {
  582. var m = 0; // 分
  583. var h = 0; // 小时
  584. if (s >= 60) {
  585. m = Math.floor(s / 60);
  586. s = Math.floor(s % 60);
  587. if (m > 60) {
  588. h = Math.floor(m / 60);
  589. m = Math.floor(m % 60);
  590. }
  591. }
  592. var r = "";
  593. r += (h == 0 ? "" : h + ":");
  594. r += (m >= 10 ? "" + m : "0" + m);
  595. r += (s >= 10 ? ":" + s : ":0" + s);
  596. return r;
  597. };
  598. /**
  599. * 看视频
  600. * @param callFun_S 播放成功时回调
  601. * @param callFun_F 播放失败时回调
  602. */
  603. CocosZ.prototype.watchAD = function (callFun_S, callFun_F) {
  604. if (callFun_S === void 0) { callFun_S = null; }
  605. if (callFun_F === void 0) { callFun_F = null; }
  606. if (callFun_S) {
  607. if (ATRewardedVideoJSSDK_1.default.hasAdReady(ATAndroidJS2_1.default.getPlacementId())) {
  608. console.log('zh:AD ready for idx2');
  609. ATRewardedVideoJSSDK_1.default.showAd(ATAndroidJS2_1.default.getPlacementId());
  610. console.log('zh: 开始回调1');
  611. callFun_S();
  612. }
  613. else {
  614. console.log('zh:AD not ready for idx2');
  615. console.log('zh: 开始回调2');
  616. callFun_S();
  617. }
  618. }
  619. else if (callFun_F) {
  620. callFun_F();
  621. }
  622. if (2 > 1) {
  623. return;
  624. }
  625. //下面是原先的代码
  626. if (this.isDeBug) {
  627. if (callFun_S) {
  628. callFun_S();
  629. }
  630. else if (callFun_F) {
  631. callFun_F();
  632. }
  633. return;
  634. }
  635. console.log('zh:AD 00000000000000000' + this.isDeBug);
  636. if (exports.cocosz.audioMgr.videoOn)
  637. return;
  638. exports.cocosz.audioMgr.videoOn = true;
  639. exports.cocosz.pauseCount++;
  640. exports.cocosz.audioMgr.stopAll();
  641. Utils_1.utils.adManager.ShowVideo(function (ret, msg) {
  642. exports.cocosz.audioMgr.videoOn = false;
  643. exports.cocosz.pauseCount--;
  644. exports.cocosz.audioMgr.playBgm();
  645. if (ret) {
  646. callFun_S && callFun_S();
  647. }
  648. else {
  649. callFun_F && callFun_F();
  650. msg = msg ? msg : i18n.t("msg.video_load_fail"); //视频加载失败
  651. Msg_1.default.Show(msg);
  652. }
  653. });
  654. };
  655. /**
  656. *
  657. * @param 分享成功回调
  658. * @param 分享失败回调
  659. */
  660. CocosZ.prototype.share = function (callFun_S, callFun_F) {
  661. var _this = this;
  662. if (callFun_S === void 0) { callFun_S = null; }
  663. if (callFun_F === void 0) { callFun_F = null; }
  664. if (this.isDeBug) {
  665. callFun_S && callFun_S();
  666. exports.cocosz.dataMgr.shareNum++;
  667. }
  668. else {
  669. var startTime_1 = (new Date()).getTime();
  670. Utils_1.utils.share(function () {
  671. if ((new Date()).getTime() - startTime_1 > (_this.serverConfig_shareTime * 1000)) {
  672. callFun_S && callFun_S();
  673. exports.cocosz.dataMgr.shareNum++;
  674. }
  675. else {
  676. callFun_F && callFun_F();
  677. Msg_1.default.Show("请分享至不同好友才可获得奖励哦");
  678. }
  679. });
  680. }
  681. };
  682. /**
  683. * 屏幕震动功能
  684. * @param type 震动类型 传递枚举:VibrateType
  685. */
  686. CocosZ.prototype.vibrate = function (type) {
  687. if (type === void 0) { type = "short"; }
  688. if (exports.cocosz.dataMgr.ShakeOn == false)
  689. return;
  690. if (type == "short") {
  691. ATAndroidJS2_1.default.appVibrateShort();
  692. }
  693. else {
  694. //@ts-ignore
  695. ATAndroidJS2_1.default.appVibrateLong();
  696. }
  697. if (2 > 1) {
  698. return;
  699. }
  700. if (PlatUtils_1.default.IsWechat) {
  701. if (type == "short") {
  702. //@ts-ignore
  703. //使手机发生较短时间的振动(15 ms)。仅在 iPhone 7 / 7 Plus 以上及 Android 机型生效
  704. wx.vibrateShort({ success: function (res) { }, fail: function (res) { } });
  705. }
  706. else {
  707. //@ts-ignore
  708. wx.vibrateLong({ success: function (res) { }, fail: function (res) { } }); //400 ms
  709. }
  710. }
  711. else if (PlatUtils_1.default.IsOPPO) {
  712. if (type == "short") {
  713. //@ts-ignore
  714. qg.vibrateShort({ success: function (res) { }, fail: function (res) { } }); //(20 ms)
  715. }
  716. else {
  717. //@ts-ignore
  718. qg.vibrateLong({ success: function (res) { }, fail: function (res) { } }); //400 ms
  719. }
  720. }
  721. else if (PlatUtils_1.default.IsVIVO) {
  722. if (type == "short") {
  723. //@ts-ignore
  724. qg.vibrateShort(); //(15 ms)
  725. }
  726. else {
  727. //@ts-ignore
  728. qg.vibrateLong(); //400 ms
  729. }
  730. }
  731. else if (PlatUtils_1.default.IsQQ) {
  732. if (type == "short") {
  733. //@ts-ignore
  734. //(15 ms),仅在 iPhone 7/7 Plus 以上及 Android 机型生效。
  735. qq.vibrateShort({ success: function (res) { }, fail: function (res) { } });
  736. }
  737. else {
  738. //@ts-ignore
  739. qq.vibrateLong({ success: function (res) { }, fail: function (res) { } }); //400 ms
  740. }
  741. }
  742. else if (PlatUtils_1.default.IsDouyin) {
  743. if (type == "short") {
  744. //@ts-ignore
  745. tt.vibrateShort({ success: function (res) { }, fail: function (res) { } });
  746. }
  747. else {
  748. //@ts-ignore
  749. tt.vibrateLong({ success: function (res) { }, fail: function (res) { } }); //400 ms
  750. }
  751. }
  752. else if (PlatUtils_1.default.IsBaidu) {
  753. if (type == "short") {
  754. //@ts-ignore
  755. //(15 ms),仅在 iPhone 7/7 Plus 以上及 Android 机型生效。
  756. swan.vibrateShort({ success: function (res) { }, fail: function (res) { } });
  757. }
  758. else {
  759. //@ts-ignore
  760. swan.vibrateLong({ success: function (res) { }, fail: function (res) { } }); //400 ms
  761. }
  762. }
  763. else if (PlatUtils_1.default.IsNativeAndroid) {
  764. if (type == "short") {
  765. //@ts-ignore
  766. jsb.reflection.callStaticMethod(Utils_1.utils.Tool_Native.jniClassName, "vibrateShort", "()V");
  767. }
  768. else {
  769. //@ts-ignore
  770. jsb.reflection.callStaticMethod(Utils_1.utils.Tool_Native.jniClassName, "vibrateLong", "()V");
  771. }
  772. }
  773. };
  774. __decorate([
  775. property()
  776. ], CocosZ.prototype, "btnDebug", void 0);
  777. __decorate([
  778. property({ visible: false })
  779. ], CocosZ.prototype, "curLanguage", void 0);
  780. __decorate([
  781. property({ visible: false })
  782. ], CocosZ.prototype, "_curLang", void 0);
  783. __decorate([
  784. property({ type: cc.Enum(Languages), displayName: "当前语言", tooltip: "zh(中文) en(英文)" })
  785. ], CocosZ.prototype, "curLang", null);
  786. __decorate([
  787. property({ type: cc.AudioClip })
  788. ], CocosZ.prototype, "audioList", void 0);
  789. CocosZ = __decorate([
  790. ccclass
  791. ], CocosZ);
  792. return CocosZ;
  793. }(cc.Component));
  794. exports.default = CocosZ;
  795. cc._RF.pop();