1
0
Fork 0
spacetac/src/ui/map/MissionLocationMarker.ts

70 lines
2.3 KiB
TypeScript
Raw Normal View History

2017-09-24 22:23:22 +00:00
module TK.SpaceTac.UI {
2017-07-11 22:28:45 +00:00
/**
* Marker to show a mission location on the map
*/
export class MissionLocationMarker {
2017-08-21 22:41:44 +00:00
private view: BaseView
2017-07-11 22:28:45 +00:00
private container: Phaser.Group
2018-01-31 18:19:50 +00:00
private markers: [StarLocation | Star, string][] = []
2017-07-11 22:28:45 +00:00
private zoomed = true
2018-01-31 18:19:50 +00:00
private current_star?: Star
2017-07-11 22:28:45 +00:00
constructor(view: BaseView, parent: Phaser.Group) {
2017-08-21 22:41:44 +00:00
this.view = view;
2017-07-11 22:28:45 +00:00
this.container = view.game.add.group(parent, "mission_markers");
}
/**
2017-08-21 22:41:44 +00:00
* Set the active markers (location and image name)
2017-07-11 22:28:45 +00:00
*/
2017-08-21 22:41:44 +00:00
setMarkers(markers: [StarLocation | Star, string][]): void {
2017-07-11 22:28:45 +00:00
this.markers = markers;
this.refresh();
}
/**
* Set the zoom level
*/
setZoom(level: number, star: Star): void {
this.zoomed = level >= 2;
this.current_star = star;
this.refresh();
}
/**
* Refresh the display
*/
refresh(): void {
this.container.removeAll(true);
2017-08-21 22:41:44 +00:00
this.markers.forEach(([location, name], index) => {
2017-07-11 22:28:45 +00:00
let focus = this.zoomed ? location : (location instanceof StarLocation ? location.star : location);
if (location !== this.current_star || !this.zoomed) {
let marker = this.getMarker(focus, index - 1);
2017-08-21 22:41:44 +00:00
let image = this.view.newImage(name, marker.x, marker.y);
2017-07-11 22:28:45 +00:00
image.scale.set(marker.scale);
image.anchor.set(0.5);
this.container.add(image);
}
});
}
private getMarker(focus: Star | StarLocation, offset: number): { x: number, y: number, scale: number } {
if (focus instanceof StarLocation) {
let system = focus.star;
return {
x: focus.universe_x + offset * system.radius * 0.05,
y: focus.universe_y - system.radius * 0.08,
scale: system.radius * 0.001
}
} else {
return {
x: focus.x + offset * focus.radius * 0.6,
y: focus.y - focus.radius * 0.7,
scale: focus.radius * 0.01
}
}
}
}
}