From 8e6aaf70c3ad8c34c998dc83254c009d4b90af98 Mon Sep 17 00:00:00 2001 From: Iamgoofball Date: Tue, 30 Jan 2018 10:16:39 -0800 Subject: [PATCH 1/2] Cleans up wirer code. (#35116) * Cleans up wirer code. :cl: Iamgoofball fix: Minor code cleanup on the wirer /:cl: --- .../integrated_electronics/core/wirer.dm | 97 ++++++++++--------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/code/modules/integrated_electronics/core/wirer.dm b/code/modules/integrated_electronics/core/wirer.dm index bfbbfa4864..bd54a7d8e6 100644 --- a/code/modules/integrated_electronics/core/wirer.dm +++ b/code/modules/integrated_electronics/core/wirer.dm @@ -22,59 +22,60 @@ if(!io.holder.assembly) to_chat(user, "\The [io.holder] needs to be secured inside an assembly first.") return - if(mode == WIRE) - selected_io = io - to_chat(user, "You attach a data wire to \the [selected_io.holder]'s [selected_io.name] data channel.") - mode = WIRING - update_icon() - else if(mode == 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 incompatable. 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) + switch(mode) + if(WIRE) + selected_io = 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. - selected_io = null - - else if(mode == UNWIRE) - selected_io = 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 - - else if(mode == 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].") + 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. selected_io = null - mode = UNWIRE + + if(UNWIRE) + selected_io = 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() - else - to_chat(user, "\The [selected_io.holder]'s [selected_io.name] and \the [io.holder]'s \ - [io.name] are not connected.") 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. + 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.") + return + /obj/item/device/integrated_electronics/wirer/attack_self(mob/user) switch(mode) if(WIRE) @@ -97,4 +98,4 @@ #undef WIRE #undef WIRING #undef UNWIRE -#undef UNWIRING \ No newline at end of file +#undef UNWIRING