Fix: Bespoke DCS elements use all requested args. (#26387)

This commit is contained in:
warriorstar-orion
2024-08-06 15:29:39 -04:00
committed by GitHub
parent 52327cea40
commit 78ef86989f
8 changed files with 19 additions and 9 deletions
+1 -1
View File
@@ -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)
@@ -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))
+11 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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.")