From 077e2d4eee3d46d0ec555dc1bd43c9d43cde5c2f Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Thu, 11 May 2023 06:57:55 +0100 Subject: [PATCH] [MIRROR] Makes update_icon_updates_onmob more robust [MDB IGNORE] (#21076) * Makes update_icon_updates_onmob more robust (#75324) Safeguards against #74965 happening in the future. Noticed a bunch of these were using ITEM_SLOT_HANDS. This is incorrect, as the element already automatically updates held items. grep'd it to catch future instances. Likewise, a number of objects weren't passing slot_flags to the element, meaning it wasn't actually updating those things properly when they were being worn. I've simplified this so now the element will automatically update all slot_flags, and passing an additional slot to the element when being added is only needed for additional slots that might need to be updated. This also means if slot_flags change, the element will now update correctly as well. :cl: ShizCalev code: The update_icon_updates_onmob element will now automatically update all slots in an item's slot_flags var. This does fix multiple things that weren't updating properly. Passing a slot to the element is now only necessary if you want to add additional slots to be updated. /:cl: * Makes update_icon_updates_onmob more robust --------- Co-authored-by: ShizCalev --- code/datums/elements/update_icon_updates_onmob.dm | 4 ++-- code/game/objects/items/boxcutter.dm | 2 +- code/game/objects/items/cigs_lighters.dm | 2 +- code/game/objects/items/defib.dm | 2 +- code/game/objects/items/devices/flashlight.dm | 2 +- code/game/objects/items/flamethrower.dm | 2 +- code/game/objects/items/handcuffs.dm | 2 +- code/game/objects/items/latexballoon.dm | 2 +- code/game/objects/items/rcd/RCL.dm | 2 +- code/game/objects/items/storage/belt.dm | 2 +- code/game/objects/items/tanks/jetpack.dm | 2 +- code/game/objects/items/tools/weldingtool.dm | 2 +- code/game/objects/items/toys.dm | 2 +- code/game/objects/items/weaponry.dm | 4 ++-- .../antagonists/abductor/equipment/abduction_gear.dm | 2 +- code/modules/clothing/glasses/engine_goggles.dm | 2 +- code/modules/clothing/head/hardhat.dm | 2 +- code/modules/clothing/head/helmet.dm | 3 +-- code/modules/clothing/shoes/bananashoes.dm | 2 +- code/modules/clothing/shoes/magboots.dm | 2 +- code/modules/clothing/shoes/sneakers.dm | 2 +- code/modules/clothing/shoes/wheelys.dm | 2 +- code/modules/clothing/suits/reactive_armour.dm | 2 +- code/modules/power/cable.dm | 2 +- code/modules/power/lighting/light_items.dm | 2 +- code/modules/power/pipecleaners.dm | 2 +- tools/ci/check_grep.sh | 7 +++++++ 27 files changed, 35 insertions(+), 29 deletions(-) diff --git a/code/datums/elements/update_icon_updates_onmob.dm b/code/datums/elements/update_icon_updates_onmob.dm index a056801fba2..cfbf16317fa 100644 --- a/code/datums/elements/update_icon_updates_onmob.dm +++ b/code/datums/elements/update_icon_updates_onmob.dm @@ -3,7 +3,7 @@ /datum/element/update_icon_updates_onmob element_flags = ELEMENT_BESPOKE argument_hash_start_idx = 2 - ///The ITEM_SLOT_X flags to update on the parent mob. (Ex: ITEM_SLOT_HANDS|ITEM_SLOT_FEET) + ///The ITEM_SLOT_X flags to update on the parent mob in additon to the item's slot_flags. (Ex: Passing ITEM_SLOT_HANDCUFFED for sneakers will update the handcuff overlays in addition to ITEM_SLOT_FEET's overlays when their icon changes.) var/update_flags = NONE ///Should the element call [/mob/proc/update_body()] in addition to clothing updates? var/update_body = FALSE @@ -24,6 +24,6 @@ if(M.is_holding(target)) M.update_held_items() else - M.update_clothing(update_flags) + M.update_clothing((target.slot_flags|update_flags)) if(update_body) M.update_body() diff --git a/code/game/objects/items/boxcutter.dm b/code/game/objects/items/boxcutter.dm index d6fc81fc82a..7b7749a63b3 100644 --- a/code/game/objects/items/boxcutter.dm +++ b/code/game/objects/items/boxcutter.dm @@ -20,7 +20,7 @@ /obj/item/boxcutter/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDS) + AddElement(/datum/element/update_icon_updates_onmob) AddComponent(/datum/component/butchering, \ speed = 7 SECONDS, \ effectiveness = 100, \ diff --git a/code/game/objects/items/cigs_lighters.dm b/code/game/objects/items/cigs_lighters.dm index 0208e5802ed..264847e3cb6 100644 --- a/code/game/objects/items/cigs_lighters.dm +++ b/code/game/objects/items/cigs_lighters.dm @@ -183,7 +183,7 @@ CIGARETTE PACKETS ARE IN FANCY.DM if(starts_lit) light() AddComponent(/datum/component/knockoff, 90, list(BODY_ZONE_PRECISE_MOUTH), slot_flags) //90% to knock off when wearing a mask - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_MASK|ITEM_SLOT_HANDS) + AddElement(/datum/element/update_icon_updates_onmob) icon_state = icon_off inhand_icon_state = inhand_icon_off diff --git a/code/game/objects/items/defib.dm b/code/game/objects/items/defib.dm index e52e317e2c5..058516130d3 100644 --- a/code/game/objects/items/defib.dm +++ b/code/game/objects/items/defib.dm @@ -355,7 +355,7 @@ /obj/item/shockpaddles/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDS|ITEM_SLOT_BACK) + AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_BACK) AddComponent(/datum/component/two_handed, force_unwielded=8, force_wielded=12) /obj/item/shockpaddles/Destroy() diff --git a/code/game/objects/items/devices/flashlight.dm b/code/game/objects/items/devices/flashlight.dm index 20f586d23a5..192606f191f 100644 --- a/code/game/objects/items/devices/flashlight.dm +++ b/code/game/objects/items/devices/flashlight.dm @@ -462,7 +462,7 @@ /obj/item/flashlight/flare/candle/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDS) + AddElement(/datum/element/update_icon_updates_onmob) /** * Just checks the wax level of the candle for displaying the correct sprite. diff --git a/code/game/objects/items/flamethrower.dm b/code/game/objects/items/flamethrower.dm index 9be8532e036..f889c3bea5f 100644 --- a/code/game/objects/items/flamethrower.dm +++ b/code/game/objects/items/flamethrower.dm @@ -33,7 +33,7 @@ /obj/item/flamethrower/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDS) + AddElement(/datum/element/update_icon_updates_onmob) /obj/item/flamethrower/Destroy() if(weldtool) diff --git a/code/game/objects/items/handcuffs.dm b/code/game/objects/items/handcuffs.dm index bffd8aeabba..d482639d2a3 100644 --- a/code/game/objects/items/handcuffs.dm +++ b/code/game/objects/items/handcuffs.dm @@ -166,7 +166,7 @@ ) AddElement(/datum/element/contextual_screentip_item_typechecks, hovering_item_typechecks) - AddElement(/datum/element/update_icon_updates_onmob, (slot_flags|ITEM_SLOT_HANDCUFFED)) + AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDCUFFED) if(new_color) set_cable_color(new_color) diff --git a/code/game/objects/items/latexballoon.dm b/code/game/objects/items/latexballoon.dm index c055aa2702e..062f474307b 100644 --- a/code/game/objects/items/latexballoon.dm +++ b/code/game/objects/items/latexballoon.dm @@ -21,7 +21,7 @@ /obj/item/latexballoon/Initialize(mapload) . = ..() AddElement(/datum/element/atmos_sensitive, mapload) - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDS) + AddElement(/datum/element/update_icon_updates_onmob) /obj/item/latexballoon/proc/set_state(state_to_set) state = state_to_set diff --git a/code/game/objects/items/rcd/RCL.dm b/code/game/objects/items/rcd/RCL.dm index 2bef59d875b..a3c1a0b48f3 100644 --- a/code/game/objects/items/rcd/RCL.dm +++ b/code/game/objects/items/rcd/RCL.dm @@ -27,7 +27,7 @@ /obj/item/rcl/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDS) + AddElement(/datum/element/update_icon_updates_onmob) AddComponent(/datum/component/two_handed, wield_callback = CALLBACK(src, PROC_REF(on_wield)), unwield_callback = CALLBACK(src, PROC_REF(on_unwield))) /// triggered on wield of two handed item diff --git a/code/game/objects/items/storage/belt.dm b/code/game/objects/items/storage/belt.dm index 799b75b6b55..bc8d7a4f862 100644 --- a/code/game/objects/items/storage/belt.dm +++ b/code/game/objects/items/storage/belt.dm @@ -809,7 +809,7 @@ /obj/item/storage/belt/sabre/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_BELT) + AddElement(/datum/element/update_icon_updates_onmob) atom_storage.max_slots = 1 atom_storage.rustle_sound = FALSE diff --git a/code/game/objects/items/tanks/jetpack.dm b/code/game/objects/items/tanks/jetpack.dm index e91030b8ca3..592b4b6606c 100644 --- a/code/game/objects/items/tanks/jetpack.dm +++ b/code/game/objects/items/tanks/jetpack.dm @@ -19,7 +19,7 @@ . = ..() get_mover = CALLBACK(src, PROC_REF(get_user)) check_on_move = CALLBACK(src, PROC_REF(allow_thrust), 0.01) - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_BACK | ITEM_SLOT_SUITSTORE) + AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_SUITSTORE) refresh_jetpack() /obj/item/tank/jetpack/Destroy() diff --git a/code/game/objects/items/tools/weldingtool.dm b/code/game/objects/items/tools/weldingtool.dm index e40a1995573..e78d138f126 100644 --- a/code/game/objects/items/tools/weldingtool.dm +++ b/code/game/objects/items/tools/weldingtool.dm @@ -57,7 +57,7 @@ /obj/item/weldingtool/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDS) + AddElement(/datum/element/update_icon_updates_onmob) AddElement(/datum/element/tool_flash, light_range) AddElement(/datum/element/falling_hazard, damage = force, wound_bonus = wound_bonus, hardhat_safety = TRUE, crushes = FALSE, impact_sound = hitsound) diff --git a/code/game/objects/items/toys.dm b/code/game/objects/items/toys.dm index d45b5def782..81e3d3e64f0 100644 --- a/code/game/objects/items/toys.dm +++ b/code/game/objects/items/toys.dm @@ -44,7 +44,7 @@ /obj/item/toy/waterballoon/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDS) + AddElement(/datum/element/update_icon_updates_onmob) create_reagents(10) /obj/item/toy/waterballoon/attack(mob/living/carbon/human/M, mob/user) diff --git a/code/game/objects/items/weaponry.dm b/code/game/objects/items/weaponry.dm index b629f8f8c3a..a5b08d573bc 100644 --- a/code/game/objects/items/weaponry.dm +++ b/code/game/objects/items/weaponry.dm @@ -414,7 +414,7 @@ for further reading, please see: https://github.com/tgstation/tgstation/pull/301 /obj/item/switchblade/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDS) + AddElement(/datum/element/update_icon_updates_onmob) AddComponent(/datum/component/butchering, \ speed = 7 SECONDS, \ effectiveness = 100, \ @@ -984,7 +984,7 @@ for further reading, please see: https://github.com/tgstation/tgstation/pull/301 wield_callback = CALLBACK(src, PROC_REF(on_wield)), \ unwield_callback = CALLBACK(src, PROC_REF(on_unwield)), \ ) - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDS) + AddElement(/datum/element/update_icon_updates_onmob) /obj/item/highfrequencyblade/update_icon_state() icon_state = "hfrequency[HAS_TRAIT(src, TRAIT_WIELDED)]" diff --git a/code/modules/antagonists/abductor/equipment/abduction_gear.dm b/code/modules/antagonists/abductor/equipment/abduction_gear.dm index d6cf4acbd1e..2e92f39eab5 100644 --- a/code/modules/antagonists/abductor/equipment/abduction_gear.dm +++ b/code/modules/antagonists/abductor/equipment/abduction_gear.dm @@ -480,7 +480,7 @@ Congratulations! You are now trained for invasive xenobiology research!"} /obj/item/melee/baton/abductor/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDS) + AddElement(/datum/element/update_icon_updates_onmob) /obj/item/melee/baton/abductor/proc/toggle(mob/living/user=usr) if(!AbductorCheck(user)) diff --git a/code/modules/clothing/glasses/engine_goggles.dm b/code/modules/clothing/glasses/engine_goggles.dm index 2185dd19fde..c5c971d80aa 100644 --- a/code/modules/clothing/glasses/engine_goggles.dm +++ b/code/modules/clothing/glasses/engine_goggles.dm @@ -30,7 +30,7 @@ /obj/item/clothing/glasses/meson/engine/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_EYES) + AddElement(/datum/element/update_icon_updates_onmob) START_PROCESSING(SSobj, src) update_appearance() diff --git a/code/modules/clothing/head/hardhat.dm b/code/modules/clothing/head/hardhat.dm index 35f6f388b8f..8d31b70b640 100644 --- a/code/modules/clothing/head/hardhat.dm +++ b/code/modules/clothing/head/hardhat.dm @@ -38,7 +38,7 @@ /obj/item/clothing/head/utility/hardhat/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HEAD) + AddElement(/datum/element/update_icon_updates_onmob) /obj/item/clothing/head/utility/hardhat/attack_self(mob/living/user) toggle_helmet_light(user) diff --git a/code/modules/clothing/head/helmet.dm b/code/modules/clothing/head/helmet.dm index 13cd675c303..e6ef50879c4 100644 --- a/code/modules/clothing/head/helmet.dm +++ b/code/modules/clothing/head/helmet.dm @@ -14,7 +14,6 @@ clothing_flags = SNUG_FIT | PLASMAMAN_HELMET_EXEMPT flags_cover = HEADCOVERSEYES flags_inv = HIDEHAIR - dog_fashion = /datum/dog_fashion/head/helmet /datum/armor/head_helmet @@ -29,7 +28,7 @@ /obj/item/clothing/head/helmet/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HEAD) + AddElement(/datum/element/update_icon_updates_onmob) /obj/item/clothing/head/helmet/sec diff --git a/code/modules/clothing/shoes/bananashoes.dm b/code/modules/clothing/shoes/bananashoes.dm index 198e50bca1f..46e98db0a8c 100644 --- a/code/modules/clothing/shoes/bananashoes.dm +++ b/code/modules/clothing/shoes/bananashoes.dm @@ -16,7 +16,7 @@ /obj/item/clothing/shoes/clown_shoes/banana_shoes/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_FEET) + AddElement(/datum/element/update_icon_updates_onmob) AddComponent(/datum/component/material_container, list(/datum/material/bananium), 100 * SHEET_MATERIAL_AMOUNT, MATCONTAINER_EXAMINE|MATCONTAINER_ANY_INTENT|MATCONTAINER_SILENT, allowed_items=/obj/item/stack) AddComponent(/datum/component/squeak, list('sound/items/bikehorn.ogg'=1), 75, falloff_exponent = 20) RegisterSignal(src, COMSIG_SHOES_STEP_ACTION, PROC_REF(on_step)) diff --git a/code/modules/clothing/shoes/magboots.dm b/code/modules/clothing/shoes/magboots.dm index dace486c41a..2ae13924ded 100644 --- a/code/modules/clothing/shoes/magboots.dm +++ b/code/modules/clothing/shoes/magboots.dm @@ -23,7 +23,7 @@ /obj/item/clothing/shoes/magboots/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, slot_flags) + AddElement(/datum/element/update_icon_updates_onmob) RegisterSignal(src, COMSIG_SPEED_POTION_APPLIED, PROC_REF(on_speed_potioned)) /// Signal handler for [COMSIG_SPEED_POTION_APPLIED]. Speed potion removes the active slowdown diff --git a/code/modules/clothing/shoes/sneakers.dm b/code/modules/clothing/shoes/sneakers.dm index 16048e167b5..ec2ae14ef92 100644 --- a/code/modules/clothing/shoes/sneakers.dm +++ b/code/modules/clothing/shoes/sneakers.dm @@ -90,7 +90,7 @@ /obj/item/clothing/shoes/sneakers/orange/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, (slot_flags|ITEM_SLOT_HANDCUFFED)) + AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDCUFFED) /obj/item/clothing/shoes/sneakers/orange/handle_atom_del(atom/deleting_atom) if(deleting_atom == attached_cuffs) diff --git a/code/modules/clothing/shoes/wheelys.dm b/code/modules/clothing/shoes/wheelys.dm index 055c463c44b..8d2e4c47e67 100644 --- a/code/modules/clothing/shoes/wheelys.dm +++ b/code/modules/clothing/shoes/wheelys.dm @@ -20,7 +20,7 @@ /obj/item/clothing/shoes/wheelys/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_FEET) + AddElement(/datum/element/update_icon_updates_onmob) wheels = new wheels(null) wheels.link_shoes(src) diff --git a/code/modules/clothing/suits/reactive_armour.dm b/code/modules/clothing/suits/reactive_armour.dm index 3ebc278764b..353c49dfc66 100644 --- a/code/modules/clothing/suits/reactive_armour.dm +++ b/code/modules/clothing/suits/reactive_armour.dm @@ -57,7 +57,7 @@ /obj/item/clothing/suit/armor/reactive/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_OCLOTHING) + AddElement(/datum/element/update_icon_updates_onmob) /obj/item/clothing/suit/armor/reactive/update_icon_state() . = ..() diff --git a/code/modules/power/cable.dm b/code/modules/power/cable.dm index 033014e237b..146deeecb37 100644 --- a/code/modules/power/cable.dm +++ b/code/modules/power/cable.dm @@ -461,7 +461,7 @@ GLOBAL_LIST_INIT(wire_node_generating_types, typecacheof(list(/obj/structure/gri pixel_x = base_pixel_x + rand(-2, 2) pixel_y = base_pixel_y + rand(-2, 2) - AddElement(/datum/element/update_icon_updates_onmob, slot_flags) + AddElement(/datum/element/update_icon_updates_onmob) update_appearance() diff --git a/code/modules/power/lighting/light_items.dm b/code/modules/power/lighting/light_items.dm index 44a2cc2d89a..a0b4ebcab86 100644 --- a/code/modules/power/lighting/light_items.dm +++ b/code/modules/power/lighting/light_items.dm @@ -20,7 +20,7 @@ /obj/item/light/Initialize(mapload) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_HANDS) + AddElement(/datum/element/update_icon_updates_onmob) AddComponent(/datum/component/golem_food, golem_food_key = /obj/item/light, extra_validation = CALLBACK(src, PROC_REF(is_intact))) /// Returns true if bulb is intact diff --git a/code/modules/power/pipecleaners.dm b/code/modules/power/pipecleaners.dm index bb37f8b29a2..5806edd5d59 100644 --- a/code/modules/power/pipecleaners.dm +++ b/code/modules/power/pipecleaners.dm @@ -254,7 +254,7 @@ By design, d1 is the smallest direction and d2 is the highest /obj/item/stack/pipe_cleaner_coil/Initialize(mapload, new_amount = null, list/mat_override=null, mat_amt=1, param_color = null) . = ..() - AddElement(/datum/element/update_icon_updates_onmob, slot_flags) + AddElement(/datum/element/update_icon_updates_onmob) if(param_color) set_pipecleaner_color(param_color) if(!color) diff --git a/tools/ci/check_grep.sh b/tools/ci/check_grep.sh index 103fb855e50..00dc3386d19 100644 --- a/tools/ci/check_grep.sh +++ b/tools/ci/check_grep.sh @@ -160,6 +160,13 @@ if $grep 'balloon_alert\(.*?, ?"[A-Z]' $code_files; then st=1 fi; +part "update_icon_updates_onmob element usage" +if $grep 'AddElement\(/datum/element/update_icon_updates_onmob.+ITEM_SLOT_HANDS' $code_files; then + echo + echo -e "${RED}ERROR: update_icon_updates_onmob element automatically updates ITEM_SLOT_HANDS, this is redundant and should be removed.${NC}" + st=1 +fi; + part "common spelling mistakes" if $grep -i 'centcomm' $code_files; then echo