255 lines
5.9 KiB
JavaScript
255 lines
5.9 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '625c07TpBBFqYXa1zAulYZU', 'cmp.login.loading');
|
|
// Scripts/mod/login/cmp/cmp.login.loading.js
|
|
|
|
"use strict";
|
|
|
|
/******************************************************************
|
|
*
|
|
* 启动
|
|
*
|
|
******************************************************************/
|
|
|
|
var WndLogin = require("scene.login");
|
|
var ModuleInfo = require("modulelist");
|
|
var BDef = require("bridge.define");
|
|
|
|
// 加载阶段
|
|
var Stages = {
|
|
"basic": [10, "LoadingTexts"],
|
|
// 核心文本
|
|
"config": [20, "LoadingConfigs"],
|
|
//
|
|
"mods": [30, "LoadingMods"],
|
|
// 业务模块载入
|
|
"ready": [50, "LoadingReady"],
|
|
// 前端准备完毕同步
|
|
"svrData": [80, "LoadingInitModules"],
|
|
// 基本数据同步
|
|
"preload": [95, "LoadingPreload"],
|
|
// 资源预加载
|
|
"done": [100, "LoadingDone"] // 进入游戏
|
|
};
|
|
|
|
// 本地准备完毕进度
|
|
var ReadyProgress = 30;
|
|
cc.Class({
|
|
"extends": cc.Component,
|
|
properties: {
|
|
wndLogin: {
|
|
"default": null,
|
|
type: WndLogin
|
|
},
|
|
progBar: {
|
|
"default": null,
|
|
type: cc.ProgressBar
|
|
},
|
|
labTip: {
|
|
"default": null,
|
|
type: cc.Label
|
|
},
|
|
labPercent: {
|
|
"default": null,
|
|
type: cc.Label
|
|
}
|
|
},
|
|
// 载入
|
|
onLoad: function onLoad() {
|
|
this.progCur = 0;
|
|
this.progTar = 0;
|
|
this.progSpeed = 0;
|
|
this.isReady = false;
|
|
this.descError = "";
|
|
this.progBar.progress = 0;
|
|
this.labTip.string = "";
|
|
this.labPercent = "";
|
|
|
|
// 如果是返回到登录的
|
|
var stage = nx.bridge.vgetOld("GS");
|
|
if (stage == BDef.GameStage.Game) {
|
|
// 更新阶段
|
|
this.setStage("ready");
|
|
} else {
|
|
// 重新开始加载
|
|
this.loadTexts();
|
|
}
|
|
},
|
|
// 检查是否准备完成
|
|
checkReady: function checkReady(_init) {
|
|
if (_init === void 0) {
|
|
_init = false;
|
|
}
|
|
if (!this.node.active) {
|
|
return;
|
|
}
|
|
|
|
// 是否发生错误
|
|
if (nx.dt.strNEmpty(this.descError)) {
|
|
nx.mbox(this.descError, ['retry'], function (_key, _box) {
|
|
nx.restart();
|
|
}, "LoadingError");
|
|
return;
|
|
}
|
|
|
|
// 准备完成
|
|
if (this.isReady) {
|
|
this.readyResources();
|
|
}
|
|
},
|
|
// 更新
|
|
update: function update(_dt) {
|
|
if (this.progSpeed <= 0 || this.progCur >= this.progTar) {
|
|
return;
|
|
}
|
|
this.progCur += this.progSpeed * _dt;
|
|
if (this.progCur >= this.progTar) {
|
|
this.progCur = this.progTar;
|
|
}
|
|
if (this.progCur > 100) {
|
|
this.progCur = 100;
|
|
}
|
|
if (this.progBar) {
|
|
this.progBar.progress = this.progCur / 100;
|
|
}
|
|
if (this.labPercent) {
|
|
this.labPercent.string = Math.floor(this.progCur) + "%";
|
|
}
|
|
if (this.progCur >= ReadyProgress && !this.isReady) {
|
|
this.isReady = true;
|
|
this.checkReady();
|
|
return;
|
|
}
|
|
},
|
|
// 文本载入
|
|
loadTexts: function loadTexts() {
|
|
var _this = this;
|
|
// 更新阶段
|
|
this.setStage("basic");
|
|
nx.text.rebuild(false, function (_err, _cnt, _max) {
|
|
if (_err) {
|
|
_this.setError("errLoadingText");
|
|
return;
|
|
}
|
|
if (_cnt >= _max) {
|
|
_this.loadCfgs();
|
|
}
|
|
});
|
|
},
|
|
// 配置载入
|
|
loadCfgs: function loadCfgs() {
|
|
// 更新阶段
|
|
this.setStage("config");
|
|
var self = this;
|
|
var queue = nx.dt.objClone(ModuleInfo.configs);
|
|
var popup = function popup() {
|
|
if (queue.length == 0) {
|
|
self.instModules();
|
|
return;
|
|
}
|
|
var tm = queue.shift();
|
|
var path = cc.path.join("configs/excels", tm);
|
|
cc.loader.loadRes(path, function (err, data) {
|
|
if (err) {
|
|
console.log("data not exist!!!!!", tm);
|
|
} else {
|
|
game.configs[tm] = data.json;
|
|
}
|
|
popup();
|
|
});
|
|
};
|
|
// 开始
|
|
popup();
|
|
},
|
|
// 模块载入
|
|
instModules: function instModules() {
|
|
// 更新阶段
|
|
this.setStage("mods");
|
|
var ModuleInfo = require("modulelist");
|
|
var queue = nx.dt.objClone(ModuleInfo.modules);
|
|
while (queue.length > 0) {
|
|
var item = queue.shift();
|
|
nx.bridge.mods.install(item[0], item[1]);
|
|
}
|
|
;
|
|
|
|
// 预加载资源
|
|
// this.preloadResources();
|
|
},
|
|
|
|
// 资源准备完毕
|
|
readyResources: function readyResources() {
|
|
var _this2 = this;
|
|
// 更新阶段
|
|
this.setStage("ready");
|
|
nx.bridge.game.gameReady(function (_ret, _data) {
|
|
if (!_ret) {
|
|
_this2.setError(_data);
|
|
return;
|
|
}
|
|
|
|
// 模块首次刷新
|
|
_this2.initModules();
|
|
});
|
|
},
|
|
// 模块首次刷新
|
|
initModules: function initModules() {
|
|
var _this3 = this;
|
|
// 更新阶段
|
|
this.setStage("svrData");
|
|
nx.bridge.game.initModules(function (_ret, _data) {
|
|
if (!_ret) {
|
|
_this3.setError(_data);
|
|
return;
|
|
}
|
|
|
|
// 预加载资源
|
|
_this3.preloadResources();
|
|
});
|
|
},
|
|
// 预加载资源
|
|
preloadResources: function preloadResources() {
|
|
// 更新阶段
|
|
this.setStage("preload");
|
|
var self = this;
|
|
var queue = [];
|
|
|
|
// 首次进入引导
|
|
if (nx.dt.arrEmpty(nx.bridge.plot.records.ids)) {
|
|
queue = [cc.path.join("prefab/mainui", "wnd_first_enter"), cc.path.join("prefab/plot", "wnd_plot_dialogue")];
|
|
} else {
|
|
queue = [cc.path.join("prefab/mainui", "scene_main")];
|
|
}
|
|
var next = function next() {
|
|
if (queue.length == 0) {
|
|
self.loadingDone();
|
|
return;
|
|
}
|
|
nx.res.loadPrefab(queue.shift(), function () {
|
|
next();
|
|
});
|
|
};
|
|
next();
|
|
},
|
|
// 加载完毕
|
|
loadingDone: function loadingDone() {
|
|
// 更新阶段
|
|
this.setStage("done");
|
|
this.scheduleOnce(function () {
|
|
nx.bridge.game.enterGame();
|
|
}, 0.2);
|
|
},
|
|
// 发生错误
|
|
setError: function setError(_desc) {
|
|
this.descError = _desc || "";
|
|
nx.error("发生错误:" + _desc);
|
|
},
|
|
// 设置进度
|
|
setStage: function setStage(_st) {
|
|
var info = Stages[_st];
|
|
this.progTar = info[0];
|
|
this.progSpeed = (this.progTar - this.progCur) * 2;
|
|
this.labTip.string = nx.text.getKey(info[1]);
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |