2017-01-11 17:31:21 +00:00
|
|
|
/// <reference path="../TestGame.ts"/>
|
2015-02-26 00:00:00 +00:00
|
|
|
|
2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac.UI.Specs {
|
2017-02-21 22:38:31 +00:00
|
|
|
describe("ActionBar", function () {
|
|
|
|
let testgame = setupBattleview();
|
|
|
|
|
|
|
|
it("lists available actions for selected ship", function () {
|
|
|
|
var bar = testgame.battleview.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-02-19 21:33:07 +00:00
|
|
|
expect(bar.action_icons.length).toBe(0);
|
2015-02-26 00:00:00 +00:00
|
|
|
|
|
|
|
// Ship with no equipment (only endturn action)
|
2017-02-21 22:38:31 +00:00
|
|
|
testgame.battleview.player = ship.getPlayer();
|
2015-02-26 00:00:00 +00:00
|
|
|
bar.setShip(ship);
|
2017-02-19 21:33:07 +00:00
|
|
|
expect(bar.action_icons.length).toBe(1);
|
|
|
|
expect(bar.action_icons[0].action.code).toEqual("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-02-19 21:33:07 +00:00
|
|
|
expect(bar.action_icons.length).toBe(2);
|
|
|
|
expect(bar.action_icons[0].action.code).toEqual("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-02-19 21:33:07 +00:00
|
|
|
expect(bar.action_icons.length).toBe(3);
|
2017-04-18 19:51:23 +00:00
|
|
|
expect(bar.action_icons[1].action.code).toEqual("fire-equipment");
|
2015-02-26 00:00:00 +00:00
|
|
|
});
|
|
|
|
|
2017-02-21 22:38:31 +00:00
|
|
|
it("mark actions that would become unavailable after use", function () {
|
|
|
|
let battleview = testgame.battleview;
|
2015-02-26 00:00:00 +00:00
|
|
|
var bar = battleview.action_bar;
|
2017-02-09 00:00:35 +00:00
|
|
|
var ship = new Ship();
|
2015-02-26 00:00:00 +00:00
|
|
|
ship.arena_x = 1;
|
|
|
|
ship.arena_y = 8;
|
2017-04-18 19:51:23 +00:00
|
|
|
var engine = TestTools.addEngine(ship, 0.5);
|
|
|
|
var weapon1 = TestTools.addWeapon(ship, 100, 3);
|
|
|
|
var weapon2 = TestTools.addWeapon(ship, 100, 5);
|
2015-02-26 00:00:00 +00:00
|
|
|
battleview.battle.playing_ship = ship;
|
|
|
|
battleview.player = ship.getPlayer();
|
|
|
|
|
2017-02-07 19:15:21 +00:00
|
|
|
ship.setAttribute("power_capacity", 10);
|
|
|
|
ship.setValue("power", 9);
|
2015-02-26 00:00:00 +00:00
|
|
|
bar.setShip(ship);
|
|
|
|
|
2017-02-19 21:33:07 +00:00
|
|
|
expect(bar.action_icons.length).toBe(4);
|
2015-02-26 00:00:00 +00:00
|
|
|
|
2017-06-21 23:32:18 +00:00
|
|
|
var checkFading = (fading: number[], available: number[], message: string) => {
|
2015-02-26 00:00:00 +00:00
|
|
|
fading.forEach((index: number) => {
|
2017-02-19 21:33:07 +00:00
|
|
|
var icon = bar.action_icons[index];
|
2017-06-21 23:32:18 +00:00
|
|
|
expect(icon.fading || !icon.active).toBe(true, `${message} - ${index} should be fading`);
|
2015-02-26 00:00:00 +00:00
|
|
|
});
|
|
|
|
available.forEach((index: number) => {
|
2017-02-19 21:33:07 +00:00
|
|
|
var icon = bar.action_icons[index];
|
2017-06-21 23:32:18 +00:00
|
|
|
expect(icon.fading).toBe(false, `${message} - ${index} should be available`);
|
2015-02-26 00:00:00 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-06-21 23:32:18 +00:00
|
|
|
bar.updateSelectedActionPower(3, 0, bar.action_icons[1].action);
|
|
|
|
checkFading([], [0, 1, 2, 3], "Weapon 1 leaves all choices open");
|
2017-01-19 23:39:13 +00:00
|
|
|
bar.actionEnded();
|
2015-02-26 00:00:00 +00:00
|
|
|
|
2017-06-21 23:32:18 +00:00
|
|
|
bar.updateSelectedActionPower(5, 0, bar.action_icons[2].action);
|
|
|
|
checkFading([2], [0, 1, 3], "Weapon 2 can't be fired twice");
|
2017-01-19 23:39:13 +00:00
|
|
|
bar.actionEnded();
|
2015-02-26 00:00:00 +00:00
|
|
|
|
2017-02-07 19:15:21 +00:00
|
|
|
ship.setValue("power", 7);
|
2017-06-21 23:32:18 +00:00
|
|
|
bar.updateSelectedActionPower(5, 0, bar.action_icons[2].action);
|
|
|
|
checkFading([1, 2], [0, 3], "Not enough AP for both weapons");
|
2017-01-19 23:39:13 +00:00
|
|
|
bar.actionEnded();
|
2015-02-26 00:00:00 +00:00
|
|
|
|
2017-02-07 19:15:21 +00:00
|
|
|
ship.setValue("power", 3);
|
2017-06-21 23:32:18 +00:00
|
|
|
bar.updateSelectedActionPower(3, 0, bar.action_icons[1].action);
|
|
|
|
checkFading([0, 1, 2], [3], "Not enough AP to move");
|
2017-01-19 23:39:13 +00:00
|
|
|
bar.actionEnded();
|
2015-02-26 00:00:00 +00:00
|
|
|
|
|
|
|
// Dynamic AP usage for move actions
|
2017-02-07 19:15:21 +00:00
|
|
|
ship.setValue("power", 6);
|
2017-06-21 23:32:18 +00:00
|
|
|
bar.updateSelectedActionPower(2, 0, bar.action_icons[0].action);
|
|
|
|
checkFading([2], [0, 1, 3], "2 move power used");
|
|
|
|
bar.updateSelectedActionPower(4, 0, bar.action_icons[0].action);
|
|
|
|
checkFading([1, 2], [0, 3], "4 move power used");
|
|
|
|
bar.updateSelectedActionPower(6, 0, bar.action_icons[0].action);
|
|
|
|
checkFading([0, 1, 2], [3], "6 move power used");
|
|
|
|
bar.updateSelectedActionPower(8, 0, bar.action_icons[0].action);
|
|
|
|
checkFading([0, 1, 2], [3], "8 move power used");
|
2017-01-19 23:39:13 +00:00
|
|
|
bar.actionEnded();
|
2015-02-26 00:00:00 +00:00
|
|
|
});
|
2017-02-19 21:33:07 +00:00
|
|
|
|
2017-02-21 22:38:31 +00:00
|
|
|
it("updates power points display", function () {
|
|
|
|
let bar = testgame.battleview.action_bar;
|
2017-02-19 21:33:07 +00:00
|
|
|
|
|
|
|
function check(available = 0, using = 0, used = 0) {
|
|
|
|
expect(bar.power.children.length).toBe(available + using + used);
|
|
|
|
bar.power.children.forEach((child, idx) => {
|
|
|
|
let img = <Phaser.Image>child;
|
|
|
|
if (idx < available) {
|
2017-08-24 23:02:32 +00:00
|
|
|
expect(img.name).toEqual("battle-actionbar-power-available");
|
2017-02-19 21:33:07 +00:00
|
|
|
} else if (idx < available + using) {
|
2017-08-24 23:02:32 +00:00
|
|
|
expect(img.name).toEqual("battle-actionbar-power-move");
|
2017-02-19 21:33:07 +00:00
|
|
|
} else {
|
2017-08-24 23:02:32 +00:00
|
|
|
expect(img.name).toEqual("battle-actionbar-power-used");
|
2017-02-19 21:33:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// not owned ship
|
|
|
|
let ship = new Ship();
|
|
|
|
TestTools.setShipAP(ship, 8);
|
|
|
|
bar.setShip(ship);
|
|
|
|
check();
|
|
|
|
|
|
|
|
// owned ship
|
2017-02-21 22:38:31 +00:00
|
|
|
ship.fleet = testgame.battleview.player.fleet;
|
2017-02-19 21:33:07 +00:00
|
|
|
bar.setShip(ship);
|
|
|
|
check(8);
|
|
|
|
|
|
|
|
// used points
|
|
|
|
ship.setValue("power", 6);
|
2017-06-13 20:48:43 +00:00
|
|
|
testgame.battleview.log_processor.jumpToEnd();
|
2017-02-19 21:33:07 +00:00
|
|
|
check(6, 0, 2);
|
|
|
|
|
|
|
|
// using points
|
|
|
|
bar.updatePower(5);
|
|
|
|
check(1, 5, 2);
|
|
|
|
|
|
|
|
// decrease
|
|
|
|
ship.setAttribute("power_capacity", 3);
|
2017-06-13 20:48:43 +00:00
|
|
|
testgame.battleview.log_processor.jumpToEnd();
|
2017-02-19 21:33:07 +00:00
|
|
|
check(3);
|
|
|
|
});
|
2015-02-26 00:00:00 +00:00
|
|
|
});
|
|
|
|
}
|