Replaces /image with /mutable_appearance, where appropriate (#26518)

In cases where you're creating an image to use as an overlay, it makes more sense to use a mutable_appearance if you can. The image will create a static appearance for not just the image but also each intermediate step if you change vars along the way. The mutable appearance avoids this unnecessary and expensive process. The only situation that requires an image instead of a mutable_appearance is if the overlay is supposed to be directional. MA's ignore direction while images don't. I dunno why, probably another BYOND-ism.

I added a convenience function, mutable_appearance(), designed to emulate image(). Also went ahead and set the default plane of /mutable_appearance to FLOAT_PLANE because it's fucking 0 by default.

Several overlays that were image() calls were changed to just text strings when I could. overlays += "string" has the same result as overlays += image(icon, "string") and saves a proc call.
This commit is contained in:
MrPerson
2017-04-25 03:15:16 -07:00
committed by AnturK
parent 572696292a
commit ff3f84ab81
151 changed files with 763 additions and 921 deletions
+1 -5
View File
@@ -110,12 +110,8 @@
/datum/action/proc/ApplyIcon(obj/screen/movable/action_button/current_button)
if(icon_icon && button_icon_state && current_button.button_icon_state != button_icon_state)
var/image/img
img = image(icon_icon, current_button, button_icon_state)
img.pixel_x = 0
img.pixel_y = 0
current_button.cut_overlays(TRUE)
current_button.add_overlay(img)
current_button.add_overlay(mutable_appearance(icon_icon, button_icon_state))
current_button.button_icon_state = button_icon_state
+1 -1
View File
@@ -83,7 +83,7 @@
var/mob/living/silicon/ai/A = S
A.can_be_carded = FALSE
A.requires_power = POWER_REQ_CLOCKCULT
var/list/AI_frame = list(image('icons/mob/clockwork_mobs.dmi', A, "aiframe")) //make the AI's cool frame
var/list/AI_frame = list(mutable_appearance('icons/mob/clockwork_mobs.dmi', "aiframe")) //make the AI's cool frame
for(var/d in GLOB.cardinal)
AI_frame += image('icons/mob/clockwork_mobs.dmi', A, "eye[rand(1, 10)]", dir = d) //the eyes are randomly fast or slow
A.add_overlay(AI_frame)
+2 -2
View File
@@ -31,9 +31,9 @@
if(speak_emote)
D.speak_emote = speak_emote
/datum/dog_fashion/proc/get_image(var/dir)
/datum/dog_fashion/proc/get_overlay(var/dir)
if(icon_file && obj_icon_state)
var/image/corgI = image(icon_file, icon_state = obj_icon_state, dir = dir)
var/image/corgI = image(icon_file, obj_icon_state, dir = dir)
corgI.alpha = obj_alpha
corgI.color = obj_color
return corgI
+18
View File
@@ -0,0 +1,18 @@
// Mutable appearances are an inbuilt byond datastructure. Read the documentation on them by hitting F1 in DM.
// Basically use them instead of images for overlays/underlays and when changing an object's appearance if you're doing so with any regularity.
// Unless you need the overlay/underlay to have a different direction than the base object. Then you have to use an image due to a bug.
// Mutable appearances are children of images, just so you know.
/mutable_appearance/New()
..()
plane = FLOAT_PLANE // No clue why this is 0 by default yet images are on FLOAT_PLANE
// And yes this does have to be in the constructor, BYOND ignores it if you set it as a normal var
// Helper similar to image()
/proc/mutable_appearance(icon, icon_state = "", layer = FLOAT_LAYER)
var/mutable_appearance/MA = new()
MA.icon = icon
MA.icon_state = icon_state
MA.layer = layer
return MA
+7 -7
View File
@@ -15,7 +15,7 @@ GLOBAL_LIST_EMPTY(mutations_list)
var/lowest_value = 256 * 8
var/text_gain_indication = ""
var/text_lose_indication = ""
var/list/visual_indicators = list()
var/list/mutable_appearance/visual_indicators = list()
var/layer_used = MUTATIONS_LAYER //which mutation layer to use
var/list/species_allowed = list() //to restrict mutation to only certain species
var/health_req //minimum health required to acquire the mutation
@@ -161,7 +161,7 @@ GLOBAL_LIST_EMPTY(mutations_list)
/datum/mutation/human/telekinesis/New()
..()
visual_indicators |= image("icon"='icons/effects/genetics.dmi', "icon_state"="telekinesishead", "layer"=-MUTATIONS_LAYER)
visual_indicators |= mutable_appearance('icons/effects/genetics.dmi', "telekinesishead", -MUTATIONS_LAYER)
/datum/mutation/human/telekinesis/get_visual_indicator(mob/living/carbon/human/owner)
return visual_indicators[1]
@@ -180,7 +180,7 @@ GLOBAL_LIST_EMPTY(mutations_list)
/datum/mutation/human/cold_resistance/New()
..()
visual_indicators |= image("icon"='icons/effects/genetics.dmi', "icon_state"="fire", "layer"=-MUTATIONS_LAYER)
visual_indicators |= mutable_appearance('icons/effects/genetics.dmi', "fire", -MUTATIONS_LAYER)
/datum/mutation/human/cold_resistance/get_visual_indicator(mob/living/carbon/human/owner)
return visual_indicators[1]
@@ -618,7 +618,7 @@ GLOBAL_LIST_EMPTY(mutations_list)
/datum/mutation/human/laser_eyes/New()
..()
visual_indicators |= image("icon"='icons/effects/genetics.dmi', "icon_state"="lasereyes", "layer"=-FRONT_MUTATIONS_LAYER)
visual_indicators |= mutable_appearance('icons/effects/genetics.dmi', "lasereyes", -FRONT_MUTATIONS_LAYER)
/datum/mutation/human/laser_eyes/get_visual_indicator(mob/living/carbon/human/owner)
return visual_indicators[1]
@@ -640,11 +640,11 @@ GLOBAL_LIST_EMPTY(mutations_list)
var/list/mut_overlay = list()
if(overlays_standing[CM.layer_used])
mut_overlay = overlays_standing[CM.layer_used]
var/image/V = CM.get_visual_indicator(src)
var/mutable_appearance/V = CM.get_visual_indicator(src)
if(!mut_overlay.Find(V)) //either we lack the visual indicator or we have the wrong one
remove_overlay(CM.layer_used)
for(var/image/I in CM.visual_indicators)
mut_overlay.Remove(I)
for(var/mutable_appearance/MA in CM.visual_indicators)
mut_overlay.Remove(MA)
mut_overlay |= V
overlays_standing[CM.layer_used] = mut_overlay
apply_overlay(CM.layer_used)