Improve null handling

This commit is contained in:
Jordan Eldredge 2021-06-08 16:48:04 -07:00
parent 2661293a4d
commit a46363dcfe
2 changed files with 7 additions and 9 deletions

View file

@ -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);

View file

@ -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");