Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/asset-manager/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@nanoforge-dev/asset-manager",
"version": "1.3.1",
"version": "1.3.2-alpha.make-get-asset-not-throw-if-undefined.0",
"description": "NanoForge Engine - Asset Manager",
"keywords": [
"nanoforge",
Expand Down
9 changes: 7 additions & 2 deletions packages/asset-manager/src/asset-manager.library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ export class AssetManagerLibrary extends BaseAssetManagerLibrary {
* collapsed and trailing slashes are removed.
*
* @param path - Virtual path of the asset (e.g. "/textures/hero.png").
* @returns An `NfFile` handle for the requested asset.
* @returns An `NfFile` handle for the requested asset, or `undefined` if no asset path is provided.
* @throws `NfNotFound` When no asset is registered at the given path.
* @throws `NfNotInitializedException` When called before `__init` has resolved.
*/
public getAsset(path: string): NfFile {
public getAsset(path: string): NfFile;
public getAsset(path: "" | undefined): undefined;
public getAsset(path: string | undefined): NfFile | undefined {
if (!this._assets) this.throwNotInitializedError();

if (!path) return undefined;

const res = this._assets.get(this._parsePath(path));
if (!res) throw new NfNotFound(path, "Asset");
return new NfFile(res);
Expand Down
5 changes: 5 additions & 0 deletions packages/asset-manager/test/asset-manager.library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,10 @@ describe("AssetManagerLibrary", () => {
it("should throw NfNotFound for an unknown wgsl", () => {
expect(() => library.getAsset("unknown.wgsl")).toThrow(NfNotFound);
});

it("should return undefined for an undefined path", () => {
expect(library.getAsset(undefined)).toBe(undefined);
expect(library.getAsset("")).toBe(undefined);
});
});
});
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@nanoforge-dev/common",
"version": "1.3.1",
"version": "1.3.2-alpha.make-get-asset-not-throw-if-undefined.0",
"description": "NanoForge Engine - Common",
"keywords": [
"nanoforge",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export abstract class BaseAssetManagerLibrary extends Library implements IAssetM
* @throws `NfNotInitializedException` When called before `__init` has resolved.
*/
public abstract getAsset(path: string): NfFile;
public abstract getAsset(path: "" | undefined): undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export interface IAssetManagerLibrary extends IExposedLibrary {
* Retrieve a registered file asset by its virtual path.
*
* @param path - Virtual path of the asset (e.g. "/textures/hero.png").
* @returns An `NfFile` handle for the requested asset.
* @returns An `NfFile` handle for the requested asset, or `undefined` if no asset path is provided.
* @throws `NfNotFound` When no asset is registered at the given path.
*/
getAsset(path: string): NfFile;
getAsset(path: "" | undefined): undefined;
}