Skip to content

Commit eca6ea7

Browse files
committed
fix item tag groups linting errors and confusion
1 parent 9ba6abd commit eca6ea7

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

src/engine/config/config-handler.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,14 @@ export async function loadGameConfigurations(): Promise<void> {
7373

7474
/**
7575
* find all items in all select groups
76-
* @param groupKey string or array of string of which to find items connected with
76+
* @param groupKeys array of string of which to find items connected with
7777
* @return itemsKeys array of itemkeys in all select groups
7878
*/
79-
export const findItemTagsInGroup = (groupKey: string | string[]): string[] => {
80-
if(!groupKey) {
81-
return [];
82-
}
83-
84-
if(Array.isArray(groupKey)) {
85-
const collection: Record<string, boolean> = {}
86-
groupKey.forEach((currentGroup) => {
87-
const items = findItemTagsInGroup(currentGroup);
88-
items.forEach((item) => collection[item] = true)
89-
})
90-
return Object.keys(collection)
91-
}
92-
93-
return Object.keys(itemGroupMap[groupKey] || {})
79+
export const findItemTagsInGroups = (groupKeys: string[]): string[] => {
80+
return Object.keys(groupKeys.reduce<Record<string, boolean>>((all, groupKey)=> {
81+
const items = itemGroupMap[groupKey] || {};
82+
return { ...all, ...items };
83+
}, {}));
9484
}
9585

9686

@@ -103,7 +93,7 @@ export const findItemTagsInGroupFilter = (groupKeys: string[]): string[] => {
10393
if(!groupKeys || groupKeys.length === 0) {
10494
return [];
10595
}
106-
let collection: Record<string, boolean> | undefined = undefined
96+
let collection: Record<string, boolean> | undefined = undefined;
10797
groupKeys.forEach((groupKey) => {
10898
if(!collection) {
10999
collection = { ...(itemGroupMap[groupKey] || {}) };
@@ -115,10 +105,10 @@ export const findItemTagsInGroupFilter = (groupKeys: string[]): string[] => {
115105
if(!(existingItemKey in current)) {
116106
delete collection[existingItemKey];
117107
}
118-
})
119-
})
108+
});
109+
});
120110

121-
return Object.keys(collection)
111+
return Object.keys(collection);
122112
}
123113

124114

src/plugins/commands/groups-debug.plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { commandActionHandler } from '@engine/action';
2-
import { findItemTagsInGroup, findItemTagsInGroupFilter } from '@engine/config/config-handler';
2+
import { findItemTagsInGroups, findItemTagsInGroupFilter } from '@engine/config/config-handler';
33

44
const selectGroups: commandActionHandler = ({ player, args, isConsole }) => {
55
const groups: string | number = args.groupkeys;
@@ -8,7 +8,7 @@ const selectGroups: commandActionHandler = ({ player, args, isConsole }) => {
88
return;
99
}
1010
player.sendLogMessage('results:', isConsole);
11-
findItemTagsInGroup(groups.split(',')).forEach((itemName) => {
11+
findItemTagsInGroups(groups.split(',')).forEach((itemName) => {
1212
player.sendLogMessage(itemName, isConsole);
1313
});
1414
return;

0 commit comments

Comments
 (0)