gameManager.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. import { _decorator, AudioClip, AudioSource, Component, Node, Size, Sprite, SpriteFrame, sys, UITransform, Vec3 } from 'cc';
  2. import { game_run } from './game_run';
  3. import { attributes_data, LevelItemData, other_widget_finish_listen_item, scene_item_data, sysMessage, task_data, ui_att_item, UserData, UserUnlockLevesData, widget_item_data } from '../../data/data';
  4. import { config } from '../config';
  5. import { sceneManager } from './sceneManager';
  6. import { http } from '../http';
  7. import { tools } from '../tools';
  8. import { taskServce } from './TaskSchedule/taskServce';
  9. import { ClientEvent } from '../clientEvent';
  10. import { sysSound } from './sysSound';
  11. import { SdkUtil } from '../sdkUtil';
  12. import { statisticsManager } from '../statisticsManager';
  13. import { fail } from './ui/fail';
  14. const { ccclass, property } = _decorator;
  15. @ccclass('gameManager')
  16. export class gameManager extends Component {
  17. private mGameRun:game_run = null;
  18. private mGameData:scene_item_data[] = [];
  19. private mCurSceneIndex:number =0; //当前第几个场景
  20. public static Singleton:gameManager = null;
  21. private static g_userData:UserData;
  22. private static g_userUnlockLevesData:UserUnlockLevesData;
  23. public static res_map:Map<string,SpriteFrame> = new Map()
  24. public static mp3_cache:Map<string,AudioClip> = new Map()
  25. private mLevelData:LevelItemData = null;
  26. private static sys_data:sysMessage = null;
  27. private static isLoadingStatus:boolean = false;
  28. public static lookVideoAdsNumber:number = 0;
  29. public static isTestUser:boolean = false;
  30. @property(sceneManager) mSceneManager:sceneManager = null;
  31. @property(sysSound) mSysSound:sysSound = null;
  32. protected start(): void {
  33. gameManager.Singleton = this;
  34. }
  35. public static isFreeAds():boolean {
  36. // return false
  37. if(sys.platform==sys.Platform.MOBILE_BROWSER) {
  38. return true
  39. }
  40. if(gameManager.isTestUser) {
  41. return true
  42. }
  43. return false
  44. }
  45. public static is24Free():boolean{
  46. if(gameManager.getStaticUserData().freeTime==undefined){
  47. gameManager.getStaticUserData().freeTime = 0;
  48. gameManager.saveUserData()
  49. }
  50. if(gameManager.getStaticUserData().freeTime!=0){
  51. let cur_time = new Date()
  52. let old_time = new Date(gameManager.getStaticUserData().freeTime)
  53. let timeDiff = cur_time.getTime() - old_time.getTime();
  54. // console.log("old",tools.getLocalTime(old))
  55. // console.log("cur",tools.getLocalTime(cur))
  56. var seconds = Math.floor(timeDiff / 1000);
  57. var minutes = Math.floor(seconds / 60);
  58. // var hours = Math.floor(minutes / 60);
  59. console.log("相隔几分钟",minutes)
  60. if(minutes>=1440){
  61. gameManager.getStaticUserData().freeTime = 0;
  62. gameManager.saveUserData()
  63. return false;
  64. }else{
  65. return true;
  66. }
  67. }
  68. return false;
  69. }
  70. public static setUser24Free(){
  71. gameManager.g_userData.freeTime = new Date().getTime()
  72. gameManager.saveUserData()
  73. }
  74. public static loadSceneRes(level_id:number,scene_num:number,cb){
  75. if(scene_num<1){
  76. return
  77. }
  78. gameManager.isLoadingStatus = true;
  79. let scene_count = 0;
  80. let start_loading_all_res =()=>{
  81. let count = 0;
  82. let num = 0;
  83. let load_call = ()=>{
  84. count++;
  85. // console.log("count",count,num,scene_count,scene_num)
  86. if(scene_count==scene_num){
  87. if(count>=num){
  88. gameManager.isLoadingStatus = false;
  89. console.log("完成全部加载!")
  90. }
  91. }
  92. }
  93. if(scene_num<=2){
  94. gameManager.isLoadingStatus = false;
  95. console.log("完成全部加载!")
  96. return
  97. }
  98. for (let i = 2; i <= scene_num; i++) {
  99. let url = http.get_level_resource(level_id,i)
  100. http.run_get_static(url,(err,data)=>{
  101. if(!err){
  102. let _data = JSON.parse(data)
  103. scene_count++;
  104. num += _data.content.length;
  105. if(scene_count==scene_num){
  106. if(num==0){
  107. gameManager.isLoadingStatus = false;
  108. console.log("完成全部加载!")
  109. return
  110. }else{
  111. if(count>=num){
  112. gameManager.isLoadingStatus = false;
  113. console.log("完成全部加载!")
  114. return
  115. }
  116. }
  117. }
  118. // console.log("run_get:",scene_count,_data.content.length,i)
  119. for (let index = 0; index < _data.content.length; index++) {
  120. const url:string = _data.content[index];
  121. load_res(url,load_call)
  122. }
  123. }else{
  124. tools.showToast(`获取关卡错误${err}`)
  125. }
  126. })
  127. }
  128. }
  129. // console.log("scene_num",scene_num)
  130. let load_res = (url:string,call)=>{
  131. let hz = url.substring(url.length-3,url.length);
  132. if(hz==="png"||hz==="jpg"){
  133. tools.loadSceneImg(url,(d)=>{
  134. first_load_res.delete(url)
  135. gameManager.res_map.set(d.url,d.sf)
  136. call()
  137. })
  138. }
  139. if(hz==="mp3"){
  140. tools.loadSceneMp3(url,(d)=>{
  141. first_load_res.delete(url)
  142. gameManager.mp3_cache.set(d.url,d.clip)
  143. call()
  144. })
  145. }
  146. }
  147. let first_finish_call = ()=>{
  148. first_load_res.forEach((v,k)=>{
  149. const url:string =k;
  150. load_res(url,()=>{
  151. if(first_load_res.size<=0){
  152. cb()
  153. start_loading_all_res()
  154. }
  155. })
  156. })
  157. }
  158. let first_count = 0;
  159. let first_load_res:Map<string,boolean> = new Map;
  160. for (let i = 0; i < 2; i++) {
  161. let url = http.get_level_resource(level_id,i)
  162. http.run_get_static(url,(err,data)=>{
  163. if(!err){
  164. let _data = JSON.parse(data)
  165. first_count++;
  166. for (let index = 0; index < _data.content.length; index++) {
  167. const url:string = _data.content[index];
  168. first_load_res.set(url,false)
  169. }
  170. if(first_count==2){
  171. scene_count=1;
  172. first_finish_call()
  173. }
  174. }
  175. })
  176. }
  177. }
  178. public setLevelData(data:LevelItemData){
  179. this.mLevelData = data;
  180. }
  181. public getLevelData(){
  182. return this.mLevelData;
  183. }
  184. public static setSysData(data:sysMessage){
  185. gameManager.sys_data = data;
  186. }
  187. public static getSysData(){
  188. return gameManager.sys_data;
  189. }
  190. public static loadSceneMp3(){
  191. }
  192. public static getUserData():UserData{
  193. let str = sys.localStorage.getItem(config.USER_DATA)
  194. if(str==undefined||str==""||str==null){
  195. return null;
  196. }
  197. let user:UserData = JSON.parse(str)
  198. return user;
  199. }
  200. public static getStaticUserData(){
  201. return gameManager.g_userData
  202. }
  203. public static setUserData(user:UserData){
  204. gameManager.g_userData = user;
  205. gameManager.saveUserData()
  206. }
  207. public static saveUserData(){
  208. if(gameManager.g_userData!=null){
  209. sys.localStorage.setItem(config.USER_DATA, JSON.stringify(gameManager.g_userData));
  210. }
  211. }
  212. public reLife(){
  213. let ad_id = SdkUtil.getAdId(config.AD_TYPE.RE_LIFE)
  214. SdkUtil.showVideoAd(ad_id,(res)=>{
  215. if(res.isEnded){
  216. this.mGameRun.onlaunch(()=>{
  217. gameManager.Singleton.startLevelGame()
  218. })
  219. }
  220. // 统计-激励视频广告
  221. let level_id = gameManager.Singleton.getLevelData().id
  222. let collect_data = statisticsManager.get_collect_data(level_id, res, config.STATISTICS_ACTION_TYPE.GUAN_KA_FU_HUO)
  223. statisticsManager.request_collect_rewardVideoData(collect_data)
  224. })
  225. }
  226. public reStartGame(){
  227. this.mGameRun.onlaunch(()=>{
  228. this.mCurSceneIndex = 0;
  229. gameManager.Singleton.startLevelGame()
  230. })
  231. }
  232. public levleIsUnLock(levle_id:number){
  233. let isunlock = false;
  234. for (let index = 0; index < gameManager.getStaticUserData().unlock_levels.length; index++) {
  235. const id = gameManager.getStaticUserData().unlock_levels[index];
  236. if(id==levle_id){
  237. isunlock = true;
  238. break;
  239. }
  240. }
  241. return isunlock
  242. }
  243. public unLockLevel(levle_id:number){
  244. let is_have = false;
  245. for (let index = 0; index < gameManager.getStaticUserData().unlock_levels.length; index++) {
  246. const id = gameManager.getStaticUserData().unlock_levels[index];
  247. if(id==levle_id){
  248. is_have = true;
  249. break;
  250. }
  251. }
  252. if(!is_have){
  253. gameManager.getStaticUserData().unlock_levels.push(levle_id)
  254. gameManager.saveUserData()
  255. gameManager.Singleton.sync_data()
  256. }
  257. }
  258. public sync_data(){
  259. let url = http.sync_data()
  260. let unlock_levels = gameManager.getStaticUserData().unlock_levels;
  261. http.run_post(url,{"unlock_levels":JSON.stringify(unlock_levels)},(err,data)=>{
  262. if(!err){
  263. }
  264. })
  265. }
  266. public nextScene(){
  267. this.onLaunch(()=>{
  268. this.mCurSceneIndex++;
  269. let not_scene = false;
  270. if(this.mCurSceneIndex>=this.mGameData.length){
  271. not_scene = true;
  272. }
  273. if(!not_scene){
  274. this.mGameRun.unInit()
  275. this.startLevelGame()
  276. }else{
  277. // tools.showToast("没有场景了!")
  278. }
  279. })
  280. }
  281. public gameOver(){
  282. ClientEvent.dispatchEvent(config.EventRun.ON_WIN)
  283. }
  284. public gotoGameLevel() {
  285. SdkUtil.ttStartScreenRecording()
  286. }
  287. public backGameList(){
  288. if(!gameManager.isLoadingStatus){
  289. this.unscheduleAllCallbacks()
  290. this.mGameRun.backGameList()
  291. gameManager.Singleton.mSceneManager.play_music()
  292. }else{
  293. console.log("没有全部加载完成!")
  294. }
  295. SdkUtil.ttStopScreenRecording(true)
  296. }
  297. public initEvent(){
  298. ClientEvent.offAll(config.EventRun.NOTICE_EVENT)
  299. ClientEvent.offAll(config.EventRun.WIDGET_FINISH)
  300. ClientEvent.offAll(config.EventRun.WIDGET_FAIL)
  301. ClientEvent.offAll(config.EventRun.ON_WIDGET_FINISH_COLLECT_EVENT)
  302. ClientEvent.offAll(config.EventRun.WIDGET_HIDE)
  303. ClientEvent.offAll(config.EventRun.SHOW_ZHAO_BU_TONG_FINISH_STATUS)
  304. ClientEvent.offAll(config.EventRun.TOP_VIEW_CLOSE)
  305. ClientEvent.offAll(config.EventRun.TOP_VIEW_FINISH)
  306. ClientEvent.offAll(config.EventRun.TOP_VIEW_FAIL)
  307. ClientEvent.offAll(config.EventRun.ON_COUNT_DOWN_FAIL)
  308. ClientEvent.offAll(config.EventRun.ON_COUNT_DOWN_START)
  309. ClientEvent.offAll(config.EventRun.ON_SHOW_RULE_BTN)
  310. ClientEvent.offAll(config.EventRun.ON_BOSS_HURT)
  311. ClientEvent.on(config.EventRun.WIDGET_FINISH,this.onWidgetFinishEvent.bind(this),this)
  312. ClientEvent.on(config.EventRun.WIDGET_FAIL,this.onWidgetFailEvent.bind(this),this)
  313. ClientEvent.on(config.EventRun.TOP_VIEW_CLOSE,this.onUiCloseEvent.bind(this),this)
  314. ClientEvent.on(config.EventRun.TOP_VIEW_FINISH,this.onUiFinishEvent.bind(this),this)
  315. ClientEvent.on(config.EventRun.TOP_VIEW_FAIL,this.onUiFailEvent.bind(this),this)
  316. ClientEvent.on(config.EventRun.ON_COUNT_DOWN_FAIL,this.onCountDownFailEvent.bind(this),this)
  317. ClientEvent.on(config.EventRun.ON_COUNT_DOWN_START,this.onStartCountDownEvent.bind(this),this)
  318. }
  319. public initGR(gr:game_run){
  320. this.mGameRun = gr;
  321. gameManager.Singleton = this;
  322. this.mSceneManager.init(this)
  323. this.clearRes()
  324. }
  325. public clearRes(){
  326. gameManager.res_map.clear()
  327. gameManager.mp3_cache.clear()
  328. }
  329. public init(gr:game_run,data:scene_item_data[]){
  330. // this.mGameRun = gr;
  331. // gameManager.Singleton = this;
  332. // this.mSceneManager.init(this)
  333. // this.mCurSceneIndex = main.Singleton.edit_scene_view.getCurSelectSceneIndex()
  334. // this.mGameData = data;
  335. // if( this.mGameData.length<=0){
  336. // return tools.showToast("错误的场景信息")
  337. // }
  338. // this.startLevelGame()
  339. }
  340. public runGame(data:scene_item_data[]){
  341. this.mCurSceneIndex = 0;
  342. this.mGameData = data;
  343. if( this.mGameData.length<=0){
  344. return tools.showToast("错误的场景信息")
  345. }
  346. this.startLevelGame()
  347. }
  348. public onLaunch(call){
  349. this.mGameRun.onlaunch(call)
  350. }
  351. FilterChildScene(data:scene_item_data[]){
  352. let temp_scene = []
  353. for (let index = 0; index < data.length; index++) {
  354. const element = data[index];
  355. if(!element.is_child_scene){
  356. temp_scene.push(element)
  357. }
  358. }
  359. return temp_scene;
  360. }
  361. protected onDestroy(): void {
  362. ClientEvent.off(config.EventRun.WIDGET_FINISH,this.onWidgetFinishEvent.bind(this),this)
  363. }
  364. public startLevelGame(){
  365. this.mGameRun.unInit()
  366. this.initEvent()
  367. // console.log("this.mGameData",this.mGameData,this.mCurSceneIndex)
  368. this.mSceneManager.startLevelGame(this.mGameData[this.mCurSceneIndex])
  369. taskServce.initTask(this.mGameData[this.mCurSceneIndex]._task_data)
  370. this.scheduleOnce(()=>{
  371. this.startGame()
  372. },0.5)
  373. if(gameManager.Singleton.getLevelData()){
  374. // this.mSceneManager.playMusic(this.mLevelData.piped_music,true)
  375. }
  376. }
  377. public loadScene(pages: scene_item_data[],type:number){
  378. this.mGameRun.loadSceneLayer(pages,type)
  379. }
  380. public loadUi(ui_widge_list:widget_item_data[]){
  381. this.mGameRun.loadUILayer(ui_widge_list)
  382. }
  383. public loadTextSound(ui_widge_list:widget_item_data[]){
  384. this.mGameRun.loadTextSound(ui_widge_list)
  385. }
  386. public loadQuestion(ui_widge_list:widget_item_data[]){
  387. this.mGameRun.initQuestionList(ui_widge_list)
  388. }
  389. public initCountDownList(ui_widge_list:widget_item_data[]){
  390. this.mGameRun.initCountDownList(ui_widge_list)
  391. }
  392. public initTaskUi(data:task_data){
  393. this.mGameRun.initTaskUi(data)
  394. }
  395. public startGame(){
  396. taskServce.startFirstEvent()
  397. }
  398. public showCheck(call){
  399. this.mGameRun.showCheck(call)
  400. }
  401. public showLoadingLevel(){
  402. this.mGameRun.showLoadingLevel()
  403. }
  404. public hideLoadingLevel(){
  405. this.mGameRun.hideLoadingLevel()
  406. }
  407. public showUnLockView(lock_one_call,lock_all_one_day){
  408. this.mGameRun.showUnLockView(lock_one_call,lock_all_one_day)
  409. }
  410. public static getWidgetList(scene_data:scene_item_data):widget_item_data[]{
  411. let temp:widget_item_data[] = []
  412. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  413. const data = scene_data.page_widget_list[index];
  414. if(data.type<=4 ){
  415. temp.push(data)
  416. }
  417. }
  418. return temp;
  419. }
  420. public static getUIWidgetList(scene_data:scene_item_data){
  421. let temp:widget_item_data[] = []
  422. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  423. const data = scene_data.page_widget_list[index];
  424. if(data.type===config.Widget_Type_List.UI_TOP){
  425. if(data.att.top_data!=null&&data.att.top_data.top_ui_type!=config.top_view_type.__null){
  426. temp.push(data)
  427. }
  428. }
  429. }
  430. return temp;
  431. }
  432. public isCurScenePageCheckWidgetFinish(widget_id:number){
  433. return this.mGameRun.isCurScenePageCheckWidgetFinish(widget_id);
  434. }
  435. public isCurScenePageCheckWidgetShow(widget_id:number){
  436. return this.mGameRun.isCurScenePageCheckWidgetShow(widget_id);
  437. }
  438. public static getQuestionwidgetList(scene_data:scene_item_data){
  439. let temp:widget_item_data[] = []
  440. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  441. const data = scene_data.page_widget_list[index];
  442. if(data.type===config.Widget_Type_List.QUESTION_SELECT){
  443. if(data.att.question_select!=null){
  444. temp.push(data)
  445. }
  446. }
  447. }
  448. return temp;
  449. }
  450. public static getTextSoundWidgetList(scene_data:scene_item_data){
  451. let temp:widget_item_data[] = []
  452. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  453. const data = scene_data.page_widget_list[index];
  454. if(data.type===config.Widget_Type_List.TEXT_SOUND){
  455. if(data.att.text_sound_data!=null){
  456. temp.push(data)
  457. }
  458. }
  459. }
  460. return temp;
  461. }
  462. public static getCountDownWidgetList(scene_data:scene_item_data){
  463. let temp:widget_item_data[] = []
  464. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  465. const data = scene_data.page_widget_list[index];
  466. if(data.type===config.Widget_Type_List.COUNT_DOWN){
  467. if(data.att.count_down!=null){
  468. temp.push(data)
  469. }
  470. }
  471. }
  472. return temp;
  473. }
  474. public static getCacheSpriteFrameByName(node:Node,sfName:string){
  475. let sf = gameManager.res_map.get(sfName)
  476. if(sf==null){
  477. if(node!=null){
  478. tools.loadUrl(sfName,node.getComponent(Sprite))
  479. }
  480. }
  481. return sf
  482. }
  483. public static getCacheSoundByName(sfName:string){
  484. // return control.mp3_cache.get(sfName)
  485. return gameManager.mp3_cache.get(sfName)
  486. }
  487. public static initUiBaseAtt(node:Node,att:ui_att_item){
  488. node.getComponent(UITransform).setContentSize(new Size(att.width,att.height))
  489. node.position = new Vec3(att.x,att.y);
  490. node.getComponent(Sprite).spriteFrame = gameManager.getCacheSpriteFrameByName(node,att.res)
  491. }
  492. onWidgetFinishEvent(widget_id:number){
  493. taskServce.onWidgetFinishEvent(widget_id)
  494. }
  495. onWidgetFailEvent(widget_id:number){
  496. taskServce.onWidgetFailEvent(widget_id)
  497. }
  498. onUiCloseEvent(event_id:number){
  499. taskServce.extEventByEventId(event_id)
  500. }
  501. onUiFinishEvent(event_id:number){
  502. taskServce.extEventByEventId(event_id)
  503. }
  504. onUiFailEvent(event_id:number){
  505. taskServce.extEventByEventId(event_id)
  506. }
  507. onCountDownFailEvent(event_id:number){
  508. taskServce.extEventByEventId(event_id)
  509. }
  510. onStartCountDownEvent(event_id:number){
  511. taskServce.extEventByEventId(event_id)
  512. }
  513. exeEvent(event_id:number){
  514. taskServce.extEventByEventId(event_id)
  515. }
  516. showFindRuleTips(){
  517. this.mGameRun.showFindRuleTips()
  518. }
  519. showTips(){
  520. this.mGameRun.showTips()
  521. }
  522. showRule(){
  523. this.mGameRun.showRule()
  524. }
  525. getSceneManager(){
  526. return this.mSceneManager;
  527. }
  528. IsOpenRuleStatus(){
  529. return taskServce.guo_ju_qing_binding_event_id==-1;
  530. }
  531. //点击按钮音效
  532. public sys_click_button_music(){
  533. if(gameManager.sys_data!=null){
  534. this.mSysSound.playSound(gameManager.sys_data.content.sys_click_button_music)
  535. }
  536. }
  537. // //失败吓人音效
  538. // public sys_fail_scary_music(){
  539. // if(gameManager.sys_data!=null){
  540. // this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_scary_music)
  541. // }
  542. // }
  543. //失败后攻击音效
  544. public sys_fail_attack_music(){
  545. if(gameManager.sys_data!=null){
  546. this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_attack_music)
  547. }
  548. }
  549. //失败提示音效
  550. public sys_fail_prompt_music(){
  551. if(gameManager.sys_data!=null){
  552. this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_prompt_music)
  553. }
  554. }
  555. //正确通关音效
  556. public sys_success_complete_music(){
  557. if(gameManager.sys_data!=null){
  558. this.mSysSound.playSound(gameManager.sys_data.content.sys_success_complete_music)
  559. }
  560. }
  561. //点击正确细节音效
  562. public sys_click_correct_detail_music(){
  563. if(gameManager.sys_data!=null){
  564. this.mSysSound.playSound(gameManager.sys_data.content.sys_click_correct_detail_music)
  565. }
  566. }
  567. public checkWidgetList(list:other_widget_finish_listen_item[]):number{
  568. let event_id = -1;
  569. for (let index = 0; index < list.length; index++) {
  570. const item = list[index];
  571. let isFinish = this.mGameRun.isCurScenePageCheckWidgetFinish(item.widget_id)
  572. if(!isFinish){
  573. event_id = item.event_id;
  574. break;
  575. }
  576. }
  577. return event_id;
  578. }
  579. public static getUserUnlockLevesData():UserUnlockLevesData{
  580. if(gameManager.g_userUnlockLevesData == null) {
  581. gameManager.g_userUnlockLevesData = new UserUnlockLevesData()
  582. }
  583. return gameManager.g_userUnlockLevesData;
  584. }
  585. public static setUserUnlockLevesData(data:any){
  586. if(gameManager.g_userUnlockLevesData == null) {
  587. gameManager.g_userUnlockLevesData = new UserUnlockLevesData()
  588. }
  589. if(data != null) {
  590. gameManager.g_userUnlockLevesData = data.content
  591. // console.log('g_userUnlockLevesData=',gameManager.g_userUnlockLevesData)
  592. }
  593. }
  594. public static request_user_unlock_number_status(status = config.User_unlock_levels_number_status.GET, success_callback:any, fail_callback:any) {
  595. if(status != config.User_unlock_levels_number_status.GET) {
  596. gameManager.Singleton.showLoadingLevel()
  597. }
  598. http.run_post(http.user_unlock_number_status(),{'stype':status}, (err,data)=> {
  599. // console.log('err=',err,'status=',status,'解锁次数=',data)
  600. if(status != config.User_unlock_levels_number_status.GET) {
  601. gameManager.Singleton.hideLoadingLevel()
  602. }
  603. if(!err) {
  604. let _data = JSON.parse(data)
  605. if(_data.code==config.MSG_CODE.SUCCESS){
  606. gameManager.setUserUnlockLevesData(_data)
  607. success_callback(_data)
  608. } else{
  609. fail_callback()
  610. }
  611. } else {
  612. fail_callback()
  613. }
  614. })
  615. }
  616. }