-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
136 additions
and
287 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
type AssetHost = { | ||
baseUrl: string; | ||
normalizePath: boolean; | ||
}; | ||
|
||
const getAssetUrl = (host: AssetHost, path: string) => { | ||
const urlPath = host.normalizePath ? normalizePath(path) : path; | ||
return `${host.baseUrl}/${urlPath}`; | ||
}; | ||
|
||
const loadAsset = async (host: AssetHost, path: string) => { | ||
const response = await fetch(getAssetUrl(host, path)); | ||
|
||
// Handle non-2xx responses | ||
if (!response.ok) { | ||
throw new Error(`Error loading asset: ${response.status} ${response.statusText}`); | ||
} | ||
|
||
return response.arrayBuffer(); | ||
}; | ||
|
||
/** | ||
* Given an MPQ-style path, return a normalized version of the path with all backslashes turned | ||
* to forward slashes, leading and trailing whitespace removed, and all characters turned to | ||
* lowercase. | ||
* | ||
* @param path | ||
*/ | ||
const normalizePath = (path: string) => path.trim().toLowerCase().replaceAll(/\\/g, '/'); | ||
|
||
export { AssetHost, getAssetUrl, loadAsset, normalizePath }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.