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

Surface icon baking removal #59

Merged
merged 1 commit into from
Nov 12, 2023
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
157 changes: 5 additions & 152 deletions code/game/objects/structures/surface.dm
Original file line number Diff line number Diff line change
@@ -1,153 +1,14 @@
//Surface structures are structures that can have items placed on them
/obj/structure/surface
health = 100
var/list/update_types = list(
/obj/item/reagent_container/glass,
/obj/item/storage,
/obj/item/reagent_container/food/snacks
)
//add items there that behave like structures for whatever dumb reason
var/list/blacklisted_item_types = list(
/obj/item/device/radio/intercom,
/obj/item/device/sentry_computer
)

/obj/structure/surface/Initialize()
. = ..()
return INITIALIZE_HINT_LATELOAD

/obj/structure/surface/LateInitialize()
attach_all()
update_icon()

/obj/structure/surface/Destroy()
detach_all()
. = ..()

/obj/structure/surface/ex_act(severity, direction, datum/cause_data/cause_data)
health -= severity
if(health <= 0)
var/location = get_turf(src)
handle_debris(severity, direction)
detach_all()
for(var/obj/item/O in loc)
O.explosion_throw(severity, direction)
qdel(src)
if(prob(66))
create_shrapnel(location, rand(1,4), direction, , /datum/ammo/bullet/shrapnel/light, cause_data)
return TRUE

/obj/structure/surface/proc/attach_all()
for(var/obj/item/O in loc)
if(in_blacklist(O))
continue
attach_item(O, FALSE)
draw_item_overlays()

/obj/structure/surface/proc/in_blacklist(obj/item/O)
for(var/allowed_type in blacklisted_item_types)
if(istype(O, allowed_type))
return TRUE
return FALSE

/obj/structure/surface/proc/attach_item(obj/item/O, update = TRUE)
if(!O)
return
if(O.luminosity) //it can't make light as an overlay
return
O.forceMove(src)
RegisterSignal(O, COMSIG_ATOM_DECORATED, PROC_REF(decorate_update))
if(update)
draw_item_overlays()

/obj/structure/surface/proc/detach_item(obj/item/O)
O.scatter_item()
UnregisterSignal(O, COMSIG_ATOM_DECORATED)
draw_item_overlays()
return

/obj/structure/surface/proc/decorate_update(obj/item/O)
SIGNAL_HANDLER
draw_item_overlays()

/obj/structure/surface/proc/detach_all()
overlays.Cut()
for(var/obj/item/O in contents)
UnregisterSignal(O, COMSIG_ATOM_DECORATED)
O.forceMove(loc)

/obj/structure/surface/proc/get_item(list/click_data)
var/i = LAZYLEN(contents)
if(!click_data)
return
if(i < 1)
return FALSE
for(i, i >= 1, i--)//starting from the end because that's where the topmost is
var/obj/item/O = contents[i]
var/bounds_x = text2num(click_data["icon-x"])-1 - O.pixel_x
var/bounds_y = text2num(click_data["icon-y"])-1 - O.pixel_y
if(bounds_x < 0 || bounds_y < 0)
continue
var/icon/I = icon(O.icon, O.icon_state)
var/p = I.GetPixel(bounds_x, bounds_y)
if(p)
return O
return FALSE

/obj/structure/surface/proc/draw_item_overlays()
overlays.Cut()
for(var/obj/item/O in contents)
var/image/I = image(O.icon)
I.appearance = O.appearance
I.appearance_flags |= RESET_COLOR
I.overlays = O.overlays
LAZYADD(overlays, I)

/obj/structure/surface/clicked(mob/user, list/mods)
if(mods["shift"] && !mods["middle"])
var/obj/item/O = get_item(mods)
if(!O)
return ..()
if(O.can_examine(user))
O.examine(user)
return TRUE
..()

/obj/structure/surface/proc/try_to_open_container(mob/user, mods)
if(!Adjacent(user))
return

