From 57bb62d341eab93b06d3c7839e618efa4bc4f870 Mon Sep 17 00:00:00 2001 From: Fluffy <65877598+FluffyGhoster@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:33:06 +0100 Subject: [PATCH] Updated english_list proc to not runtime when the input is null (#18295) * sdfa * sdfa --- code/__HELPERS/lists.dm | 30 ++++++++++----- html/changelogs/fluffyghost-englishlist.yml | 41 +++++++++++++++++++++ 2 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 html/changelogs/fluffyghost-englishlist.yml diff --git a/code/__HELPERS/lists.dm b/code/__HELPERS/lists.dm index 1bc0957e571..33512ca4517 100644 --- a/code/__HELPERS/lists.dm +++ b/code/__HELPERS/lists.dm @@ -19,15 +19,27 @@ /proc/sort_list(list/list_to_sort, cmp=/proc/cmp_text_asc) return sortTim(list_to_sort.Copy(), cmp) -//Returns a list in plain english as a string -/proc/english_list(var/list/input, nothing_text = "nothing", and_text = " and ", comma_text = ", ", final_comma_text = "") - // this proc cannot be merged with counting_english_list to maintain compatibility - // with shoddy use of this proc for code logic and for cases that require original order - switch(input.len) - if(0) return nothing_text - if(1) return "[input[1]]" - if(2) return "[input[1]][and_text][input[2]]" - else return "[jointext(input, comma_text, 1, -1)][final_comma_text][and_text][input[input.len]]" +///Returns a list in plain english as a string +/proc/english_list(list/input, nothing_text = "nothing", and_text = " and ", comma_text = ", ", final_comma_text = "" ) + var/total = length(input) + switch(total) + if (0) + return "[nothing_text]" + if (1) + return "[input[1]]" + if (2) + return "[input[1]][and_text][input[2]]" + else + var/output = "" + var/index = 1 + while (index < total) + if (index == total - 1) + comma_text = final_comma_text + + output += "[input[index]][comma_text]" + index++ + + return "[output][and_text][input[index]]" //Returns a newline-separated list that counts equal-ish items, outputting count and item names, optionally with icons and specific determiners /proc/counting_english_list(var/list/input, output_icons = TRUE, determiners = DET_NONE, nothing_text = "nothing", line_prefix = "\t", first_item_prefix = "\n", last_item_suffix = "\n", and_text = "\n", comma_text = "\n", final_comma_text = "") diff --git a/html/changelogs/fluffyghost-englishlist.yml b/html/changelogs/fluffyghost-englishlist.yml new file mode 100644 index 00000000000..5e5e1b20b82 --- /dev/null +++ b/html/changelogs/fluffyghost-englishlist.yml @@ -0,0 +1,41 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# wip (For works in progress) +# tweak +# soundadd +# sounddel +# rscadd (general adding of nice things) +# rscdel (general deleting of nice things) +# imageadd +# imagedel +# maptweak +# spellcheck (typo fixes) +# experiment +# balance +# admin +# backend +# security +# refactor +################################# + +# Your name. +author: FluffyGhost + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries. +# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog. +changes: + - backend: "Updated english_list proc to not runtime when the input is null, blessed code from TG."