71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
module SpaceTac.View {
|
|
"use strict";
|
|
|
|
// Bar with all playing ships, by play order
|
|
export class ShipList extends Phaser.Group {
|
|
// Link to the parent battleview
|
|
battleview: BattleView;
|
|
|
|
// List of ship items
|
|
ships: ShipListItem[];
|
|
|
|
// Create an empty action bar
|
|
constructor(battleview: BattleView) {
|
|
this.battleview = battleview;
|
|
this.ships = [];
|
|
|
|
super(battleview.game, battleview.ui);
|
|
battleview.ui.add(this);
|
|
|
|
if (battleview.battle) {
|
|
this.setShipsFromBattle(battleview.battle);
|
|
}
|
|
this.update();
|
|
}
|
|
|
|
// Update the bar status (and position)
|
|
update() {
|
|
super.update();
|
|
|
|
this.y = 100;
|
|
}
|
|
|
|
// Clear the action icons
|
|
clearAll(): void {
|
|
this.ships.forEach((ship: ShipListItem) => {
|
|
ship.destroy();
|
|
});
|
|
this.ships = [];
|
|
}
|
|
|
|
// Set the ship list from a battle
|
|
setShipsFromBattle(battle: Game.Battle): void {
|
|
this.clearAll();
|
|
battle.play_order.forEach((ship: Game.Ship) => {
|
|
this.addShip(ship);
|
|
}, this);
|
|
}
|
|
|
|
// Add a ship icon
|
|
addShip(ship: Game.Ship): ShipListItem {
|
|
var owned = ship.getPlayer() === this.battleview.player;
|
|
var result = new ShipListItem(this, 0, this.ships.length * 50, ship, owned);
|
|
this.ships.push(result);
|
|
this.add(result);
|
|
return result;
|
|
}
|
|
|
|
// Find an item for a ship
|
|
// Returns null if not found
|
|
findItem(ship: Game.Ship): ShipListItem {
|
|
var found: ShipListItem = null;
|
|
this.ships.forEach((item: ShipListItem) => {
|
|
if (item.ship === ship) {
|
|
found = item;
|
|
}
|
|
});
|
|
return found;
|
|
}
|
|
}
|
|
}
|