diff --git a/TODO b/TODO index 20312b9..01eded9 100644 --- a/TODO +++ b/TODO @@ -20,6 +20,7 @@ * Arena: display effects description instead of attribute changes * Arena: add auto-move to attack * Arena: fix effects originating from real ship location instead of current sprite (when AI fires then moves) +* Arena: add engine trail * Actions: show power usage/recovery in power bar, on action hover * Actions: fix targetting not resetting when using keyboard shortcuts * Suspend AI operation when the game is paused (window not focused) diff --git a/src/ui/battle/ActionBar.ts b/src/ui/battle/ActionBar.ts index c680c53..5820b45 100644 --- a/src/ui/battle/ActionBar.ts +++ b/src/ui/battle/ActionBar.ts @@ -88,6 +88,7 @@ module TS.SpaceTac.UI { } } } + return 0; }); } diff --git a/src/ui/battle/ArenaShip.ts b/src/ui/battle/ArenaShip.ts index cdcf34a..03c06e8 100644 --- a/src/ui/battle/ArenaShip.ts +++ b/src/ui/battle/ArenaShip.ts @@ -94,7 +94,8 @@ module TS.SpaceTac.UI { ); // Set location - this.position.set(ship.arena_x, ship.arena_y); + this.position.set(ship.arena_x - 150 * Math.cos(ship.arena_angle), ship.arena_y - 150 * Math.sin(ship.arena_angle)); + this.moveTo(ship.arena_x, ship.arena_y, ship.arena_angle); // Log processing this.battleview.log_processor.registerForShip(ship, event => this.processLogEvent(event)); @@ -103,21 +104,31 @@ module TS.SpaceTac.UI { /** * Process a log event for this ship */ - private processLogEvent(event: BaseLogEvent) { + private processLogEvent(event: BaseLogEvent): number { if (event instanceof EffectAddedEvent || event instanceof EffectRemovedEvent || event instanceof EffectDurationChangedEvent) { this.updateStickyEffects(); + return 0; } else if (event instanceof ValueChangeEvent) { if (event.value.name == "hull") { this.info_toggle.start(1500, true); this.info_hull.setValue(event.value.get(), event.value.getMaximal() || 0); + return 0; } else if (event.value.name == "shield") { this.info_toggle.start(1500, true); this.info_shield.setValue(event.value.get(), event.value.getMaximal() || 0); + return 0; } else { this.displayValueChanged(event); + return 0; } } else if (event instanceof DamageEvent) { this.displayEffect(`${event.hull + event.shield} damage`, false); + return 0; + } else if (event instanceof MoveEvent) { + let duration = this.moveTo(event.target.x, event.target.y, event.facing_angle, !event.initial); + return duration; + } else { + return 0; } } @@ -167,7 +178,8 @@ module TS.SpaceTac.UI { */ moveTo(x: number, y: number, facing_angle: number, animate = true): number { if (animate) { - return Animations.moveInSpace(this, x, y, facing_angle, this.sprite); + let duration = Animations.moveInSpace(this, x, y, facing_angle, this.sprite); + return duration; } else { this.x = x; this.y = y; diff --git a/src/ui/battle/LogProcessor.ts b/src/ui/battle/LogProcessor.ts index d0eff48..5116d86 100644 --- a/src/ui/battle/LogProcessor.ts +++ b/src/ui/battle/LogProcessor.ts @@ -42,18 +42,27 @@ module TS.SpaceTac.UI { * * The difference with registering directly to the BattleLog is that events may be delayed * for animations. + * + * The callback may return the duration it needs to display the change. */ - register(callback: LogSubscriber) { - this.forwarding.push(callback); + register(callback: (event: BaseLogEvent) => number) { + this.forwarding.push(event => { + let duration = callback(event); + if (duration) { + this.delayNextEvents(duration); + } + }); } /** * Register a sub-subscriber, to receive events for a specific ship */ - registerForShip(ship: Ship, callback: LogSubscriber) { + registerForShip(ship: Ship, callback: (event: BaseLogShipEvent) => number) { this.register(event => { if (event instanceof BaseLogShipEvent && event.ship === ship) { - callback(event); + return callback(event); + } else { + return 0; } }); } @@ -98,8 +107,6 @@ module TS.SpaceTac.UI { if (event instanceof ShipChangeEvent) { this.processShipChangeEvent(event); - } else if (event instanceof MoveEvent) { - this.processMoveEvent(event); } else if (event instanceof DeathEvent) { this.processDeathEvent(event); } else if (event instanceof FireEvent) { @@ -158,15 +165,6 @@ module TS.SpaceTac.UI { } } - // Ship moved - private processMoveEvent(event: MoveEvent): void { - var sprite = this.view.arena.findShipSprite(event.ship); - if (sprite) { - let duration = sprite.moveTo(event.target.x, event.target.y, event.facing_angle, !event.initial); - this.delayNextEvents(duration); - } - } - // A ship died private processDeathEvent(event: DeathEvent): void { if (this.view.ship_hovered === event.ship) { diff --git a/src/ui/battle/ShipList.ts b/src/ui/battle/ShipList.ts index 2a92f3a..6fd0db3 100644 --- a/src/ui/battle/ShipList.ts +++ b/src/ui/battle/ShipList.ts @@ -29,8 +29,8 @@ module TS.SpaceTac.UI { this.info_button = new Phaser.Button(this.game, 0, 0, "battle-shiplist-info-button"); this.info_button.position.set(0, this.height - this.info_button.height); UITools.setHoverClick(this.info_button, - () => this.battleview.arena.setTacticalMode(true), - () => this.battleview.arena.setTacticalMode(false), + () => this.battleview.toggle_tactical_mode.start(), + () => this.battleview.toggle_tactical_mode.stop(), () => null); this.addChild(this.info_button);