From a7f1cb41abbad7408f27f8a7d5535af7da911bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 7 Jan 2015 01:00:00 +0100 Subject: [PATCH] Added tslint style checker --- buildout.cfg | 1 + gulpfile.js | 15 +++- src/scripts/GameRouter.ts | 2 + src/scripts/game/Battle.ts | 64 +++++++------- src/scripts/game/BattleLog.ts | 6 +- src/scripts/game/Fleet.ts | 4 +- src/scripts/game/Player.ts | 4 +- src/scripts/game/RandomGenerator.ts | 7 +- src/scripts/game/Ship.ts | 4 +- src/scripts/game/Target.ts | 4 +- src/scripts/game/Universe.ts | 2 + src/scripts/game/actions/BaseAction.ts | 4 +- src/scripts/game/actions/EndTurnAction.ts | 4 +- src/scripts/game/actions/MoveAction.ts | 4 +- src/scripts/game/events/BaseLogEvent.ts | 4 +- src/scripts/game/events/MoveEvent.ts | 4 +- src/scripts/game/events/ShipChangeEvent.ts | 4 +- src/scripts/game/specs/Battle.spec.ts | 6 +- src/scripts/game/specs/BattleLog.spec.ts | 8 +- src/scripts/game/specs/EndTurnAction.spec.ts | 2 + src/scripts/game/specs/MoveAction.spec.ts | 18 ++-- src/scripts/game/specs/Ship.spec.ts | 12 +-- src/scripts/view/Boot.ts | 6 +- src/scripts/view/Main.ts | 3 +- src/scripts/view/Preload.ts | 6 +- src/scripts/view/UIGroup.ts | 2 + src/scripts/view/battle/ActionBar.ts | 8 +- src/scripts/view/battle/ActionIcon.ts | 6 +- src/scripts/view/battle/Arena.ts | 4 +- src/scripts/view/battle/BattleView.ts | 2 + src/scripts/view/battle/LogProcessor.ts | 6 +- src/scripts/view/battle/ShipArenaSprite.ts | 2 + src/scripts/view/battle/ShipCard.ts | 4 +- src/scripts/view/battle/ShipListItem.ts | 8 +- src/scripts/view/battle/Targetting.ts | 24 +++--- src/scripts/view/specs/Targetting.spec.ts | 4 +- tslint.json | 87 ++++++++++++++++++++ 37 files changed, 259 insertions(+), 96 deletions(-) create mode 100644 tslint.json diff --git a/buildout.cfg b/buildout.cfg index 9623da1..54e2a48 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -49,6 +49,7 @@ packages = gulp-open gulp-processhtml gulp-sourcemaps + gulp-tslint gulp-typescript gulp-uglifyjs gulp-util diff --git a/gulpfile.js b/gulpfile.js index e11c444..574fd66 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,6 +7,7 @@ var gulp = require('gulp'), processhtml = require('gulp-processhtml'), connect = require('gulp-connect'), karma = require('gulp-karma'), + tslint = require('gulp-tslint'), open = require('gulp-open'), del = require('del'), uglify = require('gulp-uglifyjs'), @@ -67,6 +68,14 @@ gulp.task('tests', ['typescript'], function () { .pipe(karma({configFile: 'karma.conf.js', action: 'run'})) }); +gulp.task('tslint', function () { + return gulp.src(['src/scripts/game/**/*.ts', 'src/scripts/view/**/*.ts']) + .pipe(tslint()) + .pipe(tslint.report('verbose', { + emitError: false + })); +}); + gulp.task('processhtml', function () { return gulp.src(paths.index) .pipe(processhtml()) @@ -79,7 +88,7 @@ gulp.task('reload', ['typescript'], function () { }); gulp.task('watch', function () { - gulp.watch(paths.ts, ['typescript', 'tests', 'reload']); + gulp.watch(paths.ts, ['typescript', 'tslint', 'tests', 'reload']); gulp.watch(paths.less, ['less', 'reload']); gulp.watch(paths.index, ['reload']); }); @@ -115,8 +124,8 @@ gulp.task('deploy', function () { }); gulp.task('default', function () { - runSequence('clean', ['typescript', 'less', 'connect', 'watch'], ['tests', 'open']); + runSequence('clean', ['typescript', 'tslint', 'less', 'connect', 'watch'], ['tests', 'open']); }); gulp.task('build', function () { - return runSequence('clean', ['typescript', 'less', 'copy', 'minifyJs', 'minifyCss', 'processhtml']); + return runSequence('clean', ['typescript', 'tslint', 'less', 'copy', 'minifyJs', 'minifyCss', 'processhtml']); }); diff --git a/src/scripts/GameRouter.ts b/src/scripts/GameRouter.ts index 9ef5522..006320f 100644 --- a/src/scripts/GameRouter.ts +++ b/src/scripts/GameRouter.ts @@ -1,6 +1,8 @@ /// module SpaceTac { + "use strict"; + // Router between game views export class GameRouter extends Phaser.Game { constructor() { diff --git a/src/scripts/game/Battle.ts b/src/scripts/game/Battle.ts index b25afd6..f64f059 100644 --- a/src/scripts/game/Battle.ts +++ b/src/scripts/game/Battle.ts @@ -1,4 +1,6 @@ module SpaceTac.Game { + "use strict"; + // A turn-based battle between fleets export class Battle { // Log of all battle events @@ -23,13 +25,23 @@ module SpaceTac.Game { this.playing_ship = null; } + // Create a quick random battle, for testing purposes + static newQuickRandom(): Battle { + var player1 = Player.newQuickRandom("John"); + var player2 = Player.newQuickRandom("Carl"); + + var result = new Battle(player1.fleet, player2.fleet); + result.start(); + return result; + } + // Create play order, performing an initiative throw throwInitiative(gen: RandomGenerator = new RandomGenerator()): void { var play_order: Ship[] = []; // Throw each ship's initiative - this.fleets.forEach(function (fleet) { - fleet.ships.forEach(function (ship) { + this.fleets.forEach(function (fleet: Fleet) { + fleet.ships.forEach(function (ship: Ship) { ship.throwInitiative(gen); play_order.push(ship); }); @@ -42,23 +54,6 @@ module SpaceTac.Game { this.play_order = play_order; } - // Defines the initial ship positions for one fleet - // x and y are the center of the fleet placement - // facing_angle is the forward angle in radians - private placeFleetShips(fleet: Fleet, x: number, y: number, facing_angle: number): void { - var side_angle = facing_angle + Math.PI * 0.5; - var spacing = 50; - var total_length = spacing * (fleet.ships.length - 1); - var dx = Math.cos(side_angle); - var dy = Math.sin(side_angle); - x -= dx * total_length * 0.5; - y -= dy * total_length * 0.5; - for (var i = 0; i < fleet.ships.length; i++) { - fleet.ships[i].setArenaPosition(x + i * dx * spacing, y + i * dy * spacing); - fleet.ships[i].setArenaFacingAngle(facing_angle); - } - } - // Defines the initial ship positions of all engaged fleets placeShips(): void { this.placeFleetShips(this.fleets[0], 100, 100, 0); @@ -68,10 +63,10 @@ module SpaceTac.Game { // End the current ship turn, passing control to the next one in play order // If at the end of the play order, next turn will start automatically // Member 'play_order' must be defined before calling this function - advanceToNextShip(log: boolean=true): void { + advanceToNextShip(log: boolean = true): void { var previous_ship = this.playing_ship; - if (this.play_order.length == 0) { + if (this.play_order.length === 0) { this.playing_ship_index = null; this.playing_ship = null; } else { @@ -108,7 +103,7 @@ module SpaceTac.Game { var log = this.log; // Simulate initial ship placement - this.play_order.forEach((ship) => { + this.play_order.forEach((ship: Ship) => { log.add(new MoveEvent(ship, ship.arena_x, ship.arena_y)); }); @@ -116,14 +111,21 @@ module SpaceTac.Game { log.add(new ShipChangeEvent(this.playing_ship, this.playing_ship)); } - // Create a quick random battle, for testing purposes - static newQuickRandom(): Battle { - var player1 = Player.newQuickRandom("John"); - var player2 = Player.newQuickRandom("Carl"); - - var result = new Battle(player1.fleet, player2.fleet); - result.start(); - return result; + // Defines the initial ship positions for one fleet + // x and y are the center of the fleet placement + // facing_angle is the forward angle in radians + private placeFleetShips(fleet: Fleet, x: number, y: number, facing_angle: number): void { + var side_angle = facing_angle + Math.PI * 0.5; + var spacing = 50; + var total_length = spacing * (fleet.ships.length - 1); + var dx = Math.cos(side_angle); + var dy = Math.sin(side_angle); + x -= dx * total_length * 0.5; + y -= dy * total_length * 0.5; + for (var i = 0; i < fleet.ships.length; i++) { + fleet.ships[i].setArenaPosition(x + i * dx * spacing, y + i * dy * spacing); + fleet.ships[i].setArenaFacingAngle(facing_angle); + } } } -} \ No newline at end of file +} diff --git a/src/scripts/game/BattleLog.ts b/src/scripts/game/BattleLog.ts index bc3e6d5..f575542 100644 --- a/src/scripts/game/BattleLog.ts +++ b/src/scripts/game/BattleLog.ts @@ -1,4 +1,6 @@ module SpaceTac.Game { + "use strict"; + // Log of a battle // This keeps track of all events in a battle // It also allows to register a callback to receive these events @@ -19,7 +21,7 @@ module SpaceTac.Game { add(event: BaseLogEvent) { this.events.push(event); - this.subscribers.forEach((subscriber) => { + this.subscribers.forEach((subscriber: Function) => { subscriber(event); }); } @@ -39,4 +41,4 @@ module SpaceTac.Game { } } } -} \ No newline at end of file +} diff --git a/src/scripts/game/Fleet.ts b/src/scripts/game/Fleet.ts index ba281e6..7c052b3 100644 --- a/src/scripts/game/Fleet.ts +++ b/src/scripts/game/Fleet.ts @@ -1,4 +1,6 @@ module SpaceTac.Game { + "use strict"; + // A fleet of ships export class Fleet { // Fleet owner @@ -19,4 +21,4 @@ module SpaceTac.Game { this.ships.push(ship); } } -} \ No newline at end of file +} diff --git a/src/scripts/game/Player.ts b/src/scripts/game/Player.ts index 01f36d9..4ddcf7a 100644 --- a/src/scripts/game/Player.ts +++ b/src/scripts/game/Player.ts @@ -1,4 +1,6 @@ module SpaceTac.Game { + "use strict"; + // One player (human or IA) export class Player { // Current fleet @@ -21,4 +23,4 @@ module SpaceTac.Game { return player; } } -} \ No newline at end of file +} diff --git a/src/scripts/game/RandomGenerator.ts b/src/scripts/game/RandomGenerator.ts index 9a1bca9..44c9b20 100644 --- a/src/scripts/game/RandomGenerator.ts +++ b/src/scripts/game/RandomGenerator.ts @@ -1,4 +1,6 @@ module SpaceTac.Game { + "use strict"; + // Random generator, used in all throws export class RandomGenerator { // Array of next values, empty for a correct generator @@ -13,8 +15,7 @@ module SpaceTac.Game { throw(level: number): number { if (this.fake_values.length > 0) { return this.fake_values.shift() * level; - } - else { + } else { return Math.random() * level; } } @@ -26,4 +27,4 @@ module SpaceTac.Game { this.fake_values.push(value); } } -} \ No newline at end of file +} diff --git a/src/scripts/game/Ship.ts b/src/scripts/game/Ship.ts index ce6c7d5..bc85da0 100644 --- a/src/scripts/game/Ship.ts +++ b/src/scripts/game/Ship.ts @@ -1,4 +1,6 @@ module SpaceTac.Game { + "use strict"; + // A single ship in a Fleet export class Ship { // Fleet this ship is a member of @@ -126,4 +128,4 @@ module SpaceTac.Game { this.useActionPoints(cost); } } -} \ No newline at end of file +} diff --git a/src/scripts/game/Target.ts b/src/scripts/game/Target.ts index 24e9a10..4489c3e 100644 --- a/src/scripts/game/Target.ts +++ b/src/scripts/game/Target.ts @@ -1,4 +1,6 @@ module SpaceTac.Game { + "use strict"; + // Target for a capability // This could be a location in space, or a ship export class Target { @@ -26,4 +28,4 @@ module SpaceTac.Game { return new Target(x, y, null); } } -} \ No newline at end of file +} diff --git a/src/scripts/game/Universe.ts b/src/scripts/game/Universe.ts index ddcbd84..a004bde 100644 --- a/src/scripts/game/Universe.ts +++ b/src/scripts/game/Universe.ts @@ -1,4 +1,6 @@ module SpaceTac.Game { + "use strict"; + // Main game universe export class Universe { // Current connected player diff --git a/src/scripts/game/actions/BaseAction.ts b/src/scripts/game/actions/BaseAction.ts index b7e7b21..c0b9d5f 100644 --- a/src/scripts/game/actions/BaseAction.ts +++ b/src/scripts/game/actions/BaseAction.ts @@ -1,4 +1,6 @@ module SpaceTac.Game { + "use strict"; + // Base class for action definitions export class BaseAction { // Identifier code for the type of action @@ -65,4 +67,4 @@ module SpaceTac.Game { return false; } } -} \ No newline at end of file +} diff --git a/src/scripts/game/actions/EndTurnAction.ts b/src/scripts/game/actions/EndTurnAction.ts index bd01f05..7eb8352 100644 --- a/src/scripts/game/actions/EndTurnAction.ts +++ b/src/scripts/game/actions/EndTurnAction.ts @@ -1,4 +1,6 @@ module SpaceTac.Game { + "use strict"; + // Action to end the ship's turn export class EndTurnAction extends BaseAction { constructor() { @@ -14,4 +16,4 @@ module SpaceTac.Game { return true; } } -} \ No newline at end of file +} diff --git a/src/scripts/game/actions/MoveAction.ts b/src/scripts/game/actions/MoveAction.ts index c75daf2..8a4843a 100644 --- a/src/scripts/game/actions/MoveAction.ts +++ b/src/scripts/game/actions/MoveAction.ts @@ -1,4 +1,6 @@ module SpaceTac.Game { + "use strict"; + // Action to move to a given location export class MoveAction extends BaseAction { constructor() { @@ -21,4 +23,4 @@ module SpaceTac.Game { return true; } } -} \ No newline at end of file +} diff --git a/src/scripts/game/events/BaseLogEvent.ts b/src/scripts/game/events/BaseLogEvent.ts index f5b2911..af29149 100644 --- a/src/scripts/game/events/BaseLogEvent.ts +++ b/src/scripts/game/events/BaseLogEvent.ts @@ -1,4 +1,6 @@ module SpaceTac.Game { + "use strict"; + // Base class for a BattleLog event export class BaseLogEvent { // Code of the event (its type) @@ -16,4 +18,4 @@ module SpaceTac.Game { this.target = target; } } -} \ No newline at end of file +} diff --git a/src/scripts/game/events/MoveEvent.ts b/src/scripts/game/events/MoveEvent.ts index ee811c9..0285d47 100644 --- a/src/scripts/game/events/MoveEvent.ts +++ b/src/scripts/game/events/MoveEvent.ts @@ -1,8 +1,10 @@ module SpaceTac.Game { + "use strict"; + // Event logged when a ship moves export class MoveEvent extends BaseLogEvent { constructor(ship: Ship, x: number, y: number) { super("move", ship, Target.newFromLocation(x, y)); } } -} \ No newline at end of file +} diff --git a/src/scripts/game/events/ShipChangeEvent.ts b/src/scripts/game/events/ShipChangeEvent.ts index 83c2342..29a7a03 100644 --- a/src/scripts/game/events/ShipChangeEvent.ts +++ b/src/scripts/game/events/ShipChangeEvent.ts @@ -1,8 +1,10 @@ module SpaceTac.Game { + "use strict"; + // Battle event, when a ship turn ended, and advanced to a new one export class ShipChangeEvent extends BaseLogEvent { constructor(ship: Ship, new_ship: Ship) { super("ship_change", ship, new_ship ? Target.newFromShip(new_ship) : null); } } -} \ No newline at end of file +} diff --git a/src/scripts/game/specs/Battle.spec.ts b/src/scripts/game/specs/Battle.spec.ts index 058397e..f7cc4a6 100644 --- a/src/scripts/game/specs/Battle.spec.ts +++ b/src/scripts/game/specs/Battle.spec.ts @@ -1,6 +1,8 @@ /// module SpaceTac.Game { + "use strict"; + describe("Battle", function () { it("defines play order by initiative throws", function () { var fleet1 = new Fleet(null); @@ -27,7 +29,7 @@ module SpaceTac.Game { expect(battle.play_order).toEqual([ship1, ship4, ship5, ship3, ship2]); }); - it("places ships on lines, facing the arena center", function(){ + it("places ships on lines, facing the arena center", function () { var fleet1 = new Fleet(null); var fleet2 = new Fleet(null); @@ -61,7 +63,7 @@ module SpaceTac.Game { expect(ship5.arena_angle).toBeCloseTo(Math.PI, 0.0001); }); - it("advances to next ship in play order", function(){ + it("advances to next ship in play order", function () { var fleet1 = new Fleet(null); var fleet2 = new Fleet(null); diff --git a/src/scripts/game/specs/BattleLog.spec.ts b/src/scripts/game/specs/BattleLog.spec.ts index b087a60..0e5a67b 100644 --- a/src/scripts/game/specs/BattleLog.spec.ts +++ b/src/scripts/game/specs/BattleLog.spec.ts @@ -1,6 +1,7 @@ /// module SpaceTac.Game { + "use strict"; // Check a single game log event function checkEvent(got: BaseLogEvent, ship: Ship, code: string, @@ -42,7 +43,7 @@ module SpaceTac.Game { var received: BaseLogEvent[] = []; var fake = new FakeEvent(); - var sub = log.subscribe(function (event) { + var sub = log.subscribe(function (event: BaseLogEvent) { received.push(event); }); @@ -75,9 +76,10 @@ module SpaceTac.Game { expect(battle.log.events.length).toBe(9); for (var i = 0; i < 8; i++) { - checkEvent(battle.log.events[i], battle.play_order[i], "move", null, battle.play_order[i].arena_x, battle.play_order[i].arena_y); + checkEvent(battle.log.events[i], battle.play_order[i], "move", null, + battle.play_order[i].arena_x, battle.play_order[i].arena_y); } checkEvent(battle.log.events[8], battle.playing_ship, "ship_change", battle.playing_ship); }); }); -} \ No newline at end of file +} diff --git a/src/scripts/game/specs/EndTurnAction.spec.ts b/src/scripts/game/specs/EndTurnAction.spec.ts index eab56b9..c3ea386 100644 --- a/src/scripts/game/specs/EndTurnAction.spec.ts +++ b/src/scripts/game/specs/EndTurnAction.spec.ts @@ -1,6 +1,8 @@ /// module SpaceTac.Game.Specs { + "use strict"; + describe("EndTurnAction", () => { it("can't be applied to non-playing ship", () => { var battle = Battle.newQuickRandom(); diff --git a/src/scripts/game/specs/MoveAction.spec.ts b/src/scripts/game/specs/MoveAction.spec.ts index e51eb33..4981a0e 100644 --- a/src/scripts/game/specs/MoveAction.spec.ts +++ b/src/scripts/game/specs/MoveAction.spec.ts @@ -1,8 +1,10 @@ /// module SpaceTac.Game { + "use strict"; + describe("MoveAction", function () { - it("checks movement against remaining AP", function(){ + it("checks movement against remaining AP", function () { var ship = new Ship(null, "Test"); ship.ap_current = 6; ship.movement_cost = 2; @@ -13,15 +15,15 @@ module SpaceTac.Game { var result = action.checkTarget(null, ship, Target.newFromLocation(0, 2)); expect(result).toEqual(Target.newFromLocation(0, 2)); - var result = action.checkTarget(null, ship, Target.newFromLocation(0, 8)); + result = action.checkTarget(null, ship, Target.newFromLocation(0, 8)); expect(result).toEqual(Target.newFromLocation(0, 3)); ship.ap_current = 0; - var result = action.checkTarget(null, ship, Target.newFromLocation(0, 8)); + result = action.checkTarget(null, ship, Target.newFromLocation(0, 8)); expect(result).toBeNull(); }); - it("forbids targetting a ship", function(){ + it("forbids targetting a ship", function () { var ship1 = new Ship(null, "Test1"); var ship2 = new Ship(null, "Test2"); var action = new MoveAction(); @@ -29,11 +31,11 @@ module SpaceTac.Game { var result = action.checkTarget(null, ship1, Target.newFromShip(ship1)); expect(result).toBeNull(); - var result = action.checkTarget(null, ship1, Target.newFromShip(ship2)); + result = action.checkTarget(null, ship1, Target.newFromShip(ship2)); expect(result).toBeNull(); }); - it("applies to ship location, battle log and AP", function(){ + it("applies to ship location, battle log and AP", function () { var battle = new Battle(null, null); var ship = new Ship(null, "Test"); ship.ap_current = 5; @@ -48,7 +50,7 @@ module SpaceTac.Game { expect(ship.arena_y).toBeCloseTo(3.535533, 0.00001); expect(ship.ap_current).toEqual(0); - var result = action.apply(battle, ship, Target.newFromLocation(10, 10)); + result = action.apply(battle, ship, Target.newFromLocation(10, 10)); expect(result).toBe(false); expect(ship.arena_x).toBeCloseTo(3.535533, 0.00001); expect(ship.arena_y).toBeCloseTo(3.535533, 0.00001); @@ -62,4 +64,4 @@ module SpaceTac.Game { expect(battle.log.events[0].target.y).toBeCloseTo(3.535533, 0.00001); }); }); -} \ No newline at end of file +} diff --git a/src/scripts/game/specs/Ship.spec.ts b/src/scripts/game/specs/Ship.spec.ts index d21a67d..2125c59 100644 --- a/src/scripts/game/specs/Ship.spec.ts +++ b/src/scripts/game/specs/Ship.spec.ts @@ -1,8 +1,10 @@ /// module SpaceTac.Game { - describe("Ship", function(){ - it("limits movement range by action points", function(){ + "use strict"; + + describe("Ship", function () { + it("limits movement range by action points", function () { var ship = new Ship(null, "Test"); ship.ap_current = 8; ship.movement_cost = 3; @@ -11,12 +13,12 @@ module SpaceTac.Game { var point = ship.getLongestMove(51, 52); expect(point).toEqual([51, 52]); - var point = ship.getLongestMove(60, 55); + point = ship.getLongestMove(60, 55); expect(point[0]).toBeCloseTo(52.385139, 0.0001); expect(point[1]).toBeCloseTo(51.19256, 0.0001); }); - it("moves and consumes action points", function(){ + it("moves and consumes action points", function () { var ship = new Ship(null, "Test"); ship.ap_current = 8; ship.movement_cost = 3; @@ -33,4 +35,4 @@ module SpaceTac.Game { expect(ship.arena_y).toEqual(50); }); }); -} \ No newline at end of file +} diff --git a/src/scripts/view/Boot.ts b/src/scripts/view/Boot.ts index 60982f2..dafe49b 100644 --- a/src/scripts/view/Boot.ts +++ b/src/scripts/view/Boot.ts @@ -1,7 +1,9 @@ module SpaceTac.View { + "use strict"; + export class Boot extends Phaser.State { preload() { - this.load.image('preload-bar', 'assets/images/preloader.gif'); + this.load.image("preload-bar", "assets/images/preloader.gif"); } create() { @@ -10,7 +12,7 @@ module SpaceTac.View { this.input.maxPointers = 1; this.stage.disableVisibilityChange = true; - this.game.state.start('preload'); + this.game.state.start("preload"); } } } diff --git a/src/scripts/view/Main.ts b/src/scripts/view/Main.ts index ec75a0e..709a6e7 100644 --- a/src/scripts/view/Main.ts +++ b/src/scripts/view/Main.ts @@ -1,6 +1,7 @@ module SpaceTac.View { - export class Main extends Phaser.State { + "use strict"; + export class Main extends Phaser.State { create() { // Switch to a test battle var battle = Game.Battle.newQuickRandom(); diff --git a/src/scripts/view/Preload.ts b/src/scripts/view/Preload.ts index 7f86cae..d21e89d 100644 --- a/src/scripts/view/Preload.ts +++ b/src/scripts/view/Preload.ts @@ -1,10 +1,12 @@ module SpaceTac.View { + "use strict"; + export class Preload extends Phaser.State { private preloadBar: Phaser.Sprite; preload() { // Add preload sprite - this.preloadBar = this.add.sprite(290, 290, 'preload-bar'); + this.preloadBar = this.add.sprite(290, 290, "preload-bar"); this.load.setPreloadSprite(this.preloadBar); // Load assets @@ -15,7 +17,7 @@ module SpaceTac.View { } create() { - this.game.state.start('main'); + this.game.state.start("main"); } } } diff --git a/src/scripts/view/UIGroup.ts b/src/scripts/view/UIGroup.ts index a1b5bd2..55e04e4 100644 --- a/src/scripts/view/UIGroup.ts +++ b/src/scripts/view/UIGroup.ts @@ -1,4 +1,6 @@ module SpaceTac.View { + "use strict"; + // Phaser Group to hold UI related objects export class UIGroup extends Phaser.Group { diff --git a/src/scripts/view/battle/ActionBar.ts b/src/scripts/view/battle/ActionBar.ts index 45facbe..0bfb452 100644 --- a/src/scripts/view/battle/ActionBar.ts +++ b/src/scripts/view/battle/ActionBar.ts @@ -1,4 +1,6 @@ module SpaceTac.View { + "use strict"; + // Bar with all available action icons displayed export class ActionBar extends Phaser.Group { // Link to the parent battleview @@ -27,7 +29,7 @@ module SpaceTac.View { // Clear the action icons clearAll(): void { - this.actions.forEach((action) => { + this.actions.forEach((action: ActionIcon) => { action.destroy(); }); this.actions = []; @@ -46,9 +48,9 @@ module SpaceTac.View { this.clearAll(); var actions = ship.getAvailableActions(); - actions.forEach((action) => { + actions.forEach((action: Game.BaseAction) => { action_bar.addAction(ship, action); }); } } -} \ No newline at end of file +} diff --git a/src/scripts/view/battle/ActionIcon.ts b/src/scripts/view/battle/ActionIcon.ts index 9acf07e..faf8f86 100644 --- a/src/scripts/view/battle/ActionIcon.ts +++ b/src/scripts/view/battle/ActionIcon.ts @@ -1,4 +1,6 @@ module SpaceTac.View { + "use strict"; + // Icon to activate a ship capability (move, fire...) export class ActionIcon extends Phaser.Button { @@ -20,7 +22,7 @@ module SpaceTac.View { this.ship = ship; this.action = action; - super(bar.game, x, y, 'action-' + action.code); + super(bar.game, x, y, "action-" + action.code); bar.add(this); // TODO Handle action.canBeUsed() result to enable/disable the button @@ -64,4 +66,4 @@ module SpaceTac.View { } } } -} \ No newline at end of file +} diff --git a/src/scripts/view/battle/Arena.ts b/src/scripts/view/battle/Arena.ts index ea9a22b..8c86701 100644 --- a/src/scripts/view/battle/Arena.ts +++ b/src/scripts/view/battle/Arena.ts @@ -1,4 +1,6 @@ module SpaceTac.View { + "use strict"; + // Graphical representation of a battle // This is the area in the BattleView that will display ships with their real positions export class Arena extends Phaser.Group { @@ -20,7 +22,7 @@ module SpaceTac.View { super(battleview.game); - var background = new Phaser.Button(battleview.game, 0, 0, 'ui-arena-background'); + var background = new Phaser.Button(battleview.game, 0, 0, "ui-arena-background"); background.scale.set(20, 10); this.background = background; diff --git a/src/scripts/view/battle/BattleView.ts b/src/scripts/view/battle/BattleView.ts index 7a42cb9..b01303a 100644 --- a/src/scripts/view/battle/BattleView.ts +++ b/src/scripts/view/battle/BattleView.ts @@ -1,4 +1,6 @@ module SpaceTac.View { + "use strict"; + // Interactive view of a Battle export class BattleView extends Phaser.State { diff --git a/src/scripts/view/battle/LogProcessor.ts b/src/scripts/view/battle/LogProcessor.ts index bc3a00f..beadddf 100644 --- a/src/scripts/view/battle/LogProcessor.ts +++ b/src/scripts/view/battle/LogProcessor.ts @@ -1,4 +1,6 @@ module SpaceTac.View { + "use strict"; + // Processor of battle log events // This will process incoming battle events, and update the battleview accordingly export class LogProcessor { @@ -20,7 +22,7 @@ module SpaceTac.View { this.battle = view.battle; this.log = view.battle.log; - this.subscription = this.log.subscribe((event) => { + this.subscription = this.log.subscribe((event: Game.BaseLogEvent) => { this.processBattleEvent(event); }); this.battle.injectInitialEvents(); @@ -54,4 +56,4 @@ module SpaceTac.View { } } } -} \ No newline at end of file +} diff --git a/src/scripts/view/battle/ShipArenaSprite.ts b/src/scripts/view/battle/ShipArenaSprite.ts index 21899ab..62ae66f 100644 --- a/src/scripts/view/battle/ShipArenaSprite.ts +++ b/src/scripts/view/battle/ShipArenaSprite.ts @@ -1,4 +1,6 @@ module SpaceTac.View { + "use strict"; + // Ship sprite in the arena (BattleView) export class ShipArenaSprite extends Phaser.Button { // Link to displayed ship diff --git a/src/scripts/view/battle/ShipCard.ts b/src/scripts/view/battle/ShipCard.ts index 579f565..4ef191d 100644 --- a/src/scripts/view/battle/ShipCard.ts +++ b/src/scripts/view/battle/ShipCard.ts @@ -1,4 +1,6 @@ module SpaceTac.View { + "use strict"; + // Card to display detailed information about a ship export class ShipCard extends Phaser.Sprite { // Displayed ship @@ -20,4 +22,4 @@ module SpaceTac.View { this.visible = (ship !== null); } } -} \ No newline at end of file +} diff --git a/src/scripts/view/battle/ShipListItem.ts b/src/scripts/view/battle/ShipListItem.ts index 52438dd..a497169 100644 --- a/src/scripts/view/battle/ShipListItem.ts +++ b/src/scripts/view/battle/ShipListItem.ts @@ -1,14 +1,16 @@ module SpaceTac.View { + "use strict"; + // One item in a ship list (used in BattleView) export class ShipListItem extends Phaser.Button { // Reference to the ship game object private ship: Game.Ship; // Create a ship button for the battle ship list - constructor(battleview: BattleView, x: number, y: number, ship:Game.Ship, owned: boolean) { + constructor(battleview: BattleView, x: number, y: number, ship: Game.Ship, owned: boolean) { this.ship = ship; - super(battleview.game, x, y, owned ? 'ui-shiplist-own' : 'ui-shiplist-enemy'); + super(battleview.game, x, y, owned ? "ui-shiplist-own" : "ui-shiplist-enemy"); battleview.ui.add(this); this.input.useHandCursor = true; @@ -20,4 +22,4 @@ module SpaceTac.View { }); } } -} \ No newline at end of file +} diff --git a/src/scripts/view/battle/Targetting.ts b/src/scripts/view/battle/Targetting.ts index 924f833..db3842e 100644 --- a/src/scripts/view/battle/Targetting.ts +++ b/src/scripts/view/battle/Targetting.ts @@ -1,16 +1,9 @@ module SpaceTac.View { + "use strict"; + // Targetting system // Allows to pick a target for an action export class Targetting { - // Access to the parent battle view - private battleview: BattleView; - - // Source of the targetting - private source: PIXI.Sprite; - - // Current target - private target: Game.Target; - // Signal to receive hovering events targetHovered: Phaser.Signal; @@ -20,6 +13,15 @@ module SpaceTac.View { // Target visual line line: Phaser.Graphics; + // Access to the parent battle view + private battleview: BattleView; + + // Source of the targetting + private source: PIXI.Sprite; + + // Current target + private target: Game.Target; + // Create a default targetting mode constructor(battleview: BattleView) { this.battleview = battleview; @@ -66,7 +68,7 @@ module SpaceTac.View { } // Set a target from a target object - setTarget(target: Game.Target, dispatch: boolean = true):void { + setTarget(target: Game.Target, dispatch: boolean = true): void { this.target = target; if (dispatch) { this.targetHovered.dispatch(this.target); @@ -95,4 +97,4 @@ module SpaceTac.View { this.targetSelected.dispatch(this.target); } } -} \ No newline at end of file +} diff --git a/src/scripts/view/specs/Targetting.spec.ts b/src/scripts/view/specs/Targetting.spec.ts index fc3d252..0f1a09c 100644 --- a/src/scripts/view/specs/Targetting.spec.ts +++ b/src/scripts/view/specs/Targetting.spec.ts @@ -1,6 +1,8 @@ /// module SpaceTac.View { + "use strict"; + describe("Targetting", () => { it("broadcasts hovering and selection events", () => { var targetting = new Targetting(null); @@ -23,4 +25,4 @@ module SpaceTac.View { expect(selected).toEqual([Game.Target.newFromLocation(1, 2)]); }); }); -} \ No newline at end of file +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..547680a --- /dev/null +++ b/tslint.json @@ -0,0 +1,87 @@ +{ + "rules": { + "ban": [true, + ["_", "extend"], + ["_", "isNull"], + ["_", "isDefined"] + ], + "class-name": true, + "comment-format": [true, + "check-space", + "!check-lowercase" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [true, 4], + "interface-name": true, + "jsdoc-format": true, + "label-position": true, + "label-undefined": true, + "max-line-length": [true, 140], + "member-ordering": [true, + "public-before-private", + "static-before-instance", + "variables-before-functions" + ], + "no-arg": true, + "no-bitwise": true, + "no-console": [true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": true, + "no-debugger": true, + "no-duplicate-key": true, + "no-duplicate-variable": true, + "no-empty": true, + "no-eval": true, + "no-string-literal": true, + "no-switch-case-fall-through": true, + "no-trailing-comma": true, + "no-trailing-whitespace": true, + "no-unused-expression": false, + "no-unused-variable": true, + "no-unreachable": true, + "no-use-before-declare": true, + "no-var-requires": true, + "one-line": [true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [true, "double"], + "radix": true, + "semicolon": true, + "triple-equals": [true, "allow-null-check"], + "typedef": [true, + "callSignature", + "indexSignature", + "parameter", + "propertySignature", + "variableDeclarator" + ], + "typedef-whitespace": [true, + ["callSignature", "noSpace"], + ["catchClause", "noSpace"], + ["indexSignature", "space"] + ], + "use-strict": [true, + "check-module", + "check-function" + ], + "variable-name": false, + "whitespace": [true, + "check-branch", + "check-decl", + "check-operator", + "check-separator", + "check-type" + ] + } +}