2017-01-11 17:31:21 +00:00
|
|
|
/// <reference path="../TestGame.ts"/>
|
2015-02-26 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("ActionBar", 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("lists available actions for selected ship", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
var bar = testgame.view.action_bar;
|
2015-02-26 00:00:00 +00:00
|
|
|
|
|
|
|
// Ship not owned by current battleview player
|
2017-02-09 00:00:35 +00:00
|
|
|
var ship = new Ship();
|
2015-02-26 00:00:00 +00:00
|
|
|
bar.setShip(ship);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(bar.action_icons.length, 0);
|
2015-02-26 00:00:00 +00:00
|
|
|
|
|
|
|
// Ship with no equipment (only endturn action)
|
2018-01-16 00:08:24 +00:00
|
|
|
let player = new Player();
|
|
|
|
ship.fleet.setPlayer(player);
|
|
|
|
testgame.view.player = player;
|
2015-02-26 00:00:00 +00:00
|
|
|
bar.setShip(ship);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(bar.action_icons.length, 1);
|
|
|
|
check.equals(bar.action_icons[0].action.code, "endturn");
|
2015-02-26 00:00:00 +00:00
|
|
|
|
|
|
|
// Add an engine, with move action
|
2017-04-18 19:51:23 +00:00
|
|
|
TestTools.addEngine(ship, 50);
|
2015-02-26 00:00:00 +00:00
|
|
|
bar.setShip(ship);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(bar.action_icons.length, 2);
|
|
|
|
check.equals(bar.action_icons[0].action.code, "move");
|
2015-02-26 00:00:00 +00:00
|
|
|
|
|
|
|
// Add a weapon, with fire action
|
2017-04-18 19:51:23 +00:00
|
|
|
TestTools.addWeapon(ship, 10, 1, 100);
|
2015-02-26 00:00:00 +00:00
|
|
|
bar.setShip(ship);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(bar.action_icons.length, 3);
|
|
|
|
check.equals(bar.action_icons[1].action.code, "fire-equipment");
|
2015-02-26 00:00:00 +00:00
|
|
|
});
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("updates power points display", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
let bar = testgame.view.action_bar;
|
2017-02-19 21:33:07 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
function checkpoints(desc: string, available = 0, using = 0, used = 0) {
|
|
|
|
check.in(desc, check => {
|
|
|
|
check.same(bar.power_icons.children.length, available + using + used, "icon count");
|
|
|
|
bar.power_icons.children.forEach((child, idx) => {
|
|
|
|
let img = <Phaser.Image>child;
|
|
|
|
if (idx < available) {
|
|
|
|
check.equals(img.name, "battle-actionbar-power-available", `icon ${idx}`);
|
|
|
|
} else if (idx < available + using) {
|
|
|
|
check.equals(img.name, "battle-actionbar-power-move", `icon ${idx}`);
|
|
|
|
} else {
|
|
|
|
check.equals(img.name, "battle-actionbar-power-used", `icon ${idx}`);
|
|
|
|
}
|
|
|
|
});
|
2017-02-19 21:33:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// not owned ship
|
|
|
|
let ship = new Ship();
|
|
|
|
TestTools.setShipAP(ship, 8);
|
|
|
|
bar.setShip(ship);
|
2017-11-14 00:07:06 +00:00
|
|
|
checkpoints("not owned ship");
|
2017-02-19 21:33:07 +00:00
|
|
|
|
|
|
|
// owned ship
|
2017-11-14 00:07:06 +00:00
|
|
|
testgame.view.player.fleet.addShip(ship);
|
|
|
|
testgame.view.battle.ships.add(duplicate(ship, TK.SpaceTac));
|
|
|
|
testgame.view.actual_battle.ships.add(ship);
|
2017-02-19 21:33:07 +00:00
|
|
|
bar.setShip(ship);
|
2017-11-14 00:07:06 +00:00
|
|
|
checkpoints("owned ship", 8);
|
2017-02-19 21:33:07 +00:00
|
|
|
|
|
|
|
// used points
|
2017-11-14 00:07:06 +00:00
|
|
|
testgame.view.actual_battle.applyDiffs(ship.getValueDiffs("power", 6));
|
|
|
|
testgame.view.log_processor.processPending();
|
|
|
|
checkpoints("2 points used", 6, 0, 2);
|
2017-02-19 21:33:07 +00:00
|
|
|
|
|
|
|
// using points
|
|
|
|
bar.updatePower(5);
|
2017-11-14 00:07:06 +00:00
|
|
|
checkpoints("5 points in targetting", 1, 5, 2);
|
2017-02-19 21:33:07 +00:00
|
|
|
|
|
|
|
// decrease
|
2017-11-14 00:07:06 +00:00
|
|
|
testgame.view.actual_battle.applyDiffs([new ShipAttributeDiff(ship, "power_capacity", { limit: 3 }, {})]);
|
|
|
|
testgame.view.log_processor.processPending();
|
|
|
|
checkpoints("limit to 3", 3);
|
2017-02-19 21:33:07 +00:00
|
|
|
});
|
2015-02-26 00:00:00 +00:00
|
|
|
});
|
|
|
|
}
|