mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-13 03:02:38 +00:00
* Refactor modular computer (and application) attackby into item_interaction (#84245)
## About The Pull Request
Sooooooooo I was recently notified of an issue (#84185) that popped up
from me replacing the `attackby(...)` chain on id cards, where it's no
longer possible to put money into IDs inside of PDAs by slapping it
against the PDA.
As I expected, this is because modular computers both still use
`attackby(...)`, and would call `attackby(...)` on the ID they contained
if hit with cash.
24a23009e8/code/modules/modular_computers/computers/item/computer.dm (L799)
Now this could've been an easy one line no-gbp fix where I just replace
it with a direct call to `insert_money(...)` on the ID and call it a
day!
But hey. Might as well get rid of the `attackby(...)` altogether while
we're at it.
First off, because the `attackby(...)` proc was getting quite bloated,
we split off all the specific item behaviours into `[X]_act(...)` type
procs to clean it up.
We then make those return item interaction flags, so we can call them on
`item_interaction(...)` after the right typecheck passes and immediately
return their results.
This also involves replacing the `application_attackby(...)` on
applications with an `application_item_interaction(...)`, and making it
return the item interaction flags too.
The code of each subsection isn't significantly different, though
reorganized a bit in some cases.
Like inserting a computer disks now tries to move it into the computer
_first_ before swapping out whichever disk is already in there, so it
doesn't swap out the disk if putting the new one in fails.
## Why It's Good For The Game
Fixes #84185.
Having more stuff be updated to the proper `item_interaction(...)`
system is cool and good.
* Refactor modular computer (and application) attackby into item_interaction
---------
Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com>
71 lines
2.6 KiB
Plaintext
71 lines
2.6 KiB
Plaintext
/datum/computer_file/program/maintenance/modsuit_control
|
|
filename = "modsuit_control"
|
|
filedesc = "MODsuit Control"
|
|
program_open_overlay = "modsuit_control"
|
|
downloader_category = PROGRAM_CATEGORY_EQUIPMENT
|
|
extended_desc = "This program allows people to connect a MODsuit to it, allowing remote control."
|
|
size = 2
|
|
tgui_id = "NtosMODsuit"
|
|
program_icon = "user-astronaut"
|
|
circuit_comp_type = /obj/item/circuit_component/mod_program/modsuit_control
|
|
|
|
///The suit we have control over.
|
|
var/obj/item/mod/control/controlled_suit
|
|
|
|
/datum/computer_file/program/maintenance/modsuit_control/Destroy()
|
|
if(controlled_suit)
|
|
unsync_modsuit()
|
|
return ..()
|
|
|
|
/datum/computer_file/program/maintenance/modsuit_control/application_item_interaction(mob/living/user, obj/item/tool, list/modifiers)
|
|
if(istype(tool, /obj/item/mod/control))
|
|
sync_modsuit(tool, user)
|
|
return ITEM_INTERACT_SUCCESS
|
|
|
|
/datum/computer_file/program/maintenance/modsuit_control/proc/sync_modsuit(obj/item/mod/control/new_modsuit, mob/living/user)
|
|
if(controlled_suit)
|
|
unsync_modsuit()
|
|
controlled_suit = new_modsuit
|
|
RegisterSignal(controlled_suit, COMSIG_QDELETING, PROC_REF(unsync_modsuit))
|
|
user?.balloon_alert(user, "suit updated")
|
|
|
|
/datum/computer_file/program/maintenance/modsuit_control/proc/unsync_modsuit(atom/source)
|
|
SIGNAL_HANDLER
|
|
UnregisterSignal(controlled_suit, COMSIG_QDELETING)
|
|
controlled_suit = null
|
|
|
|
/datum/computer_file/program/maintenance/modsuit_control/ui_data(mob/user)
|
|
var/list/data = list()
|
|
data["has_suit"] = !!controlled_suit
|
|
if(controlled_suit)
|
|
data += controlled_suit.ui_data()
|
|
return data
|
|
|
|
/datum/computer_file/program/maintenance/modsuit_control/ui_static_data(mob/user)
|
|
return controlled_suit?.ui_static_data()
|
|
|
|
/datum/computer_file/program/maintenance/modsuit_control/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
|
|
. = ..()
|
|
return controlled_suit?.ui_act(action, params, ui, state)
|
|
|
|
|
|
/obj/item/circuit_component/mod_program/modsuit_control
|
|
associated_program = /datum/computer_file/program/maintenance/modsuit_control
|
|
|
|
///Circuit port for loading a new suit to control
|
|
var/datum/port/input/suit_port
|
|
|
|
/obj/item/circuit_component/mod_program/modsuit_control/populate_ports()
|
|
. = ..()
|
|
suit_port = add_input_port("MODsuit Controlled", PORT_TYPE_ATOM)
|
|
|
|
/obj/item/circuit_component/mod_program/modsuit_control/input_received(datum/port/port)
|
|
var/datum/computer_file/program/maintenance/modsuit_control/control = associated_program
|
|
var/obj/item/mod/control/mod = suit_port.value
|
|
if(isnull(mod) && control.controlled_suit)
|
|
control.unsync_modsuit()
|
|
return
|
|
if(!istype(mod))
|
|
return
|
|
control.sync_modsuit(mod)
|