Skip to content

Commit

Permalink
Adds Grant All and Remove All buttons to ID consoles and agent IDs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy authored Sep 6, 2024
1 parent 1862522 commit 35fec30
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 45 deletions.
54 changes: 30 additions & 24 deletions code/game/objects/items/cards_ids.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1532,31 +1532,37 @@

switch(action)
if("mod_access")
var/access_type = params["access_target"]
var/try_wildcard = params["access_wildcard"]
if(access_type in access)
remove_access(list(access_type))
LOG_ID_ACCESS_CHANGE(usr, src, "removed [SSid_access.get_access_desc(access_type)]")
// monkestation start: allow multiple access edits at once
var/list/id_actions = params["actions"]
if(!islist(id_actions) || !length(id_actions))
return TRUE

if(!(access_type in target_card.access))
to_chat(usr, span_notice("ID error: ID card rejected your attempted access modification."))
LOG_ID_ACCESS_CHANGE(usr, src, "failed to add [SSid_access.get_access_desc(access_type)][try_wildcard ? " with wildcard [try_wildcard]" : ""]")
return TRUE

if(!can_add_wildcards(list(access_type), try_wildcard))
to_chat(usr, span_notice("ID error: ID card rejected your attempted access modification."))
LOG_ID_ACCESS_CHANGE(usr, src, "failed to add [SSid_access.get_access_desc(access_type)][try_wildcard ? " with wildcard [try_wildcard]" : ""]")
return TRUE

if(!add_access(list(access_type), try_wildcard))
to_chat(usr, span_notice("ID error: ID card rejected your attempted access modification."))
LOG_ID_ACCESS_CHANGE(usr, src, "failed to add [SSid_access.get_access_desc(access_type)][try_wildcard ? " with wildcard [try_wildcard]" : ""]")
return TRUE

if(access_type in ACCESS_ALERT_ADMINS)
message_admins("[ADMIN_LOOKUPFLW(usr)] just added [SSid_access.get_access_desc(access_type)] to an ID card [ADMIN_VV(src)] [(registered_name) ? "belonging to [registered_name]." : "with no registered name."]")
LOG_ID_ACCESS_CHANGE(usr, src, "added [SSid_access.get_access_desc(access_type)]")
for(var/list/id_action in id_actions)
var/access_type = id_action["access_target"]
var/try_wildcard = id_action["access_wildcard"]
if(access_type in access)
remove_access(list(access_type))
LOG_ID_ACCESS_CHANGE(usr, src, "removed [SSid_access.get_access_desc(access_type)]")
continue

if(!(access_type in target_card.access))
to_chat(usr, span_notice("ID error: ID card rejected your attempted access modification."))
LOG_ID_ACCESS_CHANGE(usr, src, "failed to add [SSid_access.get_access_desc(access_type)][try_wildcard ? " with wildcard [try_wildcard]" : ""]")
return TRUE

if(!can_add_wildcards(list(access_type), try_wildcard))
to_chat(usr, span_notice("ID error: ID card rejected your attempted access modification."))
LOG_ID_ACCESS_CHANGE(usr, src, "failed to add [SSid_access.get_access_desc(access_type)][try_wildcard ? " with wildcard [try_wildcard]" : ""]")
return TRUE

if(!add_access(list(access_type), try_wildcard))
to_chat(usr, span_notice("ID error: ID card rejected your attempted access modification."))
LOG_ID_ACCESS_CHANGE(usr, src, "failed to add [SSid_access.get_access_desc(access_type)][try_wildcard ? " with wildcard [try_wildcard]" : ""]")
return TRUE

if(access_type in ACCESS_ALERT_ADMINS)
message_admins("[ADMIN_LOOKUPFLW(usr)] just added [SSid_access.get_access_desc(access_type)] to an ID card [ADMIN_VV(src)] [(registered_name) ? "belonging to [registered_name]." : "with no registered name."]")
LOG_ID_ACCESS_CHANGE(usr, src, "added [SSid_access.get_access_desc(access_type)]")
// monkestation end
return TRUE

