| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- import GameM from "../manager/GameM"
- import LogUtil from "../utils/LogUtil";
- import { Utils } from "../utils/Utils";
- import InvestData from "./InvestData";
- import TreasureData from "./TreasureData";
- import TurntableData from "./TurntableData";
- export default class GlobalStorage {
- private static instance: GlobalStorage = null
- static get Instance(): GlobalStorage {
- if (!this.instance) {
- this.instance = new GlobalStorage()
- }
- return this.instance
- }
- constructor() {
- //this.setStorage(STORAGE_KEY.airshipTimes, 0)
- }
- speedUpTimeValue: number = null; //加速时间
- init() {
- let key = 'dddddddddddddddddddddddddddddddd'
- let value = null
- value = this.getStorage(STORAGE_KEY.ranKey, 1)
- if (value != null) {
- GameM.commonData.ranKey = Utils.Decrypt(value, key, GameM.commonData.appid, true)
- }
- value = this.getStorage(STORAGE_KEY.tmp_uin, 1)
- if (value != null) {
- GameM.commonData.tmp_uin = Utils.Decrypt(value, key, GameM.commonData.appid, true)
- }
- // console.log('GameM.commonData.ranKey ', GameM.commonData.ranKey)
- // console.log('GameM.commonData.tmp_uin ', GameM.commonData.tmp_uin)
- value = this.getStorage(STORAGE_KEY.isAuth, 1)
- if (value != null) {
- GameM.commonData.isAuth = Utils.Decrypt(value, key, GameM.commonData.appid, true) == 'true'
- }
- value = this.getStorage(STORAGE_KEY.uin, 1)
- if (value != null) {
- GameM.commonData.uin = Utils.Decrypt(value, key, GameM.commonData.appid, true)
- }
- value = this.getStorage(STORAGE_KEY.login_ticket, 1)
- if (value != null) {
- GameM.commonData.login_ticket = Utils.Decrypt(value, key, GameM.commonData.appid, true)
- }
- value = this.getStorage(STORAGE_KEY.session_key, 1)
- if (value != null) {
- GameM.commonData.session_key = Utils.Decrypt(value, key, GameM.commonData.appid, true)
- }
- value = this.getStorage(STORAGE_KEY.nickname, 1)
- if (value != null) {
- GameM.commonData.nickname = value
- }
- value = this.getStorage(STORAGE_KEY.headimgurl, 1)
- if (value != null) {
- GameM.commonData.headimgurl = value
- LogUtil.logV('GameM.commonData.headimgurl ', GameM.commonData.headimgurl)
- }
- value = this.getStorage(STORAGE_KEY.joinDraw, 1)
- if (value != null) {
- //GameM.commonData.joinDraw = utils.Decrypt(value, key, GameM.commonData.appid, true)
- TreasureData.Instance.joinDraw = Utils.Decrypt(value, key, GameM.commonData.appid, true)
- }
- value = this.getStorage(STORAGE_KEY.videoCoolDown)
- if (value != null) {
- GameM.commonData.videoCoolDown = value
- }
- value = this.getStorage(STORAGE_KEY.todayVideoTimes)
- if (value != null) {
- GameM.commonData.todayVideoTimes = value
- }
- value = this.getStorage(STORAGE_KEY.todayFullInterTimes)
- if (value != null) {
- GameM.commonData.todayFullInterTimes = value
- }
- value = this.getStorage(STORAGE_KEY.taskGuide)
- if (value != null) {
- GameM.commonData.taskGuide = value
- }
- //西游
- value = this.getStorage(STORAGE_KEY.composeMaxRoleLv)
- if (value != null) {
- GameM.commonData.composeMaxRoleLv = value
- }
- }
- /** 存储数据
- * @param key 关键字
- * @param val 数值
- * @param type 类型 默认 0 number 1 string 2 json
- */
- setStorage(key: string, val: any, type: number = 0) {
- if (type == 0) {
- cc.sys.localStorage.setItem(key, val.toString())
- }
- else if (type == 1) {
- cc.sys.localStorage.setItem(key, val)
- }
- else if (type == 2) {
- cc.sys.localStorage.setItem(key, JSON.stringify(val))
- }
- }
- /** 获取存储数据
- * @param key 关键字
- * @param type 返回类型 默认 0 number 1 string 2 json
- */
- getStorage(key: string, type: number = 0) {
- let val = null
- if (cc.sys.localStorage.getItem(key) != null && cc.sys.localStorage.getItem(key) != undefined) {
- if (type == 0) {
- val = Number(cc.sys.localStorage.getItem(key))
- }
- else if (type == 1) {
- val = cc.sys.localStorage.getItem(key)
- }
- else if (type == 2) {
- val = JSON.parse(cc.sys.localStorage.getItem(key))
- }
- }
- return val
- }
- }
- export enum STORAGE_KEY {
- lastDate = 'lastDate',
- onLineTime = 'onLineTime',
- redMoney = 'redMoney',
- step = 'step',
- videoTimes = 'videoTimes',
- canSign = 'canSign',
- gold = 'gold',
- roleData = 'roleData',
- bagCar = 'bagCar',
- signDays = 'signDays',
- onLineGetStr = 'onLineGetStr',
- maxCarLevel = 'maxCarLevel',
- buyTimeData = 'buyTimeData',
- buyTimeDataMain = 'buyTimeDataMain',
- buyTimeTotal = 'buyTimeTotal',
- speedUpTime = 'speedUpTime',
- speedUpStartTime = 'speedUpStartTime',
- speedUpTimeValue = 'sppedUpTimeValue', //加速时间 最大3小时
- gameTime = 'gameTime',
- maxCarLvCanBuy = 'maxCarLvCanBuy',
- giftCacheNum = 'giftCacheNum',
- boxCacheNum = 'boxCacheNum',
- giftTimes = 'giftTimes',
- turntableRefreshTimes = 'turntableRefreshTimes',
- turntableTimes = 'turntableTimes',
- turntableUseCard = 'turntableUseCard',
- turntableCardCount = 'turntableCardCount',
- dailyFinishTimesData = 'dailyFinishTimesData',
- dailyGetData = 'dailyGetData',
- achieveGetData = 'achieveGetData',
- composeAwardGet = 'composeAwardGet',
- composeCarTimes = 'composeCarTimes',
- airshipTimes = 'airshipTimes',
- lastVideoUpCarBuyTimes = 'lastVideoCarLevel', //上次视频升级车等级
- speedUpTotal = 'speedUpTotal',
- redMoneyRecord = 'redMoneyRecord',
- cashStatus = 'cashStatus',
- gameAdd = 'gameAdd',
- uin = 'uin', //用户id
- login_ticket = 'login_ticket', //微信ticket
- session_key = 'session_key', //玩家session
- nickname = 'nickname',
- headimgurl = 'headimgurl',
- ranKey = 'ranKey',
- tmp_uin = 'tmp_uin',
- isAuth = 'isAuth',
- dayBuyCarVideoLimitTimes = 'dayBuyCarVideoLimitTimes',
- joinDraw = 'joinDraw',
- firstLoadIn = "firstIn", //第一次进入游戏
- firstLoadEnd = "firstLoadEnd", //第一次进入游戏加载结束
- isFirstIn = 'isFirstIn', //第一次登录
- videoCoolDown = 'videoCoolDown', //看视频冷却时间
- todayVideoTimes = 'todayVideoTimes', //今日激励视频次数
- todayFullInterTimes = 'todayFullInterTimes', //今日全屏视频次数
- taskGuide = 'taskGuide', //是否显示过任务引导
- popRule = 'popRule', //是否同意协议
- todayPlayTime = 'todayPlayTime', //今日玩游戏时间 秒
- identification = 'identification', //认证 0 未认证 1 认证成人 2 认证未成年人
- showClubGirl = 'showClubGirl', // /**俱乐部广告,每天第一次登录显示 */
- //西游
- composeMaxRoleLv = "composeMaxRoleLv", //合成的角色最高等级
- CoinTipTotay = 'CoinTipTotay', //今日是否弹出过获取金币界面
- umFirst = 'umFirst', //友盟登录统计
- cashEcpmBtnState = 'cashEcpmBtnState', //提现按钮的显示状态
- }
|