瀏覽代碼

重置数据

zouyong 5 年之前
父節點
當前提交
2c940265df
共有 1 個文件被更改,包括 28 次插入11 次删除
  1. 28 11
      assets/script/game/data/GameData.ts

+ 28 - 11
assets/script/game/data/GameData.ts

@@ -37,6 +37,10 @@ export class GameData {
             return;
         }
 
+        if (this.props == null) {
+            this.props = new Map<number, object>();
+        }
+
         this.initProps(response.data.gameUserData);
 
         this.dataFinish = true;
@@ -45,19 +49,20 @@ export class GameData {
     /**
      * 保存单个数据
      */
-    public async saveProp(key: GameProp, value: number | string) {
+    public async setProp(key: GameProp, value: object) {
         let data = {
             key: key + '',
             value: value + ''
         };
         await mk.http.sendData('savePlayerProp', data);
+        this.props.set(key, value);
         this.savePropFinish = true;
     }
 
     /**
      * 保存多个数据
      */
-    public async saveProps(arr: { key: GameProp, value: number | string }[]) {
+    public async setProps(arr: { key: GameProp, value: object }[]) {
         let needProp = {};
         for (let i = 0; i < arr.length; i++) {
             needProp[arr[i].key + ''] = arr[i].value + "";
@@ -66,9 +71,22 @@ export class GameData {
             needProp: needProp
         };
         await mk.http.sendData('saveAllPlayerProp', data);
+
+        for (let i = 0; i < arr.length; i++) {
+            this.props.set(arr[i].key, arr[i].value);
+        }
+
         this.savePropsFinish = true;
     }
 
+    /** 获取属性 */
+    public getProp(key: GameProp): object {
+        if (this.props == null) {
+            return null;
+        }
+        return this.props.get(key);
+    }
+
     /**
      * 向服务器请求所有属性后更新
      */
@@ -84,20 +102,19 @@ export class GameData {
     }
 
     private initProps(data) {
-        if (this.props == null) {
-            this.props = new Map<number, object>();
-        }
         for (let key in data) {
             this.props.set(parseInt(key), JSON.parse(data[key]));
         }
     }
 
-    /** 获取属性 */
-    public getProp(key: GameProp): object {
-        if (this.props == null) {
-            return null;
-        }
-        return this.props.get(key);
+    /**
+     * 第二天需要重置的数据
+     */
+    public resetProps() {
+        let arr = [];
+        arr.push({ key: GameProp.cur_sign_day, value: 0 });
+
+        this.setProps(arr);
     }
 }