From 2329178aef012680a5c177b756a8271c4e7baf4e Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 8 Jul 2024 11:17:21 +0200 Subject: [PATCH] [MIRROR] Rewrites `GetExactComponent` to be more readable (#28708) * Rewrites `GetExactComponent` to be more readable (#84656) ## About The Pull Request Rewrites `GetExactComponent` to be 1641 compliant, and more readable ## Why It's Good For The Game This proc was quite unreadable, and less work to make the server run on 1641 ## Changelog :cl: refactor: refactored `GetExactComponent` to be 1641 compatible /:cl: * Rewrites `GetExactComponent` to be more readable --------- Co-authored-by: DGamerL <108773801+DGamerL@users.noreply.github.com> --- code/datums/components/_component.dm | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/code/datums/components/_component.dm b/code/datums/components/_component.dm index 108d303b72c..b258abed65d 100644 --- a/code/datums/components/_component.dm +++ b/code/datums/components/_component.dm @@ -273,18 +273,17 @@ */ /datum/proc/GetExactComponent(datum/component/c_type) RETURN_TYPE(c_type) - if(initial(c_type.dupe_mode) == COMPONENT_DUPE_ALLOWED || initial(c_type.dupe_mode) == COMPONENT_DUPE_SELECTIVE) + var/initial_type_mode = initial(c_type.dupe_mode) + if(initial_type_mode == COMPONENT_DUPE_ALLOWED || initial_type_mode == COMPONENT_DUPE_SELECTIVE) stack_trace("GetComponent was called to get a component of which multiple copies could be on an object. This can easily break and should be changed. Type: \[[c_type]\]") - var/list/dc = _datum_components - if(!dc) + var/list/all_components = _datum_components + if(!all_components) return null - var/datum/component/C = dc[c_type] - if(C) - if(length(C)) - var/list/component_list = C - C = component_list[1] - if(C.type == c_type) - return C + var/datum/component/potential_component + if(length(all_components)) + potential_component = all_components[c_type] + if(potential_component?.type == c_type) + return potential_component return null /**