2017-01-26 23:52:45 +00:00
|
|
|
module TS.SpaceTac.View {
|
2017-01-26 00:01:31 +00:00
|
|
|
// Group to display a star system
|
|
|
|
export class StarSystemDisplay extends Phaser.Image {
|
|
|
|
starsystem: Game.Star;
|
|
|
|
|
|
|
|
constructor(parent: UniverseMapView, starsystem: Game.Star) {
|
|
|
|
super(parent.game, starsystem.x, starsystem.y, "map-starsystem-background");
|
|
|
|
this.anchor.set(0.5, 0.5);
|
|
|
|
|
|
|
|
let scale = this.width;
|
|
|
|
this.scale.set(starsystem.radius * 2 / scale);
|
|
|
|
|
|
|
|
this.starsystem = starsystem;
|
|
|
|
|
2017-01-26 23:01:04 +00:00
|
|
|
// Show boundary
|
|
|
|
this.addCircle(starsystem.radius);
|
2017-01-26 00:01:31 +00:00
|
|
|
|
2017-01-26 23:01:04 +00:00
|
|
|
// Show locations
|
2017-01-26 00:01:31 +00:00
|
|
|
starsystem.locations.forEach(location => {
|
2017-01-29 18:34:38 +00:00
|
|
|
let location_sprite: Phaser.Image | null = null;
|
|
|
|
|
2017-01-26 00:01:31 +00:00
|
|
|
if (location.type == Game.StarLocationType.STAR) {
|
2017-01-29 18:34:38 +00:00
|
|
|
location_sprite = this.addImage(location.x, location.y, "map-location-star");
|
2017-01-26 00:01:31 +00:00
|
|
|
} else if (location.type == Game.StarLocationType.PLANET) {
|
2017-01-29 18:34:38 +00:00
|
|
|
location_sprite = this.addImage(location.x, location.y, "map-location-planet");
|
|
|
|
location_sprite.rotation = Math.atan2(location.y, location.x);
|
2017-01-26 23:01:04 +00:00
|
|
|
this.addCircle(Math.sqrt(location.x * location.x + location.y * location.y), 1);
|
|
|
|
} else if (location.type == Game.StarLocationType.WARP) {
|
2017-01-29 18:34:38 +00:00
|
|
|
location_sprite = this.addImage(location.x, location.y, "map-location-warp");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (location_sprite) {
|
|
|
|
let key = parent.player.hasVisitedLocation(location) ? (location.encounter ? "map-state-enemy" : "map-state-clear") : "map-state-unknown";
|
|
|
|
this.addImage(location.x + 0.005, location.y + 0.005, key);
|
2017-01-26 00:01:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addImage(x: number, y: number, key: string): Phaser.Image {
|
2017-01-26 23:01:04 +00:00
|
|
|
let image = this.game.add.image(x / this.scale.x, y / this.scale.y, key);
|
2017-01-26 00:01:31 +00:00
|
|
|
image.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(image);
|
|
|
|
return image;
|
|
|
|
}
|
2017-01-26 23:01:04 +00:00
|
|
|
|
|
|
|
addCircle(radius, width = 3, color = 0x424242): Phaser.Graphics {
|
|
|
|
let circle = this.game.add.graphics(0, 0);
|
|
|
|
circle.lineStyle(width, color);
|
|
|
|
circle.drawCircle(0, 0, radius * 2 / this.scale.x);
|
|
|
|
this.addChild(circle);
|
|
|
|
return circle;
|
|
|
|
}
|
2017-01-26 00:01:31 +00:00
|
|
|
}
|
|
|
|
}
|