mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 02:30:43 -05:00
Expanded getItemName()
to return short name when full name is not found
This commit is contained in:
parent
95fbe09154
commit
b7a9296fac
@ -1556,11 +1556,18 @@ export class ItemHelper
|
|||||||
/**
|
/**
|
||||||
* Get the name of an item from the locale file using the item tpl
|
* Get the name of an item from the locale file using the item tpl
|
||||||
* @param itemTpl Tpl of item to get name of
|
* @param itemTpl Tpl of item to get name of
|
||||||
* @returns Name of item
|
* @returns Full name, short name if not found
|
||||||
*/
|
*/
|
||||||
public getItemName(itemTpl: string): string
|
public getItemName(itemTpl: string): string
|
||||||
{
|
{
|
||||||
return this.localeService.getLocaleDb()[`${itemTpl} Name`];
|
const localeDb = this.localeService.getLocaleDb();
|
||||||
|
const result = localeDb[`${itemTpl} Name`];
|
||||||
|
if (result?.length > 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return localeDb[`${itemTpl} ShortName`];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -852,6 +852,24 @@ describe("ItemHelper", () =>
|
|||||||
expect(result).toBe("Roubles");
|
expect(result).toBe("Roubles");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return item short name for a valid item with empty full name", () =>
|
||||||
|
{
|
||||||
|
const databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
|
||||||
|
databaseServer.getTables().locales.global.en["5449016a4bdc2d6f028b456f Name"] = "";
|
||||||
|
const result = itemHelper.getItemName("5449016a4bdc2d6f028b456f"); // "Roubles"
|
||||||
|
|
||||||
|
expect(result).toBe("RUB");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return item short name for a valid item with undefined full name", () =>
|
||||||
|
{
|
||||||
|
const databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
|
||||||
|
databaseServer.getTables().locales.global.en["5449016a4bdc2d6f028b456f Name"] = undefined;
|
||||||
|
const result = itemHelper.getItemName("5449016a4bdc2d6f028b456f"); // "Roubles"
|
||||||
|
|
||||||
|
expect(result).toBe("RUB");
|
||||||
|
});
|
||||||
|
|
||||||
it("should return undefined for invalid item", () =>
|
it("should return undefined for invalid item", () =>
|
||||||
{
|
{
|
||||||
const result = itemHelper.getItemName("fake tpl");
|
const result = itemHelper.getItemName("fake tpl");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user