if(ishuman(user) || isrobot(user))
var/obj/item/O = get_item(mods)
if(O && isstorage(O))
var/obj/item/storage/S = O
S.open(usr)
return TRUE

/obj/structure/surface/attack_hand(mob/user, click_data)
. = ..()
if(click_data && click_data["alt"])
return
var/obj/item/O = get_item(click_data)
if(!O)
/obj/structure/surface/attackby(obj/item/W, mob/user, click_data)
if(!user.drop_inv_item_to_loc(W, loc))
return
O.attack_hand(user)
if(!LAZYISIN(contents, O))//in case attack_hand did not pick up the item
detach_item(O)

/obj/structure/surface/attackby(obj/item/W, mob/user, click_data)
var/obj/item/O = get_item(click_data)
if(!O || click_data["ctrl"])//holding the ctrl key will force it to place the object
// Placing stuff on tables
if(user.drop_inv_item_to_loc(W, loc))
auto_align(W, click_data)
user.next_move = world.time + 2
return TRUE
else if(!O.attackby(W, user))
W.afterattack(O, user, TRUE)
for(var/type in update_types)
if(istype(O, type))
draw_item_overlays()
auto_align(W, click_data)
user.next_move = world.time + 2
return TRUE

/obj/structure/surface/proc/auto_align(obj/item/W, click_data)
if(!W.center_of_mass) // Clothing, material stacks, generally items with large sprites where exact placement would be unhandy.
Expand All @@ -174,11 +35,3 @@
W.pixel_x = (CELLSIZE * (cell_x + 0.5)) - center["x"]
W.pixel_y = (CELLSIZE * (cell_y + 0.5)) - center["y"]
W.pixel_z = 0

if(!(W.flags_item & NOTABLEMERGE))
attach_item(W)

/obj/structure/surface/MouseDrop(atom/over)
. = ..()
if(over == usr && usr && usr.client && usr.client.lmb_last_mousedown_mods)
return try_to_open_container(usr, usr.client.lmb_last_mousedown_mods)
3 changes: 0 additions & 3 deletions code/game/objects/structures/tables_racks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,6 @@
verbs -= /obj/structure/surface/table/verb/do_flip
verbs += /obj/structure/surface/table/proc/do_put

detach_all()

var/list/targets = list(get_step(src, dir), get_step(src, turn(dir, 45)), get_step(src, turn(dir, -45)))
for(var/atom/movable/movable_on_table in get_turf(src))
if(!movable_on_table.anchored)
Expand Down Expand Up @@ -479,7 +477,6 @@
var/obj/structure/surface/table/T = locate() in get_step(src.loc,D)
if(T && T.flipped && T.dir == src.dir)
T.unflip()
attach_all()
update_icon()
update_adjacent()

Expand Down
3 changes: 0 additions & 3 deletions code/modules/vehicles/multitile/multitile_bump.dm
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,12 @@
return TRUE

/obj/structure/surface/handle_vehicle_bump(obj/vehicle/multitile/V)
detach_all()
playsound(V, 'sound/effects/metal_crash.ogg', 20)
visible_message(SPAN_DANGER("\The [V] crushes \the [src]!"))
qdel(src)
return TRUE

/obj/structure/surface/table/handle_vehicle_bump(obj/vehicle/multitile/V)
detach_all()
playsound(V, 'sound/effects/metal_crash.ogg', 20)
visible_message(SPAN_DANGER("\The [V] crushes \the [src]!"))
if(prob(50))
Expand All @@ -122,7 +120,6 @@
return TRUE

/obj/structure/surface/rack/handle_vehicle_bump(obj/vehicle/multitile/V)
detach_all()
playsound(V, 'sound/effects/metal_crash.ogg', 20)
visible_message(SPAN_DANGER("\The [V] crushes \the [src]!"))
deconstruct()
Expand Down
Loading