|
@@ -63,90 +63,44 @@ cc.Class({
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
start() {
|
|
start() {
|
|
|
- let self = this;
|
|
|
|
|
this._tiledMap = GlobalD.TiledMap._tiledMap;
|
|
this._tiledMap = GlobalD.TiledMap._tiledMap;
|
|
|
- // //todo 临时处理
|
|
|
|
|
- // async function dappInit() {
|
|
|
|
|
- // const dapp = new Dapp()
|
|
|
|
|
- // try {
|
|
|
|
|
- // await dapp.init()
|
|
|
|
|
- // // 获取用户信息 xxx
|
|
|
|
|
- // const { err, res } = await dapp.userInfo()
|
|
|
|
|
- // if (err === null) {
|
|
|
|
|
- // // 返回成功,见下面消息体
|
|
|
|
|
- // console.log(res)
|
|
|
|
|
- // GlobalD.GameData.Dapp.UserInfo = res;
|
|
|
|
|
- // GlobalD.GameData.onStartGame();
|
|
|
|
|
- // GameNet.getInstance().init(res.id,(data)=>{
|
|
|
|
|
- // console.log('GameNet:'+data);
|
|
|
|
|
- // }, self);
|
|
|
|
|
-
|
|
|
|
|
- // } else {
|
|
|
|
|
- // //TODO 服务错误
|
|
|
|
|
- // console.log(err)
|
|
|
|
|
- // }
|
|
|
|
|
- // const cntBalance = await dapp.cntBalance()
|
|
|
|
|
- // console.log(cntBalance) // string, 精度18,需要自行处理省略几位小数
|
|
|
|
|
- // GlobalD.GameData.SetCNT(cntBalance);
|
|
|
|
|
- // console.log("end**************");
|
|
|
|
|
- // } catch (err) {
|
|
|
|
|
- // console.log(err) // 初始化失败,运行环境不是钱包环境
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // //初始化调用 dappInit;
|
|
|
|
|
- // dappInit();
|
|
|
|
|
- try {
|
|
|
|
|
- GlobalD.dapp.cntBalance().then((cntBalance) => {
|
|
|
|
|
- console.log(cntBalance) // string, 精度18,需要自行处理省略几位小数
|
|
|
|
|
- GlobalD.GameData.SetCNT(cntBalance);
|
|
|
|
|
- });
|
|
|
|
|
- } catch (err) {
|
|
|
|
|
- console.log(err) // 初始化失败,运行环境不是钱包环境
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- this.readData = userData.readData;
|
|
|
|
|
- cc.log('playerPullInfo 读取到数据?:', this.readData)
|
|
|
|
|
- // this.Init();
|
|
|
|
|
- this.InitNextworkData();
|
|
|
|
|
- this.InitSceneInfo();
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
- onStartGame() {
|
|
|
|
|
- utils.get(utils.api.loginToken, { loginId: GlobalD.GameData.Dapp.UserInfo.id }, (res, value) => {
|
|
|
|
|
- if (value.code == 0) {
|
|
|
|
|
- /** 登录成功获取token */
|
|
|
|
|
- utils.setToken(value.data.token);
|
|
|
|
|
- // console.error("设置token,测试用。");
|
|
|
|
|
- /** 推送信息 */
|
|
|
|
|
- utils.get(utils.api.playerPullInfo, {}, (res, playerPullInfoTemp) => {
|
|
|
|
|
- let _playerData = JSON.parse(playerPullInfoTemp.data.playerData);
|
|
|
|
|
- //记录读取的数据到内存里面
|
|
|
|
|
- // 正常游戏
|
|
|
|
|
- this.readData = userData.readData = _playerData;
|
|
|
|
|
- // cc.log('playerPullInfo 读取到数据?:', this.readData)
|
|
|
|
|
- this.Init();
|
|
|
|
|
- this.InitSceneInfo();
|
|
|
|
|
- })
|
|
|
|
|
- //老铁 请选择 游戏模式
|
|
|
|
|
- //true 每次进入清除数据模式
|
|
|
|
|
- //false 正常带网络存档模式
|
|
|
|
|
- // this.isDebugMode(false);
|
|
|
|
|
- } else {
|
|
|
|
|
- console.log(res, value);
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ //调用初始化dapp
|
|
|
|
|
+ this.isDebugMode(GlobalD.dapp);
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
- //设置游戏模式
|
|
|
|
|
- isDebugMode: function (b) {
|
|
|
|
|
- if (b) {
|
|
|
|
|
- // 清除
|
|
|
|
|
- this.onClearAllData();
|
|
|
|
|
- this.getData();
|
|
|
|
|
- } else {
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据 不存在dapp 的话,使用本地测试
|
|
|
|
|
+ * @param {*} bInit
|
|
|
|
|
+ */
|
|
|
|
|
+ isDebugMode: function (bInit) {
|
|
|
|
|
+ if (bInit) {
|
|
|
//读取网络数据
|
|
//读取网络数据
|
|
|
|
|
+ try {
|
|
|
|
|
+ GlobalD.dapp.cntBalance().then((cntBalance) => {
|
|
|
|
|
+ console.log(cntBalance) // string, 精度18,需要自行处理省略几位小数
|
|
|
|
|
+ GlobalD.GameData.SetCNT(cntBalance);
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ console.error(err) // 初始化失败,运行环境不是钱包环境
|
|
|
|
|
+ }
|
|
|
|
|
+ this.readData = userData.readData;
|
|
|
|
|
+ cc.log('playerPullInfo 读取到数据?:', this.readData)
|
|
|
|
|
+ this.InitNextworkData();
|
|
|
|
|
+ this.InitSceneInfo();
|
|
|
|
|
|
|
|
|
|
+ // 自动存储数据
|
|
|
|
|
+ /**
|
|
|
|
|
+ * todo 如果退出游戏,触发一次存储。
|
|
|
|
|
+ */
|
|
|
|
|
+ this.AutoSaveData = function () {
|
|
|
|
|
+ this.pushData();
|
|
|
|
|
+ };
|
|
|
|
|
+ this.schedule(this.AutoSaveData, 20);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 清除
|
|
|
|
|
+ cc.log("本地数据重新开始,并且不初始化");
|
|
|
|
|
+ // this.onClearAllData();
|
|
|
|
|
+ this.Init();
|
|
|
|
|
+ this.InitSceneInfo();
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -192,14 +146,6 @@ cc.Class({
|
|
|
|
|
|
|
|
this.ManageUI.getComponent('ManageUI').Init();
|
|
this.ManageUI.getComponent('ManageUI').Init();
|
|
|
|
|
|
|
|
- // 自动存储数据
|
|
|
|
|
- /**
|
|
|
|
|
- * todo 如果退出游戏,触发一次存储。
|
|
|
|
|
- */
|
|
|
|
|
- this.AutoSaveData = function () {
|
|
|
|
|
- this.pushData();
|
|
|
|
|
- };
|
|
|
|
|
- this.schedule(this.AutoSaveData, 20);
|
|
|
|
|
},
|
|
},
|
|
|
InitNextworkData() {
|
|
InitNextworkData() {
|
|
|
console.log("this.readData", this.readData);
|
|
console.log("this.readData", this.readData);
|
|
@@ -273,9 +219,11 @@ cc.Class({
|
|
|
if (this.readData.TaskIconCountClick)
|
|
if (this.readData.TaskIconCountClick)
|
|
|
task.TaskIconCountClick = this.readData.TaskIconCountClick;
|
|
task.TaskIconCountClick = this.readData.TaskIconCountClick;
|
|
|
},
|
|
},
|
|
|
- //InitData
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 初始化
|
|
|
|
|
+ */
|
|
|
Init: function () {
|
|
Init: function () {
|
|
|
- let _BFirstLoadGame = this.readData ? this.readData.BFirstLoadGame : 0;
|
|
|
|
|
|
|
+ let _BFirstLoadGame = false;// this.readData ? this.readData.BFirstLoadGame : 0;
|
|
|
//date
|
|
//date
|
|
|
this.GameYear = 0;
|
|
this.GameYear = 0;
|
|
|
this.GameMonth = 0;
|
|
this.GameMonth = 0;
|
|
@@ -369,7 +317,7 @@ cc.Class({
|
|
|
1, //Holy Farmland
|
|
1, //Holy Farmland
|
|
|
1, //Holy Farmland seed
|
|
1, //Holy Farmland seed
|
|
|
];
|
|
];
|
|
|
- 建筑物数量
|
|
|
|
|
|
|
+ //建筑物数量
|
|
|
this.BuildingNumArray = [
|
|
this.BuildingNumArray = [
|
|
|
0, //公路
|
|
0, //公路
|
|
|
0, //路铲
|
|
0, //路铲
|
|
@@ -432,7 +380,7 @@ cc.Class({
|
|
|
this.LotteryTimes = 10;
|
|
this.LotteryTimes = 10;
|
|
|
|
|
|
|
|
// 1 === _BFirstLoadGame
|
|
// 1 === _BFirstLoadGame
|
|
|
- if (true) {
|
|
|
|
|
|
|
+ if (_BFirstLoadGame) {
|
|
|
console.log("this.readData", this.readData);
|
|
console.log("this.readData", this.readData);
|
|
|
// cc.log('初始化网络数据');
|
|
// cc.log('初始化网络数据');
|
|
|
//读取日期数据
|
|
//读取日期数据
|
|
@@ -834,7 +782,6 @@ cc.Class({
|
|
|
this.unschedule(this.AutoSaveData);
|
|
this.unschedule(this.AutoSaveData);
|
|
|
//任务索引
|
|
//任务索引
|
|
|
cc.sys.localStorage.removeItem('userdata');
|
|
cc.sys.localStorage.removeItem('userdata');
|
|
|
-
|
|
|
|
|
//跳回登录场景
|
|
//跳回登录场景
|
|
|
// cc.director.loadScene('Login');
|
|
// cc.director.loadScene('Login');
|
|
|
},
|
|
},
|
|
@@ -854,13 +801,13 @@ cc.Class({
|
|
|
BFirstLoadGame: 1,//只要push数据,就证明已经开始第一次游戏了
|
|
BFirstLoadGame: 1,//只要push数据,就证明已经开始第一次游戏了
|
|
|
|
|
|
|
|
/**游戏不修改,默认值 start */
|
|
/**游戏不修改,默认值 start */
|
|
|
- shareGive : this.shareGive,
|
|
|
|
|
|
|
+ shareGive: this.shareGive,
|
|
|
//签到分享给钻石金币
|
|
//签到分享给钻石金币
|
|
|
- signInGive : this.signInGive,
|
|
|
|
|
|
|
+ signInGive: this.signInGive,
|
|
|
//每个月 给的 低保
|
|
//每个月 给的 低保
|
|
|
- EveryGive : this.EveryGive,
|
|
|
|
|
|
|
+ EveryGive: this.EveryGive,
|
|
|
//公共分享
|
|
//公共分享
|
|
|
- publicGive : this.publicGive,
|
|
|
|
|
|
|
+ publicGive: this.publicGive,
|
|
|
/**游戏不修改,默认值 end */
|
|
/**游戏不修改,默认值 end */
|
|
|
|
|
|
|
|
//时间
|
|
//时间
|