From 1cd4e0c8028cc8d9422ea7a18e090f40d0089190 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 1 Feb 2021 23:43:55 +0100 Subject: [PATCH] [MIRROR] Ability to select the logic for Nanite rules (AND, OR) (#3009) * Ability to select the logic for Nanite rules (AND, OR) (#56542) Added a button to the Nanite Cloud Controller Rules UI with two states: - Meet all (default) - all rules must be met to run the program - Meet any - any of the rules must be met to run the program This change doesn't impact the default rule behavior, but gives an ability to create more flexible rule setups when needed. * Ability to select the logic for Nanite rules (AND, OR) Co-authored-by: Andrew --- .../nanites/nanite_cloud_controller.dm | 10 +++++++ .../research/nanites/nanite_programs.dm | 10 +++++-- .../tgui/interfaces/NaniteCloudControl.js | 28 +++++++++++++------ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/code/modules/research/nanites/nanite_cloud_controller.dm b/code/modules/research/nanites/nanite_cloud_controller.dm index ff016aa50bb..224e247c5b5 100644 --- a/code/modules/research/nanites/nanite_cloud_controller.dm +++ b/code/modules/research/nanites/nanite_cloud_controller.dm @@ -144,6 +144,7 @@ cloud_program["rules"] = rules if(LAZYLEN(rules)) cloud_program["has_rules"] = TRUE + cloud_program["all_rules_required"] = P.all_rules_required var/list/extra_settings = P.get_extra_settings_frontend() cloud_program["extra_settings"] = extra_settings @@ -233,6 +234,15 @@ investigate_log("[key_name(usr)] removed rule [rule.display()] from program [P.name] in cloud #[current_view]", INVESTIGATE_NANITES) . = TRUE + if("toggle_rule_logic") + var/datum/nanite_cloud_backup/backup = get_backup(current_view) + if(backup) + playsound(src, 'sound/machines/terminal_prompt.ogg', 50, FALSE) + var/datum/component/nanites/nanites = backup.nanites + var/datum/nanite_program/P = nanites.programs[text2num(params["program_id"])] + P.all_rules_required = !P.all_rules_required + investigate_log("[key_name(usr)] edited rule logic for program [P.name] into [P.all_rules_required ? "All" : "Any"] in cloud #[current_view]", INVESTIGATE_NANITES) + . = TRUE /datum/nanite_cloud_backup var/cloud_id = 0 diff --git a/code/modules/research/nanites/nanite_programs.dm b/code/modules/research/nanites/nanite_programs.dm index 7bf75a71468..a69e4e4f116 100644 --- a/code/modules/research/nanites/nanite_programs.dm +++ b/code/modules/research/nanites/nanite_programs.dm @@ -53,6 +53,7 @@ //Rules //Rules that automatically manage if the program's active without requiring separate sensor programs var/list/datum/nanite_rule/rules = list() + var/all_rules_required = TRUE //Whether all rules are required for positive condition or any of specified /datum/nanite_program/New() . = ..() @@ -92,6 +93,7 @@ for(var/R in rules) var/datum/nanite_rule/rule = R rule.copy_to(target) + target.all_rules_required = all_rules_required if(istype(target,src)) copy_extra_settings_to(target) @@ -194,11 +196,15 @@ //If false, disables active, passive effects, and triggers without consuming nanites //Can be used to avoid consuming nanites for nothing /datum/nanite_program/proc/check_conditions() + if (!LAZYLEN(rules)) + return TRUE for(var/R in rules) var/datum/nanite_rule/rule = R - if(!rule.check_rule()) + if(!all_rules_required && rule.check_rule()) + return TRUE + if(all_rules_required && !rule.check_rule()) return FALSE - return TRUE + return all_rules_required ? TRUE : FALSE //Constantly procs as long as the program is active /datum/nanite_program/proc/active_effect() diff --git a/tgui/packages/tgui/interfaces/NaniteCloudControl.js b/tgui/packages/tgui/interfaces/NaniteCloudControl.js index e88983fd33d..8c8ac7efd2c 100644 --- a/tgui/packages/tgui/interfaces/NaniteCloudControl.js +++ b/tgui/packages/tgui/interfaces/NaniteCloudControl.js @@ -197,7 +197,7 @@ export const NaniteCloudBackupDetails = (props, context) => { !!has_program && (