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

Commit

Permalink
getBaseItemsAsync, getBaseItems
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Apr 7, 2023
1 parent 4cfdacf commit 106130f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Fix commands using non-string types
Fix Escape on Menu Close for RMLUI Menu
Athena.systems.inventory.factory.getBaseItemsAsync
Athena.systems.inventory.factory.getBaseItems
--------------------------------------
--- Everything Below is Before April 2
--------------------------------------
Expand Down
37 changes: 36 additions & 1 deletion src/core/server/systems/inventory/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as alt from 'alt-server';
import Database from '@stuyk/ezmongodb';
import * as Athena from '@AthenaServer/api';

import { BaseItem, StoredItem, Item, DefaultItemBehavior, ClothingComponent } from '@AthenaShared/interfaces/item';
import { BaseItem, StoredItem, Item, DefaultItemBehavior } from '@AthenaShared/interfaces/item';
import { deepCloneObject } from '@AthenaShared/utility/deepCopy';
import { sha256 } from '@AthenaServer/utility/hash';

Expand Down Expand Up @@ -414,6 +414,37 @@ export function fromBaseToStored<CustomData = {}>(
return storedItem;
}

/**
* Waits for the database items to finish loading before returning data.
*
* @export
* @return {Promise<Array<BaseItem>>}
*/
export async function getBaseItems(): Promise<Array<BaseItem>> {
if (Overrides.getBaseItems) {
return getBaseItems();
}

await isDoneLoadingAsync();
return databaseItems;
}

/**
* Does not wait for items to load, returns what base items are in the array.
*
* Use this only during runtime; and not during startup.
*
* @export
* @return {Array<BaseItem>}
*/
export function getBaseItemsAsync(): Array<BaseItem> {
if (Overrides.getBaseItemsAsync) {
return getBaseItemsAsync();
}

return databaseItems;
}

interface FactoryFuncs {
getBaseItemAsync: typeof getBaseItemAsync;
upsertAsync: typeof upsertAsync;
Expand All @@ -423,6 +454,8 @@ interface FactoryFuncs {
fromStoredItem: typeof fromStoredItem;
toStoredItem: typeof toStoredItem;
fromBaseToStored: typeof fromBaseToStored;
getBaseItemsAsync: typeof getBaseItemsAsync;
getBaseItems: typeof getBaseItems;
}

const Overrides: Partial<FactoryFuncs> = {};
Expand All @@ -435,6 +468,8 @@ export function override(functionName: 'getBaseItem', callback: typeof getBaseIt
export function override(functionName: 'fromStoredItem', callback: typeof fromStoredItem);
export function override(functionName: 'toStoredItem', callback: typeof toStoredItem);
export function override(functionName: 'fromBaseToStored', callback: typeof fromBaseToStored);
export function override(functionName: 'getBaseItems', callback: typeof getBaseItems);
export function override(functionName: 'getBaseItemsAsync', callback: typeof getBaseItemsAsync);
/**
* Used to override inventory item factory functionality
*
Expand Down

0 comments on commit 106130f

Please sign in to comment.