46 lines
2.0 KiB
TypeScript
46 lines
2.0 KiB
TypeScript
import ActivityScheduleService from "./module/Config/ActivityScheduleService";
|
|
import HomeActivityEntryLayout from "./HomeActivityEntryLayout";
|
|
import HomePopupQueue from '../home_popup_queue/HomePopupQueue';
|
|
import CloudRiseService from './module/Config/CloudRiseService';
|
|
|
|
const { ccclass } = cc._decorator;
|
|
|
|
/** Refresh on entering/returning home; scheduled ticks only check local time boundaries. */
|
|
@ccclass
|
|
export default class HomeActivitySchedule extends cc.Component {
|
|
private visibility = 0;
|
|
lateUpdate(): void {
|
|
const load = this.node.getChildByName("Load");
|
|
HomeActivityEntryLayout.refresh(load && load.getChildByName("Top"));
|
|
}
|
|
onEnable(): void {
|
|
cc.game.on(cc.game.EVENT_SHOW, this.onShow, this);
|
|
cc.game.on(cc.game.EVENT_HIDE, this.onHide, this);
|
|
this.show(true);
|
|
}
|
|
private tick = (): void => { ActivityScheduleService.tick(); };
|
|
private onShow = (): void => { this.show(false); };
|
|
private show(entering: boolean): void {
|
|
const visibility = ++this.visibility;
|
|
const query = entering ? ActivityScheduleService.enterHome() : ActivityScheduleService.onForeground();
|
|
this.unschedule(this.tick);
|
|
this.schedule(this.tick, 1);
|
|
this.tick();
|
|
void query.then(async ok => {
|
|
if (ok && visibility === this.visibility)
|
|
await ActivityScheduleService.checkCloudRiseOpening(() => visibility === this.visibility, false);
|
|
if (entering) await CloudRiseService.sync();
|
|
}).catch(error => cc.warn(error)).then(() => {
|
|
if (entering && cc.isValid(this.node, true)) HomePopupQueue.get(this.node).completePreparation('cloud');
|
|
});
|
|
}
|
|
private onHide = (): void => {
|
|
this.visibility++; this.unschedule(this.tick); ActivityScheduleService.onBackground();
|
|
};
|
|
onDisable(): void {
|
|
this.onHide();
|
|
cc.game.off(cc.game.EVENT_SHOW, this.onShow, this);
|
|
cc.game.off(cc.game.EVENT_HIDE, this.onHide, this);
|
|
}
|
|
}
|