Skip to content

Commit

Permalink
CONFIG_GET adaptation, globvars in _globvars
Browse files Browse the repository at this point in the history
  • Loading branch information
ROdenFL committed Dec 6, 2023
1 parent 444d3a4 commit c300276
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 33 deletions.
3 changes: 3 additions & 0 deletions code/_globalvars/lists/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions code/_globalvars/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion code/controllers/configuration/configuration.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions code/controllers/configuration/entries/config.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 11 additions & 32 deletions code/modules/emoji/emoji_parse.dm
Original file line number Diff line number Diff line change
@@ -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) "<img src=\"[DISCORD_EMOJI_URL(id, size)]\" style=\"height: [imgsize]px; width: [imgsize]px;\" />"

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()
Expand All @@ -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)
Expand All @@ -47,15 +26,15 @@ var/emojiTableShownToUsers = null

/proc/generateDiscordEmojiTable()
var/const/itemsInRow = 7
var/emojisListLength = length(discordEmojis)
var/emojisListLength = length(GLOB.discordEmojis)
var/html = "<table><tbody style=\"text-align:center;vertical-align:middle;border-spacing:12px;\">"
for (var/i = 0, i < (emojisListLength / itemsInRow), i++)
var/index = (i * itemsInRow)+1
var/rowString = "<tr>"
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 += "<td>[DISCORD_EMOJI_IMAGE(emojiId, 48, 48)]<div>[emojiName]</div></td>"
else
rowString += "<td></td>"
Expand All @@ -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
Expand Down
64 changes: 64 additions & 0 deletions config/example/emojis.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c300276

Please sign in to comment.