Files
fulpstation/code/modules/paperwork/handlabeler.dm
MrPerson f7eb2c905b Unicode awareness Part 2 -- copytext() (#48512)
* Unicode support Part 2 -- copytext()

This is the transition of all copytext() calls to be unicode aware and also some nearby calls in the same functions. Most things are just replacing copytext() with copytext_char() as a terrible character limiter but a few others were slightly more involved.

I replaced a ton of
````
var/something = sanitize(input())
something = copytext(something, 1, MAX_MESSAGE_LEN)
````

with a single stripped_input() call. stripped_input() already calls html_encode(), trim(), and some other sanitization so there shouldn't be any major issues there.

This is still VERY rough btw; DNA is a mess, the status displays are complete ass, there's a copytext() in code\datums\shuttles.dm that I'm not sure what to do with, and I didn't touch anything in the tools folder. I haven't tested this much at all yet, I only got it to compile earlier this morning. There's also likely to be weird bugs until I get around to fixing length(), findtext(), and the rest of the string procs.

* Makes the code functional

* Assume color hex strings are always # followed by ascii.
Properly encodes and decodes the stuff in mob_helpers.dm which fixes some issues there.

* Removes ninjaspeak since it's unused
2020-01-18 13:07:22 +13:00

122 lines
3.9 KiB
Plaintext

/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."
icon = 'icons/obj/bureaucracy.dmi'
icon_state = "labeler0"
item_state = "flight"
var/label = null
var/labels_left = 30
var/mode = 0
/obj/item/hand_labeler/suicide_act(mob/user)
user.visible_message("<span class='suicide'>[user] is pointing [src] at [user.p_them()]self. [user.p_theyre(TRUE)] going to label [user.p_them()]self as a suicide!</span>")
labels_left = max(labels_left - 1, 0)
var/old_real_name = user.real_name
user.real_name += " (suicide)"
// no conflicts with their identification card
for(var/atom/A in user.GetAllContents())
if(istype(A, /obj/item/card/id))
var/obj/item/card/id/their_card = A
// only renames their card, as opposed to tagging everyone's
if(their_card.registered_name != old_real_name)
continue
their_card.registered_name = user.real_name
their_card.update_label()
// NOT EVEN DEATH WILL TAKE AWAY THE STAIN
user.mind.name += " (suicide)"
mode = 1
icon_state = "labeler[mode]"
label = "suicide"
return OXYLOSS
/obj/item/hand_labeler/afterattack(atom/A, mob/user,proximity)
. = ..()
if(!proximity)
return
if(!mode) //if it's off, give up.
return
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(length(A.name) + length(label) > 64)
to_chat(user, "<span class='warning'>Label too big!</span>")
return
if(ismob(A))
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])"
labels_left--
/obj/item/hand_labeler/attack_self(mob/user)
if(!user.IsAdvancedToolUser())
to_chat(user, "<span class='warning'>You don't have the dexterity to use [src]!</span>")
return
mode = !mode
icon_state = "labeler[mode]"
if(mode)
to_chat(user, "<span class='notice'>You turn on [src].</span>")
//Now let them chose the text.
var/str = reject_bad_text(stripped_input(user, "Label text?", "Set label","", MAX_NAME_LEN))
if(!str || !length(str))
to_chat(user, "<span class='warning'>Invalid text!</span>")
return
label = str
to_chat(user, "<span class='notice'>You set the text to '[str]'.</span>")
else
to_chat(user, "<span class='notice'>You turn off [src].</span>")
/obj/item/hand_labeler/attackby(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>")
qdel(I)
labels_left = initial(labels_left) //Yes, it's capped at its initial value
/obj/item/hand_labeler/borg
name = "cyborg-hand labeler"
/obj/item/hand_labeler/borg/afterattack(atom/A, mob/user, proximity)
. = ..()
if(!proximity)
return
if(!iscyborg(user))
return
var/mob/living/silicon/robot/borgy = user
var/starting_labels = initial(labels_left)
var/diff = starting_labels - labels_left
if(diff)
labels_left = starting_labels
// 50 per label. Magical cyborg paper doesn't come cheap.
var/cost = diff * 50
// If the cyborg manages to use a module without a cell, they get the paper
// for free.
if(borgy.cell)
borgy.cell.use(cost)
/obj/item/hand_labeler_refill
name = "hand labeler paper roll"
icon = 'icons/obj/bureaucracy.dmi'
desc = "A roll of paper. Use it on a hand labeler to refill it."
icon_state = "labeler_refill"
item_state = "electropack"
lefthand_file = 'icons/mob/inhands/misc/devices_lefthand.dmi'
righthand_file = 'icons/mob/inhands/misc/devices_righthand.dmi'
w_class = WEIGHT_CLASS_TINY