init
This commit is contained in:
@@ -0,0 +1,243 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
properties: {
|
||||
Progress: {
|
||||
default: null,
|
||||
type: cc.ProgressBar
|
||||
},
|
||||
ProgressText: {
|
||||
default: null,
|
||||
type: cc.Label
|
||||
},
|
||||
showText: {
|
||||
default: null,
|
||||
type: cc.Label
|
||||
}
|
||||
},
|
||||
onLoad: function () {
|
||||
this.Progress.progress = 0;
|
||||
this.lodeNum = 0;
|
||||
window.GameLoad = this;
|
||||
this.needLoadNum = 5;
|
||||
window.uc && (GlobData.isUcMiNiGame = true);
|
||||
},
|
||||
start: function () {
|
||||
if (cc.sys.platform == cc.sys.VIVO_GAME) {
|
||||
window.GameConfig.ShowTuiSongCiShu = window.ShowTuiSongCiShu;
|
||||
window.GameConfig.closebtnYC = window.closebtnYC;
|
||||
window.GameConfig.showhand = window.showhand;
|
||||
this.executeLoadSubpackage();
|
||||
} else {
|
||||
window.getMyLocation(this.executeLoadSubpackage.bind(this));
|
||||
}
|
||||
GlobData.doInitialize();
|
||||
},
|
||||
onLoadScene: function () {
|
||||
console.log("开始加载场景");
|
||||
cc.director.preloadScene("GameMain", function (e, o, t) {
|
||||
this.Progress.progress = e / o;
|
||||
this.ProgressText.string = Math.round(e / o * 100 * 10) / 10 + "%";
|
||||
}.bind(this), function () {
|
||||
console.log("home场景加载完成");
|
||||
cc.loader.onProgress = null;
|
||||
this.onToGame();
|
||||
}.bind(this));
|
||||
},
|
||||
onLoadScene_game: function () {
|
||||
cc.director.preloadScene("GameScene", function (e, o, t) {
|
||||
this.Progress.progress = e / o;
|
||||
this.ProgressText.string = Math.round(e / o * 100 * 10) / 10 + "%";
|
||||
}.bind(this), function () {
|
||||
console.log("game场景加载完成");
|
||||
cc.loader.onProgress = null;
|
||||
this.onToGame();
|
||||
}.bind(this));
|
||||
},
|
||||
onToGame: function () {
|
||||
this.lodeNum++;
|
||||
console.log("onToGame:", this.lodeNum);
|
||||
if (this.lodeNum >= this.needLoadNum) {
|
||||
cc.global.isOneShowHome = false;
|
||||
cc.director.loadScene("GameMain");
|
||||
cc.global.isShowMaincishu = 0;
|
||||
}
|
||||
},
|
||||
onLoadFunClass: function () {
|
||||
cc.Numerical = require("Numerical");
|
||||
cc.Utils = require("Utils");
|
||||
new (require("GlobalVariable"))().init();
|
||||
cc.global.Source = new (require("AudioSourceScript"))();
|
||||
cc.global.Source.init();
|
||||
cc.systemEvent.setAccelerometerEnabled(true);
|
||||
var o = cc.director.getScene().getChildByName("zhiyinNode");
|
||||
cc.game.addPersistRootNode(o);
|
||||
cc.global.zhiyinNode = o.getComponent("GuoChangScript");
|
||||
o.zIndex = 11;
|
||||
var t = cc.director.getScene().getChildByName("hintWindow");
|
||||
cc.game.addPersistRootNode(t);
|
||||
t.zIndex = 11;
|
||||
cc.global.hintText = t.getComponent("HintWindowScript");
|
||||
var i = cc.director.getScene().getChildByName("loadingWindow");
|
||||
cc.game.addPersistRootNode(i);
|
||||
i.zIndex = 10;
|
||||
cc.global.loadingWindow = i;
|
||||
console.log("功能类载入完成");
|
||||
this.onToGame();
|
||||
},
|
||||
loadAudioPath: function () {
|
||||
cc.Audios = {};
|
||||
cc.loader.loadResDir("game1/textures/sounds/", function (e, o, t) {}.bind(this), function (e, o) {
|
||||
if (null == e) {
|
||||
o.forEach(function (e) {
|
||||
cc.Audios[e.name] = e;
|
||||
});
|
||||
} else {
|
||||
console.error("声音加载出错", e);
|
||||
}
|
||||
console.log("声音全部载入完成");
|
||||
this.onToGame();
|
||||
}.bind(this));
|
||||
},
|
||||
getLocalStorage: function () {
|
||||
if (cc.sys.localStorage.getItem("gameId_hhds")) {
|
||||
console.log("不需要初始化存储");
|
||||
cc.global.isGuidance = false;
|
||||
} else {
|
||||
console.log("需要初始化存储");
|
||||
cc.sys.localStorage.clear();
|
||||
cc.sys.localStorage.setItem("gameId_hhds", "true");
|
||||
cc.global.isGuidance = true;
|
||||
}
|
||||
cc.global.Source.init();
|
||||
if (s = cc.sys.localStorage.getItem("lastOnLineTime")) {
|
||||
cc.global.lastOnLineTime = parseInt(s);
|
||||
} else {
|
||||
cc.sys.localStorage.setItem("lastOnLineTime", JSON.stringify(cc.global.lastOnLineTime));
|
||||
}
|
||||
var e = cc.sys.localStorage.getItem("signInfo");
|
||||
if (e) {
|
||||
cc.global.signInfo = JSON.parse(e);
|
||||
} else {
|
||||
cc.sys.localStorage.setItem("signInfo", JSON.stringify(cc.global.signInfo));
|
||||
}
|
||||
var o = this.onGetTimeInfo(cc.global.lastOnLineTime);
|
||||
var t = o.isSameWeek;
|
||||
var i = o.isSameDay;
|
||||
o.intervalTime;
|
||||
var n = cc.global.signInfo.days;
|
||||
var a = cc.global.signInfo.allow;
|
||||
this.isReset = false;
|
||||
if (1 == t) {
|
||||
if (!(1 == i)) {
|
||||
a = true, this.isReset = true;
|
||||
}
|
||||
} else {
|
||||
n = 0;
|
||||
a = true;
|
||||
this.isReset = true;
|
||||
}
|
||||
var c = {
|
||||
days: n,
|
||||
allow: a
|
||||
};
|
||||
cc.global.signInfo = c;
|
||||
cc.sys.localStorage.setItem("signInfo", JSON.stringify(cc.global.signInfo));
|
||||
if (1 == this.isReset) {
|
||||
cc.global.power = 10;
|
||||
cc.sys.localStorage.setItem("power", JSON.stringify(cc.global.power));
|
||||
}
|
||||
var s = new Date().getTime();
|
||||
cc.sys.localStorage.setItem("lastOnLineTime", JSON.stringify(s));
|
||||
this.onToGame();
|
||||
},
|
||||
onGetTimeInfo: function (e) {
|
||||
e > 0 || (e = parseInt(e));
|
||||
var o = new Date().getTime();
|
||||
var t = new Date(e);
|
||||
var i = new Date(o);
|
||||
var n = t.getDay();
|
||||
var a = i.getDay();
|
||||
0 == a && (a = 7);
|
||||
0 == n && (n = 7);
|
||||
var c = false;
|
||||
var s = false;
|
||||
var l = parseInt((o - e) / 1e3);
|
||||
if (n < a) {
|
||||
o - e < 6048e5 && (c = true);
|
||||
} else if (n == a && o - e < 864e5) {
|
||||
c = true, s = true;
|
||||
}
|
||||
return {
|
||||
isSameWeek: c,
|
||||
isSameDay: s,
|
||||
intervalTime: l
|
||||
};
|
||||
},
|
||||
executeLoadSubpackage: function () {
|
||||
console.log("开始加载分包");
|
||||
var e = null;
|
||||
if (e = window.swan ? window.swan : window.qq ? window.qq : window.tt ? window.tt : cc.sys.platform == cc.sys.OPPO_GAME ? window.qg : window.ks ? ks : null) {
|
||||
e.showLoading({
|
||||
title: "加载数据中,请稍等...",
|
||||
mask: true,
|
||||
success: function () {
|
||||
return console.log("loading\xA0提示框显示成功");
|
||||
}
|
||||
});
|
||||
var o = function (o, t) {
|
||||
if ((console.log("当前加载分包包名:", o), window.ks) && !kwaigame.isSupport(kwaigame.Support.features.Subpackage)) {
|
||||
window.require(o + "/main.js");
|
||||
return void ("bao3" == o && t());
|
||||
}
|
||||
e.loadSubpackage({
|
||||
name: o,
|
||||
success: function (e) {
|
||||
console.log("加载分包\xA0success");
|
||||
t();
|
||||
},
|
||||
fail: function (o) {
|
||||
console.log("加载分包\xA0fail");
|
||||
if (window.ks) {
|
||||
e.hideLoading();
|
||||
ks.showToast({
|
||||
title: "请检查网络连接是否正常",
|
||||
icon: "none",
|
||||
duration: 1e4
|
||||
});
|
||||
}
|
||||
}
|
||||
}).onProgressUpdate(function (e) {
|
||||
console.log("下载进度", e.progress);
|
||||
console.log("已经下载的数据长度", e.totalBytesWritten);
|
||||
console.log("预期需要下载的数据总长度", e.totalBytesExpectedToWrite);
|
||||
});
|
||||
};
|
||||
(function (e, t) {
|
||||
var i = 0;
|
||||
o(e[i], function n() {
|
||||
if (++i >= e.length) {
|
||||
t();
|
||||
} else {
|
||||
o(e[i], n);
|
||||
}
|
||||
});
|
||||
})(["bao1", "bao2", "bao3", "bao4", "bao5"], function () {
|
||||
e.hideLoading({});
|
||||
this.startLoadApplication();
|
||||
}.bind(this));
|
||||
} else {
|
||||
this.startLoadApplication();
|
||||
}
|
||||
},
|
||||
startLoadApplication: function () {
|
||||
console.log("游戏配置:", window.GameConfig);
|
||||
GlobData.onAndroidInit();
|
||||
this.onLoadFunClass();
|
||||
this.loadAudioPath();
|
||||
this.getLocalStorage();
|
||||
this.onLoadScene();
|
||||
this.onToGame();
|
||||
var o = require("Platform");
|
||||
cc.PlatformTools = new o();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user