123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- let GameConstant = require('GameConstant');
- let GameUpdate = require("GameUpdate");
- let Global = require("Global");
- let BaseDefine = require("BaseDefine");
- var topTipMsg = require("topTipMsg");
- let _BundleLoaderManager = null;
- window.bundles = {};
- class BundleLoaderManager {
- constructor() {
- this.taskList = {};
- this.bundleBaseData = {
- [GameConstant.KIND_ID_BRAB]: {
- bundle: "BRAB",
- taskID: 1,
- importBundle: ["TP_Public", "DSP_Public"],
- gamePrefabPath: ["BRABGameScence", "Base/TP"]
- }, [GameConstant.KIND_ID_BRTP]: {
- bundle: "BRTP",
- taskID: 2,
- importBundle: ["TP_Public", "DSP_Public"],
- gamePrefabPath: ["BRTPGameSence"]
- }, [GameConstant.KIND_ID_SGLB]: {
- bundle: "SGLB",
- taskID: 3,
- importBundle: ["LB"],
- gamePrefabPath: ["SGLBGameSence"]
- }, [GameConstant.KIND_ID_LBROMAN]: {
- bundle: "ROMAN",
- taskID: 4,
- importBundle: ["LB"],
- gamePrefabPath: ["RomanGameSence"]
- }, [GameConstant.KIND_ID_LBFRUIT]: {
- bundle: "FRUIT",
- taskID: 5,
- importBundle: ["LB"],
- gamePrefabPath: ["FruitGameSence"]
- }, [GameConstant.KIND_ID_BY]: {
- bundle: "FISH",
- taskID: 6,
- importBundle: [],
- gamePrefabPath: []
- }, [GameConstant.KIND_ID_DSP_AK47]: {
- bundle: "DSP",
- taskID: 7,
- importBundle: ["DSP_Public"],
- gamePrefabPath: ["DSP-AK47GameSence"]
- }, [GameConstant.KIND_ID_DSP_JOKER]: {
- bundle: "DSP",
- taskID: 8,
- importBundle: ["DSP_Public"],
- gamePrefabPath: ["DSP-JOKERGameSence"]
- }, [GameConstant.KIND_ID_DSP]: {
- bundle: "DSP",
- taskID: 9,
- importBundle: ["DSP_Public"],
- gamePrefabPath: ["DSPGameSence"]
- }, [GameConstant.KIND_ID_RUMMY2R]: {
- bundle: "RUMMY",
- taskID: 10,
- importBundle: [],
- gamePrefabPath: ["RUMMY2RGameSence"]
- }, [GameConstant.KIND_ID_RUMMY2R_10Z]: {
- bundle: "RUMMY",
- taskID: 11,
- importBundle: [],
- gamePrefabPath: ["RUMMY2RGameSence_10Z"]
- }, [GameConstant.KIND_ID_RUMMY]: {
- bundle: "RUMMY",
- taskID: 12,
- importBundle: [],
- gamePrefabPath: ["RUMMYGameSence"]
- }, [GameConstant.KIND_ID_RUMMY_10Z]: {
- bundle: "RUMMY",
- taskID: 13,
- importBundle: [],
- gamePrefabPath: ["RUMMYGameSence_10Z"]
- }, [GameConstant.KIND_ID_SCRATCH_CARD]: {
- bundle: "SCRATHCARD",
- taskID: 14,
- importBundle: [],
- gamePrefabPath: ["ScratchCardScene"]
- }, [GameConstant.KIND_ID_LUCKY_GAMSTONE]: {
- bundle: "LUCKYGEMSTONE",
- taskID: 15,
- importBundle: [],
- gamePrefabPath: ["LuckyGemstoneScene"]
- }, [GameConstant.KIND_ID_DZPK]: {
- bundle: "DZPK",
- taskID: 16,
- importBundle: [],
- gamePrefabPath: ["DZPKScene"]
- }, [GameConstant.KIND_ID_CACHETA]: {
- bundle: "CACHETA",
- taskID: 17,
- importBundle: [],
- gamePrefabPath: ["CachetaGameSence"]
- }, [GameConstant.KIND_ID_TRUCO]: {
- bundle: "TRUCO",
- taskID: 18,
- importBundle: [],
- gamePrefabPath: ["TrucoGameSence"]
- }, [GameConstant.KIND_ID_CRASH]: {
- bundle: "CRASH",
- taskID: 19,
- importBundle: [],
- gamePrefabPath: ["CRASH"]
- }, [GameConstant.KIND_ID_FRUIT9X]: {
- bundle: "FRUIT9X",
- taskID: 20,
- importBundle: ["LB"],
- gamePrefabPath: ["Fruit9XGameSence"]
- }, [GameConstant.KIND_ID_FRUITSLOTS]: {
- bundle: "FRUITSLOTS",
- taskID: 21,
- importBundle: [],
- gamePrefabPath: ["fruits"]
- }, [GameConstant.KIND_ID_TXGAME]: {
- bundle: "SGYYL",
- taskID: 22,
- importBundle: [],
- gamePrefabPath: ["sglbScene"]
- }, [GameConstant.KIND_ID_FOOTBALL]: {
- bundle: "FOOTBALL",
- taskID: 23,
- importBundle: ["LB"],
- gamePrefabPath: ["FootballGameSence"]
- }, [GameConstant.KIND_ID_MINES]: {
- bundle: "MINES",
- taskID: 24,
- importBundle: [],
- gamePrefabPath: ["MinesGameSence"]
- }, [GameConstant.KIND_ID_OLYMPUS]: {
- bundle: "OLYMPUS",
- taskID: 25,
- importBundle: [],
- gamePrefabPath: ["OlympusGameSence"]
- }, [GameConstant.KIND_ID_BCBM]: {
- bundle: "BCBM",
- taskID: 26,
- importBundle: [],
- gamePrefabPath: ["BCBM"]
- },
- };
- if (cc.sys.isNative) { this.jsbPath = jsb.fileUtils.getWritablePath(); }
- setInterval(() => {
- let keys = Object.keys(this.taskList);
- for (let i = 0; i < keys.length; i += 1) {
- let taskID = keys[i];
-
- if (cc.sys.os == cc.sys.OS_IOS && cc.sys.isNative) {
-
- return;
- }else if(cc.sys.os == cc.sys.OS_ANDROID && cc.sys.isNative){
- let progress = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Zip4jUtils",
- "getProgress",
- "(I)I",
- parseInt(taskID)
- );
- let a2 = parseInt((progress / 100).toFixed(2)) * 0.1;
- this.updateRefreshnComp(0.9 + a2, this.taskList[taskID]);
- if (progress == 100) {
- delete this.taskList[taskID];
- }
- }
-
-
- }
- }, 100)
- window.unZipProgress = (taskID, entryNumber, total) => {
- Global.print("window.unZipProgress taskID=" + taskID + " entryNumber="+entryNumber + " total="+total);
- let progress = (entryNumber)/(total);
- Global.print("window.unZipProgress progress=" + progress);
- let a2 = progress * 0.1;
- Global.print("window.unZipProgress a2=" + a2);
- this.updateRefreshnComp(0.9 + a2, this.taskList[""+taskID]);
- if (progress == 100) {
- delete this.taskList[taskID];
- }
- }
- window.unZipNextGo = (taskID) => {
- let keys = Object.keys(this.bundleBaseData);
- for (let i = 0; i < keys.length; i += 1) {
- if (this.bundleBaseData[keys[i]].taskID == taskID) {
- let gameName = GameConstant.getENGameNameByKindId(keys[i]);
- topTipMsg.showTopTipMsg(gameName + " atualização do jogo concluída");
- return;
- }
- }
- }
- }
- loadBundleGame(wKindID, callBack) {
- window.importBundles = {};
- this.callBack = callBack;
- let copyBundleData = this.loadBundleData(wKindID);
- this.loadBundle(copyBundleData);
- }
- loadBundleData(wKindID) {
- Global.print("BundleLoaderManager.bundleBaseData wKindID="+wKindID);
- let bundleData = this.bundleBaseData[wKindID];
- Global.print("BundleLoaderManager.bundleBaseData bundleData="+JSON.stringify(bundleData));
- if (bundleData) {
- let copyBundleData = JSON.parse(JSON.stringify(bundleData));
- return copyBundleData;
- }
- return false;
- }
- loadBundle(data) {
- Global.print("BundleLoaderManager.bundleBaseData data="+JSON.stringify(data));
- let readyLoaderBundle = null;
- if (data.importBundle.length > 0) {
- readyLoaderBundle = data.importBundle[0];
- } else {
- readyLoaderBundle = data.bundle;
- }
- let url = this.getBundleUrl(readyLoaderBundle);
- Global.print("BundleLoaderManager.bundleBaseData url="+url);
- Global.print("BundleLoaderManager.bundleBaseData cc.assetManager.getBundle()="+cc.assetManager.getBundle());
- cc.assetManager.loadBundle(url, () => {
- this.loadBundleProgress();
- }, (err, bundle) => {
- Global.print("BundleLoaderManager.bundleBaseData bundle.name="+bundle.name);
- window.bundles[bundle.name] = bundle;
- if (data.importBundle.length > 0) {
- data.importBundle.shift();
- window.importBundles[bundle.name] = bundle;
- this.loadBundle(data);
- } else {
- window.nowBundle = bundle;
- window.testFunction(bundle, data.gamePrefabPath);
- }
- });
- }
- getBundleUrl(readyLoaderBundle) {
- // if (cc.sys.localStorage.getItem(readyLoaderBundle + "isLocal") == 1) {
- // return this.jsbPath + 'sub-game/' + readyLoaderBundle;
- // } else {
- return readyLoaderBundle;
- // }
- }
- loadBundleProgress() {
- }
- hotUpdateGame(kindID) {
- if (this.bundleBaseData[kindID].bundleState == "updating") { return; }
- this.bundleBaseData[kindID].bundleState = "updating";
- let bundleName = this.bundleBaseData[kindID].bundle;
- let refreshnNode = this.foundRefreshnComp(kindID);
- // cc.vv.reflection.initSubGameOnCache(bundleName);
- let path = this.jsbPath + "blackjack-remote-asset/assets/" + bundleName + '/' + bundleName + "_project.manifest";
- let path1 = this.jsbPath + "blackjack-remote-asset/assets/" + bundleName + "/project.manifest";
- if (jsb.fileUtils.isFileExist(path1)) {
- path = path1;
- }
- cc.assetManager.loadRemote(path, (err, Asset) => {
- if (!err) {
- let bundleChecker = new GameUpdate;
- bundleChecker.goPlanA(Asset, bundleName, refreshnNode); //热更新
- bundleChecker.checkUpdate();
- }
- });
- }
- downloadGame(kindID) {
- if (this.bundleBaseData[kindID].bundleState == "downloading" ||
- this.bundleBaseData[kindID].bundleState == "unziping") { return; }
- this.bundleBaseData[kindID].bundleState = "downloading";
- let bundleName = this.bundleBaseData[kindID].bundle;
- let taskID = this.bundleBaseData[kindID].taskID;
- let refreshnNode = this.foundRefreshnComp(kindID);
- let version = parseInt(cc.vv.gameVersionInfo[bundleName]);
- let zip = BaseDefine.GAME_ZIP_URL + bundleName + "/ver_" + version + ".zip";
- cc.assetManager.loadRemote(zip, {
- ext: ".bin",
- onFileProgress: (current, total) => {
- this.current = current;
- this.total = total;
- this.updateRefreshnComp((this.current / this.total * 0.9).toFixed(2), refreshnNode);
- }
- }, (err, bufferAsset) => {
- let data = bufferAsset._buffer;
- let dirpath = jsb.fileUtils.getWritablePath() + 'zips/';
- let filepath = dirpath + bundleName + ".zip";
- if (!jsb.fileUtils.isDirectoryExist(dirpath)) {
- jsb.fileUtils.createDirectory(dirpath);
- } if (jsb.fileUtils.writeDataToFile(new Uint8Array(data), filepath)) {
- this.bundleBaseData[kindID].bundleState = "unziping";
- this.taskList[taskID] = refreshnNode;
- if (cc.sys.os == cc.sys.OS_IOS && cc.sys.isNative) {
- cc.vv.reflection.unzipFile(filepath, jsb.fileUtils.getWritablePath() + "blackjack-remote-asset/assets/" + bundleName, "123456", taskID);
- }else if(cc.sys.os == cc.sys.OS_ANDROID && cc.sys.isNative){
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity",
- "unZipPack1",
- "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V",
- "zips/" + bundleName + ".zip",
- "/blackjack-remote-asset/assets/" + bundleName,
- "123456",
- taskID
- );
- }
-
- }
- })
- }
- foundRefreshnComp(kindID) {
- let parent0 = cc.find("Canvas/RightNodeEx/RecomNode");
- let parent1 = cc.find("Canvas/SecondaryGameList/Content/LeftNode/GameList/view/content");
- let parent2 = cc.find("Canvas/RightNodeEx/GameButtonNode/ScrollView/view/content");
- let refreshnNode = [];
- for (let j = 0; j < parent0.children.length; j += 1) {
- let node = parent0.children[j];
- let updatebar = node.getChildByName("updatebar")
- let comp = updatebar.getComponent("GameUpdateShower");
- let config = comp.getGameData();
- if (config.kindID == kindID) {
- comp.readyDownload();
- refreshnNode.push(comp);
- break;
- }
- }
- for (let j = 0; j < parent1.children.length; j += 1) {
- let node = parent1.children[j];
- let updatebar = node.getChildByName("updatebar")
- let comp = updatebar.getComponent("GameUpdateShower");
- let config = comp.getGameData();
- if (config.kindID == kindID) {
- comp.readyDownload();
- refreshnNode.push(comp);
- break;
- }
- }
- for (let k = 0; k < parent2.children.length; k += 1) {
- let node = parent2.children[k];
- let updatebar = node.getChildByName("updatebar")
- let comp = updatebar.getComponent("GameUpdateShower");
- if (comp) {
- let config = comp.getGameData();
- if (config.kindID == kindID) {
- comp.readyDownload();
- refreshnNode.push(comp);
- break;
- }
- }
- }
- return refreshnNode;
- }
- updateRefreshnComp(progress, refreshnNode, type) {
- for (let i = 0; i < refreshnNode.length; i += 1) {
- let comp = refreshnNode[i];
- let kindID = comp.getGameData().kindID;
- if (progress == 1) {
- comp.overDownload();
- this.bundleBaseData[kindID].bundleState = "intoTheGame";
- } else {
- comp.gameDownloading(progress);
- }
- }
- }
- getBundleNameByKindID(KindID) {
- if (this.bundleBaseData[KindID]) {
- return this.bundleBaseData[KindID].bundle;
- }
- return null;
- }
- getBundleStateBuKindID(KindID) {
- if (this.bundleBaseData[KindID]) {
- return this.bundleBaseData[KindID].bundleState;
- }
- return null;
- }
- };
- BundleLoaderManager.Instance = function () {
- if (!_BundleLoaderManager) {
- _BundleLoaderManager = new BundleLoaderManager();
- window.BundleLoaderManager = _BundleLoaderManager;
- }
- return _BundleLoaderManager;
- }
- module.exports = BundleLoaderManager;
|