1
0
Fork 0

Updated typescript version

This commit is contained in:
Michaël Lemaire 2018-01-31 19:19:50 +01:00
parent adb3656d29
commit 8b755d9205
32 changed files with 174 additions and 205 deletions

View file

@ -34,7 +34,7 @@
"karma-spec-reporter": "0.0.31", "karma-spec-reporter": "0.0.31",
"live-server": "1.2.0", "live-server": "1.2.0",
"remap-istanbul": "0.9.5", "remap-istanbul": "0.9.5",
"typescript": "2.6.2" "typescript": "^2.7.1"
}, },
"dependencies": { "dependencies": {
"jasmine-core": "2.5.2", "jasmine-core": "2.5.2",

View file

@ -12,10 +12,10 @@ module TK.SpaceTac {
session_token: string | null session_token: string | null
// Audio manager // Audio manager
audio: UI.Audio audio!: UI.Audio
// Game options // Game options
options: UI.GameOptions options!: UI.GameOptions
// Storage used // Storage used
storage: Storage storage: Storage
@ -28,7 +28,6 @@ module TK.SpaceTac {
this.headless = headless; this.headless = headless;
this.audio = new UI.Audio(this);
this.storage = localStorage; this.storage = localStorage;
this.session = new GameSession(); this.session = new GameSession();

View file

@ -10,9 +10,9 @@ module TK.SpaceTac {
code: string code: string
// Location in arena // Location in arena
x: number x = 0
y: number y = 0
radius: number radius = 0
// Effects to apply // Effects to apply
effects: BaseEffect[] = [] effects: BaseEffect[] = []

View file

@ -51,11 +51,15 @@ module TK.SpaceTac.Specs {
equipment.action = action; equipment.action = action;
check.equals(equipment.getEffectsDescription(), "Fire (power 1, range 200km):\n• do 50 damage on target"); check.equals(equipment.getEffectsDescription(), "Fire (power 1, range 200km):\n• do 50 damage on target");
action.blast = 20; action = new TriggerAction(equipment, [new DamageEffect(50)], 1, 200, 20);
equipment.action = action;
check.equals(equipment.getEffectsDescription(), "Fire (power 1, range 200km):\n• do 50 damage in 20km radius"); check.equals(equipment.getEffectsDescription(), "Fire (power 1, range 200km):\n• do 50 damage in 20km radius");
action.blast = 0; action = new TriggerAction(equipment, [
action.effects.push(new StickyEffect(new AttributeLimitEffect("shield_capacity", 200), 3)); new DamageEffect(50),
new StickyEffect(new AttributeLimitEffect("shield_capacity", 200), 3)
], 1, 200, 0);
equipment.action = action;
check.equals(equipment.getEffectsDescription(), "Fire (power 1, range 200km):\n• do 50 damage on target\n• limit shield capacity to 200 for 3 turns on target"); check.equals(equipment.getEffectsDescription(), "Fire (power 1, range 200km):\n• do 50 damage on target\n• limit shield capacity to 200 for 3 turns on target");
}); });

View file

@ -57,7 +57,7 @@ module TK.SpaceTac {
let result = copy(this.effect); let result = copy(this.effect);
this.modifiers.forEach(modifier => { this.modifiers.forEach(modifier => {
let [name, value] = modifier; let [name, value] = modifier;
result[name] = resolveForLevel(value, level); result[name] = <any>resolveForLevel(value, level);
}); });
return result; return result;
} }

View file

@ -112,7 +112,7 @@ module TK.SpaceTac.Specs {
battle.fleets[0].addShip(ship); battle.fleets[0].addShip(ship);
let ship1 = battle.fleets[0].addShip(); let ship1 = battle.fleets[0].addShip();
let moveaction = <MoveAction>nn(simulator.findBestEngine()).action; let moveaction = <MoveAction>nn(simulator.findBestEngine()).action;
moveaction.safety_distance = 30; (<any>moveaction).safety_distance = 30;
battle.ship_separation = 30; battle.ship_separation = 30;
check.same(simulator.getApproach(moveaction, Target.newFromLocation(350, 200), 100), ApproachSimulationError.NO_MOVE_NEEDED); check.same(simulator.getApproach(moveaction, Target.newFromLocation(350, 200), 100), ApproachSimulationError.NO_MOVE_NEEDED);

View file

@ -2,10 +2,10 @@ module TK.SpaceTac {
// Range of number values // Range of number values
export class Range { export class Range {
// Minimal value // Minimal value
min: number; min = 0
// Maximal value // Maximal value
max: number; max = 0
// Create a range of values // Create a range of values
constructor(min: number, max: number | null = null) { constructor(min: number, max: number | null = null) {

View file

@ -71,9 +71,7 @@ module TK.SpaceTac.Specs {
ship.setArenaPosition(500, 500); ship.setArenaPosition(500, 500);
enemy.setArenaPosition(1000, 500); enemy.setArenaPosition(1000, 500);
var action = new MoveAction(new Equipment()); var action = new MoveAction(new Equipment(), 1000, 200);
action.distance_per_power = 1000;
action.safety_distance = 200;
var result = action.checkLocationTarget(ship, Target.newFromLocation(700, 500)); var result = action.checkLocationTarget(ship, Target.newFromLocation(700, 500));
check.equals(result, Target.newFromLocation(700, 500)); check.equals(result, Target.newFromLocation(700, 500));
@ -100,9 +98,7 @@ module TK.SpaceTac.Specs {
enemy1.setArenaPosition(0, 800); enemy1.setArenaPosition(0, 800);
enemy2.setArenaPosition(0, 1000); enemy2.setArenaPosition(0, 1000);
var action = new MoveAction(new Equipment()); var action = new MoveAction(new Equipment(), 1000, 150);
action.distance_per_power = 1000;
action.safety_distance = 150;
var result = action.checkLocationTarget(ship, Target.newFromLocation(0, 1100)); var result = action.checkLocationTarget(ship, Target.newFromLocation(0, 1100));
check.equals(result, Target.newFromLocation(0, 650)); check.equals(result, Target.newFromLocation(0, 650));
@ -117,9 +113,7 @@ module TK.SpaceTac.Specs {
enemy1.setArenaPosition(0, 500); enemy1.setArenaPosition(0, 500);
enemy2.setArenaPosition(0, 800); enemy2.setArenaPosition(0, 800);
var action = new MoveAction(new Equipment()); var action = new MoveAction(new Equipment(), 1000, 600);
action.distance_per_power = 1000;
action.safety_distance = 600;
let result = action.checkLocationTarget(ship, Target.newFromLocation(0, 1000)); let result = action.checkLocationTarget(ship, Target.newFromLocation(0, 1000));
check.equals(result, null); check.equals(result, null);

View file

@ -3,24 +3,17 @@ module TK.SpaceTac {
* Action to move the ship to a specific location * Action to move the ship to a specific location
*/ */
export class MoveAction extends BaseAction { export class MoveAction extends BaseAction {
// Distance allowed for each power point (raw, without applying maneuvrability) constructor(
distance_per_power: number // Mandatory equipment
readonly equipment: Equipment,
// Safety distance from other ships // Distance allowed for each power point (raw, without applying maneuvrability)
safety_distance: number readonly distance_per_power = 0,
// Safety distance from other ships
// Equipment cannot be null (engine) readonly safety_distance = 120,
equipment: Equipment // Impact of maneuvrability (in % of distance)
readonly maneuvrability_factor = 0
// Impact of maneuvrability (in % of distance) ) {
maneuvrability_factor: number
constructor(equipment: Equipment, distance_per_power = 0, safety_distance = 120, maneuvrability_factor = 0) {
super("move", equipment); super("move", equipment);
this.distance_per_power = distance_per_power;
this.safety_distance = safety_distance;
this.maneuvrability_factor = maneuvrability_factor;
} }
getVerb(): string { getVerb(): string {

View file

@ -7,27 +7,21 @@ module TK.SpaceTac {
* Toggle actions consume power when activated, and restore it when deactivated * Toggle actions consume power when activated, and restore it when deactivated
*/ */
export class ToggleAction extends BaseAction { export class ToggleAction extends BaseAction {
// Power consumption (for activation)
power: number
// Effect radius
radius: number
// Effects applied
effects: BaseEffect[]
// Equipment cannot be null
equipment: Equipment
// Current activation status // Current activation status
activated = false activated = false
constructor(equipment: Equipment, power = 1, radius = 0, effects: BaseEffect[] = [], code = `toggle-${equipment.code}`) { constructor(
// Mandatory equipment
readonly equipment: Equipment,
// Power consumption (while active)
readonly power = 1,
// Effect radius
readonly radius = 0,
// Effects applied
readonly effects: BaseEffect[] = [],
code = `toggle-${equipment.code}`
) {
super(code, equipment); super(code, equipment);
this.power = power;
this.radius = radius;
this.effects = effects;
} }
getVerb(): string { getVerb(): string {

View file

@ -93,9 +93,7 @@ module TK.SpaceTac.Specs {
TestTools.setAttribute(ship1, "precision", precision); TestTools.setAttribute(ship1, "precision", precision);
TestTools.setAttribute(ship2, "maneuvrability", maneuvrability); TestTools.setAttribute(ship2, "maneuvrability", maneuvrability);
let action = new TriggerAction(new Equipment()); let action = new TriggerAction(new Equipment(), [], 1, 0, 0, 0, precision_factor, maneuvrability_factor);
action.aim = precision_factor;
action.evasion = maneuvrability_factor;
check.nears(action.getSuccessFactor(ship1, ship2), result, 3, check.nears(action.getSuccessFactor(ship1, ship2), result, 3,
`precision ${precision} (weight ${precision_factor}), maneuvrability ${maneuvrability} (weight ${maneuvrability_factor})`); `precision ${precision} (weight ${precision_factor}), maneuvrability ${maneuvrability} (weight ${maneuvrability_factor})`);
} }
@ -136,8 +134,7 @@ module TK.SpaceTac.Specs {
function verify(success_base: number, luck: number, random: number, expected: number) { function verify(success_base: number, luck: number, random: number, expected: number) {
let ship1 = new Ship(); let ship1 = new Ship();
let ship2 = new Ship(); let ship2 = new Ship();
let action = new TriggerAction(new Equipment()); let action = new TriggerAction(new Equipment(), [], 1, 0, 0, 0, 0, 0, luck);
action.luck = luck;
check.patch(action, "getSuccessFactor", () => success_base); check.patch(action, "getSuccessFactor", () => success_base);
check.nears(action.getEffectiveSuccess(ship1, ship2, new SkewedRandomGenerator([random])), expected, 5, check.nears(action.getEffectiveSuccess(ship1, ship2, new SkewedRandomGenerator([random])), expected, 5,
`success ${success_base}, luck ${luck}, random ${random}`); `success ${success_base}, luck ${luck}, random ${random}`);
@ -201,32 +198,32 @@ module TK.SpaceTac.Specs {
}) })
test.case("builds a textual description", check => { test.case("builds a textual description", check => {
let action = new TriggerAction(new Equipment()); let effects: BaseEffect[] = [];
action.power = 0; let action = new TriggerAction(new Equipment(), effects, 0);
check.equals(action.getEffectsDescription(), ""); check.equals(action.getEffectsDescription(), "");
action.effects.push(new AttributeMultiplyEffect("precision", 20)); effects.push(new AttributeMultiplyEffect("precision", 20));
check.equals(action.getEffectsDescription(), "Trigger:\n• precision +20% on self"); check.equals(action.getEffectsDescription(), "Trigger:\n• precision +20% on self");
action.power = 2; action = new TriggerAction(new Equipment(), effects, 2);
check.equals(action.getEffectsDescription(), "Trigger (power 2):\n• precision +20% on self"); check.equals(action.getEffectsDescription(), "Trigger (power 2):\n• precision +20% on self");
action.range = 120; action = new TriggerAction(new Equipment(), effects, 2, 120);
check.equals(action.getEffectsDescription(), "Fire (power 2, range 120km):\n• precision +20% on target"); check.equals(action.getEffectsDescription(), "Fire (power 2, range 120km):\n• precision +20% on target");
action.aim = 10; action = new TriggerAction(new Equipment(), effects, 2, 120, 0, 0, 10);
check.equals(action.getEffectsDescription(), "Fire (power 2, range 120km, aim +10%):\n• precision +20% on target"); check.equals(action.getEffectsDescription(), "Fire (power 2, range 120km, aim +10%):\n• precision +20% on target");
action.evasion = 35; action = new TriggerAction(new Equipment(), effects, 2, 120, 0, 0, 10, 35);
check.equals(action.getEffectsDescription(), "Fire (power 2, range 120km, aim +10%, evasion -35%):\n• precision +20% on target"); check.equals(action.getEffectsDescription(), "Fire (power 2, range 120km, aim +10%, evasion -35%):\n• precision +20% on target");
action.angle = 80; action = new TriggerAction(new Equipment(), effects, 2, 120, 0, 80, 10, 35);
check.equals(action.getEffectsDescription(), "Fire (power 2, range 120km, aim +10%, evasion -35%):\n• precision +20% in 80° arc"); check.equals(action.getEffectsDescription(), "Fire (power 2, range 120km, aim +10%, evasion -35%):\n• precision +20% in 80° arc");
action.blast = 100; action = new TriggerAction(new Equipment(), effects, 2, 120, 100, 80, 10, 35);
check.equals(action.getEffectsDescription(), "Fire (power 2, range 120km, aim +10%, evasion -35%):\n• precision +20% in 100km radius"); check.equals(action.getEffectsDescription(), "Fire (power 2, range 120km, aim +10%, evasion -35%):\n• precision +20% in 100km radius");
action.luck = 15; action = new TriggerAction(new Equipment(), effects, 2, 120, 100, 80, 10, 35, 15);
check.equals(action.getEffectsDescription(), "Fire (power 2, range 120km, aim +10%, evasion -35%, luck ±15%):\n• precision +20% in 100km radius"); check.equals(action.getEffectsDescription(), "Fire (power 2, range 120km, aim +10%, evasion -35%, luck ±15%):\n• precision +20% in 100km radius");
}) })
}); });

View file

@ -7,44 +7,28 @@ module TK.SpaceTac {
* The target will be resolved as a list of ships, on which all the action effects will be applied * The target will be resolved as a list of ships, on which all the action effects will be applied
*/ */
export class TriggerAction extends BaseAction { export class TriggerAction extends BaseAction {
// Power consumption constructor(
power: number // Mandatory equipment
readonly equipment: Equipment,
// Maximal range of the weapon (distance to target) // Effects applied on target
range: number readonly effects: BaseEffect[] = [],
// Power consumption
// Radius around the target that will be impacted readonly power = 1,
blast: number // Maximal range of the weapon (distance to target)
readonly range = 0,
// Angle of the area between the source and the target that will be impacted // Radius around the target that will be impacted
angle: number readonly blast = 0,
// Angle of the area between the source and the target that will be impacted
// Influence of "precision" of firing ship (0..100) readonly angle = 0,
aim: number // Influence of "precision" of firing ship (0..100)
readonly aim = 0,
// Influence of "maneuvrability" of impacted ship (0..100) // Influence of "maneuvrability" of impacted ship (0..100)
evasion: number readonly evasion = 0,
// Influence of luck
// Influence of luck readonly luck = 0,
luck: number code = `fire-${equipment.code}`
) {
// Effects applied on target
effects: BaseEffect[]
// Equipment cannot be null
equipment: Equipment
constructor(equipment: Equipment, effects: BaseEffect[] = [], power = 1, range = 0, blast = 0, angle = 0, aim = 0, evasion = 0, luck = 0, code = `fire-${equipment.code}`) {
super(code, equipment); super(code, equipment);
this.power = power;
this.range = range;
this.effects = effects;
this.blast = blast;
this.angle = angle;
this.aim = aim;
this.evasion = evasion;
this.luck = luck;
} }
getVerb(): string { getVerb(): string {

View file

@ -27,7 +27,7 @@ module TK.SpaceTac {
feedback: AIFeedback feedback: AIFeedback
// Time at which work as started // Time at which work as started
private started: number private started = 0
constructor(ship: Ship, feedback?: AIFeedback, debug = false, timer = Timer.global, name?: string) { constructor(ship: Ship, feedback?: AIFeedback, debug = false, timer = Timer.global, name?: string) {
this.ship = ship; this.ship = ship;

View file

@ -16,8 +16,8 @@ module TK.SpaceTac {
private producers: TacticalProducer[] = [] private producers: TacticalProducer[] = []
private evaluators: TacticalEvaluator[] = [] private evaluators: TacticalEvaluator[] = []
private best: Maneuver | null private best: Maneuver | null = null
private best_score: number private best_score = 0
protected initWork(): void { protected initWork(): void {
this.best = null; this.best = null;

View file

@ -5,8 +5,6 @@ module TK.SpaceTac {
* A mission part that requires the fleet to clean a specific location of enemies * A mission part that requires the fleet to clean a specific location of enemies
*/ */
export class MissionPartCleanLocation extends MissionPartGoTo { export class MissionPartCleanLocation extends MissionPartGoTo {
ship: Ship
constructor(mission: Mission, destination: StarLocation, directive?: string) { constructor(mission: Mission, destination: StarLocation, directive?: string) {
super(mission, destination, directive || `Clean a ${StarLocationType[destination.type].toLowerCase()} in ${destination.star.name} system`); super(mission, destination, directive || `Clean a ${StarLocationType[destination.type].toLowerCase()} in ${destination.star.name} system`);
} }

View file

@ -4,29 +4,29 @@ module TK.SpaceTac.UI {
*/ */
export class BaseView extends Phaser.State { export class BaseView extends Phaser.State {
// Link to the root UI // Link to the root UI
gameui: MainUI gameui!: MainUI
// Message notifications // Message notifications
messages: Messages messages!: Messages
// Input and key bindings // Input and key bindings
inputs: InputManager inputs!: InputManager
// Animations // Animations
animations: Animations animations!: Animations
// Timing // Timing
timer: Timer timer!: Timer
// Tooltip // Tooltip
tooltip_layer: Phaser.Group tooltip_layer!: Phaser.Group
tooltip: Tooltip tooltip!: Tooltip
// Layers // Layers
layers: Phaser.Group layers!: Phaser.Group
// Modal dialogs // Modal dialogs
dialogs_layer: Phaser.Group dialogs_layer!: Phaser.Group
dialogs_opened: UIDialog[] = [] dialogs_opened: UIDialog[] = []
// Get the size of display // Get the size of display

View file

@ -9,11 +9,11 @@ module TK.SpaceTac.UI.Specs {
* Attributes should only be accessed from inside corresponding "it" blocks (they are initialized by the setup). * Attributes should only be accessed from inside corresponding "it" blocks (they are initialized by the setup).
*/ */
export class TestGame<T extends Phaser.State> { export class TestGame<T extends Phaser.State> {
ui: MainUI; ui!: MainUI;
view: T; view!: T;
multistorage: Multi.FakeRemoteStorage; multistorage!: Multi.FakeRemoteStorage;
state: string; state!: string;
clock: FakeClock; clock!: FakeClock;
} }
/** /**

View file

@ -25,7 +25,7 @@ module TK.SpaceTac.UI {
cooldown = 0 cooldown = 0
// Images // Images
img_targetting: Phaser.Image img_targetting!: Phaser.Image
img_top: Phaser.Image | null = null img_top: Phaser.Image | null = null
img_bottom: Phaser.Image img_bottom: Phaser.Image
img_power: Phaser.Image img_power: Phaser.Image
@ -33,7 +33,7 @@ module TK.SpaceTac.UI {
img_action: Phaser.Image img_action: Phaser.Image
// Indicators // Indicators
text_power: Phaser.Text text_power!: Phaser.Text
constructor(bar: ActionBar, ship: Ship, action: BaseAction, position: number) { constructor(bar: ActionBar, ship: Ship, action: BaseAction, position: number) {
this.bar = bar; this.bar = bar;

View file

@ -15,7 +15,7 @@ module TK.SpaceTac.UI {
range_hint: RangeHint range_hint: RangeHint
// Input capture // Input capture
private mouse_capture: Phaser.Button private mouse_capture?: Phaser.Button
// Input callback to receive mouse move events // Input callback to receive mouse move events
private input_callback: any = null private input_callback: any = null

View file

@ -15,56 +15,56 @@ module TK.SpaceTac.UI {
*/ */
export class BattleView extends BaseView implements IShipButton { export class BattleView extends BaseView implements IShipButton {
// Internal battle state // Internal battle state
actual_battle: Battle actual_battle!: Battle
// Displayed battle state // Displayed battle state
battle: Battle battle!: Battle
// Interacting player // Interacting player
player: Player player!: Player
// Multiplayer sharing // Multiplayer sharing
multi: MultiBattle multi!: MultiBattle
// Layers // Layers
layer_background: Phaser.Group layer_background!: Phaser.Group
layer_arena: Phaser.Group layer_arena!: Phaser.Group
layer_borders: Phaser.Group layer_borders!: Phaser.Group
layer_overlay: Phaser.Group layer_overlay!: Phaser.Group
layer_sheets: Phaser.Group layer_sheets!: Phaser.Group
// Battleground container // Battleground container
arena: Arena arena!: Arena
// Background image // Background image
background: Phaser.Image | null background!: Phaser.Image | null
// Targetting mode (null if we're not in this mode) // Targetting mode (null if we're not in this mode)
targetting: Targetting targetting!: Targetting
// Ship list // Ship list
ship_list: ShipList ship_list!: ShipList
// Action bar // Action bar
action_bar: ActionBar action_bar!: ActionBar
// Currently hovered ship // Currently hovered ship
ship_hovered: Ship | null ship_hovered!: Ship | null
// Ship tooltip // Ship tooltip
ship_tooltip: ShipTooltip ship_tooltip!: ShipTooltip
// Character sheet // Character sheet
character_sheet: CharacterSheet character_sheet!: CharacterSheet
// Subscription to the battle log // Subscription to the battle log
log_processor: LogProcessor log_processor!: LogProcessor
// True if player interaction is allowed // True if player interaction is allowed
interacting: boolean interacting!: boolean
// Tactical mode toggle // Tactical mode toggle
toggle_tactical_mode: Toggle toggle_tactical_mode!: Toggle
// Toggle for the splash screen display // Toggle for the splash screen display
splash = true splash = true

View file

@ -7,22 +7,22 @@ module TK.SpaceTac.UI {
debug = false debug = false
// Network exchange of messages // Network exchange of messages
exchange: Multi.Exchange exchange!: Multi.Exchange
// True if this peer is the primary one (the one that invited the other) // True if this peer is the primary one (the one that invited the other)
primary: boolean primary!: boolean
// Battle being played // Battle being played
battle: Battle battle!: Battle
// Count of battle log events that were processed // Count of battle log events that were processed
processed: number processed!: number
// Serializer to use for actions // Serializer to use for actions
serializer: Serializer serializer!: Serializer
// Timer for scheduling // Timer for scheduling
timer: Timer timer!: Timer
/** /**
* Setup the session other a token * Setup the session other a token

View file

@ -7,9 +7,6 @@ module TK.SpaceTac.UI {
// Reference to the ship game object // Reference to the ship game object
ship: Ship ship: Ship
// Callbacks to act as buttons
ship_buttons: IShipButton
// Player indicator // Player indicator
player_indicator: Phaser.Image player_indicator: Phaser.Image

View file

@ -12,7 +12,7 @@ module TK.SpaceTac.UI {
ship: Ship | null = null ship: Ship | null = null
action: BaseAction | null = null action: BaseAction | null = null
target: Target | null = null target: Target | null = null
mode: ActionTargettingMode mode?: ActionTargettingMode
simulation = new MoveFireResult() simulation = new MoveFireResult()
// Move and fire lines // Move and fire lines

View file

@ -25,10 +25,10 @@ module TK.SpaceTac.UI {
close_button: Phaser.Button close_button: Phaser.Button
// Currently displayed fleet // Currently displayed fleet
fleet: Fleet fleet!: Fleet
// Currently displayed ship // Currently displayed ship
ship: Ship ship!: Ship
// Ship name // Ship name
ship_name: Phaser.Text ship_name: Phaser.Text
@ -140,16 +140,21 @@ module TK.SpaceTac.UI {
* Check if the sheet should be interactive * Check if the sheet should be interactive
*/ */
isInteractive(): boolean { isInteractive(): boolean {
return bool(this.ship) && !this.ship.critical && this.interactive; return this.ship ? (!this.ship.critical && this.interactive) : false;
} }
/** /**
* Add an attribute display * Add an attribute display
*/ */
private addAttribute(attribute: keyof ShipAttributes, x: number, y: number) { private addAttribute(attribute: keyof ShipAttributes, x: number, y: number) {
if (!this.ship) {
return;
}
let ship = this.ship;
let builder = this.builder.in(this.layer_attibutes); let builder = this.builder.in(this.layer_attibutes);
let button = builder.button("character-attribute", x, y, undefined, () => this.ship.getAttributeDescription(attribute)); let button = builder.button("character-attribute", x, y, undefined, () => ship.getAttributeDescription(attribute));
let attrname = capitalize(SHIP_VALUES_NAMES[attribute]); let attrname = capitalize(SHIP_VALUES_NAMES[attribute]);
builder.in(button).text(attrname, 120, 22, { size: 20, color: "#c9d8ef", stroke_width: 1, stroke_color: "#395665" }); builder.in(button).text(attrname, 120, 22, { size: 20, color: "#c9d8ef", stroke_width: 1, stroke_color: "#395665" });
@ -160,7 +165,7 @@ module TK.SpaceTac.UI {
if (SHIP_SKILLS.hasOwnProperty(attribute)) { if (SHIP_SKILLS.hasOwnProperty(attribute)) {
this.builder.in(this.layer_upgrades).button("character-skill-upgrade", x + 292, y, () => { this.builder.in(this.layer_upgrades).button("character-skill-upgrade", x + 292, y, () => {
this.ship.upgradeSkill(<keyof ShipSkills>attribute); ship.upgradeSkill(<keyof ShipSkills>attribute);
this.refresh(); this.refresh();
}, `Spend one point to upgrade ${attrname}`); }, `Spend one point to upgrade ${attrname}`);
} }
@ -251,8 +256,8 @@ module TK.SpaceTac.UI {
cargo_slot.alpha = this.isInteractive() ? 1 : 0.5; cargo_slot.alpha = this.isInteractive() ? 1 : 0.5;
this.ship_cargo.add(cargo_slot); this.ship_cargo.add(cargo_slot);
if (idx < this.ship.cargo.length) { if (idx < ship.cargo.length) {
let equipment = new CharacterEquipment(this, this.ship.cargo[idx], cargo_slot); let equipment = new CharacterEquipment(this, ship.cargo[idx], cargo_slot);
this.layer_equipments.add(equipment); this.layer_equipments.add(equipment);
} }
}); });
@ -408,7 +413,9 @@ module TK.SpaceTac.UI {
* Refresh the sheet display * Refresh the sheet display
*/ */
refresh() { refresh() {
this.show(this.ship, false, false); if (this.ship) {
this.show(this.ship, false, false);
}
} }
/** /**

View file

@ -5,9 +5,9 @@ module TK.SpaceTac.UI {
* View to configure the initial characters in the fleet * View to configure the initial characters in the fleet
*/ */
export class FleetCreationView extends BaseView { export class FleetCreationView extends BaseView {
built_fleet: Fleet built_fleet!: Fleet
infinite_shop: Shop infinite_shop!: Shop
character_sheet: CharacterSheet character_sheet!: CharacterSheet
create() { create() {
super.create(); super.create();

View file

@ -6,7 +6,7 @@ module TK.SpaceTac.UI {
view: BaseView view: BaseView
background: Phaser.Graphics background: Phaser.Graphics
content: Phaser.Group content: Phaser.Group
item: IBounded item?: IBounded
border = 10 border = 10
margin = 6 margin = 6
viewport: IBounded | null = null viewport: IBounded | null = null
@ -55,7 +55,7 @@ module TK.SpaceTac.UI {
} }
update() { update() {
if (this.visible) { if (this.visible && this.item) {
let [width, height] = UITools.drawBackground(this.content, this.background, this.border); let [width, height] = UITools.drawBackground(this.content, this.background, this.border);
let [x, y] = this.getBestPosition(this.item, width, height); let [x, y] = this.getBestPosition(this.item, width, height);

View file

@ -4,7 +4,7 @@ module TK.SpaceTac.UI {
*/ */
export class UIConfirmDialog extends UIDialog { export class UIConfirmDialog extends UIDialog {
private result: Promise<boolean> private result: Promise<boolean>
private result_resolver: (confirmed: boolean) => void private result_resolver?: (confirmed: boolean) => void
constructor(view: BaseView, message: string) { constructor(view: BaseView, message: string) {
super(view); super(view);
@ -22,8 +22,10 @@ module TK.SpaceTac.UI {
* Force the result (simulate clicking the appropriate button) * Force the result (simulate clicking the appropriate button)
*/ */
async forceResult(confirmed: boolean): Promise<void> { async forceResult(confirmed: boolean): Promise<void> {
this.result_resolver(confirmed); if (this.result_resolver) {
await this.result; this.result_resolver(confirmed);
await this.result;
}
} }
/** /**

View file

@ -24,13 +24,13 @@ module TK.SpaceTac.UI {
private orientation: ValueBarOrientation private orientation: ValueBarOrientation
// Current value // Current value
private current: number private current = 0
// Maximal value // Maximal value
private maximal: number private maximal = 0
// Proportional value // Proportional value
private proportional: number private proportional = 0
// Original size // Original size
private original_width: number private original_width: number

View file

@ -5,9 +5,9 @@ module TK.SpaceTac.UI {
export class MissionLocationMarker { export class MissionLocationMarker {
private view: BaseView private view: BaseView
private container: Phaser.Group private container: Phaser.Group
private markers: [StarLocation | Star, string][] private markers: [StarLocation | Star, string][] = []
private zoomed = true private zoomed = true
private current_star: Star private current_star?: Star
constructor(view: BaseView, parent: Phaser.Group) { constructor(view: BaseView, parent: Phaser.Group) {
this.view = view; this.view = view;

View file

@ -15,40 +15,40 @@ module TK.SpaceTac.UI {
interactive = true interactive = true
// Layers // Layers
layer_universe: Phaser.Group layer_universe!: Phaser.Group
layer_overlay: Phaser.Group layer_overlay!: Phaser.Group
// Star systems // Star systems
starsystems: StarSystemDisplay[] = [] starsystems: StarSystemDisplay[] = []
// Links between stars // Links between stars
starlinks_group: Phaser.Group starlinks_group!: Phaser.Group
starlinks: Phaser.Graphics[] = [] starlinks: Phaser.Graphics[] = []
// Fleets // Fleets
player_fleet: FleetDisplay player_fleet!: FleetDisplay
// Markers // Markers
current_location: CurrentLocationMarker current_location!: CurrentLocationMarker
mission_markers: MissionLocationMarker mission_markers!: MissionLocationMarker
// Actions for selected location // Actions for selected location
actions: MapLocationMenu actions!: MapLocationMenu
// Active missions // Active missions
missions: ActiveMissionsDisplay missions!: ActiveMissionsDisplay
conversation: MissionConversationDisplay conversation!: MissionConversationDisplay
// Character sheet // Character sheet
character_sheet: CharacterSheet character_sheet!: CharacterSheet
// Zoom level // Zoom level
zoom = 0 zoom = 0
zoom_in: Phaser.Button zoom_in!: Phaser.Button
zoom_out: Phaser.Button zoom_out!: Phaser.Button
// Options button // Options button
button_options: Phaser.Button button_options!: Phaser.Button
/** /**
* Init the view, binding it to a universe * Init the view, binding it to a universe

View file

@ -6,13 +6,13 @@ module TK.SpaceTac.UI {
*/ */
export class MainMenu extends BaseView { export class MainMenu extends BaseView {
static returned = false static returned = false
layer_stars: Phaser.Group layer_stars!: Phaser.Group
layer_presents: Phaser.Group layer_presents!: Phaser.Group
layer_title: Phaser.Group layer_title!: Phaser.Group
button_new_game: Phaser.Button button_new_game!: Phaser.Button
button_quick_battle: Phaser.Button button_quick_battle!: Phaser.Button
button_load_game: Phaser.Button button_load_game!: Phaser.Button
dialog_load_game: LoadDialog dialog_load_game!: LoadDialog
create() { create() {
super.create(); super.create();

View file

@ -2517,9 +2517,9 @@ typedarray@^0.0.6:
version "0.0.6" version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
typescript@2.6.2: typescript@^2.7.1:
version "2.6.2" version "2.7.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4" resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.1.tgz#bb3682c2c791ac90e7c6210b26478a8da085c359"
uglify-js@^2.6: uglify-js@^2.6:
version "2.8.29" version "2.8.29"