Converts diggable from component to bespoke element (#67695)

* Changes diggable to an element and fixes it, saving on some memory.
This commit is contained in:
MrMelbert
2022-06-19 11:25:37 -04:00
committed by GitHub
parent c8f6b802c3
commit 325915e459
6 changed files with 52 additions and 34 deletions
-28
View File
@@ -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)
+46
View File
@@ -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)
+1 -1
View File
@@ -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)
+3 -3
View File
@@ -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)
+1 -1
View File
@@ -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()
. = ..()
+1 -1
View File
@@ -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"