2017-10-08 21:25:24 +00:00
|
|
|
/// <reference path="BaseView.ts"/>
|
|
|
|
|
|
|
|
module TK.SpaceTac.UI {
|
|
|
|
export enum AssetLoadingRange {
|
|
|
|
NONE,
|
|
|
|
MENU,
|
|
|
|
BATTLE,
|
|
|
|
CAMPAIGN
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loader of all game assets
|
|
|
|
*/
|
|
|
|
export class AssetLoading extends BaseView {
|
|
|
|
private static loaded = AssetLoadingRange.NONE
|
|
|
|
private required = AssetLoadingRange.NONE
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if an asset range is loaded
|
|
|
|
*/
|
|
|
|
static isRangeLoaded(game: Phaser.Game, range: AssetLoadingRange): boolean {
|
|
|
|
if (range > AssetLoading.loaded) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
init(range = AssetLoadingRange.NONE) {
|
|
|
|
super.init();
|
|
|
|
|
|
|
|
this.required = range;
|
|
|
|
}
|
|
|
|
|
|
|
|
preload() {
|
2018-04-12 22:38:46 +00:00
|
|
|
let bg = this.add.image(643, 435, "preload-background");
|
|
|
|
let bar = this.add.image(643, 435, "preload-bar");
|
2017-10-08 21:25:24 +00:00
|
|
|
this.load.setPreloadSprite(bar);
|
|
|
|
|
2018-04-12 22:38:46 +00:00
|
|
|
let text = this.add.text(this.getMidWidth(), 466, "... Loading ...", { font: "normal 36pt SpaceTac", fill: "#dbeff9" });
|
|
|
|
text.anchor.set(0.5);
|
|
|
|
|
2017-10-08 21:25:24 +00:00
|
|
|
if (this.required >= AssetLoadingRange.MENU && AssetLoading.loaded < AssetLoadingRange.MENU) {
|
|
|
|
console.log("Loading menu assets");
|
2018-03-08 21:11:14 +00:00
|
|
|
this.load.pack("stage1", `assets/pack1.json?t=${Date.now()}`);
|
2017-10-08 21:25:24 +00:00
|
|
|
|
2018-03-08 19:16:05 +00:00
|
|
|
// TODO pack
|
2017-10-08 21:25:24 +00:00
|
|
|
this.loadSheet("common/particles.png", 32);
|
|
|
|
this.loadAnimation("common/waiting.png", 128, 128, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.required >= AssetLoadingRange.BATTLE && AssetLoading.loaded < AssetLoadingRange.BATTLE) {
|
|
|
|
console.log("Loading battle assets");
|
2018-03-08 21:11:14 +00:00
|
|
|
this.load.pack("stage2", `assets/pack2.json?t=${Date.now()}`);
|
2017-10-08 21:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.required >= AssetLoadingRange.CAMPAIGN && AssetLoading.loaded < AssetLoadingRange.CAMPAIGN) {
|
|
|
|
console.log("Loading campaign assets");
|
2018-03-08 21:11:14 +00:00
|
|
|
this.load.pack("stage3", `assets/pack3.json?t=${Date.now()}`);
|
2017-10-08 21:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.load.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
create() {
|
|
|
|
super.create();
|
|
|
|
|
|
|
|
AssetLoading.loaded = Math.max(AssetLoading.loaded, this.required);
|
|
|
|
this.game.state.start("router");
|
|
|
|
}
|
|
|
|
|
|
|
|
static getKey(path: string): string {
|
|
|
|
return path.replace(/\//g, "-").replace(/\.[a-z0-9]+$/, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
loadSheet(path: string, frame_width: number, frame_height = frame_width) {
|
2018-03-08 19:16:05 +00:00
|
|
|
this.load.spritesheet(AssetLoading.getKey(path), "images/" + path, frame_width, frame_height);
|
2017-10-08 21:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
loadAnimation(path: string, frame_width: number, frame_height = frame_width, count?: number) {
|
2018-03-08 19:16:05 +00:00
|
|
|
this.load.spritesheet(AssetLoading.getKey(path), "images/" + path, frame_width, frame_height, count);
|
2017-10-15 17:54:37 +00:00
|
|
|
}
|
2017-10-08 21:25:24 +00:00
|
|
|
}
|
|
|
|
}
|