GlobalStorage.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import GameM from "../manager/GameM"
  2. import LogUtil from "../utils/LogUtil";
  3. import { Utils } from "../utils/Utils";
  4. import InvestData from "./InvestData";
  5. import TreasureData from "./TreasureData";
  6. import TurntableData from "./TurntableData";
  7. export default class GlobalStorage {
  8. private static instance: GlobalStorage = null
  9. static get Instance(): GlobalStorage {
  10. if (!this.instance) {
  11. this.instance = new GlobalStorage()
  12. }
  13. return this.instance
  14. }
  15. constructor() {
  16. //this.setStorage(STORAGE_KEY.airshipTimes, 0)
  17. }
  18. speedUpTimeValue: number = null; //加速时间
  19. init() {
  20. let key = 'dddddddddddddddddddddddddddddddd'
  21. let value = null
  22. value = this.getStorage(STORAGE_KEY.ranKey, 1)
  23. if (value != null) {
  24. GameM.commonData.ranKey = Utils.Decrypt(value, key, GameM.commonData.appid, true)
  25. }
  26. value = this.getStorage(STORAGE_KEY.tmp_uin, 1)
  27. if (value != null) {
  28. GameM.commonData.tmp_uin = Utils.Decrypt(value, key, GameM.commonData.appid, true)
  29. }
  30. // console.log('GameM.commonData.ranKey ', GameM.commonData.ranKey)
  31. // console.log('GameM.commonData.tmp_uin ', GameM.commonData.tmp_uin)
  32. value = this.getStorage(STORAGE_KEY.isAuth, 1)
  33. if (value != null) {
  34. GameM.commonData.isAuth = Utils.Decrypt(value, key, GameM.commonData.appid, true) == 'true'
  35. }
  36. value = this.getStorage(STORAGE_KEY.uin, 1)
  37. if (value != null) {
  38. GameM.commonData.uin = Utils.Decrypt(value, key, GameM.commonData.appid, true)
  39. }
  40. value = this.getStorage(STORAGE_KEY.login_ticket, 1)
  41. if (value != null) {
  42. GameM.commonData.login_ticket = Utils.Decrypt(value, key, GameM.commonData.appid, true)
  43. }
  44. value = this.getStorage(STORAGE_KEY.session_key, 1)
  45. if (value != null) {
  46. GameM.commonData.session_key = Utils.Decrypt(value, key, GameM.commonData.appid, true)
  47. }
  48. value = this.getStorage(STORAGE_KEY.nickname, 1)
  49. if (value != null) {
  50. GameM.commonData.nickname = value
  51. }
  52. value = this.getStorage(STORAGE_KEY.headimgurl, 1)
  53. if (value != null) {
  54. GameM.commonData.headimgurl = value
  55. LogUtil.logV('GameM.commonData.headimgurl ', GameM.commonData.headimgurl)
  56. }
  57. value = this.getStorage(STORAGE_KEY.joinDraw, 1)
  58. if (value != null) {
  59. //GameM.commonData.joinDraw = utils.Decrypt(value, key, GameM.commonData.appid, true)
  60. TreasureData.Instance.joinDraw = Utils.Decrypt(value, key, GameM.commonData.appid, true)
  61. }
  62. value = this.getStorage(STORAGE_KEY.videoCoolDown)
  63. if (value != null) {
  64. GameM.commonData.videoCoolDown = value
  65. }
  66. value = this.getStorage(STORAGE_KEY.todayVideoTimes)
  67. if (value != null) {
  68. GameM.commonData.todayVideoTimes = value
  69. }
  70. value = this.getStorage(STORAGE_KEY.todayFullInterTimes)
  71. if (value != null) {
  72. GameM.commonData.todayFullInterTimes = value
  73. }
  74. value = this.getStorage(STORAGE_KEY.taskGuide)
  75. if (value != null) {
  76. GameM.commonData.taskGuide = value
  77. }
  78. //西游
  79. value = this.getStorage(STORAGE_KEY.composeMaxRoleLv)
  80. if (value != null) {
  81. GameM.commonData.composeMaxRoleLv = value
  82. }
  83. }
  84. /** 存储数据
  85. * @param key 关键字
  86. * @param val 数值
  87. * @param type 类型 默认 0 number 1 string 2 json
  88. */
  89. setStorage(key: string, val: any, type: number = 0) {
  90. if (type == 0) {
  91. cc.sys.localStorage.setItem(key, val.toString())
  92. }
  93. else if (type == 1) {
  94. cc.sys.localStorage.setItem(key, val)
  95. }
  96. else if (type == 2) {
  97. cc.sys.localStorage.setItem(key, JSON.stringify(val))
  98. }
  99. }
  100. /** 获取存储数据
  101. * @param key 关键字
  102. * @param type 返回类型 默认 0 number 1 string 2 json
  103. */
  104. getStorage(key: string, type: number = 0) {
  105. let val = null
  106. if (cc.sys.localStorage.getItem(key) != null && cc.sys.localStorage.getItem(key) != undefined) {
  107. if (type == 0) {
  108. val = Number(cc.sys.localStorage.getItem(key))
  109. }
  110. else if (type == 1) {
  111. val = cc.sys.localStorage.getItem(key)
  112. }
  113. else if (type == 2) {
  114. val = JSON.parse(cc.sys.localStorage.getItem(key))
  115. }
  116. }
  117. return val
  118. }
  119. }
  120. export enum STORAGE_KEY {
  121. lastDate = 'lastDate',
  122. onLineTime = 'onLineTime',
  123. redMoney = 'redMoney',
  124. step = 'step',
  125. videoTimes = 'videoTimes',
  126. canSign = 'canSign',
  127. gold = 'gold',
  128. roleData = 'roleData',
  129. bagCar = 'bagCar',
  130. signDays = 'signDays',
  131. onLineGetStr = 'onLineGetStr',
  132. maxCarLevel = 'maxCarLevel',
  133. buyTimeData = 'buyTimeData',
  134. buyTimeDataMain = 'buyTimeDataMain',
  135. buyTimeTotal = 'buyTimeTotal',
  136. speedUpTime = 'speedUpTime',
  137. speedUpStartTime = 'speedUpStartTime',
  138. speedUpTimeValue = 'sppedUpTimeValue', //加速时间 最大3小时
  139. gameTime = 'gameTime',
  140. maxCarLvCanBuy = 'maxCarLvCanBuy',
  141. giftCacheNum = 'giftCacheNum',
  142. boxCacheNum = 'boxCacheNum',
  143. giftTimes = 'giftTimes',
  144. turntableRefreshTimes = 'turntableRefreshTimes',
  145. turntableTimes = 'turntableTimes',
  146. turntableUseCard = 'turntableUseCard',
  147. turntableCardCount = 'turntableCardCount',
  148. dailyFinishTimesData = 'dailyFinishTimesData',
  149. dailyGetData = 'dailyGetData',
  150. achieveGetData = 'achieveGetData',
  151. composeAwardGet = 'composeAwardGet',
  152. composeCarTimes = 'composeCarTimes',
  153. airshipTimes = 'airshipTimes',
  154. lastVideoUpCarBuyTimes = 'lastVideoCarLevel', //上次视频升级车等级
  155. speedUpTotal = 'speedUpTotal',
  156. redMoneyRecord = 'redMoneyRecord',
  157. cashStatus = 'cashStatus',
  158. gameAdd = 'gameAdd',
  159. uin = 'uin', //用户id
  160. login_ticket = 'login_ticket', //微信ticket
  161. session_key = 'session_key', //玩家session
  162. nickname = 'nickname',
  163. headimgurl = 'headimgurl',
  164. ranKey = 'ranKey',
  165. tmp_uin = 'tmp_uin',
  166. isAuth = 'isAuth',
  167. dayBuyCarVideoLimitTimes = 'dayBuyCarVideoLimitTimes',
  168. joinDraw = 'joinDraw',
  169. firstLoadIn = "firstIn", //第一次进入游戏
  170. firstLoadEnd = "firstLoadEnd", //第一次进入游戏加载结束
  171. isFirstIn = 'isFirstIn', //第一次登录
  172. videoCoolDown = 'videoCoolDown', //看视频冷却时间
  173. todayVideoTimes = 'todayVideoTimes', //今日激励视频次数
  174. todayFullInterTimes = 'todayFullInterTimes', //今日全屏视频次数
  175. taskGuide = 'taskGuide', //是否显示过任务引导
  176. popRule = 'popRule', //是否同意协议
  177. todayPlayTime = 'todayPlayTime', //今日玩游戏时间 秒
  178. identification = 'identification', //认证 0 未认证 1 认证成人 2 认证未成年人
  179. showClubGirl = 'showClubGirl', // /**俱乐部广告,每天第一次登录显示 */
  180. //西游
  181. composeMaxRoleLv = "composeMaxRoleLv", //合成的角色最高等级
  182. CoinTipTotay = 'CoinTipTotay', //今日是否弹出过获取金币界面
  183. umFirst = 'umFirst', //友盟登录统计
  184. cashEcpmBtnState = 'cashEcpmBtnState', //提现按钮的显示状态
  185. }