Refactor, improve, and rename canUseTopic to be can_perform_action (#73434)

This builds on what #69790 did and improved the code even further.
Notable things:
- `Topic()` is a deprecated proc in our codebase (replaced with
Javascript tgui) so it makes sense to rename `canUseTopic` to
`can_perform_action` which is more straightforward in what it does.
- Positional and named arguments have been converted into a easier to
use `action_bitflag`
- The bitflags adds some new checks you can use like: `NEED_GRAVITY |
NEED_LITERACY | NEED_LIGHT` when you want to perform an action.
- Redundant, duplicate, or dead code has been removed.
- Fixes several runtimes where `canUseTopic` was being called without a
proper target (IV drips, gibber, food processor)
- Better documentation for the proc and bitflags with examples
This commit is contained in:
Tim
2023-02-16 19:22:14 -06:00
committed by GitHub
parent 3c22292ce1
commit a1ada2c9ef
181 changed files with 353 additions and 294 deletions
@@ -96,7 +96,7 @@
. = ..()
if(. == SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN)
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
if(!ishuman(user) || !user.canUseTopic(src, be_close = TRUE))
if(!ishuman(user) || !user.can_perform_action(src))
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
if(has_buckled_mobs())
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
@@ -281,7 +281,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/chair/stool, 0)
if(over_object == usr && Adjacent(usr))
if(!item_chair || has_buckled_mobs() || src.flags_1 & NODECONSTRUCT_1)
return
if(!usr.canUseTopic(src, be_close = TRUE, no_dexterity = TRUE, no_tk = FALSE, need_hands = TRUE))
if(!usr.can_perform_action(src, NEED_DEXTERITY|NEED_HANDS))
return
usr.visible_message(span_notice("[usr] grabs \the [src.name]."), span_notice("You grab \the [src.name]."))
var/obj/item/C = new item_chair(loc)
@@ -477,7 +477,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/chair/stool/bar, 0)
/obj/structure/chair/bronze/AltClick(mob/user)
turns = 0
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = TRUE, no_tk = FALSE, need_hands = !iscyborg(user)))
if(!user.can_perform_action(src, NEED_DEXTERITY))
return
if(!(datum_flags & DF_ISPROCESSING))
user.visible_message(span_notice("[user] spins [src] around, and the last vestiges of Ratvarian technology keeps it spinning FOREVER."), \
+1 -1
View File
@@ -138,7 +138,7 @@ LINEN BINS
/obj/item/bedsheet/AltClick(mob/living/user)
// double check the canUseTopic args to make sure it's correct
if(!istype(user) || !user.canUseTopic(src, be_close = TRUE, no_dexterity = TRUE, no_tk = FALSE, need_hands = !iscyborg(user)))
if(!istype(user) || !user.can_perform_action(src, NEED_DEXTERITY))
return
dir = turn(dir, 180)
@@ -614,7 +614,7 @@
set category = "Object"
set name = "Toggle Open"
if(!usr.canUseTopic(src, be_close = TRUE) || !isturf(loc))
if(!usr.can_perform_action(src) || !isturf(loc))
return
if(iscarbon(usr) || issilicon(usr) || isdrone(usr))
@@ -677,7 +677,7 @@
/obj/structure/closet/attack_hand_secondary(mob/user, modifiers)
. = ..()
if(!user.canUseTopic(src, be_close = TRUE) || !isturf(loc))
if(!user.can_perform_action(src) || !isturf(loc))
return
if(!opened && secure)
@@ -49,7 +49,7 @@
var/t = tgui_input_text(user, "What would you like the label to be?", name, max_length = 53)
if(user.get_active_held_item() != interact_tool)
return
if(!user.canUseTopic(src, be_close = TRUE))
if(!user.can_perform_action(src))
return
handle_tag("[t ? t : initial(name)]")
return
@@ -315,7 +315,7 @@
open()
/obj/structure/closet/body_bag/environmental/prisoner/attack_hand_secondary(mob/user, modifiers)
if(!user.canUseTopic(src, be_close = TRUE) || !isturf(loc))
if(!user.can_perform_action(src) || !isturf(loc))
return
togglelock(user)
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
+2 -2
View File
@@ -516,7 +516,7 @@
if(!payments_acc)
to_chat(usr, span_notice("[src] hasn't been registered yet."))
return TRUE
if(!usr.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!usr.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return TRUE
if(!potential_acc)
to_chat(usr, span_notice("No ID card detected."))
@@ -571,7 +571,7 @@
if(payments_acc != potential_acc.registered_account)
to_chat(usr, span_warning("[src] rejects your new price."))
return
if(!usr.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!usr.can_perform_action(src, FORBID_TELEKINESIS_REACH))
to_chat(usr, span_warning("You need to get closer!"))
return
sale_price = new_price_input
+1 -1
View File
@@ -9,7 +9,7 @@
/obj/structure/sacrificealtar/AltClick(mob/living/user)
..()
if(!istype(user) || !user.canUseTopic(src, be_close = TRUE))
if(!istype(user) || !user.can_perform_action(src))
return
if(!has_buckled_mobs())
return
+1 -1
View File
@@ -111,7 +111,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/extinguisher_cabinet, 29)
toggle_cabinet(user)
/obj/structure/extinguisher_cabinet/attack_hand_secondary(mob/living/user)
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = TRUE, no_tk = FALSE, need_hands = TRUE))
if(!user.can_perform_action(src, NEED_DEXTERITY|NEED_HANDS))
return ..()
toggle_cabinet(user)
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
+1 -1
View File
@@ -107,7 +107,7 @@
. = ..()
if(.)
return
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return
if(obj_flags & IN_USE)
balloon_alert(user, "wait your turn!")
@@ -167,7 +167,7 @@
playsound(src, 'sound/machines/click.ogg', 10, TRUE)
/obj/item/plunger/AltClick(mob/user)
if(!istype(user) || !user.canUseTopic(src, be_close = TRUE))
if(!istype(user) || !user.can_perform_action(src))
return
var/new_layer = tgui_input_list(user, "Select a layer", "Layer", GLOB.plumbing_layers)
+1 -1
View File
@@ -151,7 +151,7 @@ at the cost of risking a vicious bite.**/
switch(altar_result)
if("Change Color")
var/chosen_color = input(user, "", "Choose Color", pants_color) as color|null
if(!isnull(chosen_color) && user.canUseTopic(src, be_close = TRUE))
if(!isnull(chosen_color) && user.can_perform_action(src))
pants_color = chosen_color
if("Create Artefact")
if(!COOLDOWN_FINISHED(src, use_cooldown) || status != ALTAR_INACTIVE)
+11 -11
View File
@@ -31,7 +31,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/mirror, 28)
var/new_style = tgui_input_list(user, "Select a facial hairstyle", "Grooming", GLOB.facial_hairstyles_list)
if(isnull(new_style))
return TRUE
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return TRUE //no tele-grooming
if(HAS_TRAIT(hairdresser, TRAIT_SHAVED))
to_chat(hairdresser, span_notice("If only growing back facial hair were that easy for you..."))
@@ -43,7 +43,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/mirror, 28)
var/new_style = tgui_input_list(user, "Select a hairstyle", "Grooming", GLOB.hairstyles_list)
if(isnull(new_style))
return TRUE
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return TRUE //no tele-grooming
if(HAS_TRAIT(hairdresser, TRAIT_BALD))
to_chat(hairdresser, span_notice("If only growing back hair were that easy for you..."))
@@ -167,7 +167,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/mirror, 28)
if(isnull(choice))
return TRUE
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return TRUE
switch(choice)
@@ -175,7 +175,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/mirror, 28)
var/newname = sanitize_name(tgui_input_text(amazed_human, "Who are we again?", "Name change", amazed_human.name, MAX_NAME_LEN), allow_numbers = TRUE) //It's magic so whatever.
if(!newname)
return TRUE
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return TRUE
amazed_human.real_name = newname
amazed_human.name = newname
@@ -190,7 +190,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/mirror, 28)
return TRUE
if(!selectable_races[racechoice])
return TRUE
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return TRUE
var/datum/species/newrace = selectable_races[racechoice]
@@ -204,7 +204,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/mirror, 28)
if(MUTCOLORS in amazed_human.dna.species.species_traits)
var/new_mutantcolor = input(user, "Choose your skin color:", "Race change", amazed_human.dna.features["mcolor"]) as color|null
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return TRUE
if(new_mutantcolor)
var/temp_hsv = RGBtoHSV(new_mutantcolor)
@@ -225,7 +225,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/mirror, 28)
return TRUE
if(amazed_human.gender == "male")
if(tgui_alert(amazed_human, "Become a Witch?", "Confirmation", list("Yes", "No")) == "Yes")
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return TRUE
amazed_human.gender = FEMALE
amazed_human.physique = FEMALE
@@ -235,7 +235,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/mirror, 28)
else
if(tgui_alert(amazed_human, "Become a Warlock?", "Confirmation", list("Yes", "No")) == "Yes")
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return TRUE
amazed_human.gender = MALE
amazed_human.physique = MALE
@@ -248,13 +248,13 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/mirror, 28)
if("hair")
var/hairchoice = tgui_alert(amazed_human, "Hairstyle or hair color?", "Change Hair", list("Style", "Color"))
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return TRUE
if(hairchoice == "Style") //So you just want to use a mirror then?
return ..()
else
var/new_hair_color = input(amazed_human, "Choose your hair color", "Hair Color",amazed_human.hair_color) as color|null
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return TRUE
if(new_hair_color)
amazed_human.hair_color = sanitize_hexcolor(new_hair_color)
@@ -268,7 +268,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/mirror, 28)
if(BODY_ZONE_PRECISE_EYES)
var/new_eye_color = input(amazed_human, "Choose your eye color", "Eye Color", amazed_human.eye_color_left) as color|null
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return TRUE
if(new_eye_color)
amazed_human.eye_color_left = sanitize_hexcolor(new_eye_color)
+2 -2
View File
@@ -90,7 +90,7 @@ GLOBAL_LIST_EMPTY(bodycontainers) //Let them act as spawnpoints for revenants an
var/t = tgui_input_text(user, "What would you like the label to be?", text("[]", name), null)
if (user.get_active_held_item() != P)
return
if(!user.canUseTopic(src, be_close = TRUE))
if(!user.can_perform_action(src))
return
if (t)
name = text("[]- '[]'", initial(name), t)
@@ -178,7 +178,7 @@ GLOBAL_LIST_EMPTY(bodycontainers) //Let them act as spawnpoints for revenants an
/obj/structure/bodycontainer/morgue/AltClick(mob/user)
..()
if(!user.canUseTopic(src, !issilicon(user)))
if(!user.can_perform_action(src, ALLOW_SILICON_REACH))
return
beeper = !beeper
to_chat(user, span_notice("You turn the speaker function [beeper ? "on" : "off"]."))
+2 -2
View File
@@ -165,13 +165,13 @@
to_chat(user, span_warning("The rotation is locked!"))
return FALSE
var/new_angle = tgui_input_number(user, "New angle for primary reflection face", "Reflector Angle", rotation_angle, 360)
if(isnull(new_angle) || QDELETED(user) || QDELETED(src) || !usr.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE))
if(isnull(new_angle) || QDELETED(user) || QDELETED(src) || !usr.can_perform_action(src, FORBID_TELEKINESIS_REACH))
return FALSE
set_angle(SIMPLIFY_DEGREES(new_angle))
return TRUE
/obj/structure/reflector/AltClick(mob/user)
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = TRUE, no_tk = FALSE, need_hands = !iscyborg(user)))
if(!user.can_perform_action(src, NEED_DEXTERITY))
return
else if(finished)
rotate(user)
+1 -1
View File
@@ -131,7 +131,7 @@ FLOOR SAFES
if(!ishuman(usr))
return
var/mob/living/carbon/human/user = usr
if(!user.canUseTopic(src, be_close = TRUE))
if(!user.can_perform_action(src))
return
var/canhear = FALSE
@@ -176,7 +176,7 @@
/obj/structure/training_machine/AltClick(mob/user)
. = ..()
if(!user.canUseTopic(src, be_close = TRUE, no_dexterity = TRUE, no_tk = TRUE, floor_okay = TRUE))
if(!user.can_perform_action(src, NEED_DEXTERITY|FORBID_TELEKINESIS_REACH|ALLOW_RESTING))
return
if(has_buckled_mobs())
user_unbuckle_mob(buckled_mobs[1], user)