mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-16 12:43:09 +00:00
* Additional GAGS configuration json verification (#59524) This standardizes how values are read from the json for greyscale layers so that error handling can check for some additional things: No extra keys in the json that are unknown No missing keys that a layer needs to work Values are the expected type for that key A variety of error messages have been added for various ways the json can be malformed and should hopefully provide good feedback for anyone working with greyscale configurations. * Additional GAGS configuration json verification Co-authored-by: Emmett Gaines <ninjanomnom@gmail.com>
55 lines
1.6 KiB
Plaintext
55 lines
1.6 KiB
Plaintext
/// Takes a json list and extracts a single value.
|
|
/// Subtypes represent different conversions of that value.
|
|
/datum/json_reader
|
|
|
|
/// Takes a value read directly from json and verifies/converts as needed to a result
|
|
/datum/json_reader/proc/ReadJson(value)
|
|
return
|
|
|
|
/datum/json_reader/text/ReadJson(value)
|
|
if(!istext(value))
|
|
CRASH("Text value expected but got '[value]'")
|
|
return value
|
|
|
|
/datum/json_reader/number/ReadJson(value)
|
|
var/newvalue = text2num(value)
|
|
if(!isnum(newvalue))
|
|
CRASH("Number expected but got [newvalue]")
|
|
return newvalue
|
|
|
|
/datum/json_reader/number_color_list/ReadJson(list/value)
|
|
if(!istype(value))
|
|
CRASH("Expected a list but got [value]")
|
|
var/list/new_values = list()
|
|
for(var/number_string in value)
|
|
var/new_value = text2num(number_string)
|
|
if(!isnum(new_value))
|
|
if(!istext(number_string) || number_string[1] != "#")
|
|
stack_trace("Expected list to only contain numbers or colors but got '[number_string]'")
|
|
continue
|
|
new_value = number_string
|
|
new_values += new_value
|
|
return new_values
|
|
|
|
/datum/json_reader/blend_mode
|
|
var/static/list/blend_modes = list(
|
|
"add" = ICON_ADD,
|
|
"subtract" = ICON_SUBTRACT,
|
|
"multiply" = ICON_MULTIPLY,
|
|
"or" = ICON_OR,
|
|
"overlay" = ICON_OVERLAY,
|
|
"underlay" = ICON_UNDERLAY,
|
|
)
|
|
|
|
/datum/json_reader/blend_mode/ReadJson(value)
|
|
var/new_value = blend_modes[lowertext(value)]
|
|
if(isnull(new_value))
|
|
CRASH("Blend mode expected but got '[value]'")
|
|
return new_value
|
|
|
|
/datum/json_reader/greyscale_config/ReadJson(value)
|
|
var/newvalue = SSgreyscale.configurations[value]
|
|
if(!newvalue)
|
|
CRASH("Greyscale configuration type expected but got '[value]'")
|
|
return newvalue
|