2017-01-11 17:31:21 +00:00
|
|
|
/// <reference path="../TestGame.ts"/>
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.UI.Specs {
|
2017-10-26 21:47:13 +00:00
|
|
|
testing("BattleView", test => {
|
2017-10-29 21:08:55 +00:00
|
|
|
let testgame = setupBattleview(test);
|
2017-02-21 22:38:31 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("handles ship hovering to display tooltip", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
let battleview = testgame.view;
|
2017-10-29 21:08:55 +00:00
|
|
|
check.equals(battleview.ship_hovered, null, "initial state");
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
let ship = nn(battleview.battle.playing_ship);
|
|
|
|
battleview.cursorHovered(ship.location, ship);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.same(battleview.ship_hovered, ship, "ship1 hovered");
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
ship = nn(battleview.battle.play_order[1]);
|
|
|
|
battleview.cursorHovered(ship.location, ship);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.same(battleview.ship_hovered, ship, "ship2 hovered");
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
battleview.cursorHovered(new ArenaLocation(0, 0), null);
|
2017-10-29 21:08:55 +00:00
|
|
|
check.equals(battleview.ship_hovered, null, "out");
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
battleview.cursorOnShip(ship);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.same(battleview.ship_hovered, ship, "force on");
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
battleview.cursorOffShip(battleview.battle.play_order[2]);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.same(battleview.ship_hovered, ship, "force off on wrong ship");
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
battleview.cursorOffShip(ship);
|
2017-10-29 21:08:55 +00:00
|
|
|
check.equals(battleview.ship_hovered, null, "force off");
|
2017-09-19 15:09:06 +00:00
|
|
|
});
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("forwards cursor hovering and click to targetting", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
let battleview = testgame.view;
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battleview.targetting.active, false);
|
2017-09-19 15:09:06 +00:00
|
|
|
battleview.setInteractionEnabled(true);
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2018-02-08 15:16:03 +00:00
|
|
|
let ship = nn(battleview.battle.playing_ship);
|
|
|
|
let weapon = TestTools.addWeapon(ship, 10);
|
|
|
|
battleview.enterTargettingMode(ship, weapon, ActionTargettingMode.SPACE);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battleview.targetting.active, true);
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
battleview.cursorHovered(new ArenaLocation(5, 8), null);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battleview.targetting.target, Target.newFromLocation(5, 8));
|
|
|
|
check.equals(battleview.ship_hovered, null);
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2018-02-08 15:16:03 +00:00
|
|
|
ship = battleview.battle.play_order[3];
|
2017-09-19 15:09:06 +00:00
|
|
|
battleview.cursorHovered(ship.location, ship);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battleview.targetting.target, Target.newFromLocation(ship.arena_x, ship.arena_y));
|
|
|
|
check.equals(battleview.ship_hovered, null);
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
let validate = check.patch(battleview.targetting, "validate", null);
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
check.called(validate, 0);
|
2015-01-08 00:00:00 +00:00
|
|
|
battleview.cursorClicked();
|
2017-10-29 21:08:55 +00:00
|
|
|
check.called(validate, 1);
|
2015-01-08 00:00:00 +00:00
|
|
|
|
|
|
|
battleview.exitTargettingMode();
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battleview.targetting.active, false);
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
battleview.cursorHovered(new ArenaLocation(5, 8), null);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battleview.targetting.target, null);
|
|
|
|
check.equals(battleview.ship_hovered, null);
|
2017-10-01 21:08:43 +00:00
|
|
|
|
|
|
|
battleview.cursorHovered(ship.location, ship);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battleview.targetting.target, null);
|
|
|
|
check.same(battleview.ship_hovered, ship);
|
2015-01-08 00:00:00 +00:00
|
|
|
});
|
2017-09-13 22:26:14 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("allows to choose an action and a target with shortcut keys", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
let battleview = testgame.view;
|
2017-09-13 22:26:14 +00:00
|
|
|
battleview.setInteractionEnabled(true);
|
2017-09-19 15:09:06 +00:00
|
|
|
let action_icon = battleview.action_bar.action_icons[0];
|
2017-09-13 22:26:14 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battleview.targetting.active, false);
|
|
|
|
check.equals(battleview.action_bar.hasActionSelected(), false);
|
2017-09-13 22:26:14 +00:00
|
|
|
battleview.numberPressed(battleview.action_bar.action_icons.indexOf(action_icon) + 1);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battleview.action_bar.hasActionSelected(), true);
|
|
|
|
check.equals(battleview.targetting.active, true);
|
|
|
|
check.same(battleview.targetting.action, action_icon.action);
|
|
|
|
check.equals(battleview.targetting.target, action_icon.action.getDefaultTarget(action_icon.ship));
|
2017-09-13 22:26:14 +00:00
|
|
|
battleview.numberPressed(3);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battleview.targetting.active, true);
|
|
|
|
check.same(battleview.targetting.action, action_icon.action);
|
|
|
|
check.equals(battleview.targetting.target, Target.newFromShip(battleview.battle.play_order[3]));
|
2017-09-13 22:26:14 +00:00
|
|
|
battleview.numberPressed(4);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battleview.targetting.active, true);
|
|
|
|
check.same(battleview.targetting.action, action_icon.action);
|
|
|
|
check.equals(battleview.targetting.target, Target.newFromShip(battleview.battle.play_order[4]));
|
2017-09-13 22:26:14 +00:00
|
|
|
});
|
2015-01-08 00:00:00 +00:00
|
|
|
});
|
|
|
|
}
|