Browse Source

兼容性修复

sa 6 years ago
parent
commit
280eeda6a1
2 changed files with 65 additions and 56 deletions
  1. 0 8
      assets/Script/Game/GameSence.js
  2. 65 48
      assets/Script/UserInfoJS.js

+ 0 - 8
assets/Script/Game/GameSence.js

@@ -196,14 +196,6 @@ cc.Class({
 
             this.gameOver();
 
-            // var data = [{
-            //     key: UserInfo.getCurWeekScoreValue(),
-            //     value: UserInfo.getScore().toString()
-            // }, {
-            //     key: "driLevel",
-            //     value: '0'
-            // }];
-
             if (CC_QQPLAY) {
                 this.node.parent.getChildByName("PHB").getChildByName("bg").active = false;
                 this.rankScene.status = 3;

+ 65 - 48
assets/Script/UserInfoJS.js

@@ -18,15 +18,30 @@ window.UserInfo = {
     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(CC_QQPLAY) {
+			BK.localStorage.setItem(key, value)
+		} else {
+			cc.sys.localStorage.setItem(key, value)
+		}
+	},
 
 	// 获取每周排行榜分数
 	getScore: function () {
-		let score = BK.localStorage.getItem('score');
+		let score = this.getItem('score');
 		return score ? parseInt(score) : 0;
 	},
 
 	setScore: function (value) {
-		BK.localStorage.setItem('score', "" + value);
+		this.setItem('score', "" + value);
 	},
 
 	getCurrLocalversion: function () {
@@ -36,107 +51,107 @@ window.UserInfo = {
 	},
 
 	setLocalversion: function (version) {
-		BK.localStorage.setItem("localversion", "" + version);
+		this.setItem("localversion", "" + version);
 	},
 
 	getLocalversion: function () {
-		let version = BK.localStorage.getItem('localversion');
+		let version = this.getItem('localversion');
 		if (this.IsEmpty(version)) {
-			BK.localStorage.setItem('localversion', '');
+			this.setItem('localversion', '');
 			version = '';
 		}
 		return version;
 	},
 
 	addScore: function (value) {
-		let score = BK.localStorage.getItem(this.getCurWeekScoreValue());
+		let score = this.getItem(this.getCurWeekScoreValue());
 		let inputScore = (score ? parseInt(score) : 0) + parseInt(value) + "";
-		BK.localStorage.setItem(this.getCurWeekScoreValue(), inputScore);
+		this.setItem(this.getCurWeekScoreValue(), inputScore);
 	},
 
 	/*
 		金币
 	*/
 	getGold: function () {
-		let gold = BK.localStorage.getItem('gold');
+		let gold = this.getItem('gold');
 		return gold ? parseInt(gold) : 0;
 	},
 
 	setGold: function (value) {
-		BK.localStorage.setItem('gold', "" + value);
+		this.setItem('gold', "" + value);
 	},
 
 	addGold: function (value) {
-		let gold = BK.localStorage.getItem('gold');
+		let gold = this.getItem('gold');
 		let inputGold = (gold ? parseInt(gold) : 0) + parseInt(value) + "";
-		BK.localStorage.setItem('gold', inputGold);
+		this.setItem('gold', inputGold);
 
 		this.addTotalGold(value);
 	},
 
 	addTotalGold: function (value) {
-		let goldTotal = BK.localStorage.getItem('goldTotal');
+		let goldTotal = this.getItem('goldTotal');
 		let inputGold = (goldTotal ? parseInt(goldTotal) : 0) + parseInt(value) + "";
-		BK.localStorage.setItem('goldTotal', inputGold);
+		this.setItem('goldTotal', inputGold);
 	},
 
 	getTotalGold: function () {
-		let goldTotal = BK.localStorage.getItem('goldTotal');
+		let goldTotal = this.getItem('goldTotal');
 		return goldTotal ? parseInt(goldTotal) : 0;
 	},
 
 	addStageProp: function(value) {//累计道具数
-		let propcnt = BK.localStorage.getItem('propcnt');
+		let propcnt = this.getItem('propcnt');
 		let inputCnt = (propcnt ? parseInt(propcnt) : 0) + parseInt(value) + "";
-		BK.localStorage.setItem('propcnt', inputCnt);
+		this.setItem('propcnt', inputCnt);
 	},
 
 	setStageProp: function(value) {//累计道具数		
 		let inputCnt = parseInt(value) + "";
-		BK.localStorage.setItem('propcnt', inputCnt);
+		this.setItem('propcnt', inputCnt);
 	},
 
 	getStageProp: function () {
-		let propcnt = BK.localStorage.getItem('propcnt');
+		let propcnt = this.getItem('propcnt');
 		return propcnt ? parseInt(propcnt) : 0;
 	},
 
 	getCurrentLevel: function () {
-		let level = BK.localStorage.getItem('levelSign');
+		let level = this.getItem('levelSign');
 		if (this.IsEmpty(level)) {
-			BK.localStorage.setItem('levelSign', '0');
+			this.setItem('levelSign', '0');
 			level = '0';
 		}
 		return parseInt(level);
 	},
 
 	setCurrentLevel: function (value) {
-		BK.localStorage.setItem('levelSign', value + "");
+		this.setItem('levelSign', value + "");
 	},
 
 	setFlyCnt: function(cnt) {
-		BK.localStorage.setItem('flycnt', cnt + "");
+		this.setItem('flycnt', cnt + "");
 	},
 
 	getFlyCnt: function() {
-		let level = BK.localStorage.getItem('flycnt');
+		let level = this.getItem('flycnt');
 		if (this.IsEmpty(level)) {
-			BK.localStorage.setItem('flycnt', '0');
+			this.setItem('flycnt', '0');
 			level = '0';
 		}
 		return parseInt(level);
 	},
 
 	setSkinIndex: function(skinIndex){
-		BK.localStorage.setItem('skinIndex',skinIndex + "");
+		this.setItem('skinIndex',skinIndex + "");
 	},
 
 	getSkinIndex: function()
 	{
-		let skinIndex = BK.localStorage.getItem('skinIndex');
+		let skinIndex = this.getItem('skinIndex');
 		if (this.IsEmpty(skinIndex)) 
 		{
-			BK.localStorage.setItem('skinIndex','0');
+			this.setItem('skinIndex','0');
 			skinIndex = '0';
 		}
 		return parseInt(skinIndex);
@@ -146,9 +161,9 @@ window.UserInfo = {
 		当前等级
 	*/
 	getCurrentPlane: function () {
-		let level = BK.localStorage.getItem('level');
+		let level = this.getItem('level');
 		if (this.IsEmpty(level)) {
-			BK.localStorage.setItem('level', '1');
+			this.setItem('level', '1');
 			level = '1';
 		}
 
@@ -160,14 +175,14 @@ window.UserInfo = {
 	},
 
 	setCurrentPlane: function (value) {
-		BK.localStorage.setItem('level', value + "");
+		this.setItem('level', value + "");
 	},
 
 
 	getLevelStage: function () {
-		let level = BK.localStorage.getItem('levelStage');
+		let level = this.getItem('levelStage');
 		if (this.IsEmpty(level)) {
-			BK.localStorage.setItem('levelStage', '');
+			this.setItem('levelStage', '');
 			level = '';
 		}
 
@@ -175,24 +190,24 @@ window.UserInfo = {
 	},
 
 	setLevelStage: function (value) {
-		BK.localStorage.setItem('levelStage', value + "");
+		this.setItem('levelStage', value + "");
 	},
 
 	/*
 		设置自定义数据
 	*/
 	setString: function (str, value) {
-		BK.localStorage.setItem(str, "" + value);
+		this.setItem(str, "" + value);
 	},
 
 	getString: function (str) {
-		return BK.localStorage.getItem(str);
+		return this.getItem(str);
 	},
 
 	addString: function (str, value) {
-		let data = BK.localStorage.getItem(str);
+		let data = this.getItem(str);
 		let inputData = (data ? parseInt(data) : 0) + parseInt(value) + "";
-		BK.localStorage.setItem(str, inputData);
+		this.setItem(str, inputData);
 	},
 
 	removeString: function (str) {
@@ -210,20 +225,20 @@ window.UserInfo = {
 	getMaxTime() {//历史最长时间
 		var score = this.getString('maxtime');
 		if (this.IsEmpty(score)) {
-			BK.localStorage.setItem('maxtime', "0");
+			this.setItem('maxtime', "0");
 			score = "0";
 		}
 		return parseInt(score);
 	},
 
 	setMaxTime: function (value) {
-		BK.localStorage.setItem('maxtime', value+"");
+		this.setItem('maxtime', value+"");
 	},
 
 	getHistoryScore() {//历史最高分
 		var score = this.getString('historyScore');
 		if (this.IsEmpty(score)) {
-			BK.localStorage.setItem('historyScore', "0");
+			this.setItem('historyScore', "0");
 			score = "0";
 		}
 		return parseInt(score);
@@ -252,14 +267,16 @@ window.UserInfo = {
 		var data = {
 			maxScore: score
 		}
-
-		// 保存个人数据
-		BK.QQ.saveGameData(data, function(errCode, cmd, data) {
-			// BK.UI.showAlert({
-			// 	title: 'saveGameData',
-			// 	content: JSON.stringify(data)
-			// })
-		});
+		
+		if(CC_QQPLAY) {
+			// 保存个人数据
+			BK.QQ.saveGameData(data, function(errCode, cmd, data) {
+				// BK.UI.showAlert({
+				// 	title: 'saveGameData',
+				// 	content: JSON.stringify(data)
+				// })
+			});
+		}
 	},
 
 	getCurWeekScoreValue() {