Added more resiliency to the give command for modders who dont want to add localization for their mods (!325)
Fixed cases for modded items causing problems with Commando. Co-authored-by: clodan <clodan@clodan.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/325 Co-authored-by: Alex <clodan@noreply.dev.sp-tarkov.com> Co-committed-by: Alex <clodan@noreply.dev.sp-tarkov.com>
This commit is contained in:
parent
c552c7ad67
commit
c33773a318
@ -146,16 +146,17 @@ export class GiveSptCommand implements ISptCommand
|
|||||||
commandHandler,
|
commandHandler,
|
||||||
`An error occurred while trying to use localized text. Locale will be defaulted to 'en'.`,
|
`An error occurred while trying to use localized text. Locale will be defaulted to 'en'.`,
|
||||||
);
|
);
|
||||||
this.logger.error(e);
|
this.logger.warning(e);
|
||||||
locale = "en";
|
locale = "en";
|
||||||
}
|
}
|
||||||
|
|
||||||
const localizedGlobal = this.databaseServer.getTables().locales.global[locale];
|
const localizedGlobal = this.databaseServer.getTables().locales.global[locale] ??
|
||||||
|
this.databaseServer.getTables().locales.global.en;
|
||||||
|
|
||||||
const closestItemsMatchedByName = this.itemHelper.getItems()
|
const closestItemsMatchedByName = this.itemHelper.getItems()
|
||||||
.filter((i) => this.isItemAllowed(i))
|
.filter((i) => this.isItemAllowed(i))
|
||||||
.map((i) => localizedGlobal[`${i?._id} Name`]?.toLowerCase())
|
.map((i) => localizedGlobal[`${i?._id} Name`]?.toLowerCase() ?? i._props.Name)
|
||||||
.filter((i) => i !== undefined)
|
.filter((i) => i !== undefined && i !== "")
|
||||||
.map(i => ({match: stringSimilarity(item.toLocaleLowerCase(), i.toLocaleLowerCase()), itemName: i}))
|
.map(i => ({match: stringSimilarity(item.toLocaleLowerCase(), i.toLocaleLowerCase()), itemName: i}))
|
||||||
.sort((a1, a2) => a2.match - a1.match);
|
.sort((a1, a2) => a2.match - a1.match);
|
||||||
|
|
||||||
@ -186,7 +187,7 @@ export class GiveSptCommand implements ISptCommand
|
|||||||
const tplId = isItemName
|
const tplId = isItemName
|
||||||
? this.itemHelper.getItems()
|
? this.itemHelper.getItems()
|
||||||
.filter((i) => this.isItemAllowed(i))
|
.filter((i) => this.isItemAllowed(i))
|
||||||
.find((i) => this.databaseServer.getTables().locales.global[locale][`${i?._id} Name`]?.toLowerCase() === item)._id
|
.find((i) => (this.databaseServer.getTables().locales.global[locale][`${i?._id} Name`]?.toLowerCase() ?? i._props.Name) === item)._id
|
||||||
: item;
|
: item;
|
||||||
|
|
||||||
const checkedItem = this.itemHelper.getItem(tplId);
|
const checkedItem = this.itemHelper.getItem(tplId);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user