From 2f4fb6f68ac64b51f2f53bfd81db59ccc0663132 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 9 Mar 2017 15:22:34 -0500 Subject: [PATCH] Makes the preloader apply text macros: Re-engineering (#24614) * Add apply_text_macros * Make the map loader use text macros * Cleanup --- code/__HELPERS/text.dm | 57 ++++++++++++++++++++++++++++++++++ code/modules/mapping/reader.dm | 2 ++ 2 files changed, 59 insertions(+) diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index a01887727c1..e6b35c29431 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -554,3 +554,60 @@ var/list/binary = list("0","1") var/list/tosend = list() tosend["data"] = finalized log << json_encode(tosend) + +//Used for applying byonds text macros to strings that are loaded at runtime +/proc/apply_text_macros(string) + var/next_backslash = findtext(string, "\\") + if(!next_backslash) + return string + + var/leng = length(string) + + var/next_space = findtext(string, " ", next_backslash + 1) + if(!next_space) + next_space = leng - next_backslash + + if(!next_space) //trailing bs + return string + + var/base = next_backslash == 1 ? "" : copytext(string, 1, next_backslash) + var/macro = lowertext(copytext(string, next_backslash + 1, next_space)) + var/rest = next_backslash > leng ? "" : copytext(string, next_space + 1) + + //See http://www.byond.com/docs/ref/info.html#/DM/text/macros + switch(macro) + //prefixes/agnostic + if("the") + rest = text("\the []", rest) + if("a") + rest = text("\a []", rest) + if("an") + rest = text("\an []", rest) + if("proper") + rest = text("\proper []", rest) + if("improper") + rest = text("\improper []", rest) + if("roman") + rest = text("\roman []", rest) + //postfixes + if("th") + base = text("[]\th", rest) + if("s") + base = text("[]\s", rest) + if("he") + base = text("[]\he", rest) + if("she") + base = text("[]\she", rest) + if("his") + base = text("[]\his", rest) + if("himself") + base = text("[]\himself", rest) + if("herself") + base = text("[]\herself", rest) + if("hers") + base = text("[]\hers", rest) + + testing("Substituted macro(\\[macro]) in string([string]). Result: \"[base + rest]\"") + . = base + if(rest) + . += .(rest) \ No newline at end of file diff --git a/code/modules/mapping/reader.dm b/code/modules/mapping/reader.dm index 35c38e56b90..d5f5a003464 100644 --- a/code/modules/mapping/reader.dm +++ b/code/modules/mapping/reader.dm @@ -436,6 +436,8 @@ var/global/dmm_suite/preloader/_preloader = new var/value = attributes[attribute] if(islist(value)) value = deepCopyList(value) + if(istext(value)) + value = apply_text_macros(value) what.vars[attribute] = value use_preloader = FALSE