Commonize sort method

This commit is contained in:
isaisstillalive 2020-07-05 21:17:12 +09:00
parent 1d44690482
commit d0d8314d81
1 changed files with 18 additions and 12 deletions

View File

@ -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