Fixed input remove listener. Run tsfmt.

This commit is contained in:
Davide Tantillo 2024-09-30 11:52:02 +02:00
parent 2db1873fd5
commit 95f2119e46
3 changed files with 1101 additions and 1101 deletions

View File

@ -119,23 +119,23 @@ export class AssetManagerBase implements Disposable {
loadJson (path: string, loadJson (path: string,
success: (path: string, object: object) => void = () => { }, success: (path: string, object: object) => void = () => { },
error: (path: string, message: string) => void = () => { }) { error: (path: string, message: string) => void = () => { }) {
path = this.start(path); path = this.start(path);
if (this.reuseAssets(path, success, error)) return; if (this.reuseAssets(path, success, error)) return;
this.assetsLoaded[path] = new Promise<any>((resolve, reject) => { this.assetsLoaded[path] = new Promise<any>((resolve, reject) => {
this.downloader.downloadJson(path, (data: object): void => { this.downloader.downloadJson(path, (data: object): void => {
this.success(success, path, data); this.success(success, path, data);
resolve(data); resolve(data);
}, (status: number, responseText: string): void => { }, (status: number, responseText: string): void => {
const errorMsg = `Couldn't load JSON ${path}: status ${status}, ${responseText}`; const errorMsg = `Couldn't load JSON ${path}: status ${status}, ${responseText}`;
this.error(error, path, errorMsg); this.error(error, path, errorMsg);
reject(errorMsg); reject(errorMsg);
});
}); });
});
} }
reuseAssets(path: string, reuseAssets (path: string,
success: (path: string, data: any) => void = () => { }, success: (path: string, data: any) => void = () => { },
error: (path: string, message: string) => void = () => { }) { error: (path: string, message: string) => void = () => { }) {
const loadedStatus = this.assetsLoaded[path]; const loadedStatus = this.assetsLoaded[path];
@ -152,45 +152,45 @@ export class AssetManagerBase implements Disposable {
success: (path: string, texture: Texture) => void = () => { }, success: (path: string, texture: Texture) => void = () => { },
error: (path: string, message: string) => void = () => { }) { error: (path: string, message: string) => void = () => { }) {
path = this.start(path); path = this.start(path);
if (this.reuseAssets(path, success, error)) return; if (this.reuseAssets(path, success, error)) return;
this.assetsLoaded[path] = new Promise<any>((resolve, reject) => { this.assetsLoaded[path] = new Promise<any>((resolve, reject) => {
let isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document); let isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document);
let isWebWorker = !isBrowser; // && typeof importScripts !== 'undefined'; let isWebWorker = !isBrowser; // && typeof importScripts !== 'undefined';
if (isWebWorker) { if (isWebWorker) {
fetch(path, { mode: <RequestMode>"cors" }).then((response) => { fetch(path, { mode: <RequestMode>"cors" }).then((response) => {
if (response.ok) return response.blob(); if (response.ok) return response.blob();
const errorMsg = `Couldn't load image: ${path}`; const errorMsg = `Couldn't load image: ${path}`;
this.error(error, path, `Couldn't load image: ${path}`); this.error(error, path, `Couldn't load image: ${path}`);
reject(errorMsg); reject(errorMsg);
}).then((blob) => { }).then((blob) => {
return blob ? createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }) : null; return blob ? createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }) : null;
}).then((bitmap) => { }).then((bitmap) => {
if (bitmap) { if (bitmap) {
const texture = this.textureLoader(bitmap) const texture = this.textureLoader(bitmap)
this.success(success, path, texture);
resolve(texture);
};
});
} else {
let image = new Image();
image.crossOrigin = "anonymous";
image.onload = () => {
const texture = this.textureLoader(image)
this.success(success, path, texture); this.success(success, path, texture);
resolve(texture); resolve(texture);
}; };
image.onerror = () => { });
const errorMsg = `Couldn't load image: ${path}`; } else {
this.error(error, path, errorMsg); let image = new Image();
reject(errorMsg); image.crossOrigin = "anonymous";
}; image.onload = () => {
if (this.downloader.rawDataUris[path]) path = this.downloader.rawDataUris[path]; const texture = this.textureLoader(image)
image.src = path; this.success(success, path, texture);
} resolve(texture);
}); };
image.onerror = () => {
const errorMsg = `Couldn't load image: ${path}`;
this.error(error, path, errorMsg);
reject(errorMsg);
};
if (this.downloader.rawDataUris[path]) path = this.downloader.rawDataUris[path];
image.src = path;
}
});
} }
loadTextureAtlas (path: string, loadTextureAtlas (path: string,
@ -272,7 +272,7 @@ export class AssetManagerBase implements Disposable {
} }
// Promisified versions of load function // Promisified versions of load function
async loadBinaryAsync(path: string) { async loadBinaryAsync (path: string) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.loadBinary(path, this.loadBinary(path,
(_, binary) => resolve(binary), (_, binary) => resolve(binary),
@ -281,7 +281,7 @@ export class AssetManagerBase implements Disposable {
}); });
} }
async loadJsonAsync(path: string) { async loadJsonAsync (path: string) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.loadJson(path, this.loadJson(path,
(_, object) => resolve(object), (_, object) => resolve(object),
@ -290,7 +290,7 @@ export class AssetManagerBase implements Disposable {
}); });
} }
async loadTextureAsync(path: string) { async loadTextureAsync (path: string) {
return new Promise<Texture>((resolve, reject) => { return new Promise<Texture>((resolve, reject) => {
this.loadTexture(path, this.loadTexture(path,
(_, texture) => resolve(texture), (_, texture) => resolve(texture),
@ -299,7 +299,7 @@ export class AssetManagerBase implements Disposable {
}); });
} }
async loadTextureAtlasAsync(path: string) { async loadTextureAtlasAsync (path: string) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.loadTextureAtlas(path, this.loadTextureAtlas(path,
(_, atlas) => resolve(atlas), (_, atlas) => resolve(atlas),
@ -308,7 +308,7 @@ export class AssetManagerBase implements Disposable {
}); });
} }
async loadTextureAtlasButNoTexturesAsync(path: string) { async loadTextureAtlasButNoTexturesAsync (path: string) {
return new Promise<TextureAtlas>((resolve, reject) => { return new Promise<TextureAtlas>((resolve, reject) => {
this.loadTextureAtlasButNoTextures(path, this.loadTextureAtlasButNoTextures(path,
(_, atlas) => resolve(atlas), (_, atlas) => resolve(atlas),

View File

@ -212,16 +212,16 @@ export class Input implements Disposable {
} }
} }
dispose(): void { dispose (): void {
const element = this.element; const element = this.element;
element.addEventListener("mousedown", this.callbacks.mouseDown, true); element.removeEventListener("mousedown", this.callbacks.mouseDown, true);
element.addEventListener("mousemove", this.callbacks.mouseMove, true); element.removeEventListener("mousemove", this.callbacks.mouseMove, true);
element.addEventListener("mouseup", this.callbacks.mouseUp, true); element.removeEventListener("mouseup", this.callbacks.mouseUp, true);
element.addEventListener("wheel", this.callbacks.mouseWheel, true); element.removeEventListener("wheel", this.callbacks.mouseWheel, true);
element.addEventListener("touchstart", this.callbacks.touchStart, { passive: false, capture: false }); element.removeEventListener("touchstart", this.callbacks.touchStart, { capture: false });
element.addEventListener("touchmove", this.callbacks.touchMove, { passive: false, capture: false }); element.removeEventListener("touchmove", this.callbacks.touchMove, { capture: false });
element.addEventListener("touchend", this.callbacks.touchEnd, { passive: false, capture: false }); element.removeEventListener("touchend", this.callbacks.touchEnd, { capture: false });
element.addEventListener("touchcancel", this.callbacks.touchEnd); element.removeEventListener("touchcancel", this.callbacks.touchEnd);
this.listeners.length = 0; this.listeners.length = 0;
} }

File diff suppressed because it is too large Load Diff