Skip to content

Commit

Permalink
[PORT] Lightswitch context and deconstruction from TG (PR#79416) (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
TyrantCerberus authored Jun 1, 2024
1 parent da0e8a2 commit e291aa9
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions code/game/machinery/lightswitch.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
var/area/area = null
///Range of the light emitted when powered, but off
var/light_on_range = 1
/// Should this lightswitch automatically rename itself to match the area it's in?
var/autoname = TRUE

/obj/machinery/light_switch/Initialize(mapload)
. = ..()
Expand All @@ -30,11 +32,22 @@ MAPPING_DIRECTIONAL_HELPERS_ROBUST(/obj/machinery/light_switch, 32, -18, 33, -33
if(!area)
area = get_area(src)

if(!name)
name = "light switch ([area.name])"
if(autoname)
name = "[area.name] light switch"

register_context()
update_appearance()

/obj/machinery/light_switch/add_context(atom/source, list/context, obj/item/held_item, mob/user)
. = ..()
if(isnull(held_item))
context[SCREENTIP_CONTEXT_LMB] = area.lightswitch ? "Flick off" : "Flick on"
return CONTEXTUAL_SCREENTIP_SET
if(held_item.tool_behaviour == TOOL_SCREWDRIVER)
context[SCREENTIP_CONTEXT_RMB] = "Deconstruct"
return CONTEXTUAL_SCREENTIP_SET
return .

/obj/machinery/light_switch/update_appearance(updates=ALL)
. = ..()
luminosity = (machine_stat & NOPOWER) ? 0 : 1
Expand All @@ -57,11 +70,19 @@ MAPPING_DIRECTIONAL_HELPERS_ROBUST(/obj/machinery/light_switch, 32, -18, 33, -33
/obj/machinery/light_switch/examine(mob/user)
. = ..()
. += "It is [(machine_stat & NOPOWER) ? "unpowered" : (area.lightswitch ? "on" : "off")]."
. += span_notice("It is <b>screwed</b> in place.")

/obj/machinery/light_switch/interact(mob/user)
. = ..()
set_lights(!area.lightswitch)

/obj/machinery/light_switch/attackby_secondary(obj/item/weapon, mob/user, params)
if(weapon.tool_behaviour == TOOL_SCREWDRIVER)
to_chat(user, "You pop \the [src] off the wall.")
deconstruct()
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
return ..()

/obj/machinery/light_switch/proc/set_lights(status)
if(area.lightswitch == status)
return
Expand Down

0 comments on commit e291aa9

Please sign in to comment.