2017-01-11 17:31:21 +00:00
|
|
|
/// <reference path="../TestGame.ts"/>
|
2015-04-26 17:15:45 +00:00
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.UI.Specs {
|
2017-10-25 22:45:53 +00:00
|
|
|
testing("ShipList", test => {
|
2017-10-29 21:08:55 +00:00
|
|
|
let testgame = setupEmptyView(test);
|
2017-02-21 22:38:31 +00:00
|
|
|
|
2017-10-25 22:45:53 +00:00
|
|
|
function createList(): ShipList {
|
|
|
|
let view = testgame.view;
|
|
|
|
let battle = new Battle();
|
2018-01-16 00:08:24 +00:00
|
|
|
let player = new Player();
|
|
|
|
battle.fleets[0].setPlayer(player);
|
2017-10-25 22:45:53 +00:00
|
|
|
let tactical_mode = new Toggle();
|
2017-10-29 21:08:55 +00:00
|
|
|
let ship_buttons = {
|
|
|
|
cursorOnShip: nop,
|
|
|
|
cursorOffShip: nop,
|
|
|
|
cursorClicked: nop,
|
|
|
|
};
|
2018-01-16 00:08:24 +00:00
|
|
|
let list = new ShipList(view, battle, player, tactical_mode, ship_buttons);
|
2017-10-25 22:45:53 +00:00
|
|
|
return list;
|
|
|
|
}
|
2015-04-26 17:15:45 +00:00
|
|
|
|
2017-10-25 22:45:53 +00:00
|
|
|
test.case("handles play position of ships", check => {
|
|
|
|
let list = createList();
|
|
|
|
let battle = list.battle;
|
2017-11-14 00:07:06 +00:00
|
|
|
check.in("initial", check => {
|
|
|
|
check.equals(list.items.length, 0, "no item at first");
|
|
|
|
});
|
2017-02-16 22:59:41 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
let ship = battle.fleets[0].addShip();
|
2018-02-08 15:16:03 +00:00
|
|
|
TestTools.setShipModel(ship, 10, 0);
|
2017-10-25 22:45:53 +00:00
|
|
|
list.setShipsFromBattle(battle, false);
|
2017-11-14 00:07:06 +00:00
|
|
|
check.in("one ship added but not in play order", check => {
|
|
|
|
check.equals(list.items.length, 1, "item count");
|
|
|
|
check.equals(list.items[0].visible, false, "ship card not visible");
|
|
|
|
});
|
2015-04-26 17:15:45 +00:00
|
|
|
|
2017-10-25 22:45:53 +00:00
|
|
|
battle.throwInitiative();
|
|
|
|
list.refresh(false);
|
2017-11-14 00:07:06 +00:00
|
|
|
check.in("ship now in play order", check => {
|
|
|
|
check.equals(list.items[0].visible, true, "ship card visible");
|
|
|
|
});
|
2015-04-26 17:15:45 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
ship = battle.fleets[1].addShip();
|
2018-02-08 15:16:03 +00:00
|
|
|
TestTools.setShipModel(ship, 10, 0);
|
2017-10-25 22:45:53 +00:00
|
|
|
battle.throwInitiative();
|
|
|
|
list.setShipsFromBattle(battle, false);
|
2017-11-14 00:07:06 +00:00
|
|
|
check.in("ship added in the other fleet", check => {
|
|
|
|
check.equals(list.items.length, 2, "item count");
|
|
|
|
check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(2, 843), "first ship position");
|
|
|
|
check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(2, 744), "second ship position");
|
|
|
|
});
|
2017-10-25 22:45:53 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
battle.setPlayingShip(battle.play_order[0]);
|
2017-10-25 22:45:53 +00:00
|
|
|
list.refresh(false);
|
2017-11-14 00:07:06 +00:00
|
|
|
check.in("started", check => {
|
2018-04-16 18:12:51 +00:00
|
|
|
check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(-14, 962), "first ship position");
|
2017-11-14 00:07:06 +00:00
|
|
|
check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(2, 843), "second ship position");
|
|
|
|
});
|
2017-10-25 22:45:53 +00:00
|
|
|
|
|
|
|
battle.advanceToNextShip();
|
|
|
|
list.refresh(false);
|
2017-11-14 00:07:06 +00:00
|
|
|
check.in("end turn", check => {
|
|
|
|
check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(2, 843), "first ship position");
|
2018-04-16 18:12:51 +00:00
|
|
|
check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(-14, 962), "second ship position");
|
2017-11-14 00:07:06 +00:00
|
|
|
});
|
2017-10-29 21:08:55 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
ship = battle.fleets[1].addShip();
|
2018-02-08 15:16:03 +00:00
|
|
|
TestTools.setShipModel(ship, 10, 0);
|
2017-10-25 22:45:53 +00:00
|
|
|
battle.throwInitiative();
|
2017-11-14 00:07:06 +00:00
|
|
|
battle.setPlayingShip(battle.play_order[0]);
|
2017-10-25 22:45:53 +00:00
|
|
|
list.setShipsFromBattle(battle, false);
|
2017-11-14 00:07:06 +00:00
|
|
|
check.in("third ship added", check => {
|
|
|
|
check.equals(list.items.length, 3, "item count");
|
2018-04-16 18:12:51 +00:00
|
|
|
check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(-14, 962), "first ship position");
|
2017-11-14 00:07:06 +00:00
|
|
|
check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(2, 843), "second ship position");
|
|
|
|
check.equals(nn(list.findItem(battle.play_order[2])).position, new Phaser.Point(2, 744), "third ship position");
|
|
|
|
});
|
2017-10-25 22:45:53 +00:00
|
|
|
|
|
|
|
let dead = battle.play_order[1];
|
|
|
|
dead.setDead();
|
|
|
|
list.refresh(false);
|
2017-11-14 00:07:06 +00:00
|
|
|
check.in("ship dead", check => {
|
|
|
|
check.equals(list.items.length, 3, "item count");
|
2018-04-16 18:12:51 +00:00
|
|
|
check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(-14, 962), "first ship position");
|
2017-11-14 00:07:06 +00:00
|
|
|
check.equals(nn(list.findItem(dead)).position, new Phaser.Point(200, 843), "dead ship position");
|
|
|
|
check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(2, 843), "second ship position");
|
|
|
|
});
|
2015-04-26 17:15:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|