Skip to content

Commit

Permalink
Surface icon baking removal (#4894)
Browse files Browse the repository at this point in the history
# About the pull request

I am taking Morrow's PR:
cmss13-devs/cmss13-pve#59

# Explain why it's good for the game

Allows you to right-click the table and see all its contents

# Changelog

:cl:
del: Removes icon baking on surfaces (primarily seen on tables)
/:cl:
  • Loading branch information
BeagleGaming1 committed Nov 13, 2023
1 parent 387c021 commit 9be06a2
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 174 deletions.
4 changes: 1 addition & 3 deletions code/__DEFINES/equipment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@
#define CAN_DIG_SHRAPNEL (1<<11)
/// whether it has an animated icon state of "[icon_state]_on" to be used during surgeries.
#define ANIMATED_SURGICAL_TOOL (1<<12)
/// The item goes on top of tables, instead of into them with the overlay system
#define NOTABLEMERGE (1<<13)
/// Has heat source but isn't 'on fire' and thus can be stored
#define IGNITING_ITEM (1<<14)
#define IGNITING_ITEM (1<<13)
//==========================================================================================


Expand Down
1 change: 0 additions & 1 deletion code/_globalvars/bitfields.dm
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ DEFINE_BITFIELD(flags_item, list(
"ITEM_OVERRIDE_NORTHFACE" = ITEM_OVERRIDE_NORTHFACE,
"CAN_DIG_SHRAPNEL" = CAN_DIG_SHRAPNEL,
"ANIMATED_SURGICAL_TOOL" = ANIMATED_SURGICAL_TOOL,
"NOTABLEMERGE" = NOTABLEMERGE,
"IGNITING_ITEM" = IGNITING_ITEM,
))

Expand Down
2 changes: 0 additions & 2 deletions code/game/objects/items/toys/cards.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
icon = 'icons/obj/items/playing_cards.dmi'
icon_state = "deck"
w_class = SIZE_TINY
flags_item = NOTABLEMERGE

var/base_icon = "deck"
var/max_cards = 52
Expand Down Expand Up @@ -262,7 +261,6 @@
icon = 'icons/obj/items/playing_cards.dmi'
icon_state = "empty"
w_class = SIZE_TINY
flags_item = NOTABLEMERGE

var/concealed = FALSE
var/pile_state = FALSE
Expand Down
175 changes: 14 additions & 161 deletions code/game/objects/structures/surface.dm
Original file line number Diff line number Diff line change
@@ -1,159 +1,20 @@
//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)
/obj/structure/surface/attackby(obj/item/attacking_item, mob/user, click_data)
if(!user.drop_inv_item_to_loc(attacking_item, loc))
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)
auto_align(attacking_item, click_data)
user.next_move = world.time + 2
return TRUE

/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)
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()

/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.
W.pixel_x = rand(-W.randpixel, W.randpixel)
W.pixel_y = rand(-W.randpixel, W.randpixel)
W.pixel_z = 0
/obj/structure/surface/proc/auto_align(obj/item/new_item, click_data)
if(!new_item.center_of_mass) // Clothing, material stacks, generally items with large sprites where exact placement would be unhandy.
new_item.pixel_x = rand(-new_item.randpixel, new_item.randpixel)
new_item.pixel_y = rand(-new_item.randpixel, new_item.randpixel)
new_item.pixel_z = 0
return

if(!click_data)
Expand All @@ -169,16 +30,8 @@
var/cell_x = Clamp(round(mouse_x/CELLSIZE), 0, CELLS-1) // Ranging from 0 to CELLS-1
var/cell_y = Clamp(round(mouse_y/CELLSIZE), 0, CELLS-1)

var/list/center = cached_key_number_decode(W.center_of_mass)

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)
var/list/center = cached_key_number_decode(new_item.center_of_mass)

/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)
new_item.pixel_x = (CELLSIZE * (cell_x + 0.5)) - center["x"]
new_item.pixel_y = (CELLSIZE * (cell_y + 0.5)) - center["y"]
new_item.pixel_z = 0
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
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/xenomorph/Facehuggers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
flags_inventory = COVEREYES|ALLOWINTERNALS|COVERMOUTH|ALLOWREBREATH|CANTSTRIP
flags_armor_protection = BODY_FLAG_FACE|BODY_FLAG_EYES
flags_atom = NO_FLAGS
flags_item = NOBLUDGEON|NOTABLEMERGE
flags_item = NOBLUDGEON
throw_range = 1
layer = FACEHUGGER_LAYER
black_market_value = 20
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

0 comments on commit 9be06a2

Please sign in to comment.