mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-24 05:30:05 +01:00
[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 <mt.forspam@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -197,7 +197,7 @@ export const NaniteCloudBackupDetails = (props, context) => {
|
||||
!!has_program && (
|
||||
<Button
|
||||
icon="upload"
|
||||
content="Upload From Disk"
|
||||
content="Upload Program from Disk"
|
||||
color="good"
|
||||
onClick={() => act('upload_program')} />
|
||||
)
|
||||
@@ -223,14 +223,24 @@ export const NaniteCloudBackupDetails = (props, context) => {
|
||||
mt={-2}
|
||||
title="Rules"
|
||||
level={2}
|
||||
buttons={(!!can_rule
|
||||
&& <Button
|
||||
icon="plus"
|
||||
content="Add Rule from Disk"
|
||||
color="good"
|
||||
onClick={() => act('add_rule', {
|
||||
program_id: program.id,
|
||||
})} />
|
||||
buttons={(
|
||||
<>
|
||||
{!!can_rule && (
|
||||
<Button
|
||||
icon="plus"
|
||||
content="Add Rule from Disk"
|
||||
color="good"
|
||||
onClick={() => act('add_rule', {
|
||||
program_id: program.id,
|
||||
})} />
|
||||
)}
|
||||
<Button
|
||||
icon={program.all_rules_required ? 'check-double' : 'check'}
|
||||
content={program.all_rules_required ? 'Meet all' : 'Meet any'}
|
||||
onClick={() => act('toggle_rule_logic', {
|
||||
program_id: program.id,
|
||||
})} />
|
||||
</>
|
||||
)}>
|
||||
{program.has_rules ? (
|
||||
rules.map(rule => (
|
||||
|
||||
Reference in New Issue
Block a user