1
0
Fork 0
spacetac/src/ui/battle/Targetting.spec.ts

157 lines
6.8 KiB
TypeScript
Raw Normal View History

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,
2018-07-09 14:04:40 +00:00
testgame.view.toggle_tactical_mode);
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();
2017-10-09 21:13:56 +00:00
let ship = nn(testgame.view.battle.playing_ship);
ship.setArenaPosition(10, 20);
let weapon = TestTools.addWeapon(ship);
let engine = TestTools.addEngine(ship, 12);
targetting.setAction(ship, weapon);
2017-10-29 21:08:55 +00:00
let drawvector = check.patch(targetting, "drawVector", null);
let part = {
action: <BaseAction>weapon,
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]
]);
targetting.drawPart(part, false, null);
2017-10-29 21:08:55 +00:00
check.called(drawvector, [
[0x8e8e8e, 10, 20, 50, 30, 0]
]);
targetting.action = engine;
part.action = engine;
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-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("weapon", { range: 50 });
2018-03-29 22:57:53 +00:00
let collect = check.patch(action, "getImpactedShips", nnf([], iterator([
[new Ship(), new Ship(), new Ship()],
[new Ship(), new Ship()],
2017-10-29 21:08:55 +00:00
[]
2018-03-29 22:57:53 +00:00
])));
2017-10-03 16:11:30 +00:00
targetting.updateImpactIndicators(impacts, ship, action, new Target(20, 10));
2017-10-29 21:08:55 +00:00
check.called(collect, [
[ship, new Target(20, 10), ship.location]
])
2018-05-15 14:57:45 +00:00
check.equals(targetting.impact_indicators.length, 3);
2017-10-26 21:47:13 +00:00
check.equals(targetting.impact_indicators.visible, true);
2017-10-03 16:11:30 +00:00
targetting.updateImpactIndicators(impacts, ship, action, new Target(20, 11));
2017-10-29 21:08:55 +00:00
check.called(collect, [
[ship, new Target(20, 11), ship.location]
])
2018-05-15 14:57:45 +00:00
check.equals(targetting.impact_indicators.length, 2);
2017-10-26 21:47:13 +00:00
check.equals(targetting.impact_indicators.visible, true);
2017-10-03 16:11:30 +00:00
targetting.updateImpactIndicators(impacts, ship, action, new Target(20, 12));
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-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);
let engine = TestTools.addEngine(ship, 8000);
let weapon = TestTools.addWeapon(ship, 30, 5, 100, 50);
targetting.setAction(ship, weapon);
targetting.setTarget(Target.newFromLocation(156, 65));
2017-10-29 21:08:55 +00:00
check.patch(targetting, "simulate", () => {
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 = [
{ action: engine, target: Target.newFromLocation(80, 20), ap: 1, possible: true },
{ action: weapon, target: Target.newFromLocation(156, 65), ap: 5, possible: true }
]
targetting.simulation = result;
});
targetting.update();
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);
2018-05-15 14:57:45 +00:00
check.equals(targetting.fire_arrow.x, 156);
check.equals(targetting.fire_arrow.y, 65);
2017-10-26 21:47:13 +00:00
check.nears(targetting.fire_arrow.rotation, 0.534594, 5);
check.equals(targetting.impact_area.visible, true);
2018-05-15 14:57:45 +00:00
check.equals(targetting.impact_area.x, 156);
check.equals(targetting.impact_area.y, 65);
2017-10-26 21:47:13 +00:00
check.equals(targetting.move_ghost.visible, true);
2018-05-15 14:57:45 +00:00
check.equals(targetting.move_ghost.x, 80);
check.equals(targetting.move_ghost.y, 20);
2017-10-26 21:47:13 +00:00
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);
let action = TestTools.addWeapon(playing_ship);
2017-10-01 16:33:48 +00:00
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(playing_ship, action, ActionTargettingMode.SPACE);
2017-10-01 16:33:48 +00:00
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(playing_ship, action, ActionTargettingMode.SHIP);
2017-10-01 16:33:48 +00:00
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(playing_ship, action, ActionTargettingMode.SURROUNDINGS);
2017-10-01 16:33:48 +00:00
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(playing_ship, action, ActionTargettingMode.SELF);
2017-10-01 16:33:48 +00:00
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
})
});
2015-01-07 00:00:00 +00:00
}