From 37034960e3469ca7d5a9be19bbd9c5db74fc2b3c Mon Sep 17 00:00:00 2001 From: Drulikar Date: Sun, 1 Oct 2023 21:58:48 -0700 Subject: [PATCH] Argumentify the fix for respecting appearance_flags (dimension fix is unaltered) --- code/__HELPERS/icons.dm | 42 ++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/code/__HELPERS/icons.dm b/code/__HELPERS/icons.dm index 535dfed3ac1a..60d2681a1d1a 100644 --- a/code/__HELPERS/icons.dm +++ b/code/__HELPERS/icons.dm @@ -329,7 +329,8 @@ world /// appearance system (overlays/underlays, etc.) is not available. /// /// Only the first argument is required. -/proc/getFlatIcon(image/appearance, defdir, deficon, defstate, defblend, start = TRUE, no_anim = FALSE) +/// appearance_flags indicates whether appearance_flags should be respected (at the cost of about 10-20% perf) +/proc/getFlatIcon(image/appearance, defdir, deficon, defstate, defblend, start = TRUE, no_anim = FALSE, appearance_flags = FALSE) // Loop through the underlays, then overlays, sorting them into the layers list #define PROCESS_OVERLAYS_OR_UNDERLAYS(flat, process, base_layer) \ for (var/i in 1 to process.len) { \ @@ -435,6 +436,7 @@ world if(layer_image.alpha == 0) continue + // variables only relevant when accounting for appearance_flags: var/apply_color = TRUE var/apply_alpha = TRUE @@ -443,11 +445,12 @@ world add = icon(layer_image.icon, layer_image.icon_state, base_icon_dir) else // 'I' is an appearance object. var/image/layer_as_image = image(layer_image) - if(layer_as_image.appearance_flags & RESET_COLOR) - apply_color = FALSE - if(layer_as_image.appearance_flags & RESET_ALPHA) - apply_alpha = FALSE - add = getFlatIcon(layer_as_image, curdir, curicon, curstate, curblend, FALSE, no_anim) + if(appearance_flags) + if(layer_as_image.appearance_flags & RESET_COLOR) + apply_color = FALSE + if(layer_as_image.appearance_flags & RESET_ALPHA) + apply_alpha = FALSE + add = getFlatIcon(layer_as_image, curdir, curicon, curstate, curblend, FALSE, no_anim, appearance_flags) if(!add) continue @@ -476,18 +479,31 @@ world flatY1 = addY1 flatY2 = addY2 - if(apply_color && appearance.color) - if(islist(appearance.color)) - add.MapColors(arglist(appearance.color)) - else - add.Blend(appearance.color, ICON_MULTIPLY) + if(appearance_flags) + // apply parent's color/alpha to the added layers if the layer didn't opt + if(apply_color && appearance.color) + if(islist(appearance.color)) + add.MapColors(arglist(appearance.color)) + else + add.Blend(appearance.color, ICON_MULTIPLY) - if(apply_alpha && appearance.alpha < 255) - add.Blend(rgb(255, 255, 255, appearance.alpha), ICON_MULTIPLY) + if(apply_alpha && appearance.alpha < 255) + add.Blend(rgb(255, 255, 255, appearance.alpha), ICON_MULTIPLY) // Blend the overlay into the flattened icon flat.Blend(add, blendMode2iconMode(curblend), layer_image.pixel_x + 2 - flatX1, layer_image.pixel_y + 2 - flatY1) + if(!appearance_flags) + // If we didn't apply parent colors individually per layer respecting appearance_flags, then do it just the one time now + if(appearance.color) + if(islist(appearance.color)) + flat.MapColors(arglist(appearance.color)) + else + flat.Blend(appearance.color, ICON_MULTIPLY) + + if(appearance.alpha < 255) + flat.Blend(rgb(255, 255, 255, appearance.alpha), ICON_MULTIPLY) + if(no_anim) //Clean up repeated frames var/icon/cleaned = new /icon()