/obj/item/card/id/advanced/chameleon/attack_self(mob/user)
Expand Down
38 changes: 22 additions & 16 deletions code/modules/modular_computers/file_system/programs/card.dm
Original file line number Diff line number Diff line change
Expand Up @@ -215,26 +215,32 @@
if("PRG_access")
if(!computer || !authenticated_card || !inserted_auth_card)
return TRUE
playsound(computer, SFX_TERMINAL_TYPE, 50, FALSE)
var/access_type = params["access_target"]
var/try_wildcard = params["access_wildcard"]
if(!(access_type in valid_access))
stack_trace("[key_name(usr)] ([usr]) attempted to add invalid access \[[access_type]\] to [inserted_auth_card]")
// monkestation start: allow multiple access edits at once
var/list/id_actions = params["actions"]
if(!islist(id_actions) || !length(id_actions))
return TRUE
playsound(computer, SFX_TERMINAL_TYPE, 50, FALSE)
for(var/list/id_action in id_actions)
var/access_type = id_action["access_target"]
var/try_wildcard = id_action["access_wildcard"]
if(!(access_type in valid_access))
stack_trace("[key_name(usr)] ([usr]) attempted to add invalid access \[[access_type]\] to [inserted_auth_card]")
return TRUE

if(access_type in inserted_auth_card.access)
inserted_auth_card.remove_access(list(access_type))
LOG_ID_ACCESS_CHANGE(user, inserted_auth_card, "removed [SSid_access.get_access_desc(access_type)]")
return TRUE
if(access_type in inserted_auth_card.access)
inserted_auth_card.remove_access(list(access_type))
LOG_ID_ACCESS_CHANGE(user, inserted_auth_card, "removed [SSid_access.get_access_desc(access_type)]")
continue

if(!inserted_auth_card.add_access(list(access_type), try_wildcard))
to_chat(usr, span_notice("ID error: ID card rejected your attempted access modification."))
LOG_ID_ACCESS_CHANGE(user, inserted_auth_card, "failed to add [SSid_access.get_access_desc(access_type)][try_wildcard ? " with wildcard [try_wildcard]" : ""]")
return TRUE
if(!inserted_auth_card.add_access(list(access_type), try_wildcard))
to_chat(usr, span_notice("ID error: ID card rejected your attempted access modification."))
LOG_ID_ACCESS_CHANGE(user, inserted_auth_card, "failed to add [SSid_access.get_access_desc(access_type)][try_wildcard ? " with wildcard [try_wildcard]" : ""]")
return TRUE

