Ver código fonte

【修改】 修改配置表加载

Hua 1 ano atrás
pai
commit
e03ff1f1de

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

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

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

@@ -8,14 +8,16 @@ cc.Class({
8 8
         multiple:[],
9 9
         multipleCache:null,
10 10
         table:null,
11
+        tableName:"",
12
+        isLoadFinish:false,
11 13
     },
12 14
 
13 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 21
         this.mainKey = mainKey;
20 22
         this.multiple = multipleKey;
21 23
 
@@ -24,20 +26,19 @@ cc.Class({
24 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 34
     getByMainKey(idx) {
35
+        // 从缓存中拿数据
36 36
         let data = this.indexsCache[idx]
37 37
         if (data != undefined) {
38 38
             return data;
39 39
         }
40 40
         
41
+        // 找数据
41 42
         for (let d of this.table) {
42 43
             if (d[this.mainKey] == idx) {
43 44
                 data = d;
@@ -45,11 +46,15 @@ cc.Class({
45 46
             }
46 47
         }
47 48
 
49
+        // 缓存数据
48 50
         this.indexsCache[data[this.mainKey]] = data;
49 51
         return data;
50 52
     },
51 53
 
54
+    // 从多主键中,拿数据
52 55
     getByMultipleKey() {
56
+
57
+        // 参数跟多主键数量对应不上
53 58
         if (arguments.length != this.multiple.length) {
54 59
             if (arguments.length <= 0) {
55 60
                 cc.log("multiple key is null");
@@ -59,15 +64,18 @@ cc.Class({
59 64
             return null;
60 65
         }
61 66
 
67
+        // 从缓存中拿数据
62 68
         let curCache = this.findMultipleCache(arguments);
63 69
         if (curCache != null)
64 70
         {
65 71
             return curCache;
66 72
         }
67 73
 
74
+        // 查找数据
68 75
         return this.getAndAddMultiple(arguments);
69 76
     },
70 77
 
78
+    // 拿多主键数据并缓存
71 79
     getAndAddMultiple(args)
72 80
     {
73 81
         var result = [];
@@ -106,6 +114,7 @@ cc.Class({
106 114
         return result;
107 115
     },
108 116
 
117
+    // 从多主键缓存中拿数据
109 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 47
      * @returns
48 48
      */
49 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 122
     loadAllConfig () {
123
-        G.MgrUtils.loadAllConfig();
123
+        // G.MgrUtils.loadAllConfig();
124
+        G.CfgMgr.loadAllConfig()
124 125
     },
125 126
 
126 127
     // 更新检测,目前暂时跳过