1
0
Fork 0

Module renaming to avoid some errors due to file compiling order

This commit is contained in:
Michaël Lemaire 2014-12-31 01:00:00 +01:00 committed by Michaël Lemaire
parent 1efa4a0595
commit 4a5f975d25
17 changed files with 64 additions and 62 deletions

View file

@ -87,7 +87,7 @@ module SpaceTac.Game {
} }
if (log) { if (log) {
this.log.add(new Events.ShipChangeEvent(previous_ship, this.playing_ship)); this.log.add(new ShipChangeEvent(previous_ship, this.playing_ship));
} }
} }
@ -109,11 +109,11 @@ module SpaceTac.Game {
// Simulate initial ship placement // Simulate initial ship placement
this.play_order.forEach((ship) => { this.play_order.forEach((ship) => {
log.add(new Events.MoveEvent(ship, ship.arena_x, ship.arena_y)); log.add(new MoveEvent(ship, ship.arena_x, ship.arena_y));
}); });
// Simulate game turn // Simulate game turn
log.add(new Events.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 // Create a quick random battle, for testing purposes

View file

@ -4,7 +4,7 @@ module SpaceTac.Game {
// It also allows to register a callback to receive these events // It also allows to register a callback to receive these events
export class BattleLog { export class BattleLog {
// Full list of battle events // Full list of battle events
events: Events.BaseLogEvent[]; events: BaseLogEvent[];
// List of subscribers // List of subscribers
private subscribers: Function[]; private subscribers: Function[];
@ -16,7 +16,7 @@ module SpaceTac.Game {
} }
// Add a battle event to the log // Add a battle event to the log
add(event: Events.BaseLogEvent) { add(event: BaseLogEvent) {
this.events.push(event); this.events.push(event);
this.subscribers.forEach((subscriber) => { this.subscribers.forEach((subscriber) => {
@ -25,7 +25,7 @@ module SpaceTac.Game {
} }
// Subscribe a callback to receive further events // Subscribe a callback to receive further events
subscribe(callback: (event: Events.BaseLogEvent) => void): Function { subscribe(callback: (event: BaseLogEvent) => void): Function {
this.subscribers.push(callback); this.subscribers.push(callback);
return callback; return callback;
} }

View file

@ -82,9 +82,9 @@ module SpaceTac.Game {
// Get the list of actions available // Get the list of actions available
// This list does not filter out actions unavailable due to insufficient AP, it justs filter out // This list does not filter out actions unavailable due to insufficient AP, it justs filter out
// actions that are not allowed/available at all on the ship // actions that are not allowed/available at all on the ship
getAvailableActions(): Actions.BaseAction[] { getAvailableActions(): BaseAction[] {
// TODO // TODO
return [new Actions.MoveAction()]; return [new MoveAction()];
} }
// Consumes action points // Consumes action points

View file

@ -1,4 +1,4 @@
module SpaceTac.Game.Actions { module SpaceTac.Game {
// 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

View file

@ -1,4 +1,4 @@
module SpaceTac.Game.Actions { module SpaceTac.Game {
// 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() {

View file

@ -1,4 +1,4 @@
module SpaceTac.Game.Events { module SpaceTac.Game {
// 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)

View file

@ -1,4 +1,4 @@
module SpaceTac.Game.Events { module SpaceTac.Game {
// 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) {

View file

@ -1,4 +1,4 @@
module SpaceTac.Game.Events { module SpaceTac.Game {
// 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) {

View file

@ -1,26 +1,26 @@
/// <reference path="../../definitions/jasmine.d.ts"/> /// <reference path="../../definitions/jasmine.d.ts"/>
module SpaceTac.Specs { module SpaceTac.Game {
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 Game.Fleet(null); var fleet1 = new Fleet(null);
var fleet2 = new Game.Fleet(null); var fleet2 = new Fleet(null);
var ship1 = new Game.Ship(fleet1, "F1S1"); var ship1 = new Ship(fleet1, "F1S1");
ship1.initiative_level = 2; ship1.initiative_level = 2;
var ship2 = new Game.Ship(fleet1, "F1S2"); var ship2 = new Ship(fleet1, "F1S2");
ship2.initiative_level = 4; ship2.initiative_level = 4;
var ship3 = new Game.Ship(fleet1, "F1S3"); var ship3 = new Ship(fleet1, "F1S3");
ship3.initiative_level = 1; ship3.initiative_level = 1;
var ship4 = new Game.Ship(fleet2, "F2S1"); var ship4 = new Ship(fleet2, "F2S1");
ship4.initiative_level = 8; ship4.initiative_level = 8;
var ship5 = new Game.Ship(fleet2, "F2S2"); var ship5 = new Ship(fleet2, "F2S2");
ship5.initiative_level = 2; ship5.initiative_level = 2;
var battle = new Game.Battle(fleet1, fleet2); var battle = new Battle(fleet1, fleet2);
expect(battle.play_order.length).toBe(0); expect(battle.play_order.length).toBe(0);
var gen = new Game.RandomGenerator(1.0, 0.1, 1.0, 0.2, 0.6); var gen = new RandomGenerator(1.0, 0.1, 1.0, 0.2, 0.6);
battle.throwInitiative(gen); battle.throwInitiative(gen);
expect(battle.play_order.length).toBe(5); expect(battle.play_order.length).toBe(5);
@ -28,16 +28,16 @@ module SpaceTac.Specs {
}); });
it("places ships on lines, facing the arena center", function(){ it("places ships on lines, facing the arena center", function(){
var fleet1 = new Game.Fleet(null); var fleet1 = new Fleet(null);
var fleet2 = new Game.Fleet(null); var fleet2 = new Fleet(null);
var ship1 = new Game.Ship(fleet1, "F1S1"); var ship1 = new Ship(fleet1, "F1S1");
var ship2 = new Game.Ship(fleet1, "F1S2"); var ship2 = new Ship(fleet1, "F1S2");
var ship3 = new Game.Ship(fleet1, "F1S3"); var ship3 = new Ship(fleet1, "F1S3");
var ship4 = new Game.Ship(fleet2, "F2S1"); var ship4 = new Ship(fleet2, "F2S1");
var ship5 = new Game.Ship(fleet2, "F2S2"); var ship5 = new Ship(fleet2, "F2S2");
var battle = new Game.Battle(fleet1, fleet2); var battle = new Battle(fleet1, fleet2);
battle.placeShips(); battle.placeShips();
expect(ship1.arena_x).toBeCloseTo(100, 0.0001); expect(ship1.arena_x).toBeCloseTo(100, 0.0001);
@ -62,14 +62,14 @@ module SpaceTac.Specs {
}); });
it("advances to next ship in play order", function(){ it("advances to next ship in play order", function(){
var fleet1 = new Game.Fleet(null); var fleet1 = new Fleet(null);
var fleet2 = new Game.Fleet(null); var fleet2 = new Fleet(null);
var ship1 = new Game.Ship(fleet1, "F1S1"); var ship1 = new Ship(fleet1, "F1S1");
var ship2 = new Game.Ship(fleet1, "F1S2"); var ship2 = new Ship(fleet1, "F1S2");
var ship3 = new Game.Ship(fleet2, "F2S1"); var ship3 = new Ship(fleet2, "F2S1");
var battle = new Game.Battle(fleet1, fleet2); var battle = new Battle(fleet1, fleet2);
// Check empty play_order case // Check empty play_order case
expect(battle.playing_ship).toBeNull(); expect(battle.playing_ship).toBeNull();
@ -79,7 +79,7 @@ module SpaceTac.Specs {
expect(battle.playing_ship_index).toBeNull(); expect(battle.playing_ship_index).toBeNull();
// Force play order // Force play order
var gen = new Game.RandomGenerator(0.1, 0.2, 0.0); var gen = new RandomGenerator(0.1, 0.2, 0.0);
battle.throwInitiative(gen); battle.throwInitiative(gen);
expect(battle.playing_ship).toBeNull(); expect(battle.playing_ship).toBeNull();

View file

@ -1,10 +1,10 @@
/// <reference path="../../definitions/jasmine.d.ts"/> /// <reference path="../../definitions/jasmine.d.ts"/>
module SpaceTac.Specs { module SpaceTac.Game {
// Check a single game log event // Check a single game log event
function checkEvent(got: Game.Events.BaseLogEvent, ship: Game.Ship, code: string, function checkEvent(got: BaseLogEvent, ship: Ship, code: string,
target_ship: Game.Ship = null, target_x: number = null, target_y: number = null): void { target_ship: Ship = null, target_x: number = null, target_y: number = null): void {
if (target_ship) { if (target_ship) {
if (target_x === null) { if (target_x === null) {
target_x = target_ship.arena_x; target_x = target_ship.arena_x;
@ -30,7 +30,7 @@ module SpaceTac.Specs {
} }
// Fake event // Fake event
class FakeEvent extends Game.Events.BaseLogEvent { class FakeEvent extends BaseLogEvent {
constructor() { constructor() {
super("fake"); super("fake");
} }
@ -38,7 +38,7 @@ module SpaceTac.Specs {
describe("BattleLog", function () { describe("BattleLog", function () {
it("forwards events to subscribers, until unsubscribe", function () { it("forwards events to subscribers, until unsubscribe", function () {
var log = new Game.BattleLog(); var log = new BattleLog();
var received = []; var received = [];
var fake = new FakeEvent(); var fake = new FakeEvent();
@ -58,7 +58,7 @@ module SpaceTac.Specs {
}); });
it("logs ship change events", function () { it("logs ship change events", function () {
var battle = Game.Battle.newQuickRandom(); var battle = Battle.newQuickRandom();
expect(battle.log.events.length).toBe(0); expect(battle.log.events.length).toBe(0);
battle.advanceToNextShip(); battle.advanceToNextShip();
@ -67,7 +67,7 @@ module SpaceTac.Specs {
}); });
it("can receive simulated initial state events", function (){ it("can receive simulated initial state events", function (){
var battle = Game.Battle.newQuickRandom(); var battle = Battle.newQuickRandom();
expect(battle.log.events.length).toBe(0); expect(battle.log.events.length).toBe(0);

View file

@ -1,4 +1,6 @@
module SpaceTac.Game.Specs { /// <reference path="../../definitions/jasmine.d.ts"/>
module SpaceTac.Game {
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");
@ -6,7 +8,7 @@ module SpaceTac.Game.Specs {
ship.movement_cost = 2; ship.movement_cost = 2;
ship.arena_x = 0; ship.arena_x = 0;
ship.arena_y = 0; ship.arena_y = 0;
var action = new Actions.MoveAction(); var action = new MoveAction();
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));
@ -22,7 +24,7 @@ module SpaceTac.Game.Specs {
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 Actions.MoveAction(); var action = new MoveAction();
var result = action.checkTarget(null, ship1, Target.newFromShip(ship1)); var result = action.checkTarget(null, ship1, Target.newFromShip(ship1));
expect(result).toBeNull(); expect(result).toBeNull();

View file

@ -1,9 +1,9 @@
/// <reference path="../../definitions/jasmine.d.ts"/> /// <reference path="../../definitions/jasmine.d.ts"/>
module SpaceTac.Specs { module SpaceTac.Game {
describe("Ship", function(){ describe("Ship", function(){
it("limits movement range by action points", function(){ it("limits movement range by action points", function(){
var ship = new Game.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;
ship.setArenaPosition(50, 50); ship.setArenaPosition(50, 50);
@ -17,7 +17,7 @@ module SpaceTac.Specs {
}); });
it("moves and consumes action points", function(){ it("moves and consumes action points", function(){
var ship = new Game.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;
ship.setArenaPosition(50, 50); ship.setArenaPosition(50, 50);

View file

@ -18,10 +18,10 @@ module SpaceTac.View {
targetting: Targetting; targetting: Targetting;
// Card to display current playing ship // Card to display current playing ship
card_playing: Widgets.ShipCard; card_playing: ShipCard;
// Card to display hovered ship // Card to display hovered ship
card_hovered: Widgets.ShipCard; card_hovered: ShipCard;
// Currently hovered ship // Currently hovered ship
ship_hovered: Game.Ship; ship_hovered: Game.Ship;
@ -52,19 +52,19 @@ module SpaceTac.View {
game.add.existing(this.arena); game.add.existing(this.arena);
var arena = this.arena; var arena = this.arena;
this.card_playing = new Widgets.ShipCard(this, 500, 0); this.card_playing = new ShipCard(this, 500, 0);
this.card_hovered = new Widgets.ShipCard(this, 500, 300); this.card_hovered = new ShipCard(this, 500, 300);
game.stage.backgroundColor = 0x000000; game.stage.backgroundColor = 0x000000;
// Add ship buttons to UI // Add ship buttons to UI
this.battle.play_order.forEach(function (ship: Game.Ship, rank: number) { this.battle.play_order.forEach(function (ship: Game.Ship, rank: number) {
new Widgets.ShipListItem(battleview, 0, rank * 50, ship, ship.getPlayer() === player); new ShipListItem(battleview, 0, rank * 50, ship, ship.getPlayer() === player);
}); });
// Add ship sprites to arena // Add ship sprites to arena
this.battle.play_order.forEach(function (ship: Game.Ship) { this.battle.play_order.forEach(function (ship: Game.Ship) {
new Arena.ShipArenaSprite(battleview, ship); new ShipArenaSprite(battleview, ship);
}); });
// Subscribe to log events // Subscribe to log events
@ -105,7 +105,7 @@ module SpaceTac.View {
} }
// Process a BaseLogEvent // Process a BaseLogEvent
processBattleEvent(event: Game.Events.BaseLogEvent) { processBattleEvent(event: Game.BaseLogEvent) {
console.log("Battle event", event); console.log("Battle event", event);
if (event.code == "ship_change") { if (event.code == "ship_change") {
// Playing ship changed // Playing ship changed

View file

@ -1,4 +1,4 @@
module SpaceTac.View.Arena { module SpaceTac.View {
// Ship sprite in the arena (BattleView) // Ship sprite in the arena (BattleView)
export class ShipArenaSprite extends Phaser.Button { export class ShipArenaSprite extends Phaser.Button {
constructor(battleview: BattleView, ship: Game.Ship) { constructor(battleview: BattleView, ship: Game.Ship) {

View file

@ -1,4 +1,4 @@
module SpaceTac.View.Widgets { module SpaceTac.View {
// 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 {
constructor(battleview: BattleView, x: number, y:number, code: string) { constructor(battleview: BattleView, x: number, y:number, code: string) {

View file

@ -1,4 +1,4 @@
module SpaceTac.View.Widgets { module SpaceTac.View {
// 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

View file

@ -1,4 +1,4 @@
module SpaceTac.View.Widgets { module SpaceTac.View {
// 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