mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-30 00:29:02 +01:00
Refactor renaming UNIQUE_RENAME items from the pen to an element (#82491)
## About The Pull Request So a bit ago someone in code_general wanted to make plushies renamable, but learnt that just adding the `UNIQUE_RENAME` flag wouldn't work as pens would murder the plushie and only THEN let you rename it. I noted refactoring both pens and plushies to use the new `item_interaction(...)` procs would Just Solve This, but, well, they didn't really have any coding experience. But, hey, renaming being hardcoded to the pens has annoyed me ever since I laid my eyes upon the hot mess that is paperwork code. So here we are! ### We're making it an element. There's not really much to this, this is mostly the same code but moved to an element and with some minor cleanups. First, we move it all from `/obj/item/pen` to a new element we called `/datum/element/tool_renaming`. With this, instead of having it proc on `/obj/item/pen/afterattack(...)`, we register it to proc on the `COMSIG_ITEM_INTERACTING_WITH_ATOM` signal. https://github.com/tgstation/tgstation/blob/6e36ed984070d53e16bed4fa43eb0cbe6460deed/code/__DEFINES/dcs/signals/signals_atom/signals_atom_x_act.dm#L59-L62 Secondly, we realize the code is just going through each if statement regardless of whether the previous was correct. https://github.com/tgstation/tgstation/blob/6e36ed984070d53e16bed4fa43eb0cbe6460deed/code/modules/paperwork/pen.dm#L225-L258 And, as we're dealing with text, just make it a switch statement instead. ```dm switch(pen_choice) if("Rename") (...) if("Description") (...) if("Reset") (...) ``` Then, we replace all single letter variables with descriptive ones, replace the if-elses with early returns, and make it actually return item interaction flags. Finally, we slap this onto the pen, and we're done. Now we can slap it onto other fitting renaming tools, and it uses the proper item interaction system. ## Why It's Good For The Game I feel it's generally better to not hardcode this to just pens, we have plenty other writing utensils and possible renaming tools. It's also a bit cleaner than before. Apart from that, moves it from using `afterattack(...)` to the proper item interaction chain by using `COMSIG_ITEM_INTERACTING_WITH_ATOM`, which should reduce janky interactions. ## Changelog 🆑 refactor: Instead of being hardcoded to the pen, renaming items is now an element. Currently only pens have this, and functionality should be the same, but please report it if you find any items that were renamable but now aren't. /🆑
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
dart_insert_projectile_icon_state, \
|
||||
CALLBACK(src, PROC_REF(get_dart_var_modifiers))\
|
||||
)
|
||||
AddElement(/datum/element/tool_renaming)
|
||||
RegisterSignal(src, COMSIG_DART_INSERT_ADDED, PROC_REF(on_inserted_into_dart))
|
||||
RegisterSignal(src, COMSIG_DART_INSERT_REMOVED, PROC_REF(on_removed_from_dart))
|
||||
|
||||
@@ -209,54 +210,6 @@
|
||||
log_combat(user, M, "stabbed", src)
|
||||
return TRUE
|
||||
|
||||
/obj/item/pen/afterattack(obj/O, mob/living/user, proximity)
|
||||
. = ..()
|
||||
|
||||
if (!proximity)
|
||||
return .
|
||||
|
||||
. |= AFTERATTACK_PROCESSED_ITEM
|
||||
|
||||
//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.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.can_perform_action(O))
|
||||
return
|
||||
if(input == oldname || !input)
|
||||
to_chat(user, span_notice("You changed [O] to... well... [O]."))
|
||||
else
|
||||
O.AddComponent(/datum/component/rename, input, O.desc)
|
||||
to_chat(user, span_notice("You have successfully renamed \the [oldname] to [O]."))
|
||||
ADD_TRAIT(O, TRAIT_WAS_RENAMED, PEN_LABEL_TRAIT)
|
||||
O.update_appearance(UPDATE_ICON)
|
||||
|
||||
if(penchoice == "Description")
|
||||
var/input = tgui_input_text(user, "Describe [O]", "Description", "[O.desc]", 280)
|
||||
var/olddesc = O.desc
|
||||
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."))
|
||||
else
|
||||
O.AddComponent(/datum/component/rename, O.name, input)
|
||||
to_chat(user, span_notice("You have successfully changed [O]'s description."))
|
||||
ADD_TRAIT(O, TRAIT_WAS_RENAMED, PEN_LABEL_TRAIT)
|
||||
O.update_appearance(UPDATE_ICON)
|
||||
|
||||
if(penchoice == "Reset")
|
||||
if(QDELETED(O) || !user.can_perform_action(O))
|
||||
return
|
||||
|
||||
qdel(O.GetComponent(/datum/component/rename))
|
||||
to_chat(user, span_notice("You have successfully reset [O]'s name and description."))
|
||||
REMOVE_TRAIT(O, TRAIT_WAS_RENAMED, PEN_LABEL_TRAIT)
|
||||
O.update_appearance(UPDATE_ICON)
|
||||
|
||||
/obj/item/pen/get_writing_implement_details()
|
||||
return list(
|
||||
interaction_mode = MODE_WRITING,
|
||||
|
||||
Reference in New Issue
Block a user