forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional GAGS configuration json verification (tgstation#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.
- Loading branch information
1 parent
72a52f4
commit 8eed0b2
Showing
4 changed files
with
117 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters