123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- /*
- 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;
- }
- };
|