Skip to content

Commit

Permalink
Misc refactors
Browse files Browse the repository at this point in the history
Made `/mob/living/carbon/human/auto_observed()` just get the target's active inventory rather than looping through their contents.
Also made build mode not show to observing players.
  • Loading branch information
SabreML committed Feb 19, 2024
1 parent bd1e3ed commit ead2cdd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
35 changes: 18 additions & 17 deletions code/modules/mob/dead/observer/observer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -188,37 +188,38 @@
clean_observe_target()

/// When the observer target gets a screen, our observer gets a screen minus some game screens we don't want the observer to touch
/mob/dead/observer/proc/observe_target_screen_add(observe_target_mob_client, add_to_screen)
/mob/dead/observer/proc/observe_target_screen_add(observe_target_mob_client, screen_add)
SIGNAL_HANDLER

if(!client)
return

if(istype(add_to_screen, /atom/movable/screen/action_button))
return

if(istype(add_to_screen, /atom/movable/screen/fullscreen))
return
var/static/list/excluded_types = typecacheof(list(
/atom/movable/screen/fullscreen,
/atom/movable/screen/click_catcher,
/atom/movable/screen/escape_menu,
/atom/movable/screen/buildmode,
/obj/effect/detector_blip,
))

if(istype(add_to_screen, /atom/movable/screen/click_catcher))
if(!client)
return

if(istype(add_to_screen, /atom/movable/screen/escape_menu))
return
// `screen_add` can sometimes be a list, so it's safest to just handle everything as one.
var/list/stuff_to_add = (islist(screen_add) ? screen_add : list(screen_add))

if(istype(add_to_screen, /obj/effect/detector_blip))
return
for(var/item in stuff_to_add)
// Ignore anything that's in `excluded_types`.
if(is_type_in_typecache(item, excluded_types))
continue

client.add_to_screen(add_to_screen)
client.add_to_screen(screen_add)

/// When the observer target loses a screen, our observer loses it as well
/mob/dead/observer/proc/observe_target_screen_remove(observe_target_mob_client, remove_from_screen)
/mob/dead/observer/proc/observe_target_screen_remove(observe_target_mob_client, screen_remove)
SIGNAL_HANDLER

if(!client)
return

client.remove_from_screen(remove_from_screen)
client.remove_from_screen(screen_remove)

/// When the observe target ghosts our observer disconnect from their screen updates
/mob/dead/observer/proc/observe_target_ghosting(mob/observer_target_mob)
Expand Down
31 changes: 14 additions & 17 deletions code/modules/mob/living/carbon/human/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -317,25 +317,22 @@
/mob/living/carbon/human/auto_observed(mob/dead/observer/observer)
. = ..()

var/list/all_contents = get_contents()

// Handle any currently open storage containers `src` is looking at when observed.
for(var/obj/item/storage/checked_storage in all_contents)
if(!(src in checked_storage.content_watchers))
continue
// If `src` doesn't have an inventory open.
if(!s_active)
return

observer.client.add_to_screen(checked_storage.closer)
observer.client.add_to_screen(checked_storage.contents)
// Add the storage interface to `observer`'s screen.
observer.client.add_to_screen(s_active.closer)
observer.client.add_to_screen(s_active.contents)

if(checked_storage.storage_slots)
observer.client.add_to_screen(checked_storage.boxes)
else
observer.client.add_to_screen(checked_storage.storage_start)
observer.client.add_to_screen(checked_storage.storage_continue)
observer.client.add_to_screen(checked_storage.storage_end)

// Players are only able to look in one inventory at a time, so skip any others.
break
// If the storage has a set number of item slots.
if(s_active.storage_slots)
observer.client.add_to_screen(s_active.boxes)
// If the storage instead has a maximum combined item 'weight'.
else
observer.client.add_to_screen(s_active.storage_start)
observer.client.add_to_screen(s_active.storage_continue)
observer.client.add_to_screen(s_active.storage_end)

// called when something steps onto a human
// this handles mulebots and vehicles
Expand Down

0 comments on commit ead2cdd

Please sign in to comment.