Skip to content

Commit

Permalink
Adds the label component; Small tweaks to the hand labeler (tgstation…
Browse files Browse the repository at this point in the history
…#49700)

* Adds the label component

* switches to using RegisterWithParent / UnregisterFromParent

* Adds docs. Change Destroy() to qdel(src)
  • Loading branch information
spookydonut authored Mar 5, 2020
1 parent abad5db commit 50058b9
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
69 changes: 69 additions & 0 deletions code/datums/components/label.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
The label component.
This component is used to manage labels applied by the hand labeler.
Atoms can only have one instance of this component, and therefore only one label at a time.
This is to avoid having names like "Backpack (label1) (label2) (label3)". This is annoying and abnoxious to read.
When a player clicks the atom with a hand labeler to apply a label, this component gets applied to it.
If the labeler is off, the component will be removed from it, and the label will be removed from its name.
*/
/datum/component/label
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS
/// The name of the label the player is applying to the parent.
var/label_name

/datum/component/label/Initialize(_label_name)
if(!isatom(parent))
return COMPONENT_INCOMPATIBLE

label_name = _label_name

// Add the label to the name of the object in the format of: "Item name (label)"
var/atom/owner = parent
owner.name += " ([label_name])"

/datum/component/label/RegisterWithParent()
RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, .proc/RemoveLabel)
RegisterSignal(parent, COMSIG_PARENT_EXAMINE, .proc/Examine)

/datum/component/label/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_PARENT_ATTACKBY, COMSIG_PARENT_EXAMINE))

/**
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/RemoveLabel(datum/source, obj/item/attacker, mob/user)
// If the attacking object is not a hand labeler or its mode is 1 (has a label ready to apply), return.
// The hand labeler should be off (mode is 0), in order to remove a label.
var/obj/item/hand_labeler/labeler = attacker
if(!istype(labeler) || labeler.mode)
return

var/atom/owner = source // Source will be the owner / parent of this component.
owner.name = replacetext(owner.name, "([label_name])", "") // Remove the label text from the parent's name, wherever it may be.
owner.name = trim(owner.name) // Shave off any white space from the beginning or end of the parent's name.
playsound(owner, 'sound/items/poster_ripped.ogg', 20, TRUE)
to_chat(user, "<span class='warning'>You remove the label from [owner].</span>")
qdel(src) // Remove the component from the object.

/**
This proc will trigger when someone examines the parent.
It will attach the text found in the body of the proc to the `examine_list` and display it to the player examining the parent.
Arguments:
* source: The parent.
* user: The mob exmaining the parent.
* examine_list: The current list of text getting passed from the parent's normal examine() proc.
*/
/datum/component/label/proc/Examine(datum/source, mob/user, list/examine_list)
examine_list += "<span class='notice'>It has a label with some words written on it. Use a hand labeler to remove it.</span>"
9 changes: 5 additions & 4 deletions code/modules/paperwork/handlabeler.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/obj/item/hand_labeler
name = "hand labeler"
desc = "A combined label printer and applicator in a portable device, designed to be easy to operate and use."
desc = "A combined label printer, applicator, and remover, all in a single portable device. Designed to be easy to operate and use."
icon = 'icons/obj/bureaucracy.dmi'
icon_state = "labeler0"
item_state = "flight"
Expand Down Expand Up @@ -55,9 +55,10 @@
to_chat(user, "<span class='warning'>You can't label creatures!</span>") // use a collar
return

user.visible_message("<span class='notice'>[user] labels [A] as [label].</span>", \
"<span class='notice'>You label [A] as [label].</span>")
A.name = "[A.name] ([label])"
user.visible_message("<span class='notice'>[user] labels [A] with \"[label]\".</span>", \
"<span class='notice'>You label [A] with \"[label]\".</span>")
A.AddComponent(/datum/component/label, label)
playsound(A, 'sound/items/handling/component_pickup.ogg', 20, TRUE)
labels_left--


Expand Down
1 change: 1 addition & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@
#include "code\datums\components\jousting.dm"
#include "code\datums\components\knockback.dm"
#include "code\datums\components\knockoff.dm"
#include "code\datums\components\label.dm"
#include "code\datums\components\lifesteal.dm"
#include "code\datums\components\lockon_aiming.dm"
#include "code\datums\components\magnetic_catch.dm"
Expand Down

0 comments on commit 50058b9

Please sign in to comment.