#define WIRE "wire"
#define WIRING "wiring"
#define UNWIRE "unwire"
#define UNWIRING "unwiring"
/obj/item/integrated_electronics/wirer
name = "circuit wirer"
desc = "It's a small wiring tool, with a wire roll, electric soldering iron, wire cutter, and more in one package. \
The wires used are generally useful for small electronics, such as circuitboards and breadboards, as opposed to larger wires \
used for power or data transmission."
icon = 'icons/obj/integrated_electronics/electronic_tools.dmi'
icon_state = "wirer-wire"
item_state = "wirer"
w_class = WEIGHT_CLASS_SMALL
belt_storage_class = BELT_CLASS_SMALL
var/mode = WIRE
var/datum/weakref/selected_io_weakref
/obj/item/integrated_electronics/wirer/proc/get_ic_selected_io() as /datum/integrated_io
return selected_io_weakref?.resolve()
/obj/item/integrated_electronics/wirer/proc/set_ic_selected_io(datum/integrated_io/selecting)
if(!selecting)
selected_io_weakref = null
selected_io_weakref = WEAKREF(selecting)
/obj/item/integrated_electronics/wirer/update_icon()
icon_state = "wirer-[mode]"
/obj/item/integrated_electronics/wirer/proc/wire(var/datum/integrated_io/io, mob/user)
var/datum/integrated_io/selected_io = get_ic_selected_io()
if(!io.holder.assembly)
to_chat(user, "\The [io.holder] needs to be secured inside an assembly first.")
return
switch(mode)
if(WIRE)
set_ic_selected_io(io)
selected_io = get_ic_selected_io()
to_chat(user, "You attach a data wire to \the [selected_io.holder]'s [selected_io.name] data channel.")
mode = WIRING
update_icon()
if(WIRING)
if(io == selected_io)
to_chat(user, "Wiring \the [selected_io.holder]'s [selected_io.name] into itself is rather pointless.")
return
if(io.io_type != selected_io.io_type)
to_chat(user, "Those two types of channels are incompatible. The first is a [selected_io.io_type], \
while the second is a [io.io_type].")
return
if(io.holder.assembly && io.holder.assembly != selected_io.holder.assembly)
to_chat(user, "Both \the [io.holder] and \the [selected_io.holder] need to be inside the same assembly.")
return
selected_io.connect_pin(io)
to_chat(user, "You connect \the [selected_io.holder]'s [selected_io.name] to \the [io.holder]'s [io.name].")
mode = WIRE
update_icon()
selected_io.holder.interact(user) // This is to update the UI.
set_ic_selected_io(null)
if(UNWIRE)
set_ic_selected_io(io)
selected_io = get_ic_selected_io()
if(!io.linked.len)
to_chat(user, "There is nothing connected to \the [selected_io] data channel.")
selected_io = null
return
to_chat(user, "You prepare to detach a data wire from \the [selected_io.holder]'s [selected_io.name] data channel.")
mode = UNWIRING
update_icon()
return
if(UNWIRING)
if(io == selected_io)
to_chat(user, "You can't wire a pin into each other, so unwiring \the [selected_io.holder] from \
the same pin is rather moot.")
return
if(selected_io in io.linked)
selected_io.disconnect_pin(io)
to_chat(user, "You disconnect \the [selected_io.holder]'s [selected_io.name] from \
\the [io.holder]'s [io.name].")
selected_io.holder.interact(user) // This is to update the UI.
set_ic_selected_io(null)
mode = UNWIRE
update_icon()
else
to_chat(user, "\The [selected_io.holder]'s [selected_io.name] and \the [io.holder]'s \
[io.name] are not connected.")
/obj/item/integrated_electronics/wirer/attack_self(mob/user, datum/event_args/actor/actor)
. = ..()
if(.)
return
var/datum/integrated_io/selected_io = get_ic_selected_io()
switch(mode)
if(WIRE)
mode = UNWIRE
if(WIRING)
if(selected_io)
to_chat(user, "You decide not to wire the data channel.")
set_ic_selected_io(null)
mode = WIRE
if(UNWIRE)
mode = WIRE
if(UNWIRING)
if(selected_io)
to_chat(user, "You decide not to disconnect the data channel.")
set_ic_selected_io(null)
mode = UNWIRE
update_icon()
to_chat(user, "You set \the [src] to [mode].")
#undef WIRE
#undef WIRING
#undef UNWIRE
#undef UNWIRING