if(access_type in ACCESS_ALERT_ADMINS)
message_admins("[ADMIN_LOOKUPFLW(user)] just added [SSid_access.get_access_desc(access_type)] to an ID card [ADMIN_VV(inserted_auth_card)] [(inserted_auth_card.registered_name) ? "belonging to [inserted_auth_card.registered_name]." : "with no registered name."]")
LOG_ID_ACCESS_CHANGE(user, inserted_auth_card, "added [SSid_access.get_access_desc(access_type)]")
if(access_type in ACCESS_ALERT_ADMINS)
message_admins("[ADMIN_LOOKUPFLW(user)] just added [SSid_access.get_access_desc(access_type)] to an ID card [ADMIN_VV(inserted_auth_card)] [(inserted_auth_card.registered_name) ? "belonging to [inserted_auth_card.registered_name]." : "with no registered name."]")
LOG_ID_ACCESS_CHANGE(user, inserted_auth_card, "added [SSid_access.get_access_desc(access_type)]")
// monkestation end
return TRUE
// Apply template to ID card.
if("PRG_template")
Expand Down
10 changes: 8 additions & 2 deletions tgui/packages/tgui/interfaces/ChameleonCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ export const ChameleonCard = (props) => {
showBasic={!!showBasic}
accessMod={(ref, wildcard) =>
act('mod_access', {
access_target: ref,
access_wildcard: wildcard,
actions: [{ access_target: ref, access_wildcard: wildcard }],
})
}
multiAccessMod={(actions) => {
act('mod_access', {
actions: actions.map(([ref, wildcard]) => {
return { access_target: ref, access_wildcard: wildcard };
}),
});
}}
/>
</Window.Content>
</Window>
Expand Down
12 changes: 10 additions & 2 deletions tgui/packages/tgui/interfaces/NtosCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,18 @@ export const NtosCardContent = (props) => {
}
accessMod={(ref, wildcard) =>
act('PRG_access', {
access_target: ref,
access_wildcard: wildcard,
actions: [
{ access_target: ref, access_wildcard: wildcard },
],
})
}
multiAccessMod={(actions) => {
act('PRG_access', {
actions: actions.map(([ref, wildcard]) => {
return { access_target: ref, access_wildcard: wildcard };
}),
});
}}
/>
</Box>
)}
Expand Down
64 changes: 63 additions & 1 deletion tgui/packages/tgui/interfaces/common/AccessList.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { sortBy } from 'common/collections';
import { useSharedState } from '../../backend';
import { Button, Flex, Section, Tabs } from '../../components';
import { Button, Flex, Section, Tabs, Box } from '../../components';

export const AccessList = (props) => {
const {
accesses = [],
wildcardSlots = {},
selectedList = [],
accessMod,
multiAccessMod,
trimAccess = [],
accessFlags = {},
accessFlagNames = {},
Expand Down Expand Up @@ -97,6 +98,57 @@ export const AccessList = (props) => {
}
});

const [selectedAccessName] = useSharedState(
'accessName',
parsedRegions[0]?.name,
);

const handleGrantAll = () => {
// Find the selected region by name
const selectedRegion = parsedRegions.find(
(region) => region.name === selectedAccessName,
);

if (!selectedRegion) return; // If no region is selected, do nothing

const actions = [];

// Calculate the current wildcard limit and usage
const wildcard = wildcardSlots[selectedWildcard];
const wcLimit = wildcard ? wildcard.limit : -1; // -1 means no limit
const wcUsage = wildcard ? wildcard.usage.length : 0;
const wcAvail = wcLimit === -1 ? Infinity : wcLimit - wcUsage;

// Grant access for all items in the selected region, respecting the limit
selectedRegion.accesses.forEach((access) => {
if (actions.length < wcAvail && !selectedList.includes(access.ref)) {
actions.push([
access.ref,
selectedWildcard === 'None' ? null : selectedWildcard,
]);
}
});

multiAccessMod(actions);
};

const handleRemoveAll = () => {
// Find the selected region by name
const selectedRegion = parsedRegions.find(
(region) => region.name === selectedAccessName,
);

if (!selectedRegion) return; // If no region is selected, do nothing

const actions = [];
selectedRegion.accesses.forEach((access) => {
if (selectedList.includes(access.ref)) {
actions.push([access.ref, null]);
}
});
multiAccessMod(actions);
};

return (
<Section title="Access" buttons={extraButtons}>
<Flex wrap="wrap">
Expand All @@ -113,6 +165,16 @@ export const AccessList = (props) => {
<RegionTabList accesses={parsedRegions} />
</Flex.Item>
<Flex.Item grow={1}>
{!!multiAccessMod && (
<Box grow align="right">
<Button ml={1} color="good" onClick={handleGrantAll}>
Grant All
</Button>
<Button ml={1} color="bad" onClick={handleRemoveAll}>
Remove All
</Button>
</Box>
)}
<RegionAccessList
accesses={parsedRegions}
selectedList={selectedList}
Expand Down

0 comments on commit 35fec30

Please sign in to comment.