Files
Bubberstation/code/game/objects/items/binoculars.dm
Watermelon914 375a20e49b Refactors most spans into span procs (#59645)
Converts most spans into span procs. Mostly used regex for this and sorted out any compile time errors afterwards so there could be some bugs.
Was initially going to do defines, but ninja said to make it into a proc, and if there's any overhead, they can easily be changed to defines.

Makes it easier to control the formatting and prevents typos when creating spans as it'll runtime if you misspell instead of silently failing.
Reduces the code you need to write when writing spans, as you don't need to close the span as that's automatically handled by the proc.

(Note from Lemon: This should be converted to defines once we update the minimum version to 514. Didn't do it now because byond pain and such)
2021-06-14 13:03:53 -07:00

63 lines
2.0 KiB
Plaintext

/obj/item/binoculars
name = "binoculars"
desc = "Used for long-distance surveillance."
inhand_icon_state = "binoculars"
icon_state = "binoculars"
worn_icon_state = "binoculars"
lefthand_file = 'icons/mob/inhands/items_lefthand.dmi'
righthand_file = 'icons/mob/inhands/items_righthand.dmi'
slot_flags = ITEM_SLOT_BELT
w_class = WEIGHT_CLASS_SMALL
var/mob/listeningTo
var/zoom_out_amt = 5.5
var/zoom_amt = 10
/obj/item/binoculars/Initialize()
. = ..()
RegisterSignal(src, COMSIG_TWOHANDED_WIELD, .proc/on_wield)
RegisterSignal(src, COMSIG_TWOHANDED_UNWIELD, .proc/on_unwield)
/obj/item/binoculars/ComponentInitialize()
. = ..()
AddComponent(/datum/component/two_handed, force_unwielded=8, force_wielded=12)
/obj/item/binoculars/Destroy()
listeningTo = null
return ..()
/obj/item/binoculars/proc/on_wield(obj/item/source, mob/user)
SIGNAL_HANDLER
RegisterSignal(user, COMSIG_MOVABLE_MOVED, .proc/on_walk)
RegisterSignal(user, COMSIG_ATOM_DIR_CHANGE, .proc/rotate)
listeningTo = user
user.visible_message(span_notice("[user] holds [src] up to [user.p_their()] eyes."), span_notice("You hold [src] up to your eyes."))
inhand_icon_state = "binoculars_wielded"
user.regenerate_icons()
user.client.view_size.zoomOut(zoom_out_amt, zoom_amt, user.dir)
/obj/item/binoculars/proc/rotate(atom/thing, old_dir, new_dir)
SIGNAL_HANDLER
if(ismob(thing))
var/mob/lad = thing
lad.regenerate_icons()
lad.client.view_size.zoomOut(zoom_out_amt, zoom_amt, new_dir)
/obj/item/binoculars/proc/on_walk()
SIGNAL_HANDLER
attack_self(listeningTo) //Yes I have sinned, why do you ask?
/obj/item/binoculars/proc/on_unwield(obj/item/source, mob/user)
SIGNAL_HANDLER
if(listeningTo)
UnregisterSignal(user, COMSIG_MOVABLE_MOVED)
UnregisterSignal(user, COMSIG_ATOM_DIR_CHANGE)
listeningTo = null
user.visible_message(span_notice("[user] lowers [src]."), span_notice("You lower [src]."))
inhand_icon_state = "binoculars"
user.regenerate_icons()
user.client.view_size.zoomIn()