Skip to content

Proposal to replace current case 6 sorting logic with more stable name → type → ID ordering #472

@StaSiii

Description

@StaSiii

I’d like to propose an improvement to the sorting logic inside specNameSorter.
The current case 6 sorts by name (A–Z) and then by type.
This works, but it produces unstable ordering when multiple specialists share the same name and type, their relative order becomes effectively random.
I’d like to suggest replacing case 6 with this method:
Name (A–Z) --- Type (ascending) --- Unique ID (ascending)
This keeps the alphabetical behavior but ensures consistent ordering like it is in the Star menu.
Here is the proposed replacement for case 6:

case 6:
    var nameA = a.getName(false).replace(/(<([^>]+)>)/gi, "").toLowerCase(),
        nameB = b.getName(false).replace(/(<([^>]+)>)/gi, "").toLowerCase(),
        res = nameA.localeCompare(nameB);
    if(res != 0) return res;

    if(a.GetType() < b.GetType()) return -1;
    if(a.GetType() > b.GetType()) return 1;

    var aID = a.GetUniqueID(),
        bID = b.GetUniqueID();

    if(aID.uniqueID1 < bID.uniqueID1) return -1;
    if(aID.uniqueID1 > bID.uniqueID1) return 1;

    if(aID.uniqueID2 < bID.uniqueID2) return -1;
    if(aID.uniqueID2 > bID.uniqueID2) return 1;

    return 0;
break;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions