2143bcf1-8f80-4035-a6ce-c3ec84d386bd.js
3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"use strict";
cc._RF.push(module, '2143bzxj4BANabOw+yE04a9', 'GameCenter');
// script/cooperation/script/GameCenter.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const simba_sdk_1 = require("simba-sdk");
const GameConfig_1 = require("../../GameConfig");
const EventCenter_1 = require("../event/EventCenter");
const EventKit_1 = require("../event/EventKit");
const CooperationDataCenter_1 = require("./CooperationDataCenter");
/**游戏中心 */
let GameCenter = /** @class */ (() => {
class GameCenter {
constructor() {
/**是否处于正式环境[控制访问oss地址] */
this._isRelease = false;
this._disposable = null;
this._quickStartGameAppID = "";
/**响应拉取游戏中心配置文件事件监听 */
this.onRequestCooperationData = (release) => {
this._isRelease = release;
CooperationDataCenter_1.default.getInstance().requestCooperationDataFromOSS(this._isRelease);
};
/**快速开始小游戏 */
this.onQuickStartSubGame = (isRandom) => {
let list = CooperationDataCenter_1.default.getInstance().getCooperationItemDataModelList();
if (!list || list.length === 0) {
return;
}
let appId = "";
if (isRandom) {
appId = list[Math.floor(Math.random() * list.length)].appId;
}
else {
appId = "" === this._quickStartGameAppID ? list[0].appId : this._quickStartGameAppID;
}
this._quickStartGameAppID = appId;
this.openSubProgram(this._quickStartGameAppID);
};
this.onOpenSubGameByAppId = (appId) => {
this._quickStartGameAppID = appId;
// this.openSubProgram(appId);
simba_sdk_1.SDK.openProgramV2(appId);
};
}
/**游戏中心单例对象 */
static getInstance() {
if (!GameCenter._instance) {
GameCenter._instance = new GameCenter();
}
return GameCenter._instance;
}
/**初始化 */
init() {
this.registerEventListener();
}
/**注册事件监听 */
registerEventListener() {
if (this._disposable) {
this._disposable.dispose();
}
this._disposable = new EventKit_1.CompositeDisposable;
this._disposable.add(EventCenter_1.EventCenter.REQUEST_COOPERATION_DATA_FROM_OSS.on(this.onRequestCooperationData));
this._disposable.add(EventCenter_1.EventCenter.QUICK_START_SUB_GAME.on(this.onQuickStartSubGame));
this._disposable.add(EventCenter_1.EventCenter.OPEN_SUBGAME_BY_APPID.on(this.onOpenSubGameByAppId));
}
/**获取是否是正式环境 */
getIsRelease() {
return this._isRelease;
}
/**打开微信小游戏 */
openSubProgram(appId, extraData) {
return new Promise((resolve, reject) => {
if (GameConfig_1.channel != "dummy") {
wx.navigateToMiniProgram({
appId, extraData,
envVersion: 'release',
success: () => {
resolve();
},
fail: (res) => {
reject(res);
}
});
}
else {
console.log('Open other MiniProgram.');
}
});
}
}
/**单例对象 */
GameCenter._instance = null;
return GameCenter;
})();
exports.default = GameCenter;
cc._RF.pop();