e660d58f-8b2b-4ef9-a537-c92cebe7d874.js 5.47 KB
"use strict";
cc._RF.push(module, 'e660dWPiytO+aU3ySzr59h0', 'CooperationDataCenter');
// script/cooperation/script/CooperationDataCenter.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubGameLocation = void 0;
const HttpClient_1 = require("../../network/HttpClient");
const EventCenter_1 = require("../event/EventCenter");
const CooperationClassBase_1 = require("./CooperationClassBase");
var SubGameLocation;
(function (SubGameLocation) {
    SubGameLocation["MainUI"] = "mainUI";
    SubGameLocation["GameCenter"] = "gameCenter";
    SubGameLocation["MomentCenter"] = "momentCenter";
})(SubGameLocation = exports.SubGameLocation || (exports.SubGameLocation = {}));
/**
 * 数据中心
 */
let CooperationDataCenter = /** @class */ (() => {
    class CooperationDataCenter {
        constructor() {
            /**网络请求对象 */
            this._httpObj = new HttpClient_1.HttpClient("");
            /**oss配置文件缓存 */
            this._cooperationDataModels = [];
            /**当前游戏的appid */
            this._appID = "";
            /**当前游戏的gameId */
            this._gameID = "";
            /**当前游戏的渠道 */
            this._gameChannel = "";
            /**当前游戏中MainUI中需要展示的游戏 */
            this._mainUISubGameModels = [];
        }
        /**获取数据中心单例对象 */
        static getInstance() {
            return CooperationDataCenter._instance;
        }
        /**设置当前游戏的渠道 */
        setCurGameChannel(channel) {
            this._gameChannel = channel;
        }
        /**设置当前游戏的gameId */
        setCurGameID(gameId) {
            this._gameID = gameId;
        }
        /**获取当前游戏的渠道 */
        getCurGameChannel() {
            return this._gameChannel;
        }
        /**获取当前游戏的gameId */
        getCurGameID() {
            return this._gameID;
        }
        /**设置当前游戏的appid */
        setCurGameAppID(appId) {
            this._appID = appId;
        }
        /**获取当前游戏的appid */
        getCurGameAppID() {
            return this._appID;
        }
        /**获取oss配置列表 */
        getCooperationItemDataModelList() {
            return this._cooperationDataModels;
        }
        /**获取在主UI中需要展示的游戏列表 */
        getMainUISubGameDataModelList() {
            return this._mainUISubGameModels;
        }
        /**从oss上拉取配置文件 */
        async requestCooperationDataFromOSS(release) {
            try {
                this._cooperationDataModels = [];
                this._mainUISubGameModels = [];
                let ossPath = release ? CooperationClassBase_1.CooperationClassBase.COO_OSS_PATH_RELEASE : CooperationClassBase_1.CooperationClassBase.COO_OSS_PATH_DEV;
                let configPath = ossPath + CooperationDataCenter.getInstance().getCurGameID() + CooperationClassBase_1.CooperationClassBase.CONFIG_PATH;
                let resStr = await this._httpObj.get(configPath);
                let res = JSON.parse(resStr);
                if (res) {
                    let items = res.items;
                    if (items) {
                        let serialNum = 1;
                        for (let i = 0; i < items.length; i++) {
                            let item = items[i];
                            if (item && item.appId && "" !== item.appId && item.img && "" !== item.img && this._appID !== item.appId) {
                                this._cooperationDataModels.push({
                                    appId: item.appId,
                                    appName: item.name,
                                    icon: item.img,
                                    showAppName: item.showName === 1,
                                    showPlayingUser: item.showPlayingUser === 1,
                                    userMin: item.userMin ? item.userMin : 0,
                                    userMax: item.userMax ? item.userMax : 100,
                                    labelColor: item.labelColor,
                                    index: serialNum
                                });
                                if (item.independentDisplay === 1) {
                                    this._mainUISubGameModels.push({
                                        appId: item.appId,
                                        appName: item.name,
                                        icon: item.img,
                                        showAppName: item.showName === 1,
                                        showPlayingUser: item.showPlayingUser === 1,
                                        userMin: item.userMin ? item.userMin : 0,
                                        userMax: item.userMax ? item.userMax : 100,
                                        labelColor: item.labelColor,
                                        index: serialNum
                                    });
                                }
                                serialNum += 1;
                            }
                        }
                        EventCenter_1.EventCenter.COOPERATION_DATA_DOWNLOAD_SUCCEED.emit();
                    }
                }
            }
            catch (e) {
                console.error(e);
            }
        }
    }
    /**单例对象 */
    CooperationDataCenter._instance = new CooperationDataCenter();
    return CooperationDataCenter;
})();
exports.default = CooperationDataCenter;

cc._RF.pop();