2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.UI.Specs {
|
2017-10-26 21:47:13 +00:00
|
|
|
testing("Targetting", test => {
|
2017-10-29 21:08:55 +00:00
|
|
|
let testgame = setupBattleview(test);
|
2017-02-21 22:38:31 +00:00
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
function newTargetting(): Targetting {
|
2017-10-09 21:13:56 +00:00
|
|
|
return new Targetting(testgame.view,
|
|
|
|
testgame.view.action_bar,
|
|
|
|
testgame.view.toggle_tactical_mode,
|
|
|
|
testgame.view.arena.range_hint);
|
2017-09-19 15:09:06 +00:00
|
|
|
}
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("draws simulation parts", check => {
|
2017-09-19 15:09:06 +00:00
|
|
|
let targetting = newTargetting();
|
2015-01-02 00:00:00 +00:00
|
|
|
|
2017-10-09 21:13:56 +00:00
|
|
|
let ship = nn(testgame.view.battle.playing_ship);
|
2017-06-21 23:32:18 +00:00
|
|
|
ship.setArenaPosition(10, 20);
|
|
|
|
let weapon = TestTools.addWeapon(ship);
|
|
|
|
let engine = TestTools.addEngine(ship, 12);
|
|
|
|
targetting.setAction(weapon.action);
|
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
let drawvector = check.patch(targetting, "drawVector", null);
|
2015-01-02 00:00:00 +00:00
|
|
|
|
2017-06-21 23:32:18 +00:00
|
|
|
let part = {
|
2017-09-19 15:09:06 +00:00
|
|
|
action: nn(weapon.action),
|
2017-06-21 23:32:18 +00:00
|
|
|
target: new Target(50, 30),
|
|
|
|
ap: 5,
|
|
|
|
possible: true
|
|
|
|
};
|
|
|
|
targetting.drawPart(part, true, null);
|
2017-10-29 21:08:55 +00:00
|
|
|
check.called(drawvector, [
|
|
|
|
[0xdc6441, 10, 20, 50, 30, 0]
|
|
|
|
]);
|
2015-01-02 00:00:00 +00:00
|
|
|
|
2017-06-21 23:32:18 +00:00
|
|
|
targetting.drawPart(part, false, null);
|
2017-10-29 21:08:55 +00:00
|
|
|
check.called(drawvector, [
|
|
|
|
[0x8e8e8e, 10, 20, 50, 30, 0]
|
|
|
|
]);
|
2017-06-21 23:32:18 +00:00
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
targetting.action = engine.action;
|
|
|
|
part.action = nn(engine.action);
|
2017-06-21 23:32:18 +00:00
|
|
|
targetting.drawPart(part, true, null);
|
2017-10-29 21:08:55 +00:00
|
|
|
check.called(drawvector, [
|
|
|
|
[0xe09c47, 10, 20, 50, 30, 12]
|
|
|
|
]);
|
2017-10-01 16:33:48 +00:00
|
|
|
})
|
2017-01-19 18:33:56 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("updates impact indicators on ships inside the blast radius", check => {
|
2017-09-19 15:09:06 +00:00
|
|
|
let targetting = newTargetting();
|
2017-10-09 21:13:56 +00:00
|
|
|
let ship = nn(testgame.view.battle.playing_ship);
|
2017-10-03 16:11:30 +00:00
|
|
|
let impacts = targetting.impact_indicators;
|
|
|
|
let action = new TriggerAction(new Equipment(), [], 1, 0, 50);
|
2017-01-19 18:33:56 +00:00
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
let collect = check.patch(action, "getImpactedShips", iterator([
|
2017-06-21 23:32:18 +00:00
|
|
|
[new Ship(), new Ship(), new Ship()],
|
|
|
|
[new Ship(), new Ship()],
|
2017-10-29 21:08:55 +00:00
|
|
|
[]
|
|
|
|
]));
|
2017-10-03 16:11:30 +00:00
|
|
|
targetting.updateImpactIndicators(impacts, ship, action, new Target(20, 10));
|
2017-01-19 18:33:56 +00:00
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
check.called(collect, [
|
|
|
|
[ship, new Target(20, 10), ship.location]
|
|
|
|
])
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(targetting.impact_indicators.children.length, 3);
|
|
|
|
check.equals(targetting.impact_indicators.visible, true);
|
2017-01-19 18:33:56 +00:00
|
|
|
|
2017-10-03 16:11:30 +00:00
|
|
|
targetting.updateImpactIndicators(impacts, ship, action, new Target(20, 11));
|
2017-01-19 18:33:56 +00:00
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
check.called(collect, [
|
|
|
|
[ship, new Target(20, 11), ship.location]
|
|
|
|
])
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(targetting.impact_indicators.children.length, 2);
|
|
|
|
check.equals(targetting.impact_indicators.visible, true);
|
2017-01-19 18:33:56 +00:00
|
|
|
|
2017-10-03 16:11:30 +00:00
|
|
|
targetting.updateImpactIndicators(impacts, ship, action, new Target(20, 12));
|
2017-01-19 18:33:56 +00:00
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
check.called(collect, [
|
|
|
|
[ship, new Target(20, 12), ship.location]
|
|
|
|
])
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(targetting.impact_indicators.visible, false);
|
2017-10-01 16:33:48 +00:00
|
|
|
})
|
2017-06-21 23:32:18 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("updates graphics from simulation", check => {
|
2017-09-19 15:09:06 +00:00
|
|
|
let targetting = newTargetting();
|
2017-10-09 21:13:56 +00:00
|
|
|
let ship = nn(testgame.view.battle.playing_ship);
|
2017-06-21 23:32:18 +00:00
|
|
|
|
|
|
|
let engine = TestTools.addEngine(ship, 8000);
|
|
|
|
let weapon = TestTools.addWeapon(ship, 30, 5, 100, 50);
|
|
|
|
targetting.setAction(weapon.action);
|
|
|
|
targetting.setTarget(Target.newFromLocation(156, 65));
|
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
check.patch(targetting, "simulate", () => {
|
2017-06-21 23:32:18 +00:00
|
|
|
let result = new MoveFireResult();
|
|
|
|
result.success = true;
|
|
|
|
result.complete = true;
|
|
|
|
result.need_move = true;
|
|
|
|
result.move_location = Target.newFromLocation(80, 20);
|
|
|
|
result.can_move = true;
|
|
|
|
result.can_end_move = true;
|
|
|
|
result.need_fire = true;
|
|
|
|
result.can_fire = true;
|
|
|
|
result.parts = [
|
2017-09-19 15:09:06 +00:00
|
|
|
{ action: nn(engine.action), target: Target.newFromLocation(80, 20), ap: 1, possible: true },
|
|
|
|
{ action: nn(weapon.action), target: Target.newFromLocation(156, 65), ap: 5, possible: true }
|
2017-06-21 23:32:18 +00:00
|
|
|
]
|
|
|
|
targetting.simulation = result;
|
|
|
|
});
|
|
|
|
targetting.update();
|
2017-01-19 18:33:56 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(targetting.container.visible, true);
|
|
|
|
check.equals(targetting.drawn_info.visible, true);
|
|
|
|
check.equals(targetting.fire_arrow.visible, true);
|
|
|
|
check.containing(targetting.fire_arrow.position, { x: 156, y: 65 });
|
|
|
|
check.nears(targetting.fire_arrow.rotation, 0.534594, 5);
|
|
|
|
check.equals(targetting.impact_area.visible, true);
|
|
|
|
check.containing(targetting.impact_area.position, { x: 156, y: 65 });
|
|
|
|
check.equals(targetting.move_ghost.visible, true);
|
|
|
|
check.containing(targetting.move_ghost.position, { x: 80, y: 20 });
|
|
|
|
check.nears(targetting.move_ghost.rotation, 0.534594, 5);
|
2017-10-01 16:33:48 +00:00
|
|
|
})
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("snaps on ships according to targetting mode", check => {
|
2017-10-01 16:33:48 +00:00
|
|
|
let targetting = newTargetting();
|
2017-10-09 21:13:56 +00:00
|
|
|
let playing_ship = nn(testgame.view.battle.playing_ship);
|
2017-10-01 16:33:48 +00:00
|
|
|
let action = TestTools.addWeapon(playing_ship).action;
|
|
|
|
|
2017-10-09 21:13:56 +00:00
|
|
|
let ship1 = testgame.view.battle.play_order[1];
|
|
|
|
let ship2 = testgame.view.battle.play_order[2];
|
2017-10-01 16:33:48 +00:00
|
|
|
ship1.setArenaPosition(8000, 50);
|
|
|
|
ship2.setArenaPosition(8000, 230);
|
|
|
|
|
|
|
|
targetting.setAction(action, ActionTargettingMode.SPACE);
|
|
|
|
targetting.setTargetFromLocation({ x: 8000, y: 60 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(targetting.target, Target.newFromLocation(8000, 60), "space");
|
2017-10-01 16:33:48 +00:00
|
|
|
|
|
|
|
targetting.setAction(action, ActionTargettingMode.SHIP);
|
|
|
|
targetting.setTargetFromLocation({ x: 8000, y: 60 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(targetting.target, Target.newFromShip(ship1), "ship 1");
|
2017-10-01 16:33:48 +00:00
|
|
|
targetting.setTargetFromLocation({ x: 8100, y: 200 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(targetting.target, Target.newFromShip(ship2), "ship 2");
|
2017-10-01 16:33:48 +00:00
|
|
|
|
|
|
|
targetting.setAction(action, ActionTargettingMode.SURROUNDINGS);
|
|
|
|
targetting.setTargetFromLocation({ x: 8000, y: 60 });
|
2017-11-29 00:36:07 +00:00
|
|
|
check.equals(targetting.target, new Target(8000, 60, playing_ship), "surroundings 1");
|
2017-10-01 16:33:48 +00:00
|
|
|
targetting.setTargetFromLocation({ x: playing_ship.arena_x + 10, y: playing_ship.arena_y - 20 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(targetting.target, Target.newFromShip(playing_ship), "surroundings 2");
|
2017-10-01 16:33:48 +00:00
|
|
|
|
|
|
|
targetting.setAction(action, ActionTargettingMode.SELF);
|
|
|
|
targetting.setTargetFromLocation({ x: 8000, y: 60 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(targetting.target, Target.newFromShip(playing_ship), "self 1");
|
2017-10-01 16:33:48 +00:00
|
|
|
targetting.setTargetFromLocation({ x: 0, y: 0 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(targetting.target, Target.newFromShip(playing_ship), "self 2");
|
2017-10-01 16:33:48 +00:00
|
|
|
})
|
2017-10-01 18:16:41 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("updates the range hint display", check => {
|
2017-10-01 18:16:41 +00:00
|
|
|
let targetting = newTargetting();
|
2017-10-09 21:13:56 +00:00
|
|
|
let ship = nn(testgame.view.battle.playing_ship);
|
2017-10-01 18:16:41 +00:00
|
|
|
ship.setArenaPosition(0, 0);
|
|
|
|
ship.listEquipment(SlotType.Engine).forEach(engine => engine.detach());
|
|
|
|
TestTools.setShipAP(ship, 8);
|
|
|
|
let move = TestTools.addEngine(ship, 100).action;
|
|
|
|
let fire = TestTools.addWeapon(ship, 50, 2, 300, 100).action;
|
|
|
|
let last_call: any = null;
|
2017-10-29 21:08:55 +00:00
|
|
|
check.patch(targetting.range_hint, "clear", () => last_call = null);
|
|
|
|
check.patch(targetting.range_hint, "update", (ship: Ship, action: BaseAction, radius: number) => last_call = [ship, action, radius]);
|
2017-10-01 18:16:41 +00:00
|
|
|
|
|
|
|
// move action
|
|
|
|
targetting.setAction(move);
|
|
|
|
targetting.setTargetFromLocation({ x: 200, y: 0 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(last_call, [ship, move, 800]);
|
2017-10-01 18:16:41 +00:00
|
|
|
|
|
|
|
// fire action
|
|
|
|
targetting.setAction(fire);
|
|
|
|
targetting.setTargetFromLocation({ x: 200, y: 0 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(last_call, [ship, fire, undefined]);
|
2017-10-01 18:16:41 +00:00
|
|
|
|
|
|
|
// move+fire
|
|
|
|
targetting.setAction(fire);
|
|
|
|
targetting.setTargetFromLocation({ x: 400, y: 0 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(last_call, [ship, move, 600]);
|
2017-10-01 18:16:41 +00:00
|
|
|
});
|
2015-01-02 00:00:00 +00:00
|
|
|
});
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|