mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-27 12:03:52 +00:00
Improve null handling
This commit is contained in:
parent
2661293a4d
commit
a46363dcfe
2 changed files with 7 additions and 9 deletions
|
|
@ -9,9 +9,12 @@ export default class ImageManager {
|
|||
this._sizeCache = new Map();
|
||||
}
|
||||
|
||||
async getUrl(filePath: string): Promise<string> {
|
||||
async getUrl(filePath: string): Promise<string | null> {
|
||||
if (!this._urlCache.has(filePath)) {
|
||||
const zipFile = getCaseInsensitiveFile(this._zip, filePath);
|
||||
if (zipFile == null) {
|
||||
return null;
|
||||
}
|
||||
const imgBlob = await zipFile.async("blob");
|
||||
const imgUrl = await getUrlFromBlob(imgBlob);
|
||||
this._urlCache.set(filePath, imgUrl);
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ export default class SkinParser {
|
|||
assert(file != null, "Expected bitmap node to have a `file` attribute");
|
||||
|
||||
const imgUrl = await this._imageManager.getUrl(file);
|
||||
assert(imgUrl != null, `Could not find bitmap at path ${file}`);
|
||||
|
||||
const id = node.attributes.id;
|
||||
const x = num(node.attributes.x) ?? 0;
|
||||
|
|
@ -152,14 +153,8 @@ export default class SkinParser {
|
|||
height = size.height;
|
||||
}
|
||||
|
||||
const bitmap = new Bitmap({
|
||||
url: imgUrl,
|
||||
id,
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
});
|
||||
// prettier-ignore
|
||||
const bitmap = new Bitmap({ url: imgUrl, id, x, y, width, height });
|
||||
|
||||
// TODO: Store this somewhere. For now, we can just show it.
|
||||
const div = document.createElement("div");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue