f191bdcd-c97b-42b9-b0da-4c695dfed1c6.js 16.8 KB
"use strict";
cc._RF.push(module, 'f191b3NyXtCubDaTGld/tHG', 'Launcher');
// script/game/Launcher.ts

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const simba_sdk_1 = require("simba-sdk");
const AVG_1 = require("../avg/AVG");
const CCDummyObjects_1 = require("../common/CCDummyObjects");
const simba_cc_audio_manager_1 = require("simba-cc-audio-manager");
const UIManager_1 = require("../common/gameplay/managers/UIManager");
const AnimationUtils_1 = require("../common/utils/AnimationUtils");
const GameConfig_1 = require("../GameConfig");
const Enums_1 = require("./Enums");
const GameDotMgr_1 = require("./GameDotMgr");
const GameModelManager_1 = require("./model/GameModelManager");
const AlertDialogViewPresenter_1 = require("./ui/presenter/AlertDialogViewPresenter");
const MainViewPresenter_1 = require("./ui/presenter/MainViewPresenter");
const simba_cc_resutils_1 = require("simba-cc-resutils");
const CCGameCenterComponent_1 = require("../cooperation/script/CCGameCenterComponent");
const CCGameCenterNodeFactory_1 = require("../cooperation/script/CCGameCenterNodeFactory");
const CustomerServiceDataCenter_1 = require("../customerService/script/CustomerServiceDataCenter");
const EventCenter_1 = require("../cooperation/event/EventCenter");
const EventKit_1 = require("../cooperation/event/EventKit");
const UnlockSpecialPlotEventManager_1 = require("./model/UnlockSpecialPlotEventManager");
const simba_sdk_exchangecode_1 = require("simba-sdk-exchangecode");
const { ccclass, property } = cc._decorator;
let Launcher = /** @class */ (() => {
    let Launcher = class Launcher extends cc.Component {
        constructor() {
            super(...arguments);
            this.progressBar = CCDummyObjects_1.DummyProgressBar;
            this.progressLabel = CCDummyObjects_1.DummyLabel;
            this.uiRootNode = CCDummyObjects_1.DummyNode;
            this.toastParentNode = CCDummyObjects_1.DummyNode;
            this.loadingNode = CCDummyObjects_1.DummyNode;
            this.loadingRoleNode = CCDummyObjects_1.DummyNode;
            this.VerbRoot = CCDummyObjects_1.DummyNode;
            this.isLoadGameCenter = false;
            this.userIdLabel = CCDummyObjects_1.DummyLabel;
            this.hotUpdateNode = CCDummyObjects_1.DummyNode;
            this.bgSpr = CCDummyObjects_1.DummySprite;
            this.loginCount = 0;
            this._gameCenterViewNode = CCDummyObjects_1.DummyNode;
            this._disposable = new EventKit_1.CompositeDisposable;
            /**控制游戏列表是否展示 */
            this.onShowGameCenterListView = (isShow) => {
                if (!this._gameCenterViewNode) {
                    return;
                }
                this._gameCenterViewNode.active = isShow;
            };
            this.onGameStart = () => {
                this.initializeGame();
            };
            this.lateInit = async () => {
                let mainViewPromise = UIManager_1.UIManager.pushPresenter(MainViewPresenter_1.default, undefined);
                AnimationUtils_1.AnimationUtils.animateProgress(this.progressBar, 0.6, 1, this.progressLabel);
                if (CC_DEV) {
                    globalThis['PlotManager'] = AVG_1.PlotManager;
                    globalThis['GameRecord'] = AVG_1.GameRecord;
                    let ConfigManager = require('simba-config-manager');
                    globalThis['ConfigManager'] = ConfigManager;
                }
                await AVG_1.initAVG();
                //解决清档
                await this.dealEmptyRecord();
                if (GameConfig_1.GameConfig.EMPTY_RECORD_WHEN_LOGIN) {
                    AVG_1.PlotManager.stop();
                    await AVG_1.GameRecord.emptyRecords();
                }
                AnimationUtils_1.AnimationUtils.animateProgress(this.progressBar, 0.8, 1, this.progressLabel);
                await AVG_1.PlotManager.start(0, false);
                AnimationUtils_1.AnimationUtils.animateProgress(this.progressBar, 0.9, 1, this.progressLabel);
                await simba_sdk_exchangecode_1.initExchangeCode();
                // init game data
                await GameModelManager_1.GameModelManager.init((value) => {
                    AnimationUtils_1.AnimationUtils.animateProgress(this.progressBar, value, 1, this.progressLabel);
                });
                GameDotMgr_1.default.getInstance().dotLoading(Enums_1.LoadingState.LoadingStart);
                AnimationUtils_1.AnimationUtils.animateProgress(this.progressBar, 0.95, 1, this.progressLabel);
                GameDotMgr_1.default.getInstance().dotLoading(Enums_1.LoadingState.LoadingEnd);
                (await mainViewPromise).start();
                AnimationUtils_1.AnimationUtils.animateProgress(this.progressBar, 1.0, 1, this.progressLabel);
                // GameDotMgr.getInstance().dotLoading(LoadingState.EnterLobby);
                this.loadingNode.active = false;
                //检查是否解锁手表次留番外
                UnlockSpecialPlotEventManager_1.default.getInstance().nextDayUnlockedSpecialPlot(4);
            };
            this.loginGame = async () => {
                return new Promise(async (resolve, reject) => {
                    this.loginCount++;
                    try {
                        let ret = await simba_sdk_1.SDK.login();
                        if (ret) {
                            this.userIdLabel.string = ret.playerId;
                            await this.lateInit();
                            resolve();
                        }
                    }
                    catch (error) {
                        if (this.loginCount > 3) {
                            this.showLoginFailed();
                            reject(new Error("登录失败"));
                        }
                        else if (error == "timeout") {
                            this.loginGame();
                        }
                    }
                });
            };
        }
        async onLoad() {
            this.screenAdapter();
            if (cc.sys.isNative) {
                this._disposable.add(EventCenter_1.EventCenter.GameStart.on(this.onGameStart));
                let hotNode = await simba_cc_resutils_1.ResUtils.createWithPrefab('prefab/HotUpdate');
                hotNode.parent = this.hotUpdateNode;
            }
            this.scheduleOnce(() => {
                this.preloadView();
                this.preloadDir();
            });
            //关闭fps展示
            cc.debug.setDisplayStats(GameConfig_1.GameConfig.showFPS);
            /**关闭多点触摸 特效层将不能使用 */
            cc.macro.ENABLE_MULTI_TOUCH = false;
            this.fixScreenSize();
            this.scheduleOnce(async () => {
                try {
                    let node = await simba_cc_resutils_1.ResUtils.createWithPrefab('prefab/ui/VerbView');
                    node.parent = this.VerbRoot;
                }
                catch (error) {
                    console.error(error);
                }
                if (!this.isLoadGameCenter)
                    return;
                //加载矩阵导量UI
                try {
                    this._disposable.add(EventCenter_1.EventCenter.SHOW_GAME_CENTER_LIST_VIEW.on(this.onShowGameCenterListView));
                    let gameCenterMomentItem = await simba_cc_resutils_1.ResUtils.loadRes('prefab/cooperation/GameCenterMomentItem', cc.Prefab);
                    CCGameCenterNodeFactory_1.default.getInstance().registerMomentPrefab(gameCenterMomentItem);
                    let gameCenterBtn = await simba_cc_resutils_1.ResUtils.loadRes('prefab/cooperation/GameCenterBtn', cc.Prefab);
                    let gameCenterView = await simba_cc_resutils_1.ResUtils.loadRes('prefab/cooperation/GameCenterView', cc.Prefab);
                    let cooperationItem = await simba_cc_resutils_1.ResUtils.loadRes('prefab/cooperation/CooperationItem', cc.Prefab);
                    let cCGameCenterComponent = this.node.addComponent(CCGameCenterComponent_1.default);
                    cCGameCenterComponent.gameCenterBtnPrefab = gameCenterBtn;
                    cCGameCenterComponent.gameCenterViewPrefab = gameCenterView;
                    cCGameCenterComponent.gameCenterItemPrefab = cooperationItem;
                    cCGameCenterComponent.gameCenterMomentPrefab = gameCenterMomentItem;
                    cCGameCenterComponent.gameCenterParentNode = this.node;
                    cCGameCenterComponent.appID = "wx7a067b995e670485";
                    cCGameCenterComponent.gameID = "yybs";
                    cCGameCenterComponent.gameChannel = "wechat";
                    cCGameCenterComponent.isRelease = !GameConfig_1.GameConfig.debug;
                    cCGameCenterComponent.init();
                }
                catch (error) {
                    console.error(error);
                }
            });
            CustomerServiceDataCenter_1.default.getInstance().init();
            simba_cc_resutils_1.ResUtils.loadRes("audio/bgm/bayinhe", cc.AudioClip);
            simba_cc_resutils_1.ResUtils.loadRes("audio/bgm/wanshengj", cc.AudioClip);
        }
        /**创建prefab对应的节点 */
        createNode(gameCenterViewPrefab) {
            if (!gameCenterViewPrefab) {
                cc.error("gameCenterViewPrefab is not set , please check it over");
            }
            else {
                this._gameCenterViewNode = cc.instantiate(gameCenterViewPrefab);
            }
            let parentNode = cc.director.getScene();
            this._gameCenterViewNode.parent = parentNode;
            this._gameCenterViewNode.position = cc.v3(cc.winSize.width / 2, cc.winSize.height / 2, 0);
        }
        fixScreenSize() {
            // let comp = this.loadingRoleNode.getComponent(PortraitFixComponent);
            // if (comp) {
            //     comp.fixScreenSize(false);
            // }
            let sf = this.bgSpr.spriteFrame;
            this.node.getComponent(cc.Widget).updateAlignment();
            let sizeSF = sf.getOriginalSize();
            let nodeSize = cc.size(this.node.width, this.node.height);
            let scaleTemp = 1;
            let scaleX = nodeSize.width / sizeSF.width;
            let scaleY = nodeSize.height / sizeSF.height;
            scaleTemp = Math.max(scaleX, scaleY);
            this.bgSpr.node.scale = scaleTemp;
        }
        preloadView() {
            // let viewList: string[] = [
            //     'prefab/ui/MainView',
            //     'prefab/ui/MessageView',
            //     'prefab/ui/message/MessageEntryItem',
            //     'prefab/ui/BedroomView',
            //     'prefab/ui/discover/SettingView'
            // ]
            let viewList = [
                'prefab/ui/MainView',
                'prefab/ui/MessageView',
                'prefab/ui/message/MessageEntryItem'
            ];
            cc.resources.preload(viewList, (error, items) => {
            });
        }
        preloadDir() {
            cc.resources.preloadDir('plots'); //剧情数据
            cc.resources.preloadDir('userdata/language'); //语言配置
            cc.resources.preloadDir('config'); //剧情配置
            // cc.resources.preloadDir('textures/items');
        }
        screenAdapter() {
            let winSize = cc.winSize;
            if (winSize.width / winSize.height > 720 / 1280) {
                let canvas = this.node.getComponent(cc.Canvas);
                canvas.fitWidth = true;
                canvas.fitHeight = true;
            }
        }
        start() {
            if (!cc.sys.isNative)
                this.initializeGame();
        }
        async initializeGame() {
            simba_cc_audio_manager_1.AudioManager.init("audio/bgm/", "audio/effect/", "audio/voice/");
            while (true) {
                try {
                    await UIManager_1.UIManager.init(this.uiRootNode, this.toastParentNode);
                    break;
                }
                catch (e) {
                    console.error(e);
                }
            }
            AnimationUtils_1.AnimationUtils.animateProgress(this.progressBar, 0.2);
            let ret = false;
            let tryCount = 0;
            while (!ret && tryCount < 3) {
                tryCount++;
                ret = await simba_sdk_1.SDK.init();
                // initExchangeCode();
            }
            if (!ret) {
                UIManager_1.UIManager.showToast("SDK init failed. sdk初始化失败");
                return;
            }
            AnimationUtils_1.AnimationUtils.animateProgress(this.progressBar, 0.4, 1, this.progressLabel);
            await this.loginGame();
        }
        showLoginFailed() {
            let temp = {
                dataptr: {},
                titlecontent: "网络错误",
                content: "是否重新连接?",
                ishasad: false,
                istwobtn: true,
                adconfig: "",
                hasBanner: false,
                callback: (type, ret) => {
                    if (ret) {
                        this.loginCount = 0;
                        this.loginGame();
                    }
                    else {
                        cc.director.end();
                    }
                }
            };
            UIManager_1.UIManager.pushPresenter(AlertDialogViewPresenter_1.default, temp);
        }
        async dealEmptyRecord() {
            /**此次执行清档操作的版本号 */
            let optionV = "1.0.2";
            /**需要清档的玩家注册版本号列表 */
            let needEmptyRegVersionArr = ["1.0.0", "1.0.1"];
            let emptyVersionRecordKey = "empty_record_versions";
            let needEmpty = this.checkIsNeedEmptyRecord(optionV, emptyVersionRecordKey, needEmptyRegVersionArr);
            console.log("是否需要清档操作:", needEmpty);
            if (needEmpty) {
                await AVG_1.GameRecord.emptyRecords();
                AVG_1.GameRecord.globalVariables[emptyVersionRecordKey] = optionV;
                AVG_1.GameRecord.saveRecord();
            }
        }
        checkIsNeedEmptyRecord(optionV, emptyVersionRecordKey, needEmptyRegVersionArr) {
            let empty = false;
            let regV = AVG_1.GameRecord.globalVariables["register_version"];
            //不存在或者当前注册版本不在需要清档的版本内容中,则直接返回不需要清档
            if (!regV || needEmptyRegVersionArr.findIndex((v) => v == regV) === (-1)) {
                return false;
            }
            let emptyRecordVersionString = AVG_1.GameRecord.globalVariables[emptyVersionRecordKey];
            if (!emptyRecordVersionString || "" === emptyRecordVersionString.trim()) {
                return true;
            }
            empty = emptyRecordVersionString != optionV;
            return empty;
        }
    };
    __decorate([
        property({ type: cc.ProgressBar, displayName: "进度条" })
    ], Launcher.prototype, "progressBar", void 0);
    __decorate([
        property({ type: cc.Label, displayName: "进度展示文本" })
    ], Launcher.prototype, "progressLabel", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "UI根结点" })
    ], Launcher.prototype, "uiRootNode", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "场景最上层弱提示根结点" })
    ], Launcher.prototype, "toastParentNode", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "加载界面节点" })
    ], Launcher.prototype, "loadingNode", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "加载界面人物图" })
    ], Launcher.prototype, "loadingRoleNode", void 0);
    __decorate([
        property({ type: cc.Node })
    ], Launcher.prototype, "VerbRoot", void 0);
    __decorate([
        property({ tooltip: "是否加载导量UI" })
    ], Launcher.prototype, "isLoadGameCenter", void 0);
    __decorate([
        property({ type: cc.Label, displayName: "玩家ID文本" })
    ], Launcher.prototype, "userIdLabel", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "热更节点" })
    ], Launcher.prototype, "hotUpdateNode", void 0);
    __decorate([
        property(cc.Sprite)
    ], Launcher.prototype, "bgSpr", void 0);
    Launcher = __decorate([
        ccclass
    ], Launcher);
    return Launcher;
})();
exports.default = Launcher;

cc._RF.pop();