From 78ef86989f3a2f6b0e186e09cd96da9350d2db39 Mon Sep 17 00:00:00 2001 From: warriorstar-orion Date: Tue, 6 Aug 2024 15:29:39 -0400 Subject: [PATCH] Fix: Bespoke DCS elements use all requested args. (#26387) --- code/__DEFINES/dcs/dcs_flags.dm | 2 +- code/controllers/subsystem/processing/SSdcs.dm | 2 +- code/datums/elements/_element.dm | 12 +++++++++++- code/datums/elements/rad_insulation.dm | 2 +- code/datums/elements/ridable.dm | 2 +- code/datums/elements/shatters_when_thrown.dm | 2 +- code/datums/elements/strippable.dm | 2 +- code/modules/unit_tests/element_tests.dm | 4 ++-- 8 files changed, 19 insertions(+), 9 deletions(-) diff --git a/code/__DEFINES/dcs/dcs_flags.dm b/code/__DEFINES/dcs/dcs_flags.dm index 2519211c1c8..3c238acc007 100644 --- a/code/__DEFINES/dcs/dcs_flags.dm +++ b/code/__DEFINES/dcs/dcs_flags.dm @@ -12,7 +12,7 @@ /// Causes the detach proc to be called when the host object is being deleted #define ELEMENT_DETACH_ON_HOST_DESTROY (1 << 0) /** - * Only elements created with the same arguments given after `id_arg_index` share an element instance + * Only elements created with the same arguments given after `argument_hash_start_idx` share an element instance * The arguments are the same when the text and number values are the same and all other values have the same ref */ #define ELEMENT_BESPOKE (1 << 1) diff --git a/code/controllers/subsystem/processing/SSdcs.dm b/code/controllers/subsystem/processing/SSdcs.dm index a6923364fdc..83472a54655 100644 --- a/code/controllers/subsystem/processing/SSdcs.dm +++ b/code/controllers/subsystem/processing/SSdcs.dm @@ -34,7 +34,7 @@ PROCESSING_SUBSYSTEM_DEF(dcs) var/datum/element/eletype = arguments[1] var/list/fullid = list(eletype) var/list/named_arguments - for(var/i in initial(eletype.id_arg_index) to (initial(eletype.id_arg_index) || length(arguments))) + for(var/i in initial(eletype.argument_hash_start_idx) to (initial(eletype.argument_hash_end_idx) || length(arguments))) var/key = arguments[i] if(istext(key)) diff --git a/code/datums/elements/_element.dm b/code/datums/elements/_element.dm index f2f379cd0f8..cc5fc2006c5 100644 --- a/code/datums/elements/_element.dm +++ b/code/datums/elements/_element.dm @@ -10,11 +10,21 @@ /** * The index of the first attach argument to consider for duplicate elements * + * All arguments from this index onwards (1 based, until `argument_hash_end_idx` is reached, if set) + * are hashed into the key to determine if this is a new unique element or one already exists + * * Is only used when flags contains [ELEMENT_BESPOKE] * * This is infinity so you must explicitly set this */ - var/id_arg_index = INFINITY + var/argument_hash_start_idx = INFINITY + + /** + * The index of the last attach argument to consider for duplicate elements + * Only used when `element_flags` contains [ELEMENT_BESPOKE]. + * If not set, it'll copy every argument from `argument_hash_start_idx` onwards as normal + */ + var/argument_hash_end_idx = 0 /// Activates the functionality defined by the element on the given target datum /datum/element/proc/Attach(datum/target) diff --git a/code/datums/elements/rad_insulation.dm b/code/datums/elements/rad_insulation.dm index 9ba40a9b09d..673ae58df15 100644 --- a/code/datums/elements/rad_insulation.dm +++ b/code/datums/elements/rad_insulation.dm @@ -1,6 +1,6 @@ /datum/element/rad_insulation element_flags = ELEMENT_DETACH_ON_HOST_DESTROY | ELEMENT_BESPOKE - id_arg_index = 2 + argument_hash_start_idx = 2 var/amount // Multiplier for radiation strength passing through /datum/element/rad_insulation/Attach(datum/target, _amount = RAD_MEDIUM_INSULATION, protects = TRUE, contamination_proof = TRUE) diff --git a/code/datums/elements/ridable.dm b/code/datums/elements/ridable.dm index e2c9544b427..f9ef50d1ece 100644 --- a/code/datums/elements/ridable.dm +++ b/code/datums/elements/ridable.dm @@ -8,7 +8,7 @@ */ /datum/element/ridable element_flags = ELEMENT_BESPOKE - id_arg_index = 2 + argument_hash_start_idx = 2 /// The specific riding component subtype we're loading our instructions from, don't leave this as default please! var/riding_component_type = /datum/component/riding /// If we have a xenobio red potion applied to us, we get split off so we can pass our special status onto new riding components diff --git a/code/datums/elements/shatters_when_thrown.dm b/code/datums/elements/shatters_when_thrown.dm index 20e2ddbfb43..d05a00bde67 100644 --- a/code/datums/elements/shatters_when_thrown.dm +++ b/code/datums/elements/shatters_when_thrown.dm @@ -3,7 +3,7 @@ */ /datum/element/shatters_when_thrown element_flags = ELEMENT_BESPOKE - id_arg_index = 2 + argument_hash_start_idx = 2 /// What type of item is spawned as a 'shard' once the shattering happens var/obj/item/shard_type /// How many shards total are made when the thing we're attached to shatters diff --git a/code/datums/elements/strippable.dm b/code/datums/elements/strippable.dm index 349eac0653e..5ad2ad814cf 100644 --- a/code/datums/elements/strippable.dm +++ b/code/datums/elements/strippable.dm @@ -3,7 +3,7 @@ /// An element for atoms that, when dragged and dropped onto a mob, opens a strip panel. /datum/element/strippable element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH_ON_HOST_DESTROY - id_arg_index = 2 + argument_hash_start_idx = 2 /// An assoc list of keys to /datum/strippable_item var/list/items diff --git a/code/modules/unit_tests/element_tests.dm b/code/modules/unit_tests/element_tests.dm index 77c6370ec31..d497984ea49 100644 --- a/code/modules/unit_tests/element_tests.dm +++ b/code/modules/unit_tests/element_tests.dm @@ -1,4 +1,4 @@ /datum/unit_test/bespoke_element/Run() for(var/datum/element/element_type as anything in subtypesof(/datum/element)) - if(initial(element_type.element_flags) & ELEMENT_BESPOKE && initial(element_type.id_arg_index) == INFINITY) - Fail("Element type [element_type] has ELEMENT_BESPOKE and a default id_arg_index.") + if(initial(element_type.element_flags) & ELEMENT_BESPOKE && initial(element_type.argument_hash_start_idx) == INFINITY) + Fail("Element type [element_type] has ELEMENT_BESPOKE and a default argument_hash_start_idx.")