1
0
Fork 0
spacetac/src/ui/TestGame.ts

62 lines
2.1 KiB
TypeScript
Raw Normal View History

/// <reference path="battle/BattleView.ts"/>
2017-01-30 00:40:33 +00:00
/// <reference path="map/UniverseMapView.ts"/>
2015-01-08 00:00:00 +00:00
2017-02-09 00:00:35 +00:00
module TS.SpaceTac.UI.Specs {
2015-01-08 00:00:00 +00:00
// Test game wrapper (use instead of jasmine 'it')
2017-02-10 00:08:28 +00:00
export function ingame_it(desc: string, func: (game: MainUI, state: Phaser.State) => void,
2017-01-03 22:17:52 +00:00
state: Phaser.State = null, ...stateargs: any[]) {
2015-01-08 00:00:00 +00:00
it(desc, (done: () => void) => {
spyOn(console, "log").and.stub();
spyOn(console, "warn").and.stub();
2017-02-09 00:00:35 +00:00
var game = new MainUI(true);
2015-01-08 00:00:00 +00:00
2017-02-16 22:59:41 +00:00
if (game.load) {
spyOn(game.load, 'image').and.stub();
spyOn(game.load, 'audio').and.stub();
}
2017-02-10 00:08:28 +00:00
2015-01-08 00:00:00 +00:00
if (!state) {
state = new Phaser.State();
}
var orig_create = state.create;
2015-01-09 00:00:00 +00:00
state.create = function () {
2015-01-08 00:00:00 +00:00
orig_create.apply(state);
func(game, state);
done();
2015-01-09 00:00:00 +00:00
setTimeout(() => {
game.destroy();
}, 1000);
2015-01-08 00:00:00 +00:00
};
game.state.add("test", state);
var args = stateargs.slice(0);
args.unshift(true);
args.unshift(true);
args.unshift("test");
game.state.start.apply(game.state, args);
2015-01-08 00:00:00 +00:00
});
}
// Test game wrapper, with a battleview initialized on a random battle
export function inbattleview_it(desc: string, func: (battleview: BattleView) => void) {
var battleview = new BattleView();
2017-02-09 00:00:35 +00:00
var battle = Battle.newQuickRandom();
var player = battle.playing_ship.getPlayer();
ingame_it(desc, (game: Phaser.Game, state: Phaser.State) => {
func(battleview);
}, battleview, player, battle);
}
2017-01-30 00:40:33 +00:00
// Test game wrapper, with a map initialized on a random universe
export function inmapview_it(desc: string, func: (mapview: UniverseMapView) => void) {
var mapview = new UniverseMapView();
2017-02-09 00:00:35 +00:00
var session = new GameSession();
2017-01-30 00:40:33 +00:00
session.startNewGame();
ingame_it(desc, (game: Phaser.Game, state: Phaser.State) => {
func(mapview);
}, mapview, session.universe, session.player);
}
2015-01-08 00:00:00 +00:00
}