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

Stop portable machines updating their icon every atmos tick #27941

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
88 changes: 29 additions & 59 deletions code/modules/atmospherics/machinery/portable/canister.dm
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@

GLOBAL_DATUM_INIT(canister_icon_container, /datum/canister_icons, new())

#define HOLDING_TANK (1<<0)
#define CONNECTED_PORT (1<<1)
#define LOW_PRESSURE (1<<2)
#define NORMAL_PRESSURE (1<<3)
#define HIGH_PRESSURE (1<<4)
#define EXTREME_PRESSURE (1<<5)
#define NEW_COLOR (1<<6)
#define RESET (LOW_PRESSURE | NEW_COLOR)
#define LOW_PRESSURE 0
#define NORMAL_PRESSURE 1
#define HIGH_PRESSURE 2
#define EXTREME_PRESSURE 3

/obj/machinery/atmospherics/portable/canister
name = "canister"
Expand All @@ -71,9 +67,6 @@ GLOBAL_DATUM_INIT(canister_icon_container, /datum/canister_icons, new())
var/list/canister_color //variable that stores colours
var/list/color_index // list which stores tgui color indexes for the recoloring options, to enable previously-set colors to show up right

//lists for check_change()
var/list/old_color

//passed to the ui to render the color lists
var/list/colorcontainer

Expand All @@ -85,7 +78,7 @@ GLOBAL_DATUM_INIT(canister_icon_container, /datum/canister_icons, new())
power_state = NO_POWER_USE
interact_offline = TRUE
var/release_log = ""
var/update_flag = NONE
var/current_pressure_appearance

/obj/machinery/atmospherics/portable/canister/Initialize(mapload)
. = ..()
Expand All @@ -97,8 +90,6 @@ GLOBAL_DATUM_INIT(canister_icon_container, /datum/canister_icons, new())
"quart" = "none"
)

old_color = list()

