Launcher.ts
3.15 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
import { GameConfig } from "../GameConfig";
import { UIManager } from "../common/gameplay/managers/UIManager";
import { AnimationUtils } from "../common/utils/AnimationUtils";
import { PlotManager } from "../avg/PlotManager";
import { SDK } from "simba-sdk";
import { GameModelManager } from "./model/GameModelManager";
import MainViewPresenter from "./ui/presenter/MainViewPresenter";
import { DummyLabel, DummyNode, DummyProgressBar } from "../common/CCDummyObjects";
import { AudioManager } from "../common/gameplay/managers/AudioManager";
import { ResUtils } from "../common/utils/ResUtils";
const { ccclass, property } = cc._decorator;
@ccclass
export default class Launcher extends cc.Component {
@property({ type: cc.ProgressBar, displayName: "进度条" })
progressBar: cc.ProgressBar = DummyProgressBar;
@property({ type: cc.Label, displayName: "进度展示文本" })
progressLabel: cc.Label = DummyLabel;
@property({ type: cc.Node, displayName: "UI根结点" })
uiRootNode: cc.Node = DummyNode;
@property({ type: cc.Node, displayName: "引导根结点" })
guideRootNode: cc.Node = DummyNode;
@property({ type: cc.Node, displayName: '转场根节点' })
VerbRoot: cc.Node = DummyNode;
onLoad() {
let winSize = cc.winSize;
if (winSize.width / winSize.height > 720 / 1280) {
let canvas = this.node.getComponent(cc.Canvas);
canvas.fitWidth = true;
canvas.fitHeight = true;
}
//关闭fps展示
cc.debug.setDisplayStats(GameConfig.showFPS);
cc.macro.ENABLE_MULTI_TOUCH = false;
}
start() {
this.initializeGame();
}
async initializeGame() {
AudioManager.init("audio/bgm/", "audio/effect/", "audio/voice/")
await UIManager.init(this.uiRootNode!);
let mainViewPromise = UIManager.pushPresenter(MainViewPresenter, undefined);
AnimationUtils.animateProgress(this.progressBar!, 0.2);
let ret = false;
let tryCount = 0;
while (!ret && tryCount < 3) {
tryCount++;
ret = await SDK.init();
}
if (!ret) {
// TODO show error alert
console.error("SDK init failed.");
return;
}
AnimationUtils.animateProgress(this.progressBar, 0.4, 1, this.progressLabel);
tryCount = 0;
while (1) {
try {
tryCount++;
await SDK.login();
break;
} catch (e) {
if (tryCount > 3) {
console.log("SDK login failed.");
return;
}
}
}
AnimationUtils.animateProgress(this.progressBar, 0.6, 1, this.progressLabel);
await PlotManager.init();
AnimationUtils.animateProgress(this.progressBar, 0.8, 1, this.progressLabel);
await PlotManager.start();
// init game data
await GameModelManager.init();
AnimationUtils.animateProgress(this.progressBar, 1.0, 1, this.progressLabel);
await (await mainViewPromise).start();
this.node.getChildByName("Loading").active = false;
}
async startGame() {
}
}