Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help delete programs on modular computers #20580

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
to_chat(user, SPAN_WARNING("\The [src]'s screen displays, \"I/O ERROR - Unable to run [prog]\"."))
return

P.computer = src
P.set_computer(src)

if(!P.is_supported_by_hardware(hardware_flag, TRUE, user))
return
Expand Down Expand Up @@ -501,7 +501,7 @@
if(QDELETED(S))
return

S.computer = src
S.set_computer(src)

if(!S.is_supported_by_hardware(hardware_flag, 1, user))
return
Expand Down
45 changes: 41 additions & 4 deletions code/modules/modular_computers/file_system/program.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ ABSTRACT_TYPE(/datum/computer_file/program)
/// PROGRAM_STATE_KILLED or PROGRAM_STATE_BACKGROUND or PROGRAM_STATE_ACTIVE - specifies whether this program is running.
var/program_state = PROGRAM_STATE_KILLED

/// Device that runs this program.
/**
* The device that runs this program
*
* **Only supported way to set this is by calling set_computer()**
*/
var/obj/item/modular_computer/computer

/// Short description of this program's function.
Expand Down Expand Up @@ -86,13 +90,13 @@ ABSTRACT_TYPE(/datum/computer_file/program)
var/datum/nano_module/NM // If the program uses NanoModule, put it here and it will be automagically opened. Otherwise implement ui_interact.
var/nanomodule_path // Path to nanomodule, make sure to set this if implementing new program.

/datum/computer_file/program/New(var/obj/item/modular_computer/comp)
/datum/computer_file/program/New(obj/item/modular_computer/comp)
..()
if(comp)
if(comp == "Compless") // we're software in the air, don't need a computer
return
else if(istype(comp))
computer = comp
set_computer(comp)
else
crash_with("Comp was of the wrong type for [src.filename]")
else
Expand All @@ -102,7 +106,7 @@ ABSTRACT_TYPE(/datum/computer_file/program)
if(!QDELETED(computer))
computer.idle_threads -= src
computer.enabled_services -= src
computer = null
set_computer(null)
. = ..()
GC_TEMPORARY_HARDDEL

Expand Down Expand Up @@ -139,6 +143,39 @@ ABSTRACT_TYPE(/datum/computer_file/program)
temp.usage_flags = usage_flags
return temp

/**
* Sets the computer this program is running on
*
* * computer - The computer to set this program to, or `null` to remove it
*/
/datum/computer_file/program/proc/set_computer(obj/item/modular_computer/computer)
SHOULD_NOT_SLEEP(TRUE)

//Not setting something already being deleted
if(istype(computer) && QDELETED(computer))
return

//It's already the same
if(src.computer == computer)
return

//Stop listening for the old computer
if(istype(src.computer))
UnregisterSignal(src.computer, COMSIG_QDELETING)

src.computer = computer

//Start listening for the new computer, if it's one
if(istype(computer))
RegisterSignal(computer, COMSIG_QDELETING, PROC_REF(on_computer_deleted))

/**
* Handles signal when the computer we are referencing is deleted
*/
/datum/computer_file/program/proc/on_computer_deleted()
SIGNAL_HANDLER
qdel(src)

// Relays icon update to the computer.
/datum/computer_file/program/proc/update_computer_icon()
if(computer)
Expand Down
58 changes: 58 additions & 0 deletions html/changelogs/fluffyghost-helpdeleteprograms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
################################
# Example Changelog File
#
# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
#
# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
# When it is, any changes listed below will disappear.
#
# Valid Prefixes:
# bugfix
# - (fixes bugs)
# wip
# - (work in progress)
# qol
# - (quality of life)
# soundadd
# - (adds a sound)
# sounddel
# - (removes a sound)
# rscadd
# - (adds a feature)
# rscdel
# - (removes a feature)
# imageadd
# - (adds an image or sprite)
# imagedel
# - (removes an image or sprite)
# spellcheck
# - (fixes spelling or grammar)
# experiment
# - (experimental change)
# balance
# - (balance changes)
# code_imp
# - (misc internal code change)
# refactor
# - (refactors code)
# config
# - (makes a change to the config files)
# admin
# - (makes changes to administrator tools)
# server
# - (miscellaneous changes to server)
#################################

# Your name.
author: FluffyGhost

# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
delete-after: True

# Any changes you've made. See valid prefix list above.
# INDENT WITH TWO SPACES. NOT TABS. SPACES.
# SCREW THIS UP AND IT WON'T WORK.
# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit.
# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog.
changes:
- code_imp: "Hopefully helps fixes some hard references being left when deleting modular computers, in their programs."
Loading