diff --git a/src/core/Ship.ts b/src/core/Ship.ts index 2b4d4f8..8348933 100644 --- a/src/core/Ship.ts +++ b/src/core/Ship.ts @@ -75,6 +75,10 @@ module TS.SpaceTac { // List of slots, able to contain equipment slots: Slot[] + // Cargo + cargo_space: number = 0 + cargo: Equipment[] = [] + // Ship attributes attributes = new ShipAttributes() @@ -434,6 +438,13 @@ module TS.SpaceTac { } } + /** + * Set the available cargo space. + */ + setCargoSpace(cargo: number) { + this.cargo_space = cargo; + } + // Add an empty equipment slot of the given type addSlot(type: SlotType): Slot { var result = new Slot(this, type); diff --git a/src/core/ShipGenerator.spec.ts b/src/core/ShipGenerator.spec.ts index 7da28bc..3bf9b30 100644 --- a/src/core/ShipGenerator.spec.ts +++ b/src/core/ShipGenerator.spec.ts @@ -2,9 +2,10 @@ module TS.SpaceTac.Specs { describe("ShipGenerator", function () { it("can use ship model", function () { var gen = new ShipGenerator(); - var model = new ShipModel("test", 1, SlotType.Shield, SlotType.Weapon, SlotType.Weapon); + var model = new ShipModel("test", 1, 2, SlotType.Shield, SlotType.Weapon, SlotType.Weapon); var ship = gen.generate(1, model); expect(ship.model).toBe("test"); + expect(ship.cargo_space).toBe(2); expect(ship.slots.length).toBe(3); expect(ship.slots[0].type).toBe(SlotType.Shield); expect(ship.slots[1].type).toBe(SlotType.Weapon); diff --git a/src/core/ShipGenerator.ts b/src/core/ShipGenerator.ts index b35fd4e..e154a08 100644 --- a/src/core/ShipGenerator.ts +++ b/src/core/ShipGenerator.ts @@ -22,6 +22,7 @@ module TS.SpaceTac { // Apply model result.model = model.code; + result.setCargoSpace(model.cargo); model.slots.forEach((slot: SlotType) => { result.addSlot(slot); }); diff --git a/src/core/ShipModel.ts b/src/core/ShipModel.ts index 7de4918..34d0fe0 100644 --- a/src/core/ShipModel.ts +++ b/src/core/ShipModel.ts @@ -8,12 +8,16 @@ module TS.SpaceTac { // Minimal level to use this model level: number; + // Cargo space + cargo: number; + // Available slots slots: SlotType[]; - constructor(code: string, level: number, ...slots: SlotType[]) { + constructor(code: string, level: number, cargo: number, ...slots: SlotType[]) { this.code = code; this.level = level; + this.cargo = cargo; this.slots = slots; } @@ -22,9 +26,9 @@ module TS.SpaceTac { // TODO Store in cache var result = []; - result.push(new ShipModel("scout", 1, SlotType.Hull, SlotType.Power, SlotType.Power, SlotType.Engine, SlotType.Weapon)); + result.push(new ShipModel("scout", 1, 2, SlotType.Hull, SlotType.Power, SlotType.Power, SlotType.Engine, SlotType.Weapon)); - result.push(new ShipModel("whirlwind", 1, SlotType.Hull, SlotType.Shield, SlotType.Power, SlotType.Engine, + result.push(new ShipModel("whirlwind", 1, 4, SlotType.Hull, SlotType.Shield, SlotType.Power, SlotType.Engine, SlotType.Weapon, SlotType.Weapon)); return result; diff --git a/src/ui/character/CharacterCargo.ts b/src/ui/character/CharacterCargo.ts new file mode 100644 index 0000000..ba8142f --- /dev/null +++ b/src/ui/character/CharacterCargo.ts @@ -0,0 +1,18 @@ +module TS.SpaceTac.UI { + /** + * Display a ship cargo slot + */ + export class CharacterCargo extends Phaser.Image { + constructor(sheet: CharacterSheet, x: number, y: number) { + super(sheet.game, x, y, "character-cargo-slot"); + } + + /** + * Set the equipment displayed in the slot + */ + setEquipment(equipment: CharacterEquipment | null) { + this.addChild(equipment); + equipment.position.set(98, 98); + } + } +} diff --git a/src/ui/character/CharacterEquipment.ts b/src/ui/character/CharacterEquipment.ts new file mode 100644 index 0000000..23e3d36 --- /dev/null +++ b/src/ui/character/CharacterEquipment.ts @@ -0,0 +1,14 @@ +module TS.SpaceTac.UI { + /** + * Display a ship equipment, either attached to a slot, in cargo, or being dragged down + */ + export class CharacterEquipment extends Phaser.Image { + constructor(sheet: CharacterSheet, equipment: Equipment) { + let action_icon = equipment.action != null && !(equipment.action instanceof MoveAction); + super(sheet.game, 0, 0, action_icon ? `battle-actions-${equipment.action.code}` : `equipment-${equipment.code}`); + + this.anchor.set(0.5, 0.5); + this.scale.set(0.5, 0.5); + } + } +} diff --git a/src/ui/character/CharacterSheet.spec.ts b/src/ui/character/CharacterSheet.spec.ts index fc31f41..acd3775 100644 --- a/src/ui/character/CharacterSheet.spec.ts +++ b/src/ui/character/CharacterSheet.spec.ts @@ -16,10 +16,12 @@ module TS.SpaceTac.UI.Specs { ship1.addSlot(SlotType.Engine); ship1.addSlot(SlotType.Shield); ship1.addSlot(SlotType.Weapon); + ship1.setCargoSpace(3); ship1.name = "Ship 1"; let ship2 = fleet.addShip(); ship2.addSlot(SlotType.Hull); ship2.name = "Ship 2"; + ship2.setCargoSpace(2); sheet.show(ship1, false); @@ -28,12 +30,14 @@ module TS.SpaceTac.UI.Specs { expect(sheet.ship_name.text).toEqual("Ship 1"); expect(sheet.ship_slots.length).toBe(4); + expect(sheet.ship_cargo.length).toBe(3); let portrait = sheet.portraits.getChildAt(1); portrait.onInputUp.dispatch(); expect(sheet.ship_name.text).toEqual("Ship 2"); expect(sheet.ship_slots.length).toBe(1); + expect(sheet.ship_cargo.length).toBe(2); }); }); diff --git a/src/ui/character/CharacterSheet.ts b/src/ui/character/CharacterSheet.ts index e302a73..b5854af 100644 --- a/src/ui/character/CharacterSheet.ts +++ b/src/ui/character/CharacterSheet.ts @@ -25,6 +25,9 @@ module TS.SpaceTac.UI { // Ship slots ship_slots: Phaser.Group; + // Ship cargo + ship_cargo: Phaser.Group; + // Fleet's portraits portraits: Phaser.Group; @@ -62,6 +65,10 @@ module TS.SpaceTac.UI { this.ship_slots.position.set(372, 120); this.addChild(this.ship_slots); + this.ship_cargo = new Phaser.Group(this.game); + this.ship_cargo.position.set(1240, 86); + this.addChild(this.ship_cargo); + this.portraits = new Phaser.Group(this.game); this.portraits.position.set(152, 0); this.addChild(this.portraits); @@ -152,6 +159,19 @@ module TS.SpaceTac.UI { let slot_display = new CharacterSlot(this, slotsinfo.positions[idx].x, slotsinfo.positions[idx].y, slot.type); slot_display.scale.set(slotsinfo.scaling, slotsinfo.scaling); this.ship_slots.addChild(slot_display); + + if (slot.attached) { + let equipment = new CharacterEquipment(this, slot.attached); + slot_display.setEquipment(equipment); + } + }); + + slotsinfo = CharacterSheet.getSlotPositions(ship.cargo_space, 638, 496, 200, 200); + this.ship_cargo.removeAll(true); + range(ship.cargo_space).forEach(idx => { + let cargo_slot = new CharacterCargo(this, slotsinfo.positions[idx].x, slotsinfo.positions[idx].y); + cargo_slot.scale.set(slotsinfo.scaling, slotsinfo.scaling); + this.ship_cargo.addChild(cargo_slot); }); this.updateFleet(ship.fleet); @@ -177,7 +197,7 @@ module TS.SpaceTac.UI { } /** - * Get the positions and scaling for slots, to fit in ship_slots group. + * Get the positions and scaling for slots, to fit in a rectangle group. */ static getSlotPositions(count: number, areawidth: number, areaheight: number, slotwidth: number, slotheight: number): { positions: { x: number, y: number }[], scaling: number } { // Find grid size diff --git a/src/ui/character/CharacterSlot.ts b/src/ui/character/CharacterSlot.ts index 77e16da..6ae7691 100644 --- a/src/ui/character/CharacterSlot.ts +++ b/src/ui/character/CharacterSlot.ts @@ -10,5 +10,13 @@ module TS.SpaceTac.UI { sloticon.anchor.set(0.5, 0.5); this.addChild(sloticon); } + + /** + * Set the equipment displayed in the slot + */ + setEquipment(equipment: CharacterEquipment | null) { + this.addChild(equipment); + equipment.position.set(84, 83); + } } }