2017-01-03 22:17:52 +00:00
|
|
|
/// <reference path="../typings/index.d.ts"/>
|
2014-12-29 00:00:00 +00:00
|
|
|
|
2017-01-22 17:00:59 +00:00
|
|
|
if (typeof window != "undefined") {
|
|
|
|
(<any>window).describe = (<any>window).describe || function () { };
|
|
|
|
}
|
|
|
|
|
2017-01-26 23:52:45 +00:00
|
|
|
module TS.SpaceTac {
|
2014-12-29 00:00:00 +00:00
|
|
|
// Router between game views
|
2017-02-09 00:00:35 +00:00
|
|
|
export class MainUI extends Phaser.Game {
|
2015-04-07 00:00:00 +00:00
|
|
|
// Current game session
|
2017-02-09 00:00:35 +00:00
|
|
|
session: GameSession;
|
2015-04-07 00:00:00 +00:00
|
|
|
|
|
|
|
// Current focused star system
|
2017-02-09 00:00:35 +00:00
|
|
|
star: Star;
|
2015-02-27 00:00:00 +00:00
|
|
|
|
2015-04-22 21:42:40 +00:00
|
|
|
// Audio manager
|
2017-02-09 00:00:35 +00:00
|
|
|
audio: UI.Audio;
|
2015-04-22 21:42:40 +00:00
|
|
|
|
|
|
|
constructor(headless: boolean = false) {
|
2017-01-08 22:04:07 +00:00
|
|
|
super(1920, 1080, headless ? Phaser.HEADLESS : Phaser.AUTO, '-space-tac');
|
2015-04-22 21:42:40 +00:00
|
|
|
|
2017-02-09 00:00:35 +00:00
|
|
|
this.audio = new UI.Audio(this);
|
2014-12-29 00:00:00 +00:00
|
|
|
|
2017-02-09 00:00:35 +00:00
|
|
|
this.session = new GameSession();
|
2015-04-07 00:00:00 +00:00
|
|
|
this.star = null;
|
2015-02-27 00:00:00 +00:00
|
|
|
|
2017-02-09 00:00:35 +00:00
|
|
|
this.state.add('boot', UI.Boot);
|
|
|
|
this.state.add('preload', UI.Preload);
|
|
|
|
this.state.add('mainmenu', UI.MainMenu);
|
|
|
|
this.state.add('router', UI.Router);
|
|
|
|
this.state.add('battle', UI.BattleView);
|
|
|
|
this.state.add('universe', UI.UniverseMapView);
|
2014-12-29 00:00:00 +00:00
|
|
|
|
|
|
|
this.state.start('boot');
|
|
|
|
}
|
2015-02-27 00:00:00 +00:00
|
|
|
|
2015-03-04 00:00:00 +00:00
|
|
|
// Save current game in local browser storage
|
|
|
|
saveGame(): boolean {
|
2017-01-03 22:17:52 +00:00
|
|
|
if (typeof (Storage) !== "undefined") {
|
2015-04-07 00:00:00 +00:00
|
|
|
localStorage.setItem("spacetac-savegame", this.session.saveToString());
|
2017-02-09 00:00:35 +00:00
|
|
|
(<UI.BaseView>this.state.getCurrentState()).messages.addMessage("Game saved");
|
2015-03-04 00:00:00 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2017-02-09 00:00:35 +00:00
|
|
|
(<UI.BaseView>this.state.getCurrentState()).messages.addMessage("Your browser does not support saving");
|
2016-10-26 21:15:04 +00:00
|
|
|
return false;
|
2015-03-04 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load current game from local browser storage
|
|
|
|
loadGame(): boolean {
|
2017-01-03 22:17:52 +00:00
|
|
|
if (typeof (Storage) !== "undefined") {
|
2015-03-04 00:00:00 +00:00
|
|
|
var loaded = localStorage.getItem("spacetac-savegame");
|
|
|
|
if (loaded) {
|
2017-02-09 00:00:35 +00:00
|
|
|
this.session = GameSession.loadFromString(loaded);
|
2015-03-04 00:00:00 +00:00
|
|
|
console.log("Game loaded");
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
console.error("No saved game found");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.error("localStorage not available");
|
2016-10-26 21:15:04 +00:00
|
|
|
return false;
|
2015-03-04 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-07 00:00:00 +00:00
|
|
|
|
|
|
|
// Get the focuses star system
|
2017-02-09 00:00:35 +00:00
|
|
|
getFocusedStar(): Star {
|
2015-04-07 00:00:00 +00:00
|
|
|
if (this.star && this.star.universe === this.session.universe) {
|
|
|
|
return this.star;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2014-12-29 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|