Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1984 (Autopunctuation) #154

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions code/_globalvars/~doppler_globalvars/regexes.dm
Original file line number Diff line number Diff line change
@@ -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"))
9 changes: 9 additions & 0 deletions code/_globalvars/~doppler_globalvars/text.dm
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions code/modules/mob/living/living_say.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 3 additions & 2 deletions code/modules/unit_tests/say.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)")
Expand Down
2 changes: 2 additions & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading