From 2b0afbd83c99349bf2226c48b1299ae739cb3b7e Mon Sep 17 00:00:00 2001 From: larentoun <31931237+larentoun@users.noreply.github.com> Date: Mon, 4 Nov 2024 03:47:32 +0300 Subject: [PATCH 1/3] use element --- modular_ss220/_defines220/code/signals_obj.dm | 5 ++- .../_security_redalert_accesses.dm | 2 +- .../_security_redalert_accesses.dme | 1 + .../code/security_redalert_accesses.dm | 32 +++--------------- .../code/security_redalert_element.dm | 33 +++++++++++++++++++ 5 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 modular_ss220/security_redalert_accesses/code/security_redalert_element.dm diff --git a/modular_ss220/_defines220/code/signals_obj.dm b/modular_ss220/_defines220/code/signals_obj.dm index d5723b8d0843..eff11e792fe5 100644 --- a/modular_ss220/_defines220/code/signals_obj.dm +++ b/modular_ss220/_defines220/code/signals_obj.dm @@ -1,2 +1,5 @@ -/// from base of [/obj/proc/atom_destruction]: (damage_flag) +/// from base of /obj/proc/atom_destruction: (damage_flag) #define COMSIG_OBJ_DESTRUCTION "atom_destruction" + +/// from base of /obj/item/card/id: () +#define COMSIG_ID_GET_ACCESS "id_get_access" diff --git a/modular_ss220/security_redalert_accesses/_security_redalert_accesses.dm b/modular_ss220/security_redalert_accesses/_security_redalert_accesses.dm index 45810b39f2ef..6345aa707683 100644 --- a/modular_ss220/security_redalert_accesses/_security_redalert_accesses.dm +++ b/modular_ss220/security_redalert_accesses/_security_redalert_accesses.dm @@ -1,4 +1,4 @@ /datum/modpack/security_redalert_accesses name = "Доступы СБ в красный код" desc = "Добавляет доступы СБ в красный код." - author = "dj-34, Vallat" + author = "dj-34, Vallat, larentoun" diff --git a/modular_ss220/security_redalert_accesses/_security_redalert_accesses.dme b/modular_ss220/security_redalert_accesses/_security_redalert_accesses.dme index c2c82c729525..a9767b62bfbf 100644 --- a/modular_ss220/security_redalert_accesses/_security_redalert_accesses.dme +++ b/modular_ss220/security_redalert_accesses/_security_redalert_accesses.dme @@ -1,3 +1,4 @@ #include "_security_redalert_accesses.dm" #include "code/security_redalert_accesses.dm" +#include "code/security_redalert_element.dm" diff --git a/modular_ss220/security_redalert_accesses/code/security_redalert_accesses.dm b/modular_ss220/security_redalert_accesses/code/security_redalert_accesses.dm index e62b573093ad..7c1e21c9dd0b 100644 --- a/modular_ss220/security_redalert_accesses/code/security_redalert_accesses.dm +++ b/modular_ss220/security_redalert_accesses/code/security_redalert_accesses.dm @@ -1,30 +1,8 @@ -/obj/item/card/id - var/list/red_alert_given_access // Accesses that were given on red alert - /obj/item/card/id/Initialize(mapload) . = ..() - red_alert_given_access = list() - RegisterSignal(SSsecurity_level, COMSIG_SECURITY_LEVEL_CHANGED, PROC_REF(on_security_level_update)) - -/obj/item/card/id/Destroy() - return ..() - -/obj/item/card/id/proc/on_red_alert() - if(!has_access(list(), list(ACCESS_SECURITY), access)) - return - red_alert_given_access = get_region_accesses(REGION_ALL) - get_region_accesses(REGION_COMMAND) - red_alert_given_access -= access - - access |= red_alert_given_access - -/obj/item/card/id/proc/after_red_alert() - if(!has_access(list(), list(ACCESS_SECURITY), access)) - return - access -= red_alert_given_access - red_alert_given_access.Cut() + AddElement(/datum/element/red_alert_access) -/obj/item/card/id/proc/on_security_level_update() - if(SSsecurity_level.current_security_level.number_level > SEC_LEVEL_BLUE) - on_red_alert() - else - after_red_alert() +/obj/item/card/id/GetAccess() + var/list/current_access = ..() + . = current_access.Copy() + SEND_SIGNAL(src, COMSIG_ID_GET_ACCESS, .) diff --git a/modular_ss220/security_redalert_accesses/code/security_redalert_element.dm b/modular_ss220/security_redalert_accesses/code/security_redalert_element.dm new file mode 100644 index 000000000000..f36a24b55cee --- /dev/null +++ b/modular_ss220/security_redalert_accesses/code/security_redalert_element.dm @@ -0,0 +1,33 @@ +/datum/element/red_alert_access + +/datum/element/red_alert_access/Attach(datum/target, list/access = list()) + . = ..() + if(!istype(target, /obj/item/card/id)) + return ELEMENT_INCOMPATIBLE + RegisterSignal(target, COMSIG_ID_GET_ACCESS, PROC_REF(add_access)) + RegisterSignal(target, COMSIG_PARENT_EXAMINE, PROC_REF(examine)) + +/datum/element/red_alert_access/Detach(obj/item/card/id/source, force) + UnregisterSignal(source, COMSIG_ID_GET_ACCESS) + UnregisterSignal(source, COMSIG_PARENT_EXAMINE) + . = ..() + +/datum/element/red_alert_access/proc/add_access(obj/item/card/id/source, list/new_access = list()) + SIGNAL_HANDLER + if(!should_give_access(source.access)) + return + var/static/list/red_alert_access = get_region_accesses(REGION_ALL) - get_region_accesses(REGION_COMMAND) + new_access |= red_alert_access + +/datum/element/red_alert_access/proc/examine(obj/item/card/id/source, mob/user, list/examine_list) + SIGNAL_HANDLER + if(!should_give_access(source.access)) + return + examine_list += span_notice("Мигает красная лампочка с надписью \"Расширенный доступ\".") + +/datum/element/red_alert_access/proc/should_give_access(list/access) + if(SSsecurity_level.current_security_level.number_level <= SEC_LEVEL_BLUE) + return FALSE + if(!has_access(list(), list(ACCESS_SECURITY), access)) + return FALSE + return TRUE From bf00dec08c27470809fbe22e62e99c303e2c7ad9 Mon Sep 17 00:00:00 2001 From: larentoun <31931237+larentoun@users.noreply.github.com> Date: Tue, 5 Nov 2024 02:14:23 +0300 Subject: [PATCH 2/3] update comment --- modular_ss220/_defines220/code/signals_obj.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modular_ss220/_defines220/code/signals_obj.dm b/modular_ss220/_defines220/code/signals_obj.dm index eff11e792fe5..ea65465aa594 100644 --- a/modular_ss220/_defines220/code/signals_obj.dm +++ b/modular_ss220/_defines220/code/signals_obj.dm @@ -1,5 +1,5 @@ /// from base of /obj/proc/atom_destruction: (damage_flag) #define COMSIG_OBJ_DESTRUCTION "atom_destruction" -/// from base of /obj/item/card/id: () +/// from base of /obj/item/card/id: (list/access) #define COMSIG_ID_GET_ACCESS "id_get_access" From 79274d969911f2108cef94da1c176492e850c786 Mon Sep 17 00:00:00 2001 From: larentoun <31931237+larentoun@users.noreply.github.com> Date: Tue, 5 Nov 2024 21:42:56 +0300 Subject: [PATCH 3/3] Update modular_ss220/security_redalert_accesses/code/security_redalert_element.dm Co-authored-by: Mikhail Dzianishchyts --- .../code/security_redalert_element.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modular_ss220/security_redalert_accesses/code/security_redalert_element.dm b/modular_ss220/security_redalert_accesses/code/security_redalert_element.dm index f36a24b55cee..d949616271ee 100644 --- a/modular_ss220/security_redalert_accesses/code/security_redalert_element.dm +++ b/modular_ss220/security_redalert_accesses/code/security_redalert_element.dm @@ -10,7 +10,7 @@ /datum/element/red_alert_access/Detach(obj/item/card/id/source, force) UnregisterSignal(source, COMSIG_ID_GET_ACCESS) UnregisterSignal(source, COMSIG_PARENT_EXAMINE) - . = ..() + return ..() /datum/element/red_alert_access/proc/add_access(obj/item/card/id/source, list/new_access = list()) SIGNAL_HANDLER