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 20:22:14 -05:00
committed by GitHub
parent 3c22292ce1
commit a1ada2c9ef
181 changed files with 353 additions and 294 deletions
+1 -1
View File
@@ -45,7 +45,7 @@
if(!inputvalue)
return
if(user.canUseTopic(src, be_close = TRUE))
if(user.can_perform_action(src))
name = "folder[(inputvalue ? " - '[inputvalue]'" : null)]"
/obj/item/folder/proc/remove_item(obj/item/Item, mob/user)
+1 -1
View File
@@ -113,7 +113,7 @@
. += span_notice("Alt-click [src] to fold it into a paper plane.")
/obj/item/paper/AltClick(mob/living/user, obj/item/I)
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
if(istype(src, /obj/item/paper/carbon))
var/obj/item/paper/carbon/Carbon = src
+5 -5
View File
@@ -142,7 +142,7 @@
to_chat(user, span_warning("You must be holding the pen to continue!"))
return
var/deg = tgui_input_number(user, "What angle would you like to rotate the pen head to? (0-360)", "Rotate Pen Head", max_value = 360)
if(isnull(deg) || QDELETED(user) || QDELETED(src) || !user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE) || loc != user)
if(isnull(deg) || QDELETED(user) || QDELETED(src) || !user.can_perform_action(src, FORBID_TELEKINESIS_REACH) || loc != user)
return
degrees = deg
to_chat(user, span_notice("You rotate the top of the pen to [deg] degrees."))
@@ -169,12 +169,12 @@
//Changing name/description of items. Only works if they have the UNIQUE_RENAME object flag set
if(isobj(O) && (O.obj_flags & UNIQUE_RENAME))
var/penchoice = tgui_input_list(user, "What would you like to edit?", "Pen Setting", list("Rename", "Description", "Reset"))
if(QDELETED(O) || !user.canUseTopic(O, be_close = TRUE))
if(QDELETED(O) || !user.can_perform_action(O))
return
if(penchoice == "Rename")
var/input = tgui_input_text(user, "What do you want to name [O]?", "Object Name", "[O.name]", MAX_NAME_LEN)
var/oldname = O.name
if(QDELETED(O) || !user.canUseTopic(O, be_close = TRUE))
if(QDELETED(O) || !user.can_perform_action(O))
return
if(input == oldname || !input)
to_chat(user, span_notice("You changed [O] to... well... [O]."))
@@ -190,7 +190,7 @@
if(penchoice == "Description")
var/input = tgui_input_text(user, "Describe [O]", "Description", "[O.desc]", 140)
var/olddesc = O.desc
if(QDELETED(O) || !user.canUseTopic(O, be_close = TRUE))
if(QDELETED(O) || !user.can_perform_action(O))
return
if(input == olddesc || !input)
to_chat(user, span_notice("You decide against changing [O]'s description."))
@@ -200,7 +200,7 @@
O.renamedByPlayer = TRUE
if(penchoice == "Reset")
if(QDELETED(O) || !user.canUseTopic(O, be_close = TRUE))
if(QDELETED(O) || !user.can_perform_action(O))
return
qdel(O.GetComponent(/datum/component/rename))
+1 -1
View File
@@ -486,7 +486,7 @@
/obj/machinery/photocopier/MouseDrop_T(mob/target, mob/user)
check_ass() //Just to make sure that you can re-drag somebody onto it after they moved off.
if(!istype(target) || target.anchored || target.buckled || !Adjacent(target) || !user.canUseTopic(src, be_close = TRUE) || target == ass || copier_blocked())
if(!istype(target) || target.anchored || target.buckled || !Adjacent(target) || !user.can_perform_action(src) || target == ass || copier_blocked())
return
add_fingerprint(user)
if(target == user)