Commonize sort method

pull/397/head
isaisstillalive 4 years ago
parent 1d44690482
commit d0d8314d81

@ -272,18 +272,7 @@ export class HUDWaypoints extends BaseHUDPart {
zoomLevel: Math.max(this.root.camera.zoomLevel, globalConfig.mapChunkOverviewMinZoom + 0.05),
});
// Sort waypoints by name
this.waypoints.sort((a, b) => {
if (!a.label) {
return -1;
}
if (!b.label) {
return 1;
}
return this.getWaypointLabel(a)
.padEnd(MAX_LABEL_LENGTH, "0")
.localeCompare(this.getWaypointLabel(b).padEnd(MAX_LABEL_LENGTH, "0"));
});
this.sort();
// Show notification about creation
this.root.hud.signals.notification.dispatch(
@ -304,6 +293,23 @@ export class HUDWaypoints extends BaseHUDPart {
}
}
/**
* Sort waypoints by name
*/
sort() {
this.waypoints.sort((a, b) => {
if (!a.label) {
return -1;
}
if (!b.label) {
return 1;
}
return this.getWaypointLabel(a)
.padEnd(MAX_LABEL_LENGTH, "0")
.localeCompare(this.getWaypointLabel(b).padEnd(MAX_LABEL_LENGTH, "0"));
});
}
/**
* Returns the label for a given waypoint
* @param {Waypoint} waypoint

Loading…
Cancel
Save