1
0
Fork 0

Added tslint style checker

This commit is contained in:
Michaël Lemaire 2015-01-07 01:00:00 +01:00 committed by Michaël Lemaire
parent 18a20a7855
commit a7f1cb41ab
37 changed files with 259 additions and 96 deletions

View file

@ -49,6 +49,7 @@ packages =
gulp-open gulp-open
gulp-processhtml gulp-processhtml
gulp-sourcemaps gulp-sourcemaps
gulp-tslint
gulp-typescript gulp-typescript
gulp-uglifyjs gulp-uglifyjs
gulp-util gulp-util

View file

@ -7,6 +7,7 @@ var gulp = require('gulp'),
processhtml = require('gulp-processhtml'), processhtml = require('gulp-processhtml'),
connect = require('gulp-connect'), connect = require('gulp-connect'),
karma = require('gulp-karma'), karma = require('gulp-karma'),
tslint = require('gulp-tslint'),
open = require('gulp-open'), open = require('gulp-open'),
del = require('del'), del = require('del'),
uglify = require('gulp-uglifyjs'), uglify = require('gulp-uglifyjs'),
@ -67,6 +68,14 @@ gulp.task('tests', ['typescript'], function () {
.pipe(karma({configFile: 'karma.conf.js', action: 'run'})) .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 () { gulp.task('processhtml', function () {
return gulp.src(paths.index) return gulp.src(paths.index)
.pipe(processhtml()) .pipe(processhtml())
@ -79,7 +88,7 @@ gulp.task('reload', ['typescript'], function () {
}); });
gulp.task('watch', 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.less, ['less', 'reload']);
gulp.watch(paths.index, ['reload']); gulp.watch(paths.index, ['reload']);
}); });
@ -115,8 +124,8 @@ gulp.task('deploy', function () {
}); });
gulp.task('default', 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 () { gulp.task('build', function () {
return runSequence('clean', ['typescript', 'less', 'copy', 'minifyJs', 'minifyCss', 'processhtml']); return runSequence('clean', ['typescript', 'tslint', 'less', 'copy', 'minifyJs', 'minifyCss', 'processhtml']);
}); });

View file

