Skip to content

Commit

Permalink
Migrates the hand labeler to the new attack chain (#27400)
Browse files Browse the repository at this point in the history
* idk what i am doing

* reverts config.toml

* restores test_tiny

* migrates the handlabeler to new attack_chain

* return signals + datum autodoc

* return defines to handlabeler.dm

* trailing newline

* handlabeler goes backpack if no label now

* moved the labeling stuff out of interact_with_atom

* guard clause

---------

Co-authored-by: Toastical <[email protected]>
Co-authored-by: Toastical <[email protected]>
  • Loading branch information
3 people authored Jan 16, 2025
1 parent 471383b commit 166b1d5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 52 deletions.
5 changes: 5 additions & 0 deletions code/__DEFINES/dcs/datum_signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,8 @@
/// Sent when bodies transfer between shades/shards and constructs
/// from base of /datum/component/construct_held_body/proc/transfer_held_body()
#define COMSIG_SHADE_TO_CONSTRUCT_TRANSFER "shade_to_construct_transfer"


/// /datum/component/label
/// Called when a handlabeler is used on an item when off
#define COMSIG_LABEL_REMOVE "label_remove"
27 changes: 4 additions & 23 deletions code/datums/components/label.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
apply_label()

/datum/component/label/RegisterWithParent()
RegisterSignal(parent, COMSIG_ATTACK_BY, PROC_REF(on_attack_by))
RegisterSignal(parent, COMSIG_LABEL_REMOVE, PROC_REF(on_remove))
RegisterSignal(parent, COMSIG_PARENT_EXAMINE, PROC_REF(on_examine))
RegisterSignal(parent, COMSIG_ATOM_UPDATE_NAME, PROC_REF(on_update_name))

/datum/component/label/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_ATTACK_BY, COMSIG_PARENT_EXAMINE, COMSIG_ATOM_UPDATE_NAME))
UnregisterSignal(parent, list(COMSIG_LABEL_REMOVE, COMSIG_PARENT_EXAMINE, COMSIG_ATOM_UPDATE_NAME))

/**
This proc will fire after the parent is hit by a hand labeler which is trying to apply another label.
Expand All @@ -41,29 +41,10 @@
label_name = _label_name
apply_label()

/**
This proc will trigger when any object is used to attack the parent.
If the attacking object is not a hand labeler, it will return.
If the attacking object is a hand labeler it will restore the name of the parent to what it was before this component was added to it, and the component will be deleted.
Arguments:
* source: The parent.
* attacker: The object that is hitting the parent.
* user: The mob who is wielding the attacking object.
*/
/datum/component/label/proc/on_attack_by(datum/source, obj/item/attacker, mob/user)
SIGNAL_HANDLER // COMSIG_ATTACK_BY
// If the attacking object is not a hand labeler or it's not off (has a label ready to apply), return.
// The hand labeler should be off in order to remove a label.
var/obj/item/hand_labeler/labeler = attacker
if(!istype(labeler) || labeler.mode)
return

/datum/component/label/proc/on_remove(datum/source)
remove_label()
playsound(parent, 'sound/items/poster_ripped.ogg', 20, TRUE)
to_chat(user, "<span class='warning'>You remove the label from [parent].</span>")
qdel(src) // Remove the component from the object.
return TRUE

