From 90adb5e968a873fa39887eb451fc0013b4afb392 Mon Sep 17 00:00:00 2001 From: Nerevar <12636964+Nerev4r@users.noreply.github.com> Date: Sun, 13 Oct 2024 11:46:26 -0600 Subject: [PATCH] i dont wanna die --- code/_globalvars/~doppler_globalvars/regexes.dm | 5 +++++ code/_globalvars/~doppler_globalvars/text.dm | 9 +++++++++ code/modules/mob/living/living_say.dm | 4 ++++ code/modules/unit_tests/say.dm | 5 +++-- tgstation.dme | 2 ++ 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 code/_globalvars/~doppler_globalvars/regexes.dm create mode 100644 code/_globalvars/~doppler_globalvars/text.dm diff --git a/code/_globalvars/~doppler_globalvars/regexes.dm b/code/_globalvars/~doppler_globalvars/regexes.dm new file mode 100644 index 0000000000000..7ec0013eb0114 --- /dev/null +++ b/code/_globalvars/~doppler_globalvars/regexes.dm @@ -0,0 +1,5 @@ +//Does the line end in any EOL char that isn't appropriate punctuation OR does it end in a chat-formatted markdown sequence (+bold+, etc) without a period? +GLOBAL_DATUM_INIT(needs_eol_autopunctuation, /regex, regex(@"([a-zA-Z\d]|[^.?!~-][+|_])$")) + +//All non-capitalized 'i' surrounded with whitespace (aka, 'hello >i< am a cat') +GLOBAL_DATUM_INIT(noncapital_i, /regex, regex(@"\b[i]\b", "g")) diff --git a/code/_globalvars/~doppler_globalvars/text.dm b/code/_globalvars/~doppler_globalvars/text.dm new file mode 100644 index 0000000000000..f730a8ff817b0 --- /dev/null +++ b/code/_globalvars/~doppler_globalvars/text.dm @@ -0,0 +1,9 @@ +/// Ensures sentences end in appropriate punctuation (a period if none exist) and that all whitespace-bounded 'i' characters are capitalized. +/// If the sentence ends in chat-flavored markdown for bolds, italics or underscores and does not have a preceding period, exclamation mark or other flavored sentence terminator, add a period. +/// (e.g: 'Borgs are rogue' becomes 'Borgs are rogue.', '+BORGS ARE ROGUE+ becomes '+BORGS ARE ROGUE+.', '+Borgs are rogue~+' is untouched.) +/proc/autopunct_bare(input_text) + if (findtext(input_text, GLOB.needs_eol_autopunctuation)) + input_text += "." + + input_text = replacetext(input_text, GLOB.noncapital_i, "I") + return input_text diff --git a/code/modules/mob/living/living_say.dm b/code/modules/mob/living/living_say.dm index 22a4c7e2eb2eb..f1619168f0072 100644 --- a/code/modules/mob/living/living_say.dm +++ b/code/modules/mob/living/living_say.dm @@ -230,6 +230,10 @@ GLOBAL_LIST_INIT(message_modes_stat_limits, list( //Get which verb is prefixed to the message before radio but after most modifications message_mods[SAY_MOD_VERB] = say_mod(message, message_mods) + // DOPPLER EDIT ADDITION START: autopunctuation + //ensure EOL punctuation exists and that word-bounded 'i' are capitalized before we do anything else + message = autopunct_bare(message) + // DOPPLER EDIT ADDITION END //This is before anything that sends say a radio message, and after all important message type modifications, so you can scumb in alien chat or something if(saymode && !saymode.handle_message(src, message, language)) diff --git a/code/modules/unit_tests/say.dm b/code/modules/unit_tests/say.dm index a845b6ccf9886..4e2b97e682379 100644 --- a/code/modules/unit_tests/say.dm +++ b/code/modules/unit_tests/say.dm @@ -200,7 +200,8 @@ speaker.forceMove(run_loc_floor_bottom_left) listener.forceMove(locate((run_loc_floor_bottom_left.x + distance), run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z)) - var/pangram_quote = "The quick brown fox jumps over the lazy dog" + var/pangram_quote = "The quick brown fox jumps over the lazy dog." // NOVA EDIT CHANGE - account for autopunct in living_say.dm - ORIGINAL: var/pangram_quote = "The quick brown fox jumps over the lazy dog" + // speaking speaker.say(pangram_quote) @@ -241,7 +242,7 @@ listener_radio.set_frequency(FREQ_CENTCOM) listener_radio.special_channels = RADIO_SPECIAL_CENTCOM - var/pangram_quote = "The quick brown fox jumps over the lazy dog" + var/pangram_quote = "The quick brown fox jumps over the lazy dog." // NOVA EDIT CHANGE - account for autopunct in living_say.dm - ORIGINAL: var/pangram_quote = "The quick brown fox jumps over the lazy dog" speaker.say(pangram_quote) TEST_ASSERT(handle_speech_result, "Handle speech signal was not fired (radio test)") diff --git a/tgstation.dme b/tgstation.dme index d78a5a757b7ab..994e92c23f7f0 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -608,7 +608,9 @@ #include "code\_globalvars\~doppler_globalvars\bitfields.dm" #include "code\_globalvars\~doppler_globalvars\configuration.dm" #include "code\_globalvars\~doppler_globalvars\objective.dm" +#include "code\_globalvars\~doppler_globalvars\regexes.dm" #include "code\_globalvars\~doppler_globalvars\religion.dm" +#include "code\_globalvars\~doppler_globalvars\text.dm" #include "code\_js\byjax.dm" #include "code\_js\menus.dm" #include "code\_onclick\adjacent.dm"