Skip to content

Commit

Permalink
fix item tag groups linting errors and confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
Promises committed Nov 23, 2022
1 parent 9ba6abd commit eca6ea7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
30 changes: 10 additions & 20 deletions src/engine/config/config-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,14 @@ export async function loadGameConfigurations(): Promise<void> {

/**
* find all items in all select groups
* @param groupKey string or array of string of which to find items connected with
* @param groupKeys array of string of which to find items connected with
* @return itemsKeys array of itemkeys in all select groups
*/
export const findItemTagsInGroup = (groupKey: string | string[]): string[] => {
if(!groupKey) {
return [];
}

if(Array.isArray(groupKey)) {
const collection: Record<string, boolean> = {}
groupKey.forEach((currentGroup) => {
const items = findItemTagsInGroup(currentGroup);
items.forEach((item) => collection[item] = true)
})
return Object.keys(collection)
}

return Object.keys(itemGroupMap[groupKey] || {})
export const findItemTagsInGroups = (groupKeys: string[]): string[] => {
return Object.keys(groupKeys.reduce<Record<string, boolean>>((all, groupKey)=> {
const items = itemGroupMap[groupKey] || {};
return { ...all, ...items };
}, {}));
}


Expand All @@ -103,7 +93,7 @@ export const findItemTagsInGroupFilter = (groupKeys: string[]): string[] => {
if(!groupKeys || groupKeys.length === 0) {
return [];
}
let collection: Record<string, boolean> | undefined = undefined
let collection: Record<string, boolean> | undefined = undefined;
groupKeys.forEach((groupKey) => {
if(!collection) {
collection = { ...(itemGroupMap[groupKey] || {}) };
Expand All @@ -115,10 +105,10 @@ export const findItemTagsInGroupFilter = (groupKeys: string[]): string[] => {
if(!(existingItemKey in current)) {
delete collection[existingItemKey];
}
})
})
});
});

return Object.keys(collection)
return Object.keys(collection);
}


Expand Down
4 changes: 2 additions & 2 deletions src/plugins/commands/groups-debug.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { commandActionHandler } from '@engine/action';
import { findItemTagsInGroup, findItemTagsInGroupFilter } from '@engine/config/config-handler';
import { findItemTagsInGroups, findItemTagsInGroupFilter } from '@engine/config/config-handler';

const selectGroups: commandActionHandler = ({ player, args, isConsole }) => {
const groups: string | number = args.groupkeys;
Expand All @@ -8,7 +8,7 @@ const selectGroups: commandActionHandler = ({ player, args, isConsole }) => {
return;
}
player.sendLogMessage('results:', isConsole);
findItemTagsInGroup(groups.split(',')).forEach((itemName) => {
findItemTagsInGroups(groups.split(',')).forEach((itemName) => {
player.sendLogMessage(itemName, isConsole);
});
return;
Expand Down

0 comments on commit eca6ea7

Please sign in to comment.