character sheet: Added equipment display in slots and cargo slots
This commit is contained in:
parent
3f336c8d11
commit
0cdc7b3def
|
@ -75,6 +75,10 @@ module TS.SpaceTac {
|
||||||
// List of slots, able to contain equipment
|
// List of slots, able to contain equipment
|
||||||
slots: Slot[]
|
slots: Slot[]
|
||||||
|
|
||||||
|
// Cargo
|
||||||
|
cargo_space: number = 0
|
||||||
|
cargo: Equipment[] = []
|
||||||
|
|
||||||
// Ship attributes
|
// Ship attributes
|
||||||
attributes = new ShipAttributes()
|
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
|
// Add an empty equipment slot of the given type
|
||||||
addSlot(type: SlotType): Slot {
|
addSlot(type: SlotType): Slot {
|
||||||
var result = new Slot(this, type);
|
var result = new Slot(this, type);
|
||||||
|
|
|
@ -2,9 +2,10 @@ module TS.SpaceTac.Specs {
|
||||||
describe("ShipGenerator", function () {
|
describe("ShipGenerator", function () {
|
||||||
it("can use ship model", function () {
|
it("can use ship model", function () {
|
||||||
var gen = new ShipGenerator();
|
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);
|
var ship = gen.generate(1, model);
|
||||||
expect(ship.model).toBe("test");
|
expect(ship.model).toBe("test");
|
||||||
|
expect(ship.cargo_space).toBe(2);
|
||||||
expect(ship.slots.length).toBe(3);
|
expect(ship.slots.length).toBe(3);
|
||||||
expect(ship.slots[0].type).toBe(SlotType.Shield);
|
expect(ship.slots[0].type).toBe(SlotType.Shield);
|
||||||
expect(ship.slots[1].type).toBe(SlotType.Weapon);
|
expect(ship.slots[1].type).toBe(SlotType.Weapon);
|
||||||
|
|
|
@ -22,6 +22,7 @@ module TS.SpaceTac {
|
||||||
|
|
||||||
// Apply model
|
// Apply model
|
||||||
result.model = model.code;
|
result.model = model.code;
|
||||||
|
result.setCargoSpace(model.cargo);
|
||||||
model.slots.forEach((slot: SlotType) => {
|
model.slots.forEach((slot: SlotType) => {
|
||||||
result.addSlot(slot);
|
result.addSlot(slot);
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,12 +8,16 @@ module TS.SpaceTac {
|
||||||
// Minimal level to use this model
|
// Minimal level to use this model
|
||||||
level: number;
|
level: number;
|
||||||
|
|
||||||
|
// Cargo space
|
||||||
|
cargo: number;
|
||||||
|
|
||||||
// Available slots
|
// Available slots
|
||||||
slots: SlotType[];
|
slots: SlotType[];
|
||||||
|
|
||||||
constructor(code: string, level: number, ...slots: SlotType[]) {
|
constructor(code: string, level: number, cargo: number, ...slots: SlotType[]) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
|
this.cargo = cargo;
|
||||||
this.slots = slots;
|
this.slots = slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +26,9 @@ module TS.SpaceTac {
|
||||||
// TODO Store in cache
|
// TODO Store in cache
|
||||||
var result = [];
|
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));
|
SlotType.Weapon, SlotType.Weapon));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
18
src/ui/character/CharacterCargo.ts
Normal file
18
src/ui/character/CharacterCargo.ts
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
src/ui/character/CharacterEquipment.ts
Normal file
14
src/ui/character/CharacterEquipment.ts
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,10 +16,12 @@ module TS.SpaceTac.UI.Specs {
|
||||||
ship1.addSlot(SlotType.Engine);
|
ship1.addSlot(SlotType.Engine);
|
||||||
ship1.addSlot(SlotType.Shield);
|
ship1.addSlot(SlotType.Shield);
|
||||||
ship1.addSlot(SlotType.Weapon);
|
ship1.addSlot(SlotType.Weapon);
|
||||||
|
ship1.setCargoSpace(3);
|
||||||
ship1.name = "Ship 1";
|
ship1.name = "Ship 1";
|
||||||
let ship2 = fleet.addShip();
|
let ship2 = fleet.addShip();
|
||||||
ship2.addSlot(SlotType.Hull);
|
ship2.addSlot(SlotType.Hull);
|
||||||
ship2.name = "Ship 2";
|
ship2.name = "Ship 2";
|
||||||
|
ship2.setCargoSpace(2);
|
||||||
|
|
||||||
sheet.show(ship1, false);
|
sheet.show(ship1, false);
|
||||||
|
|
||||||
|
@ -28,12 +30,14 @@ module TS.SpaceTac.UI.Specs {
|
||||||
|
|
||||||
expect(sheet.ship_name.text).toEqual("Ship 1");
|
expect(sheet.ship_name.text).toEqual("Ship 1");
|
||||||
expect(sheet.ship_slots.length).toBe(4);
|
expect(sheet.ship_slots.length).toBe(4);
|
||||||
|
expect(sheet.ship_cargo.length).toBe(3);
|
||||||
|
|
||||||
let portrait = <Phaser.Button>sheet.portraits.getChildAt(1);
|
let portrait = <Phaser.Button>sheet.portraits.getChildAt(1);
|
||||||
portrait.onInputUp.dispatch();
|
portrait.onInputUp.dispatch();
|
||||||
|
|
||||||
expect(sheet.ship_name.text).toEqual("Ship 2");
|
expect(sheet.ship_name.text).toEqual("Ship 2");
|
||||||
expect(sheet.ship_slots.length).toBe(1);
|
expect(sheet.ship_slots.length).toBe(1);
|
||||||
|
expect(sheet.ship_cargo.length).toBe(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@ module TS.SpaceTac.UI {
|
||||||
// Ship slots
|
// Ship slots
|
||||||
ship_slots: Phaser.Group;
|
ship_slots: Phaser.Group;
|
||||||
|
|
||||||
|
// Ship cargo
|
||||||
|
ship_cargo: Phaser.Group;
|
||||||
|
|
||||||
// Fleet's portraits
|
// Fleet's portraits
|
||||||
portraits: Phaser.Group;
|
portraits: Phaser.Group;
|
||||||
|
|
||||||
|
@ -62,6 +65,10 @@ module TS.SpaceTac.UI {
|
||||||
this.ship_slots.position.set(372, 120);
|
this.ship_slots.position.set(372, 120);
|
||||||
this.addChild(this.ship_slots);
|
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 = new Phaser.Group(this.game);
|
||||||
this.portraits.position.set(152, 0);
|
this.portraits.position.set(152, 0);
|
||||||
this.addChild(this.portraits);
|
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);
|
let slot_display = new CharacterSlot(this, slotsinfo.positions[idx].x, slotsinfo.positions[idx].y, slot.type);
|
||||||
slot_display.scale.set(slotsinfo.scaling, slotsinfo.scaling);
|
slot_display.scale.set(slotsinfo.scaling, slotsinfo.scaling);
|
||||||
this.ship_slots.addChild(slot_display);
|
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);
|
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 } {
|
static getSlotPositions(count: number, areawidth: number, areaheight: number, slotwidth: number, slotheight: number): { positions: { x: number, y: number }[], scaling: number } {
|
||||||
// Find grid size
|
// Find grid size
|
||||||
|
|
|
@ -10,5 +10,13 @@ module TS.SpaceTac.UI {
|
||||||
sloticon.anchor.set(0.5, 0.5);
|
sloticon.anchor.set(0.5, 0.5);
|
||||||
this.addChild(sloticon);
|
this.addChild(sloticon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the equipment displayed in the slot
|
||||||
|
*/
|
||||||
|
setEquipment(equipment: CharacterEquipment | null) {
|
||||||
|
this.addChild(equipment);
|
||||||
|
equipment.position.set(84, 83);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue