From ec09ddd54710312bc2d0732788ce1a3f6c1b36aa Mon Sep 17 00:00:00 2001 From: Aronai Sieyes Date: Sat, 26 Jun 2021 11:13:57 -0400 Subject: [PATCH] Add species sorting --- code/__defines/misc.dm | 5 +++++ code/_global_vars/lists/species.dm | 7 +++---- code/_helpers/global_lists.dm | 6 ++++++ code/_helpers/sorts/comparators.dm | 7 +++++++ .../modules/mob/living/carbon/human/species/species.dm | 10 ++++++++++ .../living/carbon/human/species/station/blank_vr.dm | 3 +++ 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/code/__defines/misc.dm b/code/__defines/misc.dm index a1d7592cd75..1aab1c82e47 100644 --- a/code/__defines/misc.dm +++ b/code/__defines/misc.dm @@ -472,3 +472,8 @@ GLOBAL_LIST_INIT(all_volume_channels, list( #define TRAIT_SORT_NORMAL 1 #define TRAIT_SORT_BODYTYPE 2 #define TRAIT_SORT_SPECIES 3 + +#define SPECIES_SORT_NORMAL 1 +#define SPECIES_SORT_WHITELISTED 2 +#define SPECIES_SORT_RESTRICTED 3 +#define SPECIES_SORT_CUSTOM 4 diff --git a/code/_global_vars/lists/species.dm b/code/_global_vars/lists/species.dm index f35568b07ae..817f504f7fb 100644 --- a/code/_global_vars/lists/species.dm +++ b/code/_global_vars/lists/species.dm @@ -1,10 +1,9 @@ //Languages/species/whitelist. GLOBAL_LIST_EMPTY_TYPED(all_species, /datum/species) +GLOBAL_LIST_EMPTY_TYPED(whitelisted_species, /datum/species) // Species that require a whitelist check. +GLOBAL_LIST_EMPTY_TYPED(playable_species, /datum/species) // A list of ALL playable species, whitelisted, latejoin or otherwise. + GLOBAL_LIST_EMPTY_TYPED(all_languages, /datum/language) GLOBAL_LIST_INIT(language_name_conflicts, list()) GLOBAL_LIST_INIT(language_keys, list()) // Table of say codes for all languages GLOBAL_LIST_INIT(language_key_conflicts, list()) -GLOBAL_LIST_INIT(whitelisted_species, list(SPECIES_HUMAN)) // Species that require a whitelist check. -// VOREStation edit - include custom species -GLOBAL_LIST_INIT(playable_species, list(SPECIES_HUMAN, SPECIES_CUSTOM)) // A list of ALL playable species, whitelisted, latejoin or otherwise. -// VOREStation edit end \ No newline at end of file diff --git a/code/_helpers/global_lists.dm b/code/_helpers/global_lists.dm index 232c523b653..ca5a4e005f6 100644 --- a/code/_helpers/global_lists.dm +++ b/code/_helpers/global_lists.dm @@ -201,6 +201,12 @@ GLOBAL_LIST_EMPTY(mannequins) S.race_key = rkey //Used in mob icon caching. GLOB.all_species[S.name] = S + //Shakey shakey shake + sortTim(GLOB.all_species, /proc/cmp_species, associative = TRUE) + + //Split up the rest + for(var/speciesname in GLOB.all_species) + var/datum/species/S = GLOB.all_species[speciesname] if(!(S.spawn_flags & SPECIES_IS_RESTRICTED)) GLOB.playable_species += S.name if(S.spawn_flags & SPECIES_IS_WHITELISTED) diff --git a/code/_helpers/sorts/comparators.dm b/code/_helpers/sorts/comparators.dm index 9866d108c01..c24267e6786 100644 --- a/code/_helpers/sorts/comparators.dm +++ b/code/_helpers/sorts/comparators.dm @@ -79,12 +79,19 @@ /proc/cmp_text_asc(a,b) return sorttext(b,a) +///Tracks are sorted by genre then by title inside that. /proc/cmp_media_track_asc(datum/track/A, datum/track/B) var/genre_sort = sorttext(B.genre || "Uncategorized", A.genre || "Uncategorized") return genre_sort || sorttext(B.title, A.title) +///Filters have a numerical priority. /proc/cmp_filter_data_priority(list/A, list/B) return A["priority"] - B["priority"] +///Traits have sort they have defined on them to categorize themselves into groups. After that, alphabetical. /proc/cmp_trait_datums_name(datum/trait/A, datum/trait/B) return A.sort == B.sort ? sorttext("[B.name]","[A.name]") : A.sort - B.sort + +///Species have sort_hint they self-generate to hint themselves into groups. After that, alphabetical. +/proc/cmp_species(datum/species/A, datum/species/B) + return A.sort_hint == B.sort_hint ? sorttext("[B.name]","[A.name]") : A.sort_hint - B.sort_hint diff --git a/code/modules/mob/living/carbon/human/species/species.dm b/code/modules/mob/living/carbon/human/species/species.dm index 3ae68b2c7d8..e3ca9150f19 100644 --- a/code/modules/mob/living/carbon/human/species/species.dm +++ b/code/modules/mob/living/carbon/human/species/species.dm @@ -272,6 +272,8 @@ var/icon_height = 32 var/agility = 20 //prob() to do agile things + var/sort_hint = SPECIES_SORT_NORMAL + /datum/species/proc/update_attack_types() unarmed_attacks = list() for(var/u_type in unarmed_types) @@ -305,6 +307,14 @@ inherent_verbs = list() inherent_verbs |= /mob/living/carbon/human/proc/regurgitate + update_sort_hint() + +/datum/species/proc/update_sort_hint() + if(spawn_flags & SPECIES_IS_RESTRICTED) + sort_hint = SPECIES_SORT_RESTRICTED + else if(spawn_flags & SPECIES_IS_WHITELISTED) + sort_hint = SPECIES_SORT_WHITELISTED + /datum/species/proc/sanitize_name(var/name, var/robot = 0) return sanitizeName(name, MAX_NAME_LEN, robot) diff --git a/code/modules/mob/living/carbon/human/species/station/blank_vr.dm b/code/modules/mob/living/carbon/human/species/station/blank_vr.dm index 57b83fddcbd..fe8d8ecb687 100644 --- a/code/modules/mob/living/carbon/human/species/station/blank_vr.dm +++ b/code/modules/mob/living/carbon/human/species/station/blank_vr.dm @@ -42,6 +42,9 @@ BP_R_FOOT = list("path" = /obj/item/organ/external/foot/right, "descriptor" = "right foot") ) +/datum/species/custom/update_sort_hint() + sort_hint = SPECIES_SORT_CUSTOM + /datum/species/custom/get_race_key() var/datum/species/real = GLOB.all_species[base_species] return real.race_key