@ -1,6 +1,8 @@
/// <reference path="definitions/phaser.d.ts"/> /// <reference path="definitions/phaser.d.ts"/>
module SpaceTac { module SpaceTac {
"use strict";
// Router between game views // Router between game views
export class GameRouter extends Phaser.Game { export class GameRouter extends Phaser.Game {
constructor() { constructor() {

View file

@ -1,4 +1,6 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// A turn-based battle between fleets // A turn-based battle between fleets
export class Battle { export class Battle {
// Log of all battle events // Log of all battle events
@ -23,13 +25,23 @@ module SpaceTac.Game {
this.playing_ship = null; 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 // Create play order, performing an initiative throw
throwInitiative(gen: RandomGenerator = new RandomGenerator()): void { throwInitiative(gen: RandomGenerator = new RandomGenerator()): void {
var play_order: Ship[] = []; var play_order: Ship[] = [];
// Throw each ship's initiative // Throw each ship's initiative
this.fleets.forEach(function (fleet) { this.fleets.forEach(function (fleet: Fleet) {
fleet.ships.forEach(function (ship) { fleet.ships.forEach(function (ship: Ship) {
ship.throwInitiative(gen); ship.throwInitiative(gen);
play_order.push(ship); play_order.push(ship);
}); });
@ -42,23 +54,6 @@ module SpaceTac.Game {
this.play_order = play_order; 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 // Defines the initial ship positions of all engaged fleets
placeShips(): void { placeShips(): void {
this.placeFleetShips(this.fleets[0], 100, 100, 0); 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 // 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 // If at the end of the play order, next turn will start automatically
// Member 'play_order' must be defined before calling this function // 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; 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_index = null;
this.playing_ship = null; this.playing_ship = null;
} else { } else {
@ -108,7 +103,7 @@ module SpaceTac.Game {
var log = this.log; var log = this.log;
// Simulate initial ship placement // 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)); 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)); log.add(new ShipChangeEvent(this.playing_ship, this.playing_ship));
} }
// Create a quick random battle, for testing purposes // Defines the initial ship positions for one fleet
static newQuickRandom(): Battle { // x and y are the center of the fleet placement
var player1 = Player.newQuickRandom("John"); // facing_angle is the forward angle in radians
var player2 = Player.newQuickRandom("Carl"); private placeFleetShips(fleet: Fleet, x: number, y: number, facing_angle: number): void {
var side_angle = facing_angle + Math.PI * 0.5;
var result = new Battle(player1.fleet, player2.fleet); var spacing = 50;
result.start(); var total_length = spacing * (fleet.ships.length - 1);
return result; 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);
}
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// Log of a battle // Log of a battle
// This keeps track of all events in a battle // This keeps track of all events in a battle
// It also allows to register a callback to receive these events // It also allows to register a callback to receive these events
@ -19,7 +21,7 @@ module SpaceTac.Game {
add(event: BaseLogEvent) { add(event: BaseLogEvent) {
this.events.push(event); this.events.push(event);
this.subscribers.forEach((subscriber) => { this.subscribers.forEach((subscriber: Function) => {
subscriber(event); subscriber(event);
}); });
} }
@ -39,4 +41,4 @@ module SpaceTac.Game {
} }
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// A fleet of ships // A fleet of ships
export class Fleet { export class Fleet {
// Fleet owner // Fleet owner
@ -19,4 +21,4 @@ module SpaceTac.Game {
this.ships.push(ship); this.ships.push(ship);
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// One player (human or IA) // One player (human or IA)
export class Player { export class Player {
// Current fleet // Current fleet
@ -21,4 +23,4 @@ module SpaceTac.Game {
return player; return player;
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// Random generator, used in all throws // Random generator, used in all throws
export class RandomGenerator { export class RandomGenerator {
// Array of next values, empty for a correct generator // Array of next values, empty for a correct generator
@ -13,8 +15,7 @@ module SpaceTac.Game {
throw(level: number): number { throw(level: number): number {
if (this.fake_values.length > 0) { if (this.fake_values.length > 0) {
return this.fake_values.shift() * level; return this.fake_values.shift() * level;
} } else {
else {
return Math.random() * level; return Math.random() * level;
} }
} }
@ -26,4 +27,4 @@ module SpaceTac.Game {
this.fake_values.push(value); this.fake_values.push(value);
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// A single ship in a Fleet // A single ship in a Fleet
export class Ship { export class Ship {
// Fleet this ship is a member of // Fleet this ship is a member of
@ -126,4 +128,4 @@ module SpaceTac.Game {
this.useActionPoints(cost); this.useActionPoints(cost);
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// Target for a capability // Target for a capability
// This could be a location in space, or a ship // This could be a location in space, or a ship
export class Target { export class Target {
@ -26,4 +28,4 @@ module SpaceTac.Game {
return new Target(x, y, null); return new Target(x, y, null);
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// Main game universe // Main game universe
export class Universe { export class Universe {
// Current connected player // Current connected player

View file

@ -1,4 +1,6 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// Base class for action definitions // Base class for action definitions
export class BaseAction { export class BaseAction {
// Identifier code for the type of action // Identifier code for the type of action
@ -65,4 +67,4 @@ module SpaceTac.Game {
return false; return false;
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// Action to end the ship's turn // Action to end the ship's turn
export class EndTurnAction extends BaseAction { export class EndTurnAction extends BaseAction {
constructor() { constructor() {
@ -14,4 +16,4 @@ module SpaceTac.Game {
return true; return true;
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// Action to move to a given location // Action to move to a given location
export class MoveAction extends BaseAction { export class MoveAction extends BaseAction {
constructor() { constructor() {
@ -21,4 +23,4 @@ module SpaceTac.Game {
return true; return true;
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// Base class for a BattleLog event // Base class for a BattleLog event
export class BaseLogEvent { export class BaseLogEvent {
// Code of the event (its type) // Code of the event (its type)
@ -16,4 +18,4 @@ module SpaceTac.Game {
this.target = target; this.target = target;
} }
} }
} }

View file

@ -1,8 +1,10 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// Event logged when a ship moves // Event logged when a ship moves
export class MoveEvent extends BaseLogEvent { export class MoveEvent extends BaseLogEvent {
constructor(ship: Ship, x: number, y: number) { constructor(ship: Ship, x: number, y: number) {
super("move", ship, Target.newFromLocation(x, y)); super("move", ship, Target.newFromLocation(x, y));
} }
} }
} }

View file

@ -1,8 +1,10 @@
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// Battle event, when a ship turn ended, and advanced to a new one // Battle event, when a ship turn ended, and advanced to a new one
export class ShipChangeEvent extends BaseLogEvent { export class ShipChangeEvent extends BaseLogEvent {
constructor(ship: Ship, new_ship: Ship) { constructor(ship: Ship, new_ship: Ship) {
super("ship_change", ship, new_ship ? Target.newFromShip(new_ship) : null); super("ship_change", ship, new_ship ? Target.newFromShip(new_ship) : null);
} }
} }
} }

View file

@ -1,6 +1,8 @@
/// <reference path="../../definitions/jasmine.d.ts"/> /// <reference path="../../definitions/jasmine.d.ts"/>
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
describe("Battle", function () { describe("Battle", function () {
it("defines play order by initiative throws", function () { it("defines play order by initiative throws", function () {
var fleet1 = new Fleet(null); var fleet1 = new Fleet(null);
@ -27,7 +29,7 @@ module SpaceTac.Game {
expect(battle.play_order).toEqual([ship1, ship4, ship5, ship3, ship2]); 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 fleet1 = new Fleet(null);
var fleet2 = new Fleet(null); var fleet2 = new Fleet(null);
@ -61,7 +63,7 @@ module SpaceTac.Game {
expect(ship5.arena_angle).toBeCloseTo(Math.PI, 0.0001); 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 fleet1 = new Fleet(null);
var fleet2 = new Fleet(null); var fleet2 = new Fleet(null);

View file

@ -1,6 +1,7 @@
/// <reference path="../../definitions/jasmine.d.ts"/> /// <reference path="../../definitions/jasmine.d.ts"/>
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
// Check a single game log event // Check a single game log event
function checkEvent(got: BaseLogEvent, ship: Ship, code: string, function checkEvent(got: BaseLogEvent, ship: Ship, code: string,
@ -42,7 +43,7 @@ module SpaceTac.Game {
var received: BaseLogEvent[] = []; var received: BaseLogEvent[] = [];
var fake = new FakeEvent(); var fake = new FakeEvent();
var sub = log.subscribe(function (event) { var sub = log.subscribe(function (event: BaseLogEvent) {
received.push(event); received.push(event);
}); });
@ -75,9 +76,10 @@ module SpaceTac.Game {
expect(battle.log.events.length).toBe(9); expect(battle.log.events.length).toBe(9);
for (var i = 0; i < 8; i++) { 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); checkEvent(battle.log.events[8], battle.playing_ship, "ship_change", battle.playing_ship);
}); });
}); });
} }

View file

@ -1,6 +1,8 @@
/// <reference path="../../definitions/jasmine.d.ts"/> /// <reference path="../../definitions/jasmine.d.ts"/>
module SpaceTac.Game.Specs { module SpaceTac.Game.Specs {
"use strict";
describe("EndTurnAction", () => { describe("EndTurnAction", () => {
it("can't be applied to non-playing ship", () => { it("can't be applied to non-playing ship", () => {
var battle = Battle.newQuickRandom(); var battle = Battle.newQuickRandom();

View file

@ -1,8 +1,10 @@
/// <reference path="../../definitions/jasmine.d.ts"/> /// <reference path="../../definitions/jasmine.d.ts"/>
module SpaceTac.Game { module SpaceTac.Game {
"use strict";
describe("MoveAction", function () { describe("MoveAction", function () {
it("checks movement against remaining AP", function(){ it("checks movement against remaining AP", function () {
var ship = new Ship(null, "Test"); var ship = new Ship(null, "Test");
ship.ap_current = 6; ship.ap_current = 6;
ship.movement_cost = 2; ship.movement_cost = 2;
@ -13,15 +15,15 @@ module SpaceTac.Game {
var result = action.checkTarget(null, ship, Target.newFromLocation(0, 2)); var result = action.checkTarget(null, ship, Target.newFromLocation(0, 2));
expect(result).toEqual(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)); expect(result).toEqual(Target.newFromLocation(0, 3));
ship.ap_current = 0; 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(); expect(result).toBeNull();
}); });
it("forbids targetting a ship", function(){ it("forbids targetting a ship", function () {
var ship1 = new Ship(null, "Test1"); var ship1 = new Ship(null, "Test1");
var ship2 = new Ship(null, "Test2"); var ship2 = new Ship(null, "Test2");
var action = new MoveAction(); var action = new MoveAction();
@ -29,11 +31,11 @@ module SpaceTac.Game {
var result = action.checkTarget(null, ship1, Target.newFromShip(ship1)); var result = action.checkTarget(null, ship1, Target.newFromShip(ship1));
expect(result).toBeNull(); expect(result).toBeNull();
var result = action.checkTarget(null, ship1, Target.newFromShip(ship2)); result = action.checkTarget(null, ship1, Target.newFromShip(ship2));
expect(result).toBeNull(); 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 battle = new Battle(null, null);
var ship = new Ship(null, "Test"); var ship = new Ship(null, "Test");
ship.ap_current = 5; ship.ap_current = 5;
@ -48,7 +50,7 @@ module SpaceTac.Game {
expect(ship.arena_y).toBeCloseTo(3.535533, 0.00001); expect(ship.arena_y).toBeCloseTo(3.535533, 0.00001);
expect(ship.ap_current).toEqual(0); 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(result).toBe(false);
expect(ship.arena_x).toBeCloseTo(3.535533, 0.00001); expect(ship.arena_x).toBeCloseTo(3.535533, 0.00001);
expect(ship.arena_y).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); expect(battle.log.events[0].target.y).toBeCloseTo(3.535533, 0.00001);
}); });
}); });
} }

View file

@ -1,8 +1,10 @@
/// <reference path="../../definitions/jasmine.d.ts"/> /// <reference path="../../definitions/jasmine.d.ts"/>
module SpaceTac.Game { module SpaceTac.Game {
describe("Ship", function(){ "use strict";
it("limits movement range by action points", function(){
describe("Ship", function () {
it("limits movement range by action points", function () {
var ship = new Ship(null, "Test"); var ship = new Ship(null, "Test");
ship.ap_current = 8; ship.ap_current = 8;
ship.movement_cost = 3; ship.movement_cost = 3;
@ -11,12 +13,12 @@ module SpaceTac.Game {
var point = ship.getLongestMove(51, 52); var point = ship.getLongestMove(51, 52);
expect(point).toEqual([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[0]).toBeCloseTo(52.385139, 0.0001);
expect(point[1]).toBeCloseTo(51.19256, 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"); var ship = new Ship(null, "Test");
ship.ap_current = 8; ship.ap_current = 8;
ship.movement_cost = 3; ship.movement_cost = 3;
@ -33,4 +35,4 @@ module SpaceTac.Game {
expect(ship.arena_y).toEqual(50); expect(ship.arena_y).toEqual(50);
}); });
}); });
} }

View file

@ -1,7 +1,9 @@
module SpaceTac.View { module SpaceTac.View {
"use strict";
export class Boot extends Phaser.State { export class Boot extends Phaser.State {
preload() { preload() {
this.load.image('preload-bar', 'assets/images/preloader.gif'); this.load.image("preload-bar", "assets/images/preloader.gif");
} }
create() { create() {
@ -10,7 +12,7 @@ module SpaceTac.View {
this.input.maxPointers = 1; this.input.maxPointers = 1;
this.stage.disableVisibilityChange = true; this.stage.disableVisibilityChange = true;
this.game.state.start('preload'); this.game.state.start("preload");
} }
} }
} }

View file

@ -1,6 +1,7 @@
module SpaceTac.View { module SpaceTac.View {
export class Main extends Phaser.State { "use strict";
export class Main extends Phaser.State {
create() { create() {
// Switch to a test battle // Switch to a test battle
var battle = Game.Battle.newQuickRandom(); var battle = Game.Battle.newQuickRandom();

View file

@ -1,10 +1,12 @@
module SpaceTac.View { module SpaceTac.View {
"use strict";
export class Preload extends Phaser.State { export class Preload extends Phaser.State {
private preloadBar: Phaser.Sprite; private preloadBar: Phaser.Sprite;
preload() { preload() {
// Add preload sprite // 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); this.load.setPreloadSprite(this.preloadBar);
// Load assets // Load assets
@ -15,7 +17,7 @@ module SpaceTac.View {
} }
create() { create() {
this.game.state.start('main'); this.game.state.start("main");
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.View { module SpaceTac.View {
"use strict";
// Phaser Group to hold UI related objects // Phaser Group to hold UI related objects
export class UIGroup extends Phaser.Group { export class UIGroup extends Phaser.Group {

View file

@ -1,4 +1,6 @@
module SpaceTac.View { module SpaceTac.View {
"use strict";
// Bar with all available action icons displayed // Bar with all available action icons displayed
export class ActionBar extends Phaser.Group { export class ActionBar extends Phaser.Group {
// Link to the parent battleview // Link to the parent battleview
@ -27,7 +29,7 @@ module SpaceTac.View {
// Clear the action icons // Clear the action icons
clearAll(): void { clearAll(): void {
this.actions.forEach((action) => { this.actions.forEach((action: ActionIcon) => {
action.destroy(); action.destroy();
}); });
this.actions = []; this.actions = [];
@ -46,9 +48,9 @@ module SpaceTac.View {
this.clearAll(); this.clearAll();
var actions = ship.getAvailableActions(); var actions = ship.getAvailableActions();
actions.forEach((action) => { actions.forEach((action: Game.BaseAction) => {
action_bar.addAction(ship, action); action_bar.addAction(ship, action);
}); });
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.View { module SpaceTac.View {
"use strict";
// Icon to activate a ship capability (move, fire...) // Icon to activate a ship capability (move, fire...)
export class ActionIcon extends Phaser.Button { export class ActionIcon extends Phaser.Button {
@ -20,7 +22,7 @@ module SpaceTac.View {
this.ship = ship; this.ship = ship;
this.action = action; this.action = action;
super(bar.game, x, y, 'action-' + action.code); super(bar.game, x, y, "action-" + action.code);
bar.add(this); bar.add(this);
// TODO Handle action.canBeUsed() result to enable/disable the button // TODO Handle action.canBeUsed() result to enable/disable the button
@ -64,4 +66,4 @@ module SpaceTac.View {
} }
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.View { module SpaceTac.View {
"use strict";
// Graphical representation of a battle // Graphical representation of a battle
// This is the area in the BattleView that will display ships with their real positions // This is the area in the BattleView that will display ships with their real positions
export class Arena extends Phaser.Group { export class Arena extends Phaser.Group {
@ -20,7 +22,7 @@ module SpaceTac.View {
super(battleview.game); 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); background.scale.set(20, 10);
this.background = background; this.background = background;

View file

@ -1,4 +1,6 @@
module SpaceTac.View { module SpaceTac.View {
"use strict";
// Interactive view of a Battle // Interactive view of a Battle
export class BattleView extends Phaser.State { export class BattleView extends Phaser.State {

View file

@ -1,4 +1,6 @@
module SpaceTac.View { module SpaceTac.View {
"use strict";
// Processor of battle log events // Processor of battle log events
// This will process incoming battle events, and update the battleview accordingly // This will process incoming battle events, and update the battleview accordingly
export class LogProcessor { export class LogProcessor {
@ -20,7 +22,7 @@ module SpaceTac.View {
this.battle = view.battle; this.battle = view.battle;
this.log = view.battle.log; this.log = view.battle.log;
this.subscription = this.log.subscribe((event) => { this.subscription = this.log.subscribe((event: Game.BaseLogEvent) => {
this.processBattleEvent(event); this.processBattleEvent(event);
}); });
this.battle.injectInitialEvents(); this.battle.injectInitialEvents();
@ -54,4 +56,4 @@ module SpaceTac.View {
} }
} }
} }
} }

View file

@ -1,4 +1,6 @@
module SpaceTac.View { module SpaceTac.View {
"use strict";
// Ship sprite in the arena (BattleView) // Ship sprite in the arena (BattleView)
export class ShipArenaSprite extends Phaser.Button { export class ShipArenaSprite extends Phaser.Button {
// Link to displayed ship // Link to displayed ship

View file

@ -1,4 +1,6 @@
module SpaceTac.View { module SpaceTac.View {
"use strict";
// Card to display detailed information about a ship // Card to display detailed information about a ship
export class ShipCard extends Phaser.Sprite { export class ShipCard extends Phaser.Sprite {
// Displayed ship // Displayed ship
@ -20,4 +22,4 @@ module SpaceTac.View {
this.visible = (ship !== null); this.visible = (ship !== null);
} }
} }
} }

View file

@ -1,14 +1,16 @@
module SpaceTac.View { module SpaceTac.View {
"use strict";
// One item in a ship list (used in BattleView) // One item in a ship list (used in BattleView)
export class ShipListItem extends Phaser.Button { export class ShipListItem extends Phaser.Button {
// Reference to the ship game object // Reference to the ship game object
private ship: Game.Ship; private ship: Game.Ship;
// Create a ship button for the battle ship list // 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; 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); battleview.ui.add(this);
this.input.useHandCursor = true; this.input.useHandCursor = true;
@ -20,4 +22,4 @@ module SpaceTac.View {
}); });
} }
} }
} }

View file

@ -1,16 +1,9 @@
module SpaceTac.View { module SpaceTac.View {
"use strict";
// Targetting system // Targetting system
// Allows to pick a target for an action // Allows to pick a target for an action
export class Targetting { 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 // Signal to receive hovering events
targetHovered: Phaser.Signal; targetHovered: Phaser.Signal;
@ -20,6 +13,15 @@ module SpaceTac.View {
// Target visual line // Target visual line
line: Phaser.Graphics; 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 // Create a default targetting mode
constructor(battleview: BattleView) { constructor(battleview: BattleView) {
this.battleview = battleview; this.battleview = battleview;
@ -66,7 +68,7 @@ module SpaceTac.View {
} }
// Set a target from a target object // 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; this.target = target;
if (dispatch) { if (dispatch) {
this.targetHovered.dispatch(this.target); this.targetHovered.dispatch(this.target);
@ -95,4 +97,4 @@ module SpaceTac.View {
this.targetSelected.dispatch(this.target); this.targetSelected.dispatch(this.target);
} }
} }
} }

View file

@ -1,6 +1,8 @@
/// <reference path="../../definitions/jasmine.d.ts"/> /// <reference path="../../definitions/jasmine.d.ts"/>
module SpaceTac.View { module SpaceTac.View {
"use strict";
describe("Targetting", () => { describe("Targetting", () => {
it("broadcasts hovering and selection events", () => { it("broadcasts hovering and selection events", () => {
var targetting = new Targetting(null); var targetting = new Targetting(null);
@ -23,4 +25,4 @@ module SpaceTac.View {
expect(selected).toEqual([Game.Target.newFromLocation(1, 2)]); expect(selected).toEqual([Game.Target.newFromLocation(1, 2)]);
}); });
}); });
} }

87
tslint.json Normal file
View file

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