Files
VOREStation/code/modules/reagents/Chemistry-Colours.dm
T
Selis b0f0f4685f JSON Logging Refactor (#18252)
* First pass

* fixes

* more fixes

* num2hex length changes

* pass 2

* fixed warning

* looc log fix

* .

* update tgui

* .

* .

* .

* .

* perttier

* cleanup

* .

* .

* fix token

* no

* .

* .

* .

* ,

* modsay eventsay

* .

---------

Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
2025-09-11 17:28:20 +02:00

24 lines
935 B
Plaintext

/datum/reagents/proc/get_color()
if(!reagent_list || !reagent_list.len)
return "#ffffffff"
if(reagent_list.len == 1) // It's pretty common and saves a lot of work
var/datum/reagent/R = reagent_list[1]
return R.color
var/list/colors = list(0, 0, 0, 0)
var/tot_w = 0
for(var/datum/reagent/R in reagent_list)
var/hex = uppertext(R.color)
if(length(hex) == 7)
hex += "FF"
if(length(hex) != 9) // PANIC PANIC PANIC
WARNING("Reagent [R.id] has an incorrect color set ([R.color])")
hex = "#FFFFFFFF"
colors[1] += hex2num(copytext(hex, 2, 4)) * R.volume * R.color_weight
colors[2] += hex2num(copytext(hex, 4, 6)) * R.volume * R.color_weight
colors[3] += hex2num(copytext(hex, 6, 8)) * R.volume * R.color_weight
colors[4] += hex2num(copytext(hex, 8, 10)) * R.volume * R.color_weight
tot_w += R.volume * R.color_weight
return rgb(colors[1] / tot_w, colors[2] / tot_w, colors[3] / tot_w, colors[4] / tot_w)