Просмотр исходного кода

预加载子游戏个数改为可配置.

zhaoyu_ma 4 месяцев назад
Родитель
Сommit
4331c18b47
1 измененных файлов с 18 добавлено и 5 удалено
  1. 18 5
      luckypot_sp/assets/Lobby/scripts/homesence/homeStartDev.js

+ 18 - 5
luckypot_sp/assets/Lobby/scripts/homesence/homeStartDev.js

@@ -156,7 +156,7 @@ cc.Class({
 
 
         //设置初始预加载的子游戏
         //设置初始预加载的子游戏
     initPreSubGame(){
     initPreSubGame(){
-        /*
+        // /*
         //临时生成节点
         //临时生成节点
         let tnode = new cc.Node('lab');
         let tnode = new cc.Node('lab');
         tnode.setPosition(-521, 272);
         tnode.setPosition(-521, 272);
@@ -170,14 +170,15 @@ cc.Class({
         tnode2.addComponent(cc.Label);
         tnode2.addComponent(cc.Label);
         tnode2.getComponent(cc.Label).fontSize = 30;
         tnode2.getComponent(cc.Label).fontSize = 30;
         tnode2.parent = this.node;
         tnode2.parent = this.node;
-        */
-
+        // */
+        this.preLoadSubGameNums = 3; //预加载的子游戏个数
 
 
         let obj = [
         let obj = [
             // {kindID: GameConstant.KIND_ID_NTIGER,  weight: 30},  //老虎
             // {kindID: GameConstant.KIND_ID_NTIGER,  weight: 30},  //老虎
             // {kindID: GameConstant.KIND_ID_OLYMPUS, weight: 20},  //雷神
             // {kindID: GameConstant.KIND_ID_OLYMPUS, weight: 20},  //雷神
             // {kindID: GameConstant.KIND_ID_FRUIT9X, weight: 10}   //9线
             // {kindID: GameConstant.KIND_ID_FRUIT9X, weight: 10}   //9线
         ];
         ];
+
         for(let item of cc.vv.miniGameSort){
         for(let item of cc.vv.miniGameSort){
             if(item.KindID == GameConstant.KIND_ID_NTIGER){
             if(item.KindID == GameConstant.KIND_ID_NTIGER){
                 obj.push({kindID: GameConstant.KIND_ID_NTIGER, weight: 30});
                 obj.push({kindID: GameConstant.KIND_ID_NTIGER, weight: 30});
@@ -189,6 +190,14 @@ cc.Class({
                 obj.push({kindID: GameConstant.KIND_ID_FRUIT9X, weight: 10});
                 obj.push({kindID: GameConstant.KIND_ID_FRUIT9X, weight: 10});
             }
             }
         }
         }
+        obj.sort((a, b)=>{
+            return b.weight - a.weight;
+        });
+        if(obj.length > this.preLoadSubGameNums){
+            let lerp = obj.length - this.preLoadSubGameNums;
+            obj.splice(-lerp, lerp);
+        }
+
         let str = JSON.stringify(obj);
         let str = JSON.stringify(obj);
         let xx = Global.getLocalStorageVaule("preSubGames");
         let xx = Global.getLocalStorageVaule("preSubGames");
         if(!xx){
         if(!xx){
@@ -674,7 +683,7 @@ cc.Class({
         if(!bContain){ //当前进入的子游戏不在预加载子游戏列表中
         if(!bContain){ //当前进入的子游戏不在预加载子游戏列表中
             //移除权重最低的子游戏
             //移除权重最低的子游戏
             let tempName = config[preArr[0].kindID].bundle;
             let tempName = config[preArr[0].kindID].bundle;
-            // this.node.getChildByName('lab2').getComponent(cc.Label).string ='移除bundle: ' + tempName;
+            this.node.getChildByName('lab2').getComponent(cc.Label).string ='移除bundle: ' + tempName;
             let bundle = cc.assetManager.getBundle(tempName);
             let bundle = cc.assetManager.getBundle(tempName);
             if(bundle){
             if(bundle){
                 // window.nowBundle = null;
                 // window.nowBundle = null;
@@ -686,7 +695,11 @@ cc.Class({
             preArr[0].kindID = optdata.KindID; //给移除的bundle重新赋值
             preArr[0].kindID = optdata.KindID; //给移除的bundle重新赋值
             preArr[0].weight = 30;
             preArr[0].weight = 30;
         }
         }
-        // this.node.getChildByName('lab').getComponent(cc.Label).string =`当前bundle: ${config[preArr[0].kindID].bundle}:${preArr[0].weight},  ${config[preArr[1].kindID].bundle}:${preArr[1].weight},  ${ config[preArr[2].kindID].bundle}:${preArr[2].weight}`;
+        let des = '';
+        for(let i=0; i < preArr.length; i++){
+            des += config[preArr[i].kindID].bundle + ':' + preArr[i].weight + '  ';
+        }
+        this.node.getChildByName('lab').getComponent(cc.Label).string = '当前bundle: ' + des;
         //修改本地缓存
         //修改本地缓存
         let str = JSON.stringify(preArr);
         let str = JSON.stringify(preArr);
         Global.setLocalStorageVaule("preSubGames", str);
         Global.setLocalStorageVaule("preSubGames", str);