2025-04-24 17:03:28 +08:00

197 lines
9.0 KiB
TypeScript

import FGUtil from "../gear_2.3.4/fgui/FGUtil";
import SKHotUpdate from "../gear_2.3.4/util/SKHotUpdate";
import GameModel from "../core/GameModel";
import SKNetTask from "../gear_2.3.4/net/SKNetTask";
import JSUtil = require("../core/JSUtil");
import SKLoadData, { SKLoadType } from "../gear_2.3.4/util/SKLoadData";
import SKLoader from "../gear_2.3.4/util/SKLoader";
import SKDataUtil from "../gear_2.3.4/util/SKDataUtil";
import SKUIUtil from "../gear_2.3.4/util/SKUIUtil";
import SKLocalUtil from "../gear_2.3.4/util/SKLocalUtil";
import SKSocket from "../gear_2.3.4/net/SKSocket";
import Report from "../gear_2.3.4/net/Report";
import PetUtil from "../game/pet/PetUtil";
import SKLogger from "../gear_2.3.4/util/SKLogger";
import ItemUtil from "../core/ItemUtil";
const { ccclass, property } = cc._decorator;
@ccclass
export default class LoadSceneGo extends cc.Component {
private main: fgui.GComponent;
private load_tf: fgui.GTextField;
@property(cc.Label)
TextVersion: cc.Label = null;
onLoad() {
cc.log("LoadSceneGo")
cc.game.setFrameRate(60);
ItemUtil.launch();
JSUtil.init();
//讀取隱藏玩家設置
GameModel.hideNotTeam = SKLocalUtil.boolForKey('setting_hide_not_team');
FGUtil.regFonts("ttf", () => {
this.loadGUI();
});
GameModel.launch();
cc.debug.setDisplayStats(false)
}
loadGUI() {
FGUtil.load("gui/load_scene", null, (error) => {
if (error) {
SKLogger.warn(`加載場景錯誤:${error}`);
return;
}
this.initUI();
})
}
initUI() {
this.main = FGUtil.create("load_scene", "load_main");
FGUtil.root().addChild(this.main);
FGUtil.fitScreen(this.main);
// let version_lb = FGUtil.getTextField(this.main, "version_lb");
// if (version_lb) {
// version_lb.text = GameModel.version;
// }
let version = GameModel.version;
this.TextVersion.string = `版本號:${version}`;
this.load_tf = FGUtil.getTextField(this.main, "load_lb");
SKHotUpdate.changeBlock = (info: string) => {
this.load_tf.text = info;
};
SKHotUpdate.progressBlock = (info: string) => {
this.load_tf.text = info;
};
SKHotUpdate.endBlock = () => {
SKHotUpdate.changeBlock = null;
SKHotUpdate.progressBlock = null;
SKHotUpdate.endBlock = null;
this.loadMain();
};
SKHotUpdate.checkUpdate();
}
loadMain() {
// 遊戲首次加載
let list = [];
list.push(new SKLoadData(SKLoadType.Json, "config/game_conf", "正在獲取版本信息"));
list.push(new SKLoadData(SKLoadType.Gui, "gui/main_ui", "正在獲取版本信息"));
list.push(new SKLoadData(SKLoadType.Text, "Common/c2s", "正在獲取版本信息"));
list.push(new SKLoadData(SKLoadType.Json, "ip/ip", "正在獲取版本信息"));
list.push(new SKLoadData(SKLoadType.Dir, "Login", "正在獲取版本信息"));
list.push(new SKLoadData(SKLoadType.Dir, "prop_data", "正在獲取版本信息"));
SKLoader.shared.load(list, (data: SKLoadData, progress: number) => {
//this.load_tf.text = `${data.info}${(progress * 100).toFixed(2)}%`;
}, (data: SKLoadData, resources: any[], urls: string[]) => {
switch (data.url) {
case "config/game_conf":
let temp = SKDataUtil.jsonAssetBy(resources[0]);
GameModel.game_conf = temp.json;
PetUtil.initPetColor();
break;
case "Common/c2s":
let c2s = SKDataUtil.textAssetByList(resources, 0);
if (c2s) {
let temp = protobuf.parse(c2s.text);
SKSocket.pbroot = temp.root;
}
break;
case "ip/ip":
let ipconfig = SKDataUtil.jsonAssetByList(resources, 0);
let ip1 = ipconfig.json.i1;
let ip2 = ipconfig.json.i2;
let ip3 = ipconfig.json.i3;
let ip4 = ipconfig.json.i4;
let ip = ip1 + ip2 + ip3 + ip4;
let debug = ipconfig.json.bug;
GameModel.isDebug = debug;
Report.isDebug = GameModel.isDebug;
SKLogger.isDebug = debug;
// let debugIP1 = ipconfig.json.dip1;
// let debugIP2 = ipconfig.json.dip2;
// let debugIP = debugIP1 + debugIP2;
// if (debug) {
// if (debugIP == "127.0.0.1" && cc.sys.os == cc.sys.OS_ANDROID) {
// debugIP == "10.0.0.2";
// }
// ip = debugIP;
// }
let port1 = ipconfig.json.p1;
let port2 = ipconfig.json.p2;
let port = port1 + port2;
SKNetTask.baseURL = `http://${ip}:${port}`;
break;
case "prop_data":
for (let item of resources) {
let temp = SKDataUtil.jsonAssetBy(item);
if (temp.isValid) {
let name = temp.name;
if (name.indexOf("prop_skill") != -1) {
GameModel.conf_skill = temp.json;
} else if (name.indexOf("login_roleinfo") != -1) {
GameModel.conf_login = temp.json;
} else if (name.indexOf("prop_charge_reward1") != -1) {
GameModel.conf_charge_reward = temp.json;
} else if (name.indexOf("prop_charge_reward2") != -1) {
GameModel.conf_charge_reward2 = temp.json;
} else if (name.indexOf("prop_charge_reward3") != -1) {
GameModel.conf_charge_reward3 = temp.json;
} else if (name.indexOf("prop_xinshou_equip") != -1) {
GameModel.conf_equip = temp.json;
} else if (name.indexOf('prop_createbg') != -1) {
GameModel.conf_create_bg = temp.json;
} else if (name.indexOf('prop_rolecolor') != -1) {
GameModel.conf_role_color = temp.json;
} else if (name.indexOf('prop_role') != -1) {
GameModel.conf_role = temp.json;
} else if (name.indexOf('prop_map') != -1) {
GameModel.conf_map = temp.json;
} else if (name.indexOf('prop_charge') != -1) {
GameModel.conf_charge = temp.json;
} else if (name.indexOf('prop_level') != -1) {
GameModel.conf_level = temp.json;
} else if (name.indexOf('prop_npc') != -1) {
GameModel.conf_npc = temp.json;
} else if (name.indexOf('prop_pet') != -1) {
GameModel.conf_pet = temp.json;
} else if (name.indexOf('prop_resAnchor') != -1) {
GameModel.conf_res_anchor = temp.json;
} else if (name.indexOf('prop_skill') != -1) {
GameModel.conf_skill = temp.json;
} else if (name.indexOf('prop_task') != -1) {
GameModel.conf_task = temp.json;
} else if (name.indexOf('prop_transfer_point') != -1) {
GameModel.conf_transfer = temp.json;
} else if (name.indexOf('map_') != -1) {
let mapid = name.substr(name.indexOf('map_') + 4);
GameModel.conf_map_list[mapid] = temp.json;
} else if (name.indexOf('prop_transformmation') != -1) {
GameModel.conf_transformation = temp.json;
} else if (name.indexOf('playing_method') != -1) {
GameModel.conf_playing_method = temp.json;
} else if(name.indexOf('game_info') != -1){
GameModel.conf_game_info = temp.json;
} else {
cc.log(`未解析的JSON配置:${name}`);
}
}
}
break;
}
}, () => {
this.load_tf.text = `正在登錄...`;
SKUIUtil.loadScene("LoginScene", (completedCount, totalCount, item) => {
//let info = `加載登錄場景...${(completedCount / totalCount * 100).toFixed(2)}%`;
//this.load_tf.text = info;
}, (sceneName: string) => {
GameModel.currentScene = sceneName;
});
});
}
}