/**
This proc will trigger when someone examines the parent.
Expand Down
81 changes: 52 additions & 29 deletions code/modules/paperwork/handlabeler.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,62 @@
var/label = null
var/labels_left = 30
var/mode = LABEL_MODE_OFF
new_attack_chain = TRUE

/obj/item/hand_labeler/afterattack__legacy__attackchain(atom/A, mob/user, proximity)
if(!proximity)
return
if(mode == LABEL_MODE_OFF) //if it's off, give up.
return
/obj/item/hand_labeler/examine(mob/user)
. = ..()
. += "<span class='notice'>There [labels_left == 1 ? "is" : "are"] [labels_left] label\s remaining.</span>"
if(label)
. += "<span class='notice'>The label is currently set to \"[label]\".</span>"

/obj/item/hand_labeler/interact_with_atom(atom/target, mob/living/user, list/modifiers)
if(!mode == LABEL_MODE_OFF)
apply_label(target, user)
return ITEM_INTERACT_COMPLETE
if(remove_label(target, user))
return ITEM_INTERACT_COMPLETE

/obj/item/hand_labeler/proc/remove_label(atom/target, mob/living/user)
if(SEND_SIGNAL(target, COMSIG_LABEL_REMOVE)) // sends a signal to label.dm
playsound(target, 'sound/items/poster_ripped.ogg', 20, TRUE)
to_chat(user, "<span class='warning'>You remove the label from [target].</span>")
return TRUE

/obj/item/hand_labeler/proc/apply_label(atom/target, mob/living/user)
if(!labels_left)
to_chat(user, "<span class='warning'>No labels left!</span>")
return
if(!label || !length(label))
to_chat(user, "<span class='warning'>No text set!</span>")
return
if(ismob(A))
if(ismob(target))
to_chat(user, "<span class='warning'>You can't label creatures!</span>") // use a collar
return

if(mode == LABEL_MODE_GOAL)
if(istype(A, /obj/item))
if(istype(target, /obj/item))
to_chat(user, "<span class='warning'>Put it in a personal crate instead!</span>")
return
user.visible_message("<span class='notice'>[user] labels [A] as part of a secondary goal for [label].</span>", \
"<span class='notice'>You label [A] as part of a secondary goal for [label].</span>")
A.AddComponent(/datum/component/label/goal, label)
user.visible_message("<span class='notice'>[user] labels [target] as part of a secondary goal for [label].</span>", \
"<span class='notice'>You label [target] as part of a secondary goal for [label].</span>")
target.AddComponent(/datum/component/label/goal, label)
return

if(length(A.name) + length(label) > 64)
if(length(target.name) + length(label) > 64)
to_chat(user, "<span class='warning'>Label too big!</span>")
return

user.visible_message("<span class='notice'>[user] labels [A] as [label].</span>", \
"<span class='notice'>You label [A] as [label].</span>")
investigate_log("[key_name(user)] ([ADMIN_FLW(user,"FLW")]) labelled \"[A]\" ([ADMIN_VV(A, "VV")]) with \"[label]\" at [COORD(A.loc)] [ADMIN_JMP(A)].", INVESTIGATE_RENAME) // Investigate goes BEFORE rename so the original name is preserved in the log
A.AddComponent(/datum/component/label, label)
playsound(A, 'sound/items/handling/component_pickup.ogg', 20, TRUE)
user.visible_message("<span class='notice'>[user] labels [target] as [label].</span>", \
"<span class='notice'>You label [target] as [label].</span>")
investigate_log("[key_name(user)] ([ADMIN_FLW(user,"FLW")]) labelled \"[target]\" ([ADMIN_VV(target, "VV")]) with \"[label]\" at [COORD(target.loc)] [ADMIN_JMP(target)].", INVESTIGATE_RENAME) // Investigate goes BEFORE rename so the original name is preserved in the log
target.AddComponent(/datum/component/label, label)
playsound(target, 'sound/items/handling/component_pickup.ogg', 20, TRUE)
labels_left--

/obj/item/hand_labeler/attack_self__legacy__attackchain(mob/user as mob)
/obj/item/hand_labeler/activate_self(mob/user)
if(..())
return

// off -> normal
// normal or goal -> off
mode = !mode
Expand All @@ -65,22 +83,27 @@
else
to_chat(user, "<span class='notice'>You turn off \the [src].</span>")

/obj/item/hand_labeler/attackby__legacy__attackchain(obj/item/I, mob/user, params)
if(istype(I, /obj/item/hand_labeler_refill))
to_chat(user, "<span class='notice'>You insert [I] into [src].</span>")
/obj/item/hand_labeler/item_interaction(mob/living/user, obj/item/used, list/modifiers)
if(..())
return ITEM_INTERACT_COMPLETE

if(istype(used, /obj/item/hand_labeler_refill))
to_chat(user, "<span class='notice'>You insert [used] into [src].</span>")
user.drop_item()
qdel(I)
qdel(used)
labels_left = initial(labels_left) //Yes, it's capped at its initial value
else if(istype(I, /obj/item/card/id))
var/obj/item/card/id/id = I
return ITEM_INTERACT_COMPLETE
else if(istype(used, /obj/item/card/id))
var/obj/item/card/id/id = used
if(istype(id, /obj/item/card/id/guest) || !id.registered_name)
to_chat(user, "<span class='warning'>Invalid ID card.</span>")
return
label = id.registered_name
mode = LABEL_MODE_GOAL
to_chat(user, "<span class='notice'>You configure the hand labeler with [I].</span>")
icon_state = "labeler1"

return ITEM_INTERACT_COMPLETE
else
label = id.registered_name
mode = LABEL_MODE_GOAL
to_chat(user, "<span class='notice'>You configure the hand labeler with [used].</span>")
icon_state = "labeler1"
return ITEM_INTERACT_COMPLETE

/obj/item/hand_labeler_refill
name = "hand labeler paper roll"
Expand Down

0 comments on commit 166b1d5

Please sign in to comment.