From 8b755d920550eba5d0d0b385a5d619c49192bdc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 31 Jan 2018 19:19:50 +0100 Subject: [PATCH] Updated typescript version --- package.json | 2 +- src/MainUI.ts | 5 +- src/core/Drone.ts | 6 +- src/core/Equipment.spec.ts | 10 +++- src/core/LootTemplate.ts | 2 +- src/core/MoveFireSimulator.spec.ts | 2 +- src/core/Range.ts | 4 +- src/core/actions/MoveAction.spec.ts | 12 +--- src/core/actions/MoveAction.ts | 27 ++++----- src/core/actions/ToggleAction.ts | 28 ++++----- src/core/actions/TriggerAction.spec.ts | 27 ++++----- src/core/actions/TriggerAction.ts | 58 +++++++------------ src/core/ai/AbstractAI.ts | 2 +- src/core/ai/TacticalAI.ts | 4 +- src/core/missions/MissionPartCleanLocation.ts | 2 - src/ui/BaseView.ts | 18 +++--- src/ui/TestGame.ts | 10 ++-- src/ui/battle/ActionIcon.ts | 4 +- src/ui/battle/Arena.ts | 2 +- src/ui/battle/BattleView.ts | 40 ++++++------- src/ui/battle/MultiBattle.ts | 12 ++-- src/ui/battle/ShipListItem.ts | 3 - src/ui/battle/Targetting.ts | 2 +- src/ui/character/CharacterSheet.ts | 23 +++++--- src/ui/character/FleetCreationView.ts | 6 +- src/ui/common/Tooltip.ts | 4 +- src/ui/common/UIConfirmDialog.ts | 8 ++- src/ui/common/ValueBar.ts | 6 +- src/ui/map/MissionLocationMarker.ts | 4 +- src/ui/map/UniverseMapView.ts | 26 ++++----- src/ui/menu/MainMenu.ts | 14 ++--- yarn.lock | 6 +- 32 files changed, 174 insertions(+), 205 deletions(-) diff --git a/package.json b/package.json index 86621cb..76e47de 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "karma-spec-reporter": "0.0.31", "live-server": "1.2.0", "remap-istanbul": "0.9.5", - "typescript": "2.6.2" + "typescript": "^2.7.1" }, "dependencies": { "jasmine-core": "2.5.2", diff --git a/src/MainUI.ts b/src/MainUI.ts index 22c6e1d..62c7b40 100644 --- a/src/MainUI.ts +++ b/src/MainUI.ts @@ -12,10 +12,10 @@ module TK.SpaceTac { session_token: string | null // Audio manager - audio: UI.Audio + audio!: UI.Audio // Game options - options: UI.GameOptions + options!: UI.GameOptions // Storage used storage: Storage @@ -28,7 +28,6 @@ module TK.SpaceTac { this.headless = headless; - this.audio = new UI.Audio(this); this.storage = localStorage; this.session = new GameSession(); diff --git a/src/core/Drone.ts b/src/core/Drone.ts index ca7c507..6a8d067 100644 --- a/src/core/Drone.ts +++ b/src/core/Drone.ts @@ -10,9 +10,9 @@ module TK.SpaceTac { code: string // Location in arena - x: number - y: number - radius: number + x = 0 + y = 0 + radius = 0 // Effects to apply effects: BaseEffect[] = [] diff --git a/src/core/Equipment.spec.ts b/src/core/Equipment.spec.ts index 20f0120..87a918f 100644 --- a/src/core/Equipment.spec.ts +++ b/src/core/Equipment.spec.ts @@ -51,11 +51,15 @@ module TK.SpaceTac.Specs { equipment.action = action; 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"); - action.blast = 0; - action.effects.push(new StickyEffect(new AttributeLimitEffect("shield_capacity", 200), 3)); + action = new TriggerAction(equipment, [ + 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"); }); diff --git a/src/core/LootTemplate.ts b/src/core/LootTemplate.ts index 9b462ce..1419dea 100644 --- a/src/core/LootTemplate.ts +++ b/src/core/LootTemplate.ts @@ -57,7 +57,7 @@ module TK.SpaceTac { let result = copy(this.effect); this.modifiers.forEach(modifier => { let [name, value] = modifier; - result[name] = resolveForLevel(value, level); + result[name] = resolveForLevel(value, level); }); return result; } diff --git a/src/core/MoveFireSimulator.spec.ts b/src/core/MoveFireSimulator.spec.ts index 27d7cd8..5a90329 100644 --- a/src/core/MoveFireSimulator.spec.ts +++ b/src/core/MoveFireSimulator.spec.ts @@ -112,7 +112,7 @@ module TK.SpaceTac.Specs { battle.fleets[0].addShip(ship); let ship1 = battle.fleets[0].addShip(); let moveaction = nn(simulator.findBestEngine()).action; - moveaction.safety_distance = 30; + (moveaction).safety_distance = 30; battle.ship_separation = 30; check.same(simulator.getApproach(moveaction, Target.newFromLocation(350, 200), 100), ApproachSimulationError.NO_MOVE_NEEDED); diff --git a/src/core/Range.ts b/src/core/Range.ts index aac90ce..5d5e7fe 100644 --- a/src/core/Range.ts +++ b/src/core/Range.ts @@ -2,10 +2,10 @@ module TK.SpaceTac { // Range of number values export class Range { // Minimal value - min: number; + min = 0 // Maximal value - max: number; + max = 0 // Create a range of values constructor(min: number, max: number | null = null) { diff --git a/src/core/actions/MoveAction.spec.ts b/src/core/actions/MoveAction.spec.ts index 89c16f6..152bf59 100644 --- a/src/core/actions/MoveAction.spec.ts +++ b/src/core/actions/MoveAction.spec.ts @@ -71,9 +71,7 @@ module TK.SpaceTac.Specs { ship.setArenaPosition(500, 500); enemy.setArenaPosition(1000, 500); - var action = new MoveAction(new Equipment()); - action.distance_per_power = 1000; - action.safety_distance = 200; + var action = new MoveAction(new Equipment(), 1000, 200); var result = action.checkLocationTarget(ship, Target.newFromLocation(700, 500)); check.equals(result, Target.newFromLocation(700, 500)); @@ -100,9 +98,7 @@ module TK.SpaceTac.Specs { enemy1.setArenaPosition(0, 800); enemy2.setArenaPosition(0, 1000); - var action = new MoveAction(new Equipment()); - action.distance_per_power = 1000; - action.safety_distance = 150; + var action = new MoveAction(new Equipment(), 1000, 150); var result = action.checkLocationTarget(ship, Target.newFromLocation(0, 1100)); check.equals(result, Target.newFromLocation(0, 650)); @@ -117,9 +113,7 @@ module TK.SpaceTac.Specs { enemy1.setArenaPosition(0, 500); enemy2.setArenaPosition(0, 800); - var action = new MoveAction(new Equipment()); - action.distance_per_power = 1000; - action.safety_distance = 600; + var action = new MoveAction(new Equipment(), 1000, 600); let result = action.checkLocationTarget(ship, Target.newFromLocation(0, 1000)); check.equals(result, null); diff --git a/src/core/actions/MoveAction.ts b/src/core/actions/MoveAction.ts index e868c3b..7231c3c 100644 --- a/src/core/actions/MoveAction.ts +++ b/src/core/actions/MoveAction.ts @@ -3,24 +3,17 @@ module TK.SpaceTac { * Action to move the ship to a specific location */ export class MoveAction extends BaseAction { - // Distance allowed for each power point (raw, without applying maneuvrability) - distance_per_power: number - - // Safety distance from other ships - safety_distance: number - - // Equipment cannot be null (engine) - equipment: Equipment - - // Impact of maneuvrability (in % of distance) - maneuvrability_factor: number - - constructor(equipment: Equipment, distance_per_power = 0, safety_distance = 120, maneuvrability_factor = 0) { + constructor( + // Mandatory equipment + readonly equipment: Equipment, + // Distance allowed for each power point (raw, without applying maneuvrability) + readonly distance_per_power = 0, + // Safety distance from other ships + readonly safety_distance = 120, + // Impact of maneuvrability (in % of distance) + readonly maneuvrability_factor = 0 + ) { super("move", equipment); - - this.distance_per_power = distance_per_power; - this.safety_distance = safety_distance; - this.maneuvrability_factor = maneuvrability_factor; } getVerb(): string { diff --git a/src/core/actions/ToggleAction.ts b/src/core/actions/ToggleAction.ts index 55134ba..db10160 100644 --- a/src/core/actions/ToggleAction.ts +++ b/src/core/actions/ToggleAction.ts @@ -7,27 +7,21 @@ module TK.SpaceTac { * Toggle actions consume power when activated, and restore it when deactivated */ 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 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); - - this.power = power; - this.radius = radius; - this.effects = effects; } getVerb(): string { diff --git a/src/core/actions/TriggerAction.spec.ts b/src/core/actions/TriggerAction.spec.ts index 029b4cc..402b884 100644 --- a/src/core/actions/TriggerAction.spec.ts +++ b/src/core/actions/TriggerAction.spec.ts @@ -93,9 +93,7 @@ module TK.SpaceTac.Specs { TestTools.setAttribute(ship1, "precision", precision); TestTools.setAttribute(ship2, "maneuvrability", maneuvrability); - let action = new TriggerAction(new Equipment()); - action.aim = precision_factor; - action.evasion = maneuvrability_factor; + let action = new TriggerAction(new Equipment(), [], 1, 0, 0, 0, precision_factor, maneuvrability_factor); check.nears(action.getSuccessFactor(ship1, ship2), result, 3, `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) { let ship1 = new Ship(); let ship2 = new Ship(); - let action = new TriggerAction(new Equipment()); - action.luck = luck; + let action = new TriggerAction(new Equipment(), [], 1, 0, 0, 0, 0, 0, luck); check.patch(action, "getSuccessFactor", () => success_base); check.nears(action.getEffectiveSuccess(ship1, ship2, new SkewedRandomGenerator([random])), expected, 5, `success ${success_base}, luck ${luck}, random ${random}`); @@ -201,32 +198,32 @@ module TK.SpaceTac.Specs { }) test.case("builds a textual description", check => { - let action = new TriggerAction(new Equipment()); - action.power = 0; + let effects: BaseEffect[] = []; + let action = new TriggerAction(new Equipment(), effects, 0); 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"); - action.power = 2; + action = new TriggerAction(new Equipment(), effects, 2); 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"); - 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"); - 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"); - 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"); - 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"); - 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"); }) }); diff --git a/src/core/actions/TriggerAction.ts b/src/core/actions/TriggerAction.ts index 8f7ee8a..0d44156 100644 --- a/src/core/actions/TriggerAction.ts +++ b/src/core/actions/TriggerAction.ts @@ -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 */ export class TriggerAction extends BaseAction { - // Power consumption - power: number - - // Maximal range of the weapon (distance to target) - range: number - - // Radius around the target that will be impacted - blast: number - - // Angle of the area between the source and the target that will be impacted - angle: number - - // Influence of "precision" of firing ship (0..100) - aim: number - - // Influence of "maneuvrability" of impacted ship (0..100) - evasion: number - - // Influence of luck - luck: number - - // 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}`) { + constructor( + // Mandatory equipment + readonly equipment: Equipment, + // Effects applied on target + readonly effects: BaseEffect[] = [], + // Power consumption + readonly power = 1, + // Maximal range of the weapon (distance to target) + readonly range = 0, + // Radius around the target that will be impacted + readonly blast = 0, + // Angle of the area between the source and the target that will be impacted + readonly angle = 0, + // Influence of "precision" of firing ship (0..100) + readonly aim = 0, + // Influence of "maneuvrability" of impacted ship (0..100) + readonly evasion = 0, + // Influence of luck + readonly luck = 0, + code = `fire-${equipment.code}` + ) { 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 { diff --git a/src/core/ai/AbstractAI.ts b/src/core/ai/AbstractAI.ts index a2771df..5a3f21b 100644 --- a/src/core/ai/AbstractAI.ts +++ b/src/core/ai/AbstractAI.ts @@ -27,7 +27,7 @@ module TK.SpaceTac { feedback: AIFeedback // Time at which work as started - private started: number + private started = 0 constructor(ship: Ship, feedback?: AIFeedback, debug = false, timer = Timer.global, name?: string) { this.ship = ship; diff --git a/src/core/ai/TacticalAI.ts b/src/core/ai/TacticalAI.ts index 9eefc7c..e42eca0 100644 --- a/src/core/ai/TacticalAI.ts +++ b/src/core/ai/TacticalAI.ts @@ -16,8 +16,8 @@ module TK.SpaceTac { private producers: TacticalProducer[] = [] private evaluators: TacticalEvaluator[] = [] - private best: Maneuver | null - private best_score: number + private best: Maneuver | null = null + private best_score = 0 protected initWork(): void { this.best = null; diff --git a/src/core/missions/MissionPartCleanLocation.ts b/src/core/missions/MissionPartCleanLocation.ts index 53a1672..5653257 100644 --- a/src/core/missions/MissionPartCleanLocation.ts +++ b/src/core/missions/MissionPartCleanLocation.ts @@ -5,8 +5,6 @@ module TK.SpaceTac { * A mission part that requires the fleet to clean a specific location of enemies */ export class MissionPartCleanLocation extends MissionPartGoTo { - ship: Ship - constructor(mission: Mission, destination: StarLocation, directive?: string) { super(mission, destination, directive || `Clean a ${StarLocationType[destination.type].toLowerCase()} in ${destination.star.name} system`); } diff --git a/src/ui/BaseView.ts b/src/ui/BaseView.ts index 45f37fb..164313c 100644 --- a/src/ui/BaseView.ts +++ b/src/ui/BaseView.ts @@ -4,29 +4,29 @@ module TK.SpaceTac.UI { */ export class BaseView extends Phaser.State { // Link to the root UI - gameui: MainUI + gameui!: MainUI // Message notifications - messages: Messages + messages!: Messages // Input and key bindings - inputs: InputManager + inputs!: InputManager // Animations - animations: Animations + animations!: Animations // Timing - timer: Timer + timer!: Timer // Tooltip - tooltip_layer: Phaser.Group - tooltip: Tooltip + tooltip_layer!: Phaser.Group + tooltip!: Tooltip // Layers - layers: Phaser.Group + layers!: Phaser.Group // Modal dialogs - dialogs_layer: Phaser.Group + dialogs_layer!: Phaser.Group dialogs_opened: UIDialog[] = [] // Get the size of display diff --git a/src/ui/TestGame.ts b/src/ui/TestGame.ts index d011768..cb0faab 100644 --- a/src/ui/TestGame.ts +++ b/src/ui/TestGame.ts @@ -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). */ export class TestGame { - ui: MainUI; - view: T; - multistorage: Multi.FakeRemoteStorage; - state: string; - clock: FakeClock; + ui!: MainUI; + view!: T; + multistorage!: Multi.FakeRemoteStorage; + state!: string; + clock!: FakeClock; } /** diff --git a/src/ui/battle/ActionIcon.ts b/src/ui/battle/ActionIcon.ts index 8be408a..f41c6d4 100644 --- a/src/ui/battle/ActionIcon.ts +++ b/src/ui/battle/ActionIcon.ts @@ -25,7 +25,7 @@ module TK.SpaceTac.UI { cooldown = 0 // Images - img_targetting: Phaser.Image + img_targetting!: Phaser.Image img_top: Phaser.Image | null = null img_bottom: Phaser.Image img_power: Phaser.Image @@ -33,7 +33,7 @@ module TK.SpaceTac.UI { img_action: Phaser.Image // Indicators - text_power: Phaser.Text + text_power!: Phaser.Text constructor(bar: ActionBar, ship: Ship, action: BaseAction, position: number) { this.bar = bar; diff --git a/src/ui/battle/Arena.ts b/src/ui/battle/Arena.ts index b831af6..606cb2c 100644 --- a/src/ui/battle/Arena.ts +++ b/src/ui/battle/Arena.ts @@ -15,7 +15,7 @@ module TK.SpaceTac.UI { range_hint: RangeHint // Input capture - private mouse_capture: Phaser.Button + private mouse_capture?: Phaser.Button // Input callback to receive mouse move events private input_callback: any = null diff --git a/src/ui/battle/BattleView.ts b/src/ui/battle/BattleView.ts index 8cba1e3..a523b21 100644 --- a/src/ui/battle/BattleView.ts +++ b/src/ui/battle/BattleView.ts @@ -15,56 +15,56 @@ module TK.SpaceTac.UI { */ export class BattleView extends BaseView implements IShipButton { // Internal battle state - actual_battle: Battle + actual_battle!: Battle // Displayed battle state - battle: Battle + battle!: Battle // Interacting player - player: Player + player!: Player // Multiplayer sharing - multi: MultiBattle + multi!: MultiBattle // Layers - layer_background: Phaser.Group - layer_arena: Phaser.Group - layer_borders: Phaser.Group - layer_overlay: Phaser.Group - layer_sheets: Phaser.Group + layer_background!: Phaser.Group + layer_arena!: Phaser.Group + layer_borders!: Phaser.Group + layer_overlay!: Phaser.Group + layer_sheets!: Phaser.Group // Battleground container - arena: Arena + arena!: Arena // Background image - background: Phaser.Image | null + background!: Phaser.Image | null // Targetting mode (null if we're not in this mode) - targetting: Targetting + targetting!: Targetting // Ship list - ship_list: ShipList + ship_list!: ShipList // Action bar - action_bar: ActionBar + action_bar!: ActionBar // Currently hovered ship - ship_hovered: Ship | null + ship_hovered!: Ship | null // Ship tooltip - ship_tooltip: ShipTooltip + ship_tooltip!: ShipTooltip // Character sheet - character_sheet: CharacterSheet + character_sheet!: CharacterSheet // Subscription to the battle log - log_processor: LogProcessor + log_processor!: LogProcessor // True if player interaction is allowed - interacting: boolean + interacting!: boolean // Tactical mode toggle - toggle_tactical_mode: Toggle + toggle_tactical_mode!: Toggle // Toggle for the splash screen display splash = true diff --git a/src/ui/battle/MultiBattle.ts b/src/ui/battle/MultiBattle.ts index b60e88d..07c2b00 100644 --- a/src/ui/battle/MultiBattle.ts +++ b/src/ui/battle/MultiBattle.ts @@ -7,22 +7,22 @@ module TK.SpaceTac.UI { debug = false // Network exchange of messages - exchange: Multi.Exchange + exchange!: Multi.Exchange // True if this peer is the primary one (the one that invited the other) - primary: boolean + primary!: boolean // Battle being played - battle: Battle + battle!: Battle // Count of battle log events that were processed - processed: number + processed!: number // Serializer to use for actions - serializer: Serializer + serializer!: Serializer // Timer for scheduling - timer: Timer + timer!: Timer /** * Setup the session other a token diff --git a/src/ui/battle/ShipListItem.ts b/src/ui/battle/ShipListItem.ts index 401ef80..36cab03 100644 --- a/src/ui/battle/ShipListItem.ts +++ b/src/ui/battle/ShipListItem.ts @@ -7,9 +7,6 @@ module TK.SpaceTac.UI { // Reference to the ship game object ship: Ship - // Callbacks to act as buttons - ship_buttons: IShipButton - // Player indicator player_indicator: Phaser.Image diff --git a/src/ui/battle/Targetting.ts b/src/ui/battle/Targetting.ts index 7433afc..2abb5f5 100644 --- a/src/ui/battle/Targetting.ts +++ b/src/ui/battle/Targetting.ts @@ -12,7 +12,7 @@ module TK.SpaceTac.UI { ship: Ship | null = null action: BaseAction | null = null target: Target | null = null - mode: ActionTargettingMode + mode?: ActionTargettingMode simulation = new MoveFireResult() // Move and fire lines diff --git a/src/ui/character/CharacterSheet.ts b/src/ui/character/CharacterSheet.ts index 68339d2..1740057 100644 --- a/src/ui/character/CharacterSheet.ts +++ b/src/ui/character/CharacterSheet.ts @@ -25,10 +25,10 @@ module TK.SpaceTac.UI { close_button: Phaser.Button // Currently displayed fleet - fleet: Fleet + fleet!: Fleet // Currently displayed ship - ship: Ship + ship!: Ship // Ship name ship_name: Phaser.Text @@ -140,16 +140,21 @@ module TK.SpaceTac.UI { * Check if the sheet should be interactive */ isInteractive(): boolean { - return bool(this.ship) && !this.ship.critical && this.interactive; + return this.ship ? (!this.ship.critical && this.interactive) : false; } /** * Add an attribute display */ 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 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]); 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)) { this.builder.in(this.layer_upgrades).button("character-skill-upgrade", x + 292, y, () => { - this.ship.upgradeSkill(attribute); + ship.upgradeSkill(attribute); this.refresh(); }, `Spend one point to upgrade ${attrname}`); } @@ -251,8 +256,8 @@ module TK.SpaceTac.UI { cargo_slot.alpha = this.isInteractive() ? 1 : 0.5; this.ship_cargo.add(cargo_slot); - if (idx < this.ship.cargo.length) { - let equipment = new CharacterEquipment(this, this.ship.cargo[idx], cargo_slot); + if (idx < ship.cargo.length) { + let equipment = new CharacterEquipment(this, ship.cargo[idx], cargo_slot); this.layer_equipments.add(equipment); } }); @@ -408,7 +413,9 @@ module TK.SpaceTac.UI { * Refresh the sheet display */ refresh() { - this.show(this.ship, false, false); + if (this.ship) { + this.show(this.ship, false, false); + } } /** diff --git a/src/ui/character/FleetCreationView.ts b/src/ui/character/FleetCreationView.ts index 6e96390..438f14d 100644 --- a/src/ui/character/FleetCreationView.ts +++ b/src/ui/character/FleetCreationView.ts @@ -5,9 +5,9 @@ module TK.SpaceTac.UI { * View to configure the initial characters in the fleet */ export class FleetCreationView extends BaseView { - built_fleet: Fleet - infinite_shop: Shop - character_sheet: CharacterSheet + built_fleet!: Fleet + infinite_shop!: Shop + character_sheet!: CharacterSheet create() { super.create(); diff --git a/src/ui/common/Tooltip.ts b/src/ui/common/Tooltip.ts index af9609f..8469f05 100644 --- a/src/ui/common/Tooltip.ts +++ b/src/ui/common/Tooltip.ts @@ -6,7 +6,7 @@ module TK.SpaceTac.UI { view: BaseView background: Phaser.Graphics content: Phaser.Group - item: IBounded + item?: IBounded border = 10 margin = 6 viewport: IBounded | null = null @@ -55,7 +55,7 @@ module TK.SpaceTac.UI { } update() { - if (this.visible) { + if (this.visible && this.item) { let [width, height] = UITools.drawBackground(this.content, this.background, this.border); let [x, y] = this.getBestPosition(this.item, width, height); diff --git a/src/ui/common/UIConfirmDialog.ts b/src/ui/common/UIConfirmDialog.ts index 4eee7a6..1ce4221 100644 --- a/src/ui/common/UIConfirmDialog.ts +++ b/src/ui/common/UIConfirmDialog.ts @@ -4,7 +4,7 @@ module TK.SpaceTac.UI { */ export class UIConfirmDialog extends UIDialog { private result: Promise - private result_resolver: (confirmed: boolean) => void + private result_resolver?: (confirmed: boolean) => void constructor(view: BaseView, message: string) { super(view); @@ -22,8 +22,10 @@ module TK.SpaceTac.UI { * Force the result (simulate clicking the appropriate button) */ async forceResult(confirmed: boolean): Promise { - this.result_resolver(confirmed); - await this.result; + if (this.result_resolver) { + this.result_resolver(confirmed); + await this.result; + } } /** diff --git a/src/ui/common/ValueBar.ts b/src/ui/common/ValueBar.ts index 7f249fc..76688a9 100644 --- a/src/ui/common/ValueBar.ts +++ b/src/ui/common/ValueBar.ts @@ -24,13 +24,13 @@ module TK.SpaceTac.UI { private orientation: ValueBarOrientation // Current value - private current: number + private current = 0 // Maximal value - private maximal: number + private maximal = 0 // Proportional value - private proportional: number + private proportional = 0 // Original size private original_width: number diff --git a/src/ui/map/MissionLocationMarker.ts b/src/ui/map/MissionLocationMarker.ts index 0164cd6..61e54f4 100644 --- a/src/ui/map/MissionLocationMarker.ts +++ b/src/ui/map/MissionLocationMarker.ts @@ -5,9 +5,9 @@ module TK.SpaceTac.UI { export class MissionLocationMarker { private view: BaseView private container: Phaser.Group - private markers: [StarLocation | Star, string][] + private markers: [StarLocation | Star, string][] = [] private zoomed = true - private current_star: Star + private current_star?: Star constructor(view: BaseView, parent: Phaser.Group) { this.view = view; diff --git a/src/ui/map/UniverseMapView.ts b/src/ui/map/UniverseMapView.ts index b6ac100..3abd824 100644 --- a/src/ui/map/UniverseMapView.ts +++ b/src/ui/map/UniverseMapView.ts @@ -15,40 +15,40 @@ module TK.SpaceTac.UI { interactive = true // Layers - layer_universe: Phaser.Group - layer_overlay: Phaser.Group + layer_universe!: Phaser.Group + layer_overlay!: Phaser.Group // Star systems starsystems: StarSystemDisplay[] = [] // Links between stars - starlinks_group: Phaser.Group + starlinks_group!: Phaser.Group starlinks: Phaser.Graphics[] = [] // Fleets - player_fleet: FleetDisplay + player_fleet!: FleetDisplay // Markers - current_location: CurrentLocationMarker - mission_markers: MissionLocationMarker + current_location!: CurrentLocationMarker + mission_markers!: MissionLocationMarker // Actions for selected location - actions: MapLocationMenu + actions!: MapLocationMenu // Active missions - missions: ActiveMissionsDisplay - conversation: MissionConversationDisplay + missions!: ActiveMissionsDisplay + conversation!: MissionConversationDisplay // Character sheet - character_sheet: CharacterSheet + character_sheet!: CharacterSheet // Zoom level zoom = 0 - zoom_in: Phaser.Button - zoom_out: Phaser.Button + zoom_in!: Phaser.Button + zoom_out!: Phaser.Button // Options button - button_options: Phaser.Button + button_options!: Phaser.Button /** * Init the view, binding it to a universe diff --git a/src/ui/menu/MainMenu.ts b/src/ui/menu/MainMenu.ts index 2c24060..30a2f51 100644 --- a/src/ui/menu/MainMenu.ts +++ b/src/ui/menu/MainMenu.ts @@ -6,13 +6,13 @@ module TK.SpaceTac.UI { */ export class MainMenu extends BaseView { static returned = false - layer_stars: Phaser.Group - layer_presents: Phaser.Group - layer_title: Phaser.Group - button_new_game: Phaser.Button - button_quick_battle: Phaser.Button - button_load_game: Phaser.Button - dialog_load_game: LoadDialog + layer_stars!: Phaser.Group + layer_presents!: Phaser.Group + layer_title!: Phaser.Group + button_new_game!: Phaser.Button + button_quick_battle!: Phaser.Button + button_load_game!: Phaser.Button + dialog_load_game!: LoadDialog create() { super.create(); diff --git a/yarn.lock b/yarn.lock index 8e21509..4909a9d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2517,9 +2517,9 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript@2.6.2: - version "2.6.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4" +typescript@^2.7.1: + version "2.7.1" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.1.tgz#bb3682c2c791ac90e7c6210b26478a8da085c359" uglify-js@^2.6: version "2.8.29"