Files
Bubberstation/code/datums/greyscale/layer.dm
SkyratBot bc6c285adb [MIRROR] Advanced Greyscale Sprite Generation (#4792)
* Advanced Greyscale Sprite Generation (#58112)

* Nonfunctional greyscale code

* Functional greyscale sprites via filter

Probably going to set the icon instead later

* Switches to greyscale json config

* Adds the reference layer type and converts the other canister types

* Working previews

* Adds readme

* Fixes overlays and breaking

* Removes old canister sprites

* Removes an unused var

* Fixes tgui lints

* Removes a bunch of the old canister icon states

Yeah I need to fix relabeling as well

* Removes some debug sprites

* Sorts canister type list and breaks up base shader step

* Removes an unnecessary preview hack

* Makes prototype canister greyscale

* Properly sizes the ui

* Fills in the canister map sprite

* Adds some more warnings to layers

* Makes broken overlay more prominent

* Removes a preview var that isn't needed anymore

* Cleans up client ref in Destroy

* Cleans up the tgui window a bit

* Update GreyscaleModifyMenu.tsx

* Animates the canister falling over

* Removes a commented out line that's no longer needed

Co-authored-by: Aleksej Komarov <stylemistake@ gmail.com>

* Advanced Greyscale Sprite Generation

Co-authored-by: Emmett Gaines <ninjanomnom@gmail.com>
Co-authored-by: Aleksej Komarov <stylemistake@ gmail.com>
2021-04-10 17:59:30 +01:00

75 lines
2.5 KiB
Plaintext

/datum/greyscale_layer
var/layer_type
var/list/color_ids
var/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/greyscale_layer/New(icon_file, list/json_data)
color_ids = json_data["color_ids"]
blend_mode = blend_modes[lowertext(json_data["blend_mode"])]
if(isnull(blend_mode))
CRASH("Greyscale config for [icon_file] is missing a blend mode on a layer.")
/// Used to actualy create the layer using the given colors
/// Do not override, use InternalGenerate instead
/datum/greyscale_layer/proc/Generate(list/colors, list/render_steps)
var/list/processed_colors = list()
for(var/i in color_ids)
processed_colors += colors[i]
return InternalGenerate(processed_colors, render_steps)
/datum/greyscale_layer/proc/InternalGenerate(list/colors)
////////////////////////////////////////////////////////
// Subtypes
/// The most basic greyscale layer; a layer which is created from a single icon_state in the given icon file
/datum/greyscale_layer/icon_state
layer_type = "icon_state"
var/icon/icon
var/color_id
/datum/greyscale_layer/icon_state/New(icon_file, list/json_data)
. = ..()
var/icon_state = json_data["icon_state"]
if(!(icon_state in icon_states(icon_file)))
CRASH("Configured icon state \[[icon_state]\] was not found in [icon_file]. Double check your json configuration.")
icon = new(icon_file, json_data["icon_state"])
if(length(color_ids) > 1)
CRASH("Icon state layers can not have more than one color id")
/datum/greyscale_layer/icon_state/InternalGenerate(list/colors, list/render_steps)
. = ..()
var/icon/new_icon = icon(icon)
if(length(colors))
new_icon.Blend(colors[1], ICON_MULTIPLY)
return new_icon
/// A layer created by using another greyscale icon's configuration
/datum/greyscale_layer/reference
layer_type = "reference"
var/datum/greyscale_config/reference_config
/datum/greyscale_layer/reference/New(icon_file, list/json_data)
. = ..()
reference_config = SSgreyscale.configurations[json_data["reference_type"]]
if(!reference_config)
CRASH("An unknown greyscale configuration was given to a reference layer: [json_data["reference_type"]]")
/datum/greyscale_layer/reference/InternalGenerate(list/colors, list/render_steps)
if(render_steps)
// We're debugging
var/list/debug_data = reference_config.GenerateDebug(colors)
render_steps += debug_data["steps"]
return debug_data["icon"]
return reference_config.Generate(colors)