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",
"live-server": "1.2.0",
"remap-istanbul": "0.9.5",
"typescript": "2.6.2"
"typescript": "^2.7.1"
},
"dependencies": {
"jasmine-core": "2.5.2",

View file

@ -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();

View file

@ -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[] = []

View file

@ -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");
});

View file

@ -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] = <any>resolveForLevel(value, level);
});
return result;
}

View file

@ -112,7 +112,7 @@ module TK.SpaceTac.Specs {
battle.fleets[0].addShip(ship);
let ship1 = battle.fleets[0].addShip();
let moveaction = <MoveAction>nn(simulator.findBestEngine()).action;
moveaction.safety_distance = 30;
(<any>moveaction).safety_distance = 30;
battle.ship_separation = 30;
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
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) {

View file

@ -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);

View file

@ -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 {

View file

@ -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 {

View file

@ -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");
})
});

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
*/
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 {

View file

@ -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;

View file

@ -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;

View file

@ -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`);
}

View file

@ -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

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).
*/
export class TestGame<T extends Phaser.State> {
ui: MainUI;
view: T;
multistorage: Multi.FakeRemoteStorage;
state: string;
clock: FakeClock;
ui!: MainUI;
view!: T;
multistorage!: Multi.FakeRemoteStorage;
state!: string;
clock!: FakeClock;
}
/**

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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(<keyof ShipSkills>attribute);
ship.upgradeSkill(<keyof ShipSkills>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);
}
}
/**

View file

@ -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();

View file

@ -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);

View file

@ -4,7 +4,7 @@ module TK.SpaceTac.UI {
*/
export class UIConfirmDialog extends UIDialog {
private result: Promise<boolean>
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<void> {
this.result_resolver(confirmed);
await this.result;
if (this.result_resolver) {
this.result_resolver(confirmed);
await this.result;
}
}
/**

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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();

View file

@ -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"