/* Global UserInfo */ window.UserInfo = { /* 积分 */ shield: { count: 1 }, //护盾信息 shareLimit: 3, //分享次数限制 shareAddGold: 10, //分享增加金币数 platform: CC_WECHATGAME ? 1 : 0, //1为微信小游戏模式 shareUrl: 'https://pub.dwstatic.com/wxgame/budingGame/share/shareImage.jpg',//分享图片地址 shareDesc: '超级可爱的布丁,快来跟我一起玩吧', shareDescChanllenge: '顽强的布丁', wxversion: '6.6.3', localversion: '1.0.1', ewmurl: 'https://pub.dwstatic.com/wxgame/escape/share/2weima.jpg',//公众号二维码 GameCount: 2, getScore: function () { let score = cc.sys.localStorage.getItem(this.getCurWeekScoreValue()); return score ? parseInt(score) : 0; }, setScore: function (value) { cc.sys.localStorage.setItem(this.getCurWeekScoreValue(), "" + value); }, getCurrLocalversion: function () { if (this.IsEmpty(this.localversion)) return ""; return this.localversion; }, setLocalversion: function (version) { cc.sys.localStorage.setItem("localversion", "" + version); }, getLocalversion: function () { let version = cc.sys.localStorage.getItem('localversion'); if (this.IsEmpty(version)) { cc.sys.localStorage.setItem('localversion', ''); version = ''; } return version; }, addScore: function (value) { let score = cc.sys.localStorage.getItem(this.getCurWeekScoreValue()); let inputScore = (score ? parseInt(score) : 0) + parseInt(value) + ""; cc.sys.localStorage.setItem(this.getCurWeekScoreValue(), inputScore); }, /* 金币 */ getGold: function () { let gold = cc.sys.localStorage.getItem('gold'); return gold ? parseInt(gold) : 0; }, setGold: function (value) { cc.sys.localStorage.setItem('gold', "" + value); }, addGold: function (value) { let gold = cc.sys.localStorage.getItem('gold'); let inputGold = (gold ? parseInt(gold) : 0) + parseInt(value) + ""; cc.sys.localStorage.setItem('gold', inputGold); this.addTotalGold(value); }, addTotalGold: function (value) { let goldTotal = cc.sys.localStorage.getItem('goldTotal'); let inputGold = (goldTotal ? parseInt(goldTotal) : 0) + parseInt(value) + ""; cc.sys.localStorage.setItem('goldTotal', inputGold); }, getTotalGold: function () { let goldTotal = cc.sys.localStorage.getItem('goldTotal'); return goldTotal ? parseInt(goldTotal) : 0; }, addStageProp: function (value) {//累计道具数 let propcnt = cc.sys.localStorage.getItem('propcnt'); let inputCnt = (propcnt ? parseInt(propcnt) : 0) + parseInt(value) + ""; cc.sys.localStorage.setItem('propcnt', inputCnt); }, setStageProp: function (value) {//累计道具数 let inputCnt = parseInt(value) + ""; cc.sys.localStorage.setItem('propcnt', inputCnt); }, getStageProp: function () { let propcnt = cc.sys.localStorage.getItem('propcnt'); return propcnt ? parseInt(propcnt) : 0; }, getCurrentLevel: function () { let level = cc.sys.localStorage.getItem('levelSign'); if (this.IsEmpty(level)) { cc.sys.localStorage.setItem('levelSign', '0'); level = '0'; } return parseInt(level); }, setCurrentLevel: function (value) { cc.sys.localStorage.setItem('levelSign', value + ""); }, setFlyCnt: function (cnt) { cc.sys.localStorage.setItem('flycnt', cnt + ""); }, getFlyCnt: function () { let level = cc.sys.localStorage.getItem('flycnt'); if (this.IsEmpty(level)) { cc.sys.localStorage.setItem('flycnt', '0'); level = '0'; } return parseInt(level); }, setSkinIndex: function (skinIndex) { cc.sys.localStorage.setItem('skinIndex', skinIndex + ""); }, getSkinIndex: function () { let skinIndex = cc.sys.localStorage.getItem('skinIndex'); if (this.IsEmpty(skinIndex)) { cc.sys.localStorage.setItem('skinIndex', '0'); skinIndex = '0'; } return parseInt(skinIndex); }, /* 当前等级 */ getCurrentPlane: function () { let level = cc.sys.localStorage.getItem('level'); if (this.IsEmpty(level)) { cc.sys.localStorage.setItem('level', '1'); level = '1'; } var intLevel = parseInt(level); if (intLevel <= 0) { intLevel = 1; } return intLevel; }, setCurrentPlane: function (value) { cc.sys.localStorage.setItem('level', value + ""); }, getLevelStage: function () { let level = cc.sys.localStorage.getItem('levelStage'); if (this.IsEmpty(level)) { cc.sys.localStorage.setItem('levelStage', ''); level = ''; } return level; }, setLevelStage: function (value) { cc.sys.localStorage.setItem('levelStage', value + ""); }, /* 设置自定义数据 */ setString: function (str, value) { cc.sys.localStorage.setItem(str, value); }, getString: function (str) { return cc.sys.localStorage.getItem(str); }, addString: function (str, value) { let data = cc.sys.localStorage.getItem(str); let inputData = (data ? parseInt(data) : 0) + parseInt(value) + ""; cc.sys.localStorage.setItem(str, inputData); }, removeString: function (str) { cc.sys.localStorage.removeItem(str); }, IsEmpty(obj) {//判断是否为空 if (obj == "undefined" || obj == null || obj == "") { return true; } else { return false; } }, getMaxTime() {//历史最长时间 var score = this.getString('maxtime'); if (this.IsEmpty(score)) { cc.sys.localStorage.setItem('maxtime', "0"); score = "0"; } return parseInt(score); }, setMaxTime: function (value) { cc.sys.localStorage.setItem('maxtime', value + ""); }, getHistoryScore() {//历史最高分 var score = this.getString('historyScore'); if (this.IsEmpty(score)) { cc.sys.localStorage.setItem('historyScore', "0"); score = "0"; } return parseInt(score); }, getCurWeekScoreValue() { return this.getNowFormatDate(); }, getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var year = date.getFullYear(); // var month = date.getMonth() + 1; // if (month >= 1 && month <= 9) { // month = "0" + month; // } var week = this.Getweek(); var currentdate = year + seperator1 + week; return currentdate; }, getMonthWeek() { var date = new Date(), w = date.getDay(), d = date.getDate(); return Math.ceil( (d + 7 - w) / 7 ); }, Getweek(dateString) { var da = ''; if (dateString == undefined) { var now = new Date(); var now_m = now.getMonth() + 1; now_m = (now_m < 10) ? '0' + now_m : now_m; var now_d = now.getDate(); now_d = (now_d < 10) ? '0' + now_d : now_d; da = now.getFullYear() + '-' + now_m + '-' + now_d; } else { da = dateString; //日期格式2015-12-30 } var date1 = new Date(da.substring(0, 4), parseInt(da.substring(5, 7)) - 1, da.substring(8, 10)); //当前日期 var date2 = new Date(da.substring(0, 4), 0, 1); //1月1号 //获取1月1号星期(以周一为第一天,0周一~6周日) var dateWeekNum = date2.getDay() - 1; if (dateWeekNum < 0) { dateWeekNum = 6; } if (dateWeekNum < 4) { //前移日期 date2.setDate(date2.getDate() - dateWeekNum); } else { //后移日期 date2.setDate(date2.getDate() + 7 - dateWeekNum); } var d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000); var year = date1.getFullYear(); var week = Math.ceil((d + 1) / 7); return week; } };