diff --git a/src/ui/battle/ArenaShip.ts b/src/ui/battle/ArenaShip.ts index 56800f0..9cef581 100644 --- a/src/ui/battle/ArenaShip.ts +++ b/src/ui/battle/ArenaShip.ts @@ -60,16 +60,16 @@ module TK.SpaceTac.UI { this.frame_owner = builder.image(this.enemy ? "battle-hud-ship-enemy" : "battle-hud-ship-own", 0, 0, true); this.setPlaying(false); this.frame_hover = builder.image("battle-hud-ship-hover", 0, 0, true); - this.frame_hover.visible = false; + this.frame_hover.setVisible(false); // Add ship sprite this.sprite = builder.image(`ship-${ship.model.code}-sprite`, 0, 0, true); - this.sprite.rotation = ship.arena_angle; + this.sprite.setRotation(ship.arena_angle); // Add stasis effect this.stasis = builder.image("battle-hud-ship-stasis", 0, 0, true); - this.stasis.alpha = 0.9; - this.stasis.visible = !ship.alive; + this.stasis.setAlpha(0.9); + this.stasis.setVisible(!ship.alive); // HSP display this.hsp = builder.container("hsp", 0, 34); @@ -332,12 +332,14 @@ module TK.SpaceTac.UI { */ async moveToArenaLocation(x: number, y: number, facing_angle: number, speed = 1, engine = true): Promise { if (speed) { - let animation = bound(this.arena.view.animations, engine ? "moveInSpace" : "moveTo"); - await animation(this, x, y, facing_angle, this.sprite, speed); + if (engine) { + await this.arena.view.animations.moveInSpace(this, x, y, facing_angle, this.sprite, speed); + } else { + await this.arena.view.animations.moveTo(this, x, y, facing_angle, this.sprite, speed); + } } else { - this.x = x; - this.y = y; - this.sprite.rotation = facing_angle; + this.setPosition(x, y); + this.sprite.setRotation(facing_angle); } } diff --git a/src/ui/common/Animations.ts b/src/ui/common/Animations.ts index 622caeb..85a8e88 100644 --- a/src/ui/common/Animations.ts +++ b/src/ui/common/Animations.ts @@ -166,9 +166,14 @@ module TK.SpaceTac.UI { * Add an asynchronous animation to an object. */ addAnimation(obj: T, properties: Partial, duration: number, ease = "Linear", delay = 0, loop = 1, yoyo = false): Promise { - return new Promise(resolve => { - this.killPrevious(obj, keys(properties)); + this.killPrevious(obj, keys(properties)); + if (!duration) { + copyfields(properties, obj); + return Promise.resolve(); + } + + return new Promise(resolve => { this.tweens.add(merge({ targets: obj, ease: ease, @@ -239,9 +244,12 @@ module TK.SpaceTac.UI { * Returns the animation duration. */ moveTo(obj: Phaser.GameObjects.Components.Transform, x: number, y: number, angle: number, rotated_obj = obj, speed = 1, ease = true): Promise { - let duration_rot = this.rotationTween(rotated_obj, angle, 0.5 * speed); - let duration_pos = arenaDistance(obj, { x: x, y: y }) * 2; - return this.addAnimation(obj, { x: x, y: y }, duration_pos / speed, ease ? "Quad.easeInOut" : "Linear"); + let duration = arenaDistance(obj, { x: x, y: y }) * 2 / speed; + + return Promise.all([ + this.rotationTween(rotated_obj, angle, speed * 0.5, ease ? "Cubic.easeInOut" : "Linear"), + this.addAnimation(obj, { x: x, y: y }, duration, ease ? "Quad.easeInOut" : "Linear"), + ]).then(nop); } /** @@ -253,7 +261,8 @@ module TK.SpaceTac.UI { this.killPrevious(obj, ["x", "y"]); if (x == obj.x && y == obj.y) { - return this.rotationTween(rotated_obj, angle, 0.5 * speed); + let distance = Math.abs(angularDifference(rotated_obj.rotation, angle)); + return this.rotationTween(rotated_obj, angle, distance * 500 / speed); } else { this.killPrevious(rotated_obj, ["rotation"]); let distance = Target.newFromLocation(obj.x, obj.y).getDistanceTo(Target.newFromLocation(x, y)); diff --git a/src/ui/map/FleetDisplay.ts b/src/ui/map/FleetDisplay.ts index c33b032..1257bd4 100644 --- a/src/ui/map/FleetDisplay.ts +++ b/src/ui/map/FleetDisplay.ts @@ -91,7 +91,6 @@ module TK.SpaceTac.UI { let distance = Math.sqrt(dx * dx + dy * dy); let angle = Math.atan2(-dy, dx); this.setMoving(true); - console.error(fleet_location, location, angle); this.goToOrbitPoint(angle, 40, 1, true).then(() => { this.setRotation(-angle); let duration = 10000 * distance / speed;