From c300276030e1bd2d9ed5b9c688be39e3c0b003cf Mon Sep 17 00:00:00 2001 From: ROdenFL <144662735+ROdenFL@users.noreply.github.com> Date: Wed, 6 Dec 2023 16:24:28 +0300 Subject: [PATCH] CONFIG_GET adaptation, globvars in _globvars --- code/_globalvars/lists/misc.dm | 3 + code/_globalvars/misc.dm | 3 + .../configuration/configuration.dm | 2 +- .../configuration/entries/config.dm | 5 ++ code/modules/emoji/emoji_parse.dm | 43 ++++--------- config/example/emojis.txt | 64 +++++++++++++++++++ 6 files changed, 87 insertions(+), 33 deletions(-) create mode 100644 config/example/emojis.txt diff --git a/code/_globalvars/lists/misc.dm b/code/_globalvars/lists/misc.dm index 025cd03a230..055361280e5 100644 --- a/code/_globalvars/lists/misc.dm +++ b/code/_globalvars/lists/misc.dm @@ -68,3 +68,6 @@ GLOBAL_LIST_INIT(all_taipan_jobs, list(TAIPAN_SCIENTIST,TAIPAN_MEDIC,TAIPAN_BOTA /// List of ckeys that have seen a blurb of a given key. GLOBAL_LIST_EMPTY(blurb_witnesses) + +// List for emojis +GLOBAL_LIST_EMPTY(discordEmojis) diff --git a/code/_globalvars/misc.dm b/code/_globalvars/misc.dm index 8cc5256ed9e..e9831ce7d09 100644 --- a/code/_globalvars/misc.dm +++ b/code/_globalvars/misc.dm @@ -62,3 +62,6 @@ GLOBAL_VAR(genname) //Nanotrasen officer name for fax send via fax panel, random GLOBAL_VAR_INIT(pacifism_after_gt, FALSE) GLOBAL_VAR_INIT(communications_blackout, FALSE) + +// Emoji vars +GLOBAL_VAR_INIT(emojiTableShownToUsers, null) diff --git a/code/controllers/configuration/configuration.dm b/code/controllers/configuration/configuration.dm index c09b26c808c..8acfbb73427 100644 --- a/code/controllers/configuration/configuration.dm +++ b/code/controllers/configuration/configuration.dm @@ -52,7 +52,7 @@ GLOBAL_LIST_EMPTY(overflow_whitelist) InitEntries() //Note: `$include`s are supported. Feel free to use them. - var/list/configs = list("game_options.txt", "dbconfig.txt", "config.txt") + var/list/configs = list("game_options.txt", "dbconfig.txt", "config.txt", "emojis.txt") for(var/I in configs) if(fexists("[directory]/[I]")) for(var/J in configs) diff --git a/code/controllers/configuration/entries/config.dm b/code/controllers/configuration/entries/config.dm index fdb59a2fcba..1d3c82073df 100644 --- a/code/controllers/configuration/entries/config.dm +++ b/code/controllers/configuration/entries/config.dm @@ -659,6 +659,11 @@ key_mode = KEY_MODE_TEXT value_mode = VALUE_MODE_NUM +//Needs proper testing +/datum/config_entry/keyed_list/emoji + key_mode = KEY_MODE_TEXT + value_mode = VALUE_MODE_TEXT + /datum/config_entry/number/shadowling_max_age /datum/config_entry/flag/guest_ban diff --git a/code/modules/emoji/emoji_parse.dm b/code/modules/emoji/emoji_parse.dm index 1dac907876a..87cbfe4e323 100644 --- a/code/modules/emoji/emoji_parse.dm +++ b/code/modules/emoji/emoji_parse.dm @@ -1,32 +1,11 @@ #define DISCORD_EMOJI_URL(id, size) "https://cdn.discordapp.com/emojis/[id]?size=[size]&quality=lossless" #define DISCORD_EMOJI_IMAGE(id, size, imgsize) "" -var/list/discordEmojis = list() -var/emojiTableShownToUsers = null - /proc/loadDiscordEmojis() - discordEmojis.Cut() - emojiTableShownToUsers = null - - var/list/Lines = file2list("config/emojis.txt") - for(var/line in Lines) - if(findtext(line, "#")) - continue - - var/list/splitline = splittext(line, " = ") - if(length(splitline) != 2) - continue - - var/emojiName = ":[lowertext(splitline[1])]:" - var/emojiImage = lowertext(splitline[2]) - - if (!emojiName || !emojiImage) - continue - - if (discordEmojis.Find(emojiName)) - continue + GLOB.discordEmojis.Cut() + GLOB.emojiTableShownToUsers = null - discordEmojis[emojiName] = emojiImage + GLOB.discordEmojis = CONFIG_GET(keyed_list/emoji) /proc/handleDiscordEmojis(msg) var/list/newMsg = list() @@ -35,10 +14,10 @@ var/emojiTableShownToUsers = null var/word = listmsg[i] // Весь этот костыль с length и copytext_char нужен только потому что // lowertext(word) == lowertext(emojiName) не работает вообще по какой-то причине - for (var/emojiName in discordEmojis) + for (var/emojiName in GLOB.discordEmojis) if (length(emojiName) != length(word)) continue - var/emojiId = discordEmojis[emojiName] + var/emojiId = GLOB.discordEmojis[emojiName] word = replacetext_char(word, emojiName, DISCORD_EMOJI_IMAGE(emojiId, 32, 32)) if (copytext_char(word, 1, 2) == "<") word = lowertext(word) @@ -47,15 +26,15 @@ var/emojiTableShownToUsers = null /proc/generateDiscordEmojiTable() var/const/itemsInRow = 7 - var/emojisListLength = length(discordEmojis) + var/emojisListLength = length(GLOB.discordEmojis) var/html = "" for (var/i = 0, i < (emojisListLength / itemsInRow), i++) var/index = (i * itemsInRow)+1 var/rowString = "" for (var/j = 0, j < itemsInRow, j++) if ((index+j) <= emojisListLength) - var/emojiName = discordEmojis[index+j] - var/emojiId = discordEmojis[emojiName] + var/emojiName = GLOB.discordEmojis[index+j] + var/emojiId = GLOB.discordEmojis[emojiName] rowString += "" else rowString += "" @@ -69,11 +48,11 @@ var/emojiTableShownToUsers = null set desc = "Shows all the emojis available in OOC/LOOC/DSAY" set category = "OOC" - if (isnull(emojiTableShownToUsers)) - emojiTableShownToUsers = generateDiscordEmojiTable() + if (isnull(GLOB.emojiTableShownToUsers)) + GLOB.emojiTableShownToUsers = generateDiscordEmojiTable() var/datum/browser/popup = new(usr, "discord_emoji", "Discord emojis", 800, 460) - popup.set_content(emojiTableShownToUsers) + popup.set_content(GLOB.emojiTableShownToUsers) popup.open() #undef DISCORD_EMOJI_IMAGE diff --git a/config/example/emojis.txt b/config/example/emojis.txt new file mode 100644 index 00000000000..af2b3c6e69c --- /dev/null +++ b/config/example/emojis.txt @@ -0,0 +1,64 @@ +## Emoji list +################### +## GR - EX emoji ## +################### + +EMOJI :clueless: 1121108217888505977.png +EMOJI :1head: 852660559093694474.png +EMOJI :2head: 852660568389451808.png +EMOJI :3head: 619086835116802051.png +EMOJI :4head: 852660577246773249.png +EMOJI :5head: 619086849264189460.png +EMOJI :ache: 829695261386211350.png +EMOJI :afacepalm: 947574263886524456.png +EMOJI :alo: 618440264771567626.png +EMOJI :arolf: 910196928657113128.png +EMOJI :bigkek: 751426772599439386.png +EMOJI :keks: 656620301320192010.png +EMOJI :blessrng: 618449016841306123.png +EMOJI :catgigi: 619108484834918417.png +EMOJI :catkerz: 619108485421858816.png +EMOJI :catping: 951390117879246878.png +EMOJI :catpong: 951390056222978078.png +EMOJI :cats: 619108484515889173.png +EMOJI :4cb: 852699344888397834.png +EMOJI :cemkaauf: 772551376311418890.png +EMOJI :cemkae: 852699282342674493.png +EMOJI :chad: 988503823733620756.png +EMOJI :coolstorybob: 618449045853306893.png +EMOJI :shocked: 772549579572510780.png +EMOJI :fearlul: 852691120772743219.png +EMOJI :gagaga: 1176622673124655144.png +EMOJI :hampter: 1154473667842023555.png +EMOJI :hss: 751418350512635914.png +EMOJI :jokerge: 1069958367952519168.png +EMOJI :kekwat: 751418444460720138.png +EMOJI :kotvshlyapi: 896343514185617418.png +EMOJI :neodobryaem: 945992517374066698.png +EMOJI :odobryaem: 945992519802581043.png +EMOJI :peepo: 949203926027227199.png +EMOJI :pepeangry: 854807413496348723.png +EMOJI :pepepoint: 852661162335404102.png +EMOJI :pepechill: 751418747817951323.png +EMOJI :angryclown: 623234197989097492.png +EMOJI :pepecool: 751435240152760360.png +EMOJI :pepecry: 627932762170720266.png +EMOJI :pepekotya: 1043131822961344572.png +EMOJI :pepeok: 852661162243784734.png +EMOJI :pepepizdec: 975485750411931759.png +EMOJI :peperot: 788527487654559744.png +EMOJI :pepesleep: 620042375519272961.png +EMOJI :pepetoxic: 852699333114855475.png +EMOJI :pepewut: 618440230243926027.png +EMOJI :prayge: 829690142930632736.png +EMOJI :ratge: 852661162222026843.png +EMOJI :sadge: 772549607837794334.png +EMOJI :yepp: 829692964577476628.png +EMOJI :pog: 852664480500547584.png +EMOJI :roflcat: 975487235984097340.png +EMOJI :seemsgood: 618596234260906004.png +EMOJI :shlepa: 941689112073744405.png +EMOJI :smilew: 938010167671422976.png +EMOJI :smorch: 618596250849378317.png +EMOJI :catahui: 751426851171467276.png +EMOJI :goblin: 689541504070582287.png \ No newline at end of file
[DISCORD_EMOJI_IMAGE(emojiId, 48, 48)]
[emojiName]