2014-12-31 00:00:00 +00:00
|
|
|
module SpaceTac.View {
|
2015-01-07 00:00:00 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-12-31 00:00:00 +00:00
|
|
|
// Processor of battle log events
|
|
|
|
// This will process incoming battle events, and update the battleview accordingly
|
|
|
|
export class LogProcessor {
|
|
|
|
// Link to the battle view
|
|
|
|
private view: BattleView;
|
|
|
|
|
|
|
|
// Link to the battle
|
|
|
|
private battle: Game.Battle;
|
|
|
|
|
|
|
|
// Link to the battle log
|
|
|
|
private log: Game.BattleLog;
|
|
|
|
|
|
|
|
// Subscription identifier
|
|
|
|
private subscription: any;
|
|
|
|
|
|
|
|
// Create a log processor, linked to a battleview
|
|
|
|
constructor(view: BattleView) {
|
|
|
|
this.view = view;
|
|
|
|
this.battle = view.battle;
|
|
|
|
this.log = view.battle.log;
|
|
|
|
|
2015-01-07 00:00:00 +00:00
|
|
|
this.subscription = this.log.subscribe((event: Game.BaseLogEvent) => {
|
2014-12-31 00:00:00 +00:00
|
|
|
this.processBattleEvent(event);
|
|
|
|
});
|
|
|
|
this.battle.injectInitialEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process a BaseLogEvent
|
|
|
|
processBattleEvent(event: Game.BaseLogEvent) {
|
|
|
|
console.log("Battle event", event);
|
2015-01-02 00:00:00 +00:00
|
|
|
|
|
|
|
switch (event.code) {
|
|
|
|
case "ship_change":
|
|
|
|
// Playing ship changed
|
|
|
|
this.view.card_playing.setShip(event.target.ship);
|
|
|
|
this.view.action_bar.setShip(event.target.ship);
|
|
|
|
break;
|
|
|
|
case "move":
|
2015-01-06 00:00:00 +00:00
|
|
|
var sprite = this.view.arena.findShipSprite(event.ship);
|
|
|
|
if (sprite) {
|
2015-01-09 00:00:00 +00:00
|
|
|
var tween = this.view.game.tweens.create(sprite);
|
|
|
|
tween.to({x: event.target.x, y: event.target.y});
|
|
|
|
tween.start();
|
2015-01-06 00:00:00 +00:00
|
|
|
}
|
2015-01-02 00:00:00 +00:00
|
|
|
break;
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy the log processor
|
|
|
|
destroy() {
|
|
|
|
if (this.subscription) {
|
|
|
|
this.log.unsubscribe(this.subscription);
|
|
|
|
this.subscription = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|