Files
Bubberstation/code/game/objects/structures/table_frames.dm
_0Steven 3b73af32c5 Table frame interaction refactor (#89880)
## About The Pull Request

So I was looking for `attackby(...)` instances to kill and, hey look,
table frames- oh what the fuck is this.
Oh why does this have the same checks like five times, across the parent
type and subtypes.

So this pr's primary point is to refactor the table frame
`attackby(...)` into `item_interaction(...)`, and by extension lower the
amount of weird `attackby(...)` override jank going on with them.
Instead of having all of the subtypes define their own almost exactly
the same table construction interactions, we use a single generic
interaction chain and add a new `get_table_type(...)` proc to let
subtypes override what tables to construct for what stacks.

We also move the assigning of frame-and-stack-related things to the
actual table types themselves, instead of specifying all these
interactions on the frame.

We also add screentips for deconstruction and table construction, again
using the `get_table_type(...)` proc so screentips can differentiate
between which stacks can and can't make a table for our table without
needing to change the screentips manually for the subtypes.

Beyond that is mostly generic clean-up.

I'm a bit icky on my implementation of
`/obj/item/stack/proc/get_table_type()`, because of hardcoding for
`/obj/structure/table/greyscale`, but I think it's better than the
alternatives.
This lets us use the old method of letting all `/obj/item/stack/sheet`
subtypes use the generic material table, but limit it to working as long
as they define a `material_type`. I feel it's better than letting broken
tables exist, needing to hardcode it on the table frame, or needing to
expect people to add the generic material table `table_type` whenever
they add a `material_type` (no one would do this).
## Why It's Good For The Game

Screentips good 👍
Less jank encountered good.
Specifically the inability to deconstruct table frames on right click
when tables can be deconstructed on right click has thrown me off so
many times it's wild.
## Changelog
🆑
refactor: Refactored table frame interactions, please report any issues.
fix: You can no longer make material-less material tables out of certain
items.
fix: Fancy tables remember which carpet was used to make them, and no
longer magically transmute carpets into simpler types.
fix: You can no longer stack abductor table frame-using tables
specifically.
qol: Added screentips for deconstructing table frames and constructing
tables out of them if the material you're holding can do so.
qol: Table frames can now also be deconstructed on right click for
parity with tables, in addition to left click.
qol: Table frame interactions use balloon alerts.
/🆑
2025-03-17 02:14:43 +01:00

106 lines
3.1 KiB
Plaintext

/* Table Frames
* Contains:
* Frames
* Wooden Frames
*/
/*
* Normal Frames
*/
/obj/structure/table_frame
name = "table frame"
desc = "Four metal legs with four framing rods for a table. You could easily pass through this."
icon = 'icons/obj/structures.dmi'
icon_state = "table_frame"
density = FALSE
anchored = FALSE
layer = PROJECTILE_HIT_THRESHHOLD_LAYER
max_integrity = 100
var/framestack = /obj/item/stack/rods
var/framestackamount = 2
/obj/structure/table_frame/Initialize(mapload)
. = ..()
register_context()
/obj/structure/table_frame/add_context(atom/source, list/context, obj/item/held_item, mob/living/user)
if(isnull(held_item))
return NONE
if(held_item.tool_behaviour == TOOL_WRENCH)
context[SCREENTIP_CONTEXT_LMB] = "Deconstruct"
context[SCREENTIP_CONTEXT_RMB] = "Deconstruct"
return CONTEXTUAL_SCREENTIP_SET
if(isstack(held_item) && get_table_type(held_item))
context[SCREENTIP_CONTEXT_LMB] = "Construct table"
return CONTEXTUAL_SCREENTIP_SET
/obj/structure/table_frame/wrench_act(mob/living/user, obj/item/tool)
balloon_alert(user, "deconstructing...")
tool.play_tool_sound(src)
if(!tool.use_tool(src, user, 3 SECONDS))
return ITEM_INTERACT_BLOCKING
playsound(loc, 'sound/items/deconstruct.ogg', 50, TRUE)
deconstruct(TRUE)
return ITEM_INTERACT_SUCCESS
/obj/structure/table_frame/wrench_act_secondary(mob/living/user, obj/item/tool)
return wrench_act(user, tool)
/obj/structure/table_frame/item_interaction(mob/living/user, obj/item/tool, list/modifiers)
if(!isstack(tool))
return NONE
var/obj/item/stack/our_stack = tool
var/table_type = get_table_type(our_stack)
if(isnull(table_type))
return NONE
if(our_stack.get_amount() < 1)
balloon_alert(user, "need more material!")
return ITEM_INTERACT_BLOCKING
if(locate(/obj/structure/table) in loc)
balloon_alert(user, "can't stack tables!")
return ITEM_INTERACT_BLOCKING
balloon_alert(user, "constructing table...")
if(!do_after(user, 2 SECONDS, target = src))
return ITEM_INTERACT_BLOCKING
if((locate(/obj/structure/table) in loc) || !our_stack.use(1))
return ITEM_INTERACT_BLOCKING
new table_type(loc, src, our_stack)
qdel(src)
return ITEM_INTERACT_SUCCESS
/// Gets the table type we make with our given stack.
/obj/structure/table_frame/proc/get_table_type(obj/item/stack/our_stack)
return our_stack.get_table_type()
/obj/structure/table_frame/atom_deconstruct(disassembled = TRUE)
new framestack(get_turf(src), framestackamount)
/obj/structure/table_frame/narsie_act()
new /obj/structure/table_frame/wood(src.loc)
qdel(src)
/*
* Wooden Frames
*/
/obj/structure/table_frame/wood
name = "wooden table frame"
desc = "Four wooden legs with four framing wooden rods for a wooden table. You could easily pass through this."
icon_state = "wood_frame"
framestack = /obj/item/stack/sheet/mineral/wood
framestackamount = 2
resistance_flags = FLAMMABLE
/obj/structure/table_frame/wood/get_table_type(obj/item/stack/our_stack)
if(istype(our_stack, /obj/item/stack/sheet/mineral/wood))
return /obj/structure/table/wood
if(istype(our_stack, /obj/item/stack/tile/carpet))
return /obj/structure/table/wood/poker