colorcontainer = list(
"prim" = list(
"options" = GLOB.canister_icon_container.possiblemaincolor,
Expand Down Expand Up @@ -130,47 +121,25 @@ GLOBAL_DATUM_INIT(canister_icon_container, /datum/canister_icons, new())
if(isAntag(user))
. += "<span class='notice'>Canisters can be damaged, spilling their contents into the air, or you can just leave the release valve open.</span>"

/obj/machinery/atmospherics/portable/canister/proc/check_change()
var/old_flag = update_flag
update_flag = NONE
if(holding_tank)
update_flag |= HOLDING_TANK
if(connected_port)
update_flag |= CONNECTED_PORT

var/tank_pressure = air_contents.return_pressure()
/obj/machinery/atmospherics/portable/canister/proc/pressure_to_appearance(tank_pressure)
if(tank_pressure < 10)
update_flag |= LOW_PRESSURE
return LOW_PRESSURE
else if(tank_pressure < ONE_ATMOSPHERE)
update_flag |= NORMAL_PRESSURE
else if(tank_pressure < 15*ONE_ATMOSPHERE)
update_flag |= HIGH_PRESSURE
return NORMAL_PRESSURE
else if(tank_pressure < 15 * ONE_ATMOSPHERE)
return HIGH_PRESSURE
else
update_flag |= EXTREME_PRESSURE

if(list2params(old_color) != list2params(canister_color))
update_flag |= NEW_COLOR
old_color = canister_color.Copy()

if(update_flag == old_flag)
return FALSE
return TRUE
return EXTREME_PRESSURE

/obj/machinery/atmospherics/portable/canister/update_icon_state()
/*
(note: colors has to be applied every icon update)
*/

// Colors has to be applied every icon update
if(stat & BROKEN)
icon_state = "[canister_color["prim"]]-1"//yes, I KNOW the colours don't reflect when the can's borked, whatever.
return

if(icon_state != canister_color["prim"])
icon_state = canister_color["prim"]

if(!check_change()) //Returns FALSE if no change needed to icons.
return

/obj/machinery/atmospherics/portable/canister/update_overlays()
. = ..()
if(stat & BROKEN)
Expand All @@ -183,22 +152,20 @@ GLOBAL_DATUM_INIT(canister_icon_container, /datum/canister_icons, new())
continue
. += canister_color[C]

if(update_flag & HOLDING_TANK)
if(holding_tank)
. += "can-open"
if(update_flag & CONNECTED_PORT)
if(connected_port)
. += "can-connector"
if(update_flag & LOW_PRESSURE)

if(current_pressure_appearance == LOW_PRESSURE)
. += "can-o0"
if(update_flag & NORMAL_PRESSURE)
else if(current_pressure_appearance == NORMAL_PRESSURE)
. += "can-o1"
else if(update_flag & HIGH_PRESSURE)
else if(current_pressure_appearance == HIGH_PRESSURE)
. += "can-o2"
else if(update_flag & EXTREME_PRESSURE)
else if(current_pressure_appearance == EXTREME_PRESSURE)
. += "can-o3"

update_flag &= ~RESET //the flag NEW_COLOR represents change, not states. As such, we have to reset them to be able to detect a change on the next go.
return

/obj/machinery/atmospherics/portable/canister/temperature_expose(datum/gas_mixture/air, exposed_temperature, exposed_volume)
..()
if(exposed_temperature > temperature_resistance)
Expand Down Expand Up @@ -234,8 +201,15 @@ GLOBAL_DATUM_INIT(canister_icon_container, /datum/canister_icons, new())

T.blind_release_air(expelled_gas)

/obj/machinery/atmospherics/portable/canister/proc/sync_pressure_appearance()
var/new_pressure_appearance = pressure_to_appearance(air_contents.return_pressure())
if(current_pressure_appearance != new_pressure_appearance)
current_pressure_appearance = new_pressure_appearance
update_icon()

/obj/machinery/atmospherics/portable/canister/process_atmos()
..()
sync_pressure_appearance()
var/datum/milla_safe/canister_process/milla = new()
milla.invoke_async(src)

Expand Down Expand Up @@ -265,8 +239,7 @@ GLOBAL_DATUM_INIT(canister_icon_container, /datum/canister_icons, new())
var/datum/gas_mixture/removed = canister.air_contents.remove(transfer_moles)

environment.merge(removed)
canister.update_icon()

canister.sync_pressure_appearance()

if(canister.air_contents.return_pressure() < 1)
canister.can_label = TRUE
Expand Down Expand Up @@ -357,6 +330,7 @@ GLOBAL_DATUM_INIT(canister_icon_container, /datum/canister_icons, new())
name = T
else
name = "canister"
update_appearance(UPDATE_NAME)
else
to_chat(ui.user, "<span class='warning'>As you attempted to rename it the pressure rose!</span>")
. = FALSE
Expand Down Expand Up @@ -424,9 +398,9 @@ GLOBAL_DATUM_INIT(canister_icon_container, /datum/canister_icons, new())
color_index[ctype] = newcolor
newcolor++ // javascript starts arrays at 0, byond (for some reason) starts them at 1, this converts JS values to byond values
canister_color[ctype] = colorcontainer[ctype]["options"][newcolor]["icon"]
update_icon()

add_fingerprint(ui.user)
update_icon()

/obj/machinery/atmospherics/portable/canister/atmos_init()
. = ..()
Expand Down Expand Up @@ -532,11 +506,7 @@ GLOBAL_DATUM_INIT(canister_icon_container, /datum/canister_icons, new())
new /obj/item/stack/sheet/metal(drop_location(), 3)
qdel(src)

#undef HOLDING_TANK
#undef CONNECTED_PORT
#undef LOW_PRESSURE
#undef NORMAL_PRESSURE
#undef HIGH_PRESSURE
#undef EXTREME_PRESSURE
#undef NEW_COLOR
#undef RESET
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
air_contents.react()
return

update_icon()

/obj/machinery/atmospherics/portable/Destroy()
SSair.atmos_machinery -= src
disconnect()
Expand Down Expand Up @@ -70,6 +68,8 @@

anchored = TRUE //Prevent movement

update_icon()

return TRUE

/obj/machinery/atmospherics/portable/disconnect()
Expand All @@ -81,6 +81,8 @@
connected_port.connected_device = null
connected_port = null

update_icon()

return TRUE

/obj/machinery/atmospherics/portable/portableConnectorReturnAir()
Expand Down
Loading