123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- /*
- Global UserInfo
- */
- window.UserInfo = {
- /*
- 积分
- */
- shareLimit : 3, //分享次数限制
- shareAddGold : 10, //分享增加金币数
- platform : CC_WECHATGAME ? 1 : 0, //1为微信小游戏模式
- shareUrl : 'https://pub.dwstatic.com/wxgame/budingGame/share/shareImage2.jpg',//分享图片地址
- shareDesc : '超级可爱的布丁,快来跟我一起玩吧',
- shareDescChanllenge : '顽强的布丁',
- wxversion : '6.6.3',
- localversion : '1.0.1',
- ewmurl: 'https://pub.dwstatic.com/wxgame/escape/share/2weima.jpg',//公众号二维码
- GameCount : 2,
- getItem (key) {
- if(CC_QQPLAY) {
- return BK.localStorage.getItem(key)
- } else {
- return cc.sys.localStorage.getItem(key)
- }
- },
- setItem (key, value) {
- if(value) {
- if(CC_QQPLAY) {
- BK.localStorage.setItem(key, value.toString())
- } else {
- cc.sys.localStorage.setItem(key, value.toString())
- }
- }
- },
- // 获取每周排行榜分数
- getScore: function () {
- let score = this.getItem('score');
- return score ? parseInt(score) : 0;
- },
- setScore: function (value) {
- this.setItem('score', "" + value);
- },
- getCurrLocalversion: function () {
- if (this.IsEmpty(this.localversion))
- return "";
- return this.localversion;
- },
- setLocalversion: function (version) {
- this.setItem("localversion", "" + version);
- },
- getLocalversion: function () {
- let version = this.getItem('localversion');
- if (this.IsEmpty(version)) {
- this.setItem('localversion', '');
- version = '';
- }
- return version;
- },
- addScore: function (value) {
- let score = this.getItem(this.getCurWeekScoreValue());
- let inputScore = (score ? parseInt(score) : 0) + parseInt(value) + "";
- this.setItem(this.getCurWeekScoreValue(), inputScore);
- },
- /*
- 金币
- */
- getGold: function () {
- let gold = this.getItem('gold');
- return gold ? parseInt(gold) : 0;
- },
- setGold: function (value) {
- this.setItem('gold', "" + value);
- },
- addGold: function (value) {
- let gold = this.getItem('gold');
- let inputGold = (gold ? parseInt(gold) : 0) + parseInt(value) + "";
- this.setItem('gold', inputGold);
- this.addTotalGold(value);
- },
- addTotalGold: function (value) {
- let goldTotal = this.getItem('goldTotal');
- let inputGold = (goldTotal ? parseInt(goldTotal) : 0) + parseInt(value) + "";
- this.setItem('goldTotal', inputGold);
- },
- getTotalGold: function () {
- let goldTotal = this.getItem('goldTotal');
- return goldTotal ? parseInt(goldTotal) : 0;
- },
- addStageProp: function(value) {//累计道具数
- let propcnt = this.getItem('propcnt');
- let inputCnt = (propcnt ? parseInt(propcnt) : 0) + parseInt(value) + "";
- this.setItem('propcnt', inputCnt);
- },
- setStageProp: function(value) {//累计道具数
- let inputCnt = parseInt(value) + "";
- this.setItem('propcnt', inputCnt);
- },
- getStageProp: function () {
- let propcnt = this.getItem('propcnt');
- return propcnt ? parseInt(propcnt) : 0;
- },
- getCurrentLevel: function () {
- let level = this.getItem('levelSign');
- if (this.IsEmpty(level)) {
- this.setItem('levelSign', '0');
- level = '0';
- }
- return parseInt(level);
- },
- setCurrentLevel: function (value) {
- this.setItem('levelSign', value + "");
- },
- setFlyCnt: function(cnt) {
- this.setItem('flycnt', cnt + "");
- },
- getFlyCnt: function() {
- let level = this.getItem('flycnt');
- if (this.IsEmpty(level)) {
- this.setItem('flycnt', '0');
- level = '0';
- }
- return parseInt(level);
- },
- setSkinIndex: function(skinIndex){
- this.setItem('skinIndex',skinIndex + "");
- },
- getSkinIndex: function()
- {
- let skinIndex = this.getItem('skinIndex');
- if (this.IsEmpty(skinIndex))
- {
- this.setItem('skinIndex','0');
- skinIndex = '0';
- }
- return parseInt(skinIndex);
- },
- /*
- 当前等级
- */
- getCurrentPlane: function () {
- let level = this.getItem('level');
- if (this.IsEmpty(level)) {
- this.setItem('level', '1');
- level = '1';
- }
- var intLevel = parseInt(level);
- if (intLevel <= 0) {
- intLevel = 1;
- }
- return intLevel;
- },
- setCurrentPlane: function (value) {
- this.setItem('level', value + "");
- },
- getLevelStage: function () {
- let level = this.getItem('levelStage');
- if (this.IsEmpty(level)) {
- this.setItem('levelStage', '');
- level = '';
- }
- return level;
- },
- setLevelStage: function (value) {
- this.setItem('levelStage', value + "");
- },
- /*
- 设置自定义数据
- */
- setString: function (str, value) {
- this.setItem(str, "" + value);
- },
- getString: function (str) {
- return this.getItem(str);
- },
- addString: function (str, value) {
- let data = this.getItem(str);
- let inputData = (data ? parseInt(data) : 0) + parseInt(value) + "";
- this.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)) {
- this.setItem('maxtime', "0");
- score = "0";
- }
- return parseInt(score);
- },
- setMaxTime: function (value) {
- this.setItem('maxtime', value+"");
- },
- getHistoryScore() {//历史最高分
- var score = this.getString('historyScore');
- if (this.IsEmpty(score)) {
- this.setItem('historyScore', "0");
- score = "0";
- }
- return parseInt(score);
- },
-
- // 获取用户保存在QQ轻游戏云端的数据
- getUserGameData(callback) {
- if(CC_QQPLAY) {
- BK.QQ.loadGameData(function(errCode, cmd, data) {
- // BK.UI.showAlert({
- // title: 'loadGameData',
- // content: JSON.stringify(data)
- // })
- callback && callback(data)
- });
- } else {
- callback && callback({
- maxScore: 0
- })
- }
- },
- // 设置用户在QQ轻游戏的云端数据
- setUserGameData(score) {
- var data = {
- maxScore: score
- }
-
- if(CC_QQPLAY) {
- // 保存个人数据
- BK.QQ.saveGameData(data, function(errCode, cmd, data) {
- // BK.UI.showAlert({
- // title: 'saveGameData',
- // content: JSON.stringify(data)
- // })
- });
- }
- },
- 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;
- },
- showIndexBanner() {
- this.indexBanner = BK.Advertisement.createBannerAd({
- viewId:1001,
- style: {x: 0, y: 0}
- });
- this.indexBanner.show()
- },
- destroyIndexBanner() {
- try{
- this.indexBanner.destory()
- } catch(e) {}
- },
- showDeadBanner() {
- this.deadBanner = BK.Advertisement.createBannerAd({
- viewId:1002,
- style: {x: 0, y: 0}
- });
- this.deadBanner.show()
- },
- destroyDeadBanner() {
- try{
- this.deadBanner.destory()
- } catch(e) {}
- },
- };
|