From 325915e45984ae65da376e855a39ed41baa81a67 Mon Sep 17 00:00:00 2001 From: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Date: Sun, 19 Jun 2022 10:25:37 -0500 Subject: [PATCH] Converts diggable from component to bespoke element (#67695) * Changes diggable to an element and fixes it, saving on some memory. --- code/datums/components/diggable.dm | 28 -------------- code/datums/elements/diggable.dm | 46 +++++++++++++++++++++++ code/game/turfs/open/basalt.dm | 2 +- code/game/turfs/open/floor/fancy_floor.dm | 6 +-- code/game/turfs/open/snow.dm | 2 +- tgstation.dme | 2 +- 6 files changed, 52 insertions(+), 34 deletions(-) delete mode 100644 code/datums/components/diggable.dm create mode 100644 code/datums/elements/diggable.dm diff --git a/code/datums/components/diggable.dm b/code/datums/components/diggable.dm deleted file mode 100644 index 7239b9eb685..00000000000 --- a/code/datums/components/diggable.dm +++ /dev/null @@ -1,28 +0,0 @@ -/// Lets you make hitting a turf with a shovel pop something out, and scrape the turf -/datum/component/diggable - /// Typepath to spawn on hit - var/to_spawn - /// Amount to spawn on hit - var/amount - /// What should we tell the user they did? - var/action_text - -/datum/component/diggable/Initialize(to_spawn, amount = 1, action_text) - . = ..() - if(!isturf(parent)) - return COMPONENT_INCOMPATIBLE - - src.to_spawn = to_spawn - src.amount = amount - src.action_text = action_text - RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, .proc/handle_attack) - -/datum/component/diggable/proc/handle_attack(datum/source, obj/item/hit_by, mob/living/bastard, params) - if(hit_by.tool_behaviour != TOOL_SHOVEL || !params) - return - var/turf/parent_turf = parent - for(var/i in 1 to amount) - new to_spawn(parent_turf) - bastard.visible_message(span_notice("[bastard] digs up [parent_turf]."), span_notice("You [action_text] [parent_turf].")) - playsound(parent_turf, 'sound/effects/shovel_dig.ogg', 50, TRUE) - parent_turf.ScrapeAway(flags = CHANGETURF_INHERIT_AIR) diff --git a/code/datums/elements/diggable.dm b/code/datums/elements/diggable.dm new file mode 100644 index 00000000000..e57b24fd250 --- /dev/null +++ b/code/datums/elements/diggable.dm @@ -0,0 +1,46 @@ +/// Lets you make hitting a turf with a shovel pop something out, and scrape the turf +/datum/element/diggable + element_flags = ELEMENT_BESPOKE|ELEMENT_DETACH + id_arg_index = 2 + /// Typepath of what we spawn on shovel + var/atom/to_spawn + /// Amount to spawn on shovel + var/amount + /// What should we tell the user they did? (Eg: "You dig up the turf.") + var/action_text + /// What should we tell other people what the user did? (Eg: "Guy digs up the turf.") + var/action_text_third_person + +/datum/element/diggable/Attach(datum/target, to_spawn, amount = 1, action_text = "dig up", action_text_third_person = "digs up") + . = ..() + if(!isturf(target)) + return ELEMENT_INCOMPATIBLE + if(!to_spawn) + stack_trace("[type] wasn't passed a typepath to spawn attaching to [target].") + return ELEMENT_INCOMPATIBLE + + src.to_spawn = to_spawn + src.amount = amount + src.action_text = action_text + src.action_text_third_person = action_text_third_person + + RegisterSignal(target, COMSIG_ATOM_TOOL_ACT(TOOL_SHOVEL), .proc/on_shovel) + +/datum/element/diggable/Detach(datum/source, ...) + . = ..() + UnregisterSignal(source, COMSIG_ATOM_TOOL_ACT(TOOL_SHOVEL)) + +/// Signal proc for [COMSIG_ATOM_TOOL_ACT] via [TOOL_SHOVEL]. +/datum/element/diggable/proc/on_shovel(turf/source, mob/user, obj/item/tool) + SIGNAL_HANDLER + + for(var/i in 1 to amount) + new to_spawn(source) + + user.visible_message( + span_notice("[user] [action_text_third_person] [source]."), + span_notice("You [action_text] [source]."), + ) + + playsound(source, 'sound/effects/shovel_dig.ogg', 50, TRUE) + source.ScrapeAway(flags = CHANGETURF_INHERIT_AIR) diff --git a/code/game/turfs/open/basalt.dm b/code/game/turfs/open/basalt.dm index ce1b547fdcc..e52a6053a6e 100644 --- a/code/game/turfs/open/basalt.dm +++ b/code/game/turfs/open/basalt.dm @@ -8,7 +8,7 @@ /turf/open/misc/basalt/Initialize(mapload) . = ..() - AddComponent(/datum/component/diggable, /obj/item/stack/ore/glass/basalt, 2, "dig up") + AddElement(/datum/element/diggable, /obj/item/stack/ore/glass/basalt, 2) if(prob(15)) icon_state = "basalt[rand(0, 12)]" set_basalt_light(src) diff --git a/code/game/turfs/open/floor/fancy_floor.dm b/code/game/turfs/open/floor/fancy_floor.dm index f9bd9f0c071..8c8aac4bee0 100644 --- a/code/game/turfs/open/floor/fancy_floor.dm +++ b/code/game/turfs/open/floor/fancy_floor.dm @@ -132,7 +132,7 @@ /turf/open/floor/grass/Initialize(mapload) . = ..() spawniconchange() - AddComponent(/datum/component/diggable, /obj/item/stack/ore/glass, 2, "uproot") + AddElement(/datum/element/diggable, /obj/item/stack/ore/glass, 2, "uproot", "uproots") /turf/open/floor/grass/proc/spawniconchange() icon_state = "grass[rand(0,3)]" @@ -170,7 +170,7 @@ /turf/open/floor/fake_snow/Initialize(mapload) . = ..() - AddComponent(/datum/component/diggable, /obj/item/stack/tile/mineral/snow, 2, "dig up") + AddElement(/datum/element/diggable, /obj/item/stack/tile/mineral/snow, 2) /turf/open/floor/fake_snow/setup_broken_states() return list("snow_dug") @@ -197,7 +197,7 @@ /turf/open/floor/fakebasalt/Initialize(mapload) . = ..() - AddComponent(/datum/component/diggable, /obj/item/stack/ore/glass/basalt, 2, "dig up") + AddElement(/datum/element/diggable, /obj/item/stack/ore/glass/basalt, 2) if(prob(15)) icon_state = "basalt[rand(0, 12)]" set_basalt_light(src) diff --git a/code/game/turfs/open/snow.dm b/code/game/turfs/open/snow.dm index 4017240e3fd..27def9bdc59 100644 --- a/code/game/turfs/open/snow.dm +++ b/code/game/turfs/open/snow.dm @@ -15,7 +15,7 @@ /turf/open/misc/snow/Initialize(mapload) . = ..() - AddComponent(/datum/component/diggable, /obj/item/stack/sheet/mineral/snow, 2, "dig up") + AddElement(/datum/element/diggable, /obj/item/stack/sheet/mineral/snow, 2) /turf/open/misc/snow/break_tile() . = ..() diff --git a/tgstation.dme b/tgstation.dme index 2de3a0ccbca..777b4493b8a 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -743,7 +743,6 @@ #include "code\datums\components\deadchat_control.dm" #include "code\datums\components\dejavu.dm" #include "code\datums\components\deployable.dm" -#include "code\datums\components\diggable.dm" #include "code\datums\components\drift.dm" #include "code\datums\components\earprotection.dm" #include "code\datums\components\edit_complainer.dm" @@ -973,6 +972,7 @@ #include "code\datums\elements\death_drops.dm" #include "code\datums\elements\delete_on_drop.dm" #include "code\datums\elements\deliver_first.dm" +#include "code\datums\elements\diggable.dm" #include "code\datums\elements\digitalcamo.dm" #include "code\datums\elements\drag_pickup.dm" #include "code\datums\elements\dryable.dm"