소스 검색

【修改】 修改配置表加载

Hua 2 년 전
부모
커밋
e03ff1f1de

+ 4 - 0
assets/script/app/AppInit.js

@@ -28,6 +28,10 @@ module.exports = {
28
         ns.UIMgr = require('UIMgr')
28
         ns.UIMgr = require('UIMgr')
29
         ns.UIMgr.init();
29
         ns.UIMgr.init();
30
 
30
 
31
+        // 配置表管理器
32
+        ns.CfgMgr = require('CfgMgr'); 
33
+        ns.CfgMgr.init();
34
+
31
         // 时间工具
35
         // 时间工具
32
         ns.TimeUtils = require('TimeUtils');
36
         ns.TimeUtils = require('TimeUtils');
33
 
37
 

+ 18 - 9
assets/script/app/config/ConfigBase.js

@@ -8,14 +8,16 @@ cc.Class({
8
         multiple:[],
8
         multiple:[],
9
         multipleCache:null,
9
         multipleCache:null,
10
         table:null,
10
         table:null,
11
+        tableName:"",
12
+        isLoadFinish:false,
11
     },
13
     },
12
 
14
 
13
     ctor() {
15
     ctor() {
14
 
16
 
15
     },
17
     },
16
 
18
 
17
-    initTable(table, mainKey, multipleKey) {
18
-        this.table = table;
19
+    initTable(tableName, mainKey, multipleKey) {
20
+        this.tableName = tableName;
19
         this.mainKey = mainKey;
21
         this.mainKey = mainKey;
20
         this.multiple = multipleKey;
22
         this.multiple = multipleKey;
21
 
23
 
@@ -24,20 +26,19 @@ cc.Class({
24
         return this
26
         return this
25
     },
27
     },
26
 
28
 
27
-    // getObjectValue(object, key) {
28
-    //     if (object.hasOwnProperty(key))
29
-    //     {
30
-    //         return object[key]
31
-    //     }
32
-    //     return undefined;
33
-    // },
29
+    setTable(table) {
30
+        this.table = table
31
+    },
34
 
32
 
33
+    // 从主键中拿某一行数据
35
     getByMainKey(idx) {
34
     getByMainKey(idx) {
35
+        // 从缓存中拿数据
36
         let data = this.indexsCache[idx]
36
         let data = this.indexsCache[idx]
37
         if (data != undefined) {
37
         if (data != undefined) {
38
             return data;
38
             return data;
39
         }
39
         }
40
         
40
         
41
+        // 找数据
41
         for (let d of this.table) {
42
         for (let d of this.table) {
42
             if (d[this.mainKey] == idx) {
43
             if (d[this.mainKey] == idx) {
43
                 data = d;
44
                 data = d;
@@ -45,11 +46,15 @@ cc.Class({
45
             }
46
             }
46
         }
47
         }
47
 
48
 
49
+        // 缓存数据
48
         this.indexsCache[data[this.mainKey]] = data;
50
         this.indexsCache[data[this.mainKey]] = data;
49
         return data;
51
         return data;
50
     },
52
     },
51
 
53
 
54
+    // 从多主键中,拿数据
52
     getByMultipleKey() {
55
     getByMultipleKey() {
56
+
57
+        // 参数跟多主键数量对应不上
53
         if (arguments.length != this.multiple.length) {
58
         if (arguments.length != this.multiple.length) {
54
             if (arguments.length <= 0) {
59
             if (arguments.length <= 0) {
55
                 cc.log("multiple key is null");
60
                 cc.log("multiple key is null");
@@ -59,15 +64,18 @@ cc.Class({
59
             return null;
64
             return null;
60
         }
65
         }
61
 
66
 
67
+        // 从缓存中拿数据
62
         let curCache = this.findMultipleCache(arguments);
68
         let curCache = this.findMultipleCache(arguments);
63
         if (curCache != null)
69
         if (curCache != null)
64
         {
70
         {
65
             return curCache;
71
             return curCache;
66
         }
72
         }
67
 
73
 
74
+        // 查找数据
68
         return this.getAndAddMultiple(arguments);
75
         return this.getAndAddMultiple(arguments);
69
     },
76
     },
70
 
77
 
78
+    // 拿多主键数据并缓存
71
     getAndAddMultiple(args)
79
     getAndAddMultiple(args)
72
     {
80
     {
73
         var result = [];
81
         var result = [];
@@ -106,6 +114,7 @@ cc.Class({
106
         return result;
114
         return result;
107
     },
115
     },
108
 
116
 
117
+    // 从多主键缓存中拿数据
109
     findMultipleCache(args)
118
     findMultipleCache(args)
110
     {
119
     {
111
         // 索引缓存
120
         // 索引缓存

+ 78 - 0
assets/script/core/model/CfgMgr.js

@@ -0,0 +1,78 @@
1
+/**
2
+ * 配置表管理
3
+ */
4
+let ConfigBase = require('ConfigBase')
5
+
6
+let CfgMgr = {
7
+    init () {
8
+        if (CC_EDITOR) {
9
+            return;
10
+        }
11
+        
12
+        this.loadFinishCb = null
13
+        this.updateLoadCb = null
14
+        this.configs = {
15
+            BattleBoxAwardConfig: new ConfigBase().initTable("BattleBoxAwardConfig", "", ["boxId", "itemId"]),
16
+            BattleBoxConfig: new ConfigBase().initTable("BattleBoxConfig", "boxId"),
17
+            BattleBoxTypeConfig: new ConfigBase().initTable("BattleBoxTypeConfig", "ty"),
18
+            BattleConstConfig: new ConfigBase().initTable("BattleConstConfig", "main_key"),
19
+            BlindBoxAwardConfig: new ConfigBase().initTable("BlindBoxAwardConfig", "", ["boxId", "itemId"]),
20
+            BlindBoxConfig: new ConfigBase().initTable("BlindBoxConfig", "boxId"),
21
+            BlindBoxConstConfig: new ConfigBase().initTable("BlindBoxConstConfig", "main_key"),
22
+            BlindBoxTypeConfig: new ConfigBase().initTable("BlindBoxTypeConfig", "ty"),
23
+            DreamBox: new ConfigBase().initTable("DreamBox", "dreamBoxId"),
24
+            DreamBoxAward: new ConfigBase().initTable("DreamBoxAward", "DreamBoxId", ["DreamBoxId"]),
25
+            DreamConstConfig: new ConfigBase().initTable("DreamConstConfig", "main_key"),
26
+            GoodsConfig: new ConfigBase().initTable("GoodsConfig", "id"),
27
+            ResItemConfig: new ConfigBase().initTable("ResItemConfig", "id"),
28
+            ResItemModelConfig: new ConfigBase().initTable("ResItemModelConfig", "id"),
29
+            ResItemModelTypeConfig: new ConfigBase().initTable("ResItemModelTypeConfig", "id"),
30
+            ResItemQualityConfig: new ConfigBase().initTable("ResItemQualityConfig", "id"),
31
+            ResItemQualityPrice: new ConfigBase().initTable("ResItemQualityPrice", "id"),
32
+            ResItemSurfaceConfig: new ConfigBase().initTable("ResItemSurfaceConfig", "id"),
33
+            ResItemTypeConfig: new ConfigBase().initTable("ResItemTypeConfig", "id"),
34
+            Sheet1: new ConfigBase().initTable("Sheet1", "id"),
35
+        };
36
+        this.curLoadingIndex = 0;
37
+    },
38
+
39
+    loadAllConfig() {
40
+        this.loadConfig();
41
+    },
42
+
43
+    loadConfig() {
44
+        for (const [key, config] of Object.entries(this.configs)) {
45
+            if (config.isLoadFinish) {
46
+                continue;
47
+            }
48
+            let self = this;
49
+            cc.loader.loadRes("res_json/" + config.tableName, function(err, jsonAsset) {
50
+                if (err) {
51
+                    cc.error(err);
52
+                    return;
53
+                }
54
+
55
+                config.setTable(jsonAsset.json)
56
+                config.isLoadFinish = true;
57
+                self.curLoadingIndex += 1;
58
+                if (self.updateLoadCb) {
59
+                    self.updateLoadCb();
60
+                }
61
+                self.loadConfig()
62
+            });
63
+            break
64
+        }
65
+
66
+        if (this.curLoadingIndex < Object.keys(this.configs).length) {
67
+            return
68
+        }
69
+
70
+        if (this.loadFinishCb) {
71
+            this.loadFinishCb()
72
+        }
73
+        
74
+        cc.game.emit('e_mgr_load_config_done');
75
+    },
76
+}
77
+
78
+module.exports = CfgMgr;

+ 9 - 0
assets/script/core/model/CfgMgr.js.meta

@@ -0,0 +1,9 @@
1
+{
2
+  "ver": "1.0.8",
3
+  "uuid": "0e56f071-beb4-4f53-a1bb-74b6b2b081e6",
4
+  "isPlugin": false,
5
+  "loadPluginInWeb": true,
6
+  "loadPluginInNative": true,
7
+  "loadPluginInEditor": false,
8
+  "subMetas": {}
9
+}

+ 11 - 10
assets/script/core/utils/MgrUtils.js

@@ -47,17 +47,18 @@ module.exports = {
47
      * @returns
47
      * @returns
48
      */
48
      */
49
     loadAllConfig () {
49
     loadAllConfig () {
50
-        cc.loader.loadRes('res_json/AllConfig', cc.JsonAsset, (err, jsonAsset) => {
51
-            if (err) {
52
-                G.LogUtils.log('Load AllConfig err: %s', err.stack);
53
-                return;
54
-            }
50
+        
51
+        // cc.loader.loadRes('res_json/AllConfig', cc.JsonAsset, (err, jsonAsset) => {
52
+        //     if (err) {
53
+        //         G.LogUtils.log('Load AllConfig err: %s', err.stack);
54
+        //         return;
55
+        //     }
55
 
56
 
56
-            this.allConfig =  jsonAsset.json;
57
-            cc.loader.releaseRes('res_json/AllConfig');
57
+        //     this.allConfig =  jsonAsset.json;
58
+        //     cc.loader.releaseRes('res_json/AllConfig');
58
 
59
 
59
-            // 发送策划表更新消息
60
-            cc.game.emit('e_mgr_load_config_done');
61
-        });
60
+        //     // 发送策划表更新消息
61
+        //     cc.game.emit('e_mgr_load_config_done');
62
+        // });
62
     }
63
     }
63
 };
64
 };

+ 2 - 1
assets/script/launch/ctrl/LaunchCtrl.js

@@ -120,7 +120,8 @@ cc.Class({
120
 
120
 
121
     // 加载全部的配置
121
     // 加载全部的配置
122
     loadAllConfig () {
122
     loadAllConfig () {
123
-        G.MgrUtils.loadAllConfig();
123
+        // G.MgrUtils.loadAllConfig();
124
+        G.CfgMgr.loadAllConfig()
124
     },
125
     },
125
 
126
 
126
     // 更新检测,目前暂时跳过
127
     // 更新检测,目前暂时跳过