[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.

🆑 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.
/🆑

* Makes update_icon_updates_onmob more robust

---------

Co-authored-by: ShizCalev <ShizCalev@users.noreply.github.com>
This commit is contained in:
SkyratBot
2023-05-11 06:57:55 +01:00
committed by GitHub
parent e8343000c5
commit 077e2d4eee
27 changed files with 35 additions and 29 deletions
@@ -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()
+1 -1
View File
@@ -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, \
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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()
@@ -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.
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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()
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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)]"
@@ -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))
@@ -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()
+1 -1
View File
@@ -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)
+1 -2
View File
@@ -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
+1 -1
View File
@@ -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))
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
@@ -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()
. = ..()
+1 -1
View File
@@ -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()
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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)
+7
View File
@@ -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