Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Inventory Item Conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Apr 5, 2023
1 parent f69c9e6 commit 8d1016e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Overrides -> src/core/client/menus/object
Overrides -> src/core/client/menus/player
Overrides -> src/core/client/menus/vehicle
Athena.systems.inventory.convert.toBaseItem
Athena.systems.inventory.convert.toItem
Athena.systems.inventory.convert.toStoredItem
--------------------------------------
--- Everything Below is Before April 2
--------------------------------------
Expand Down
53 changes: 53 additions & 0 deletions src/core/server/systems/inventory/convert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as Athena from '@AthenaServer/api';
import { BaseItemEx, ItemEx, StoredItemEx } from '@AthenaShared/interfaces/item';

/**
* Converts a stored item into a full item.
*
* Does not perform any inventory changes.
*
* Returns undefined if base item was not found.
*
* @export
* @template CustomData
* @param {StoredItemEx<CustomData>} storedItem
*/
export function toItem<CustomData = {}>(storedItem: StoredItemEx<CustomData>): ItemEx<CustomData> | undefined {
const results = Athena.systems.inventory.manager.convertFromStored<CustomData>([storedItem]);

if (results.length <= 0) {
return undefined;
}

return results[0];
}

/**
* Convert a stored Item to a base item
*
* Does not perform any inventory changes.
*
* @export
* @template CustomData
* @param {StoredItemEx<CustomData>} storedItem
* @return {BaseItemEx<CustomData>}
*/
export function toBaseItem<CustomData = {}>(storedItem: StoredItemEx<CustomData>): BaseItemEx<CustomData> {
return Athena.systems.inventory.factory.getBaseItem<CustomData>(storedItem.dbName, storedItem.version);
}

/**
* Convert a Base Item to a stored item
*
* Does not perform any inventory changes.
*
* @export
* @template CustomData
* @param {BaseItemEx<CustomData>} baseItem
* @param {number} quantity
* @return {*}
*/
export function toStoredItem<CustomData = {}>(baseItem: BaseItemEx<CustomData>, quantity: number) {
return Athena.systems.inventory.factory.fromBaseToStored(baseItem, quantity);
}

1 change: 1 addition & 0 deletions src/core/server/systems/inventory/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * as clothing from './clothing';
export * as config from './config';
export * as convert from './convert';
export * as crafting from './crafting';
export * as drops from './drops';
export * as effects from './effects';
Expand Down

0 comments on commit 8d1016e

Please sign in to comment.