-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
167b62c
commit 5d8b240
Showing
2 changed files
with
34 additions
and
36 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,42 +1,42 @@ | ||
import type ImageElement from "./ImageElement.js"; | ||
|
||
export default class Frame { | ||
public index: number; | ||
public images: ImageElement[] = []; | ||
public priority: number = 0; | ||
public index: number; | ||
public images: ImageElement[] = []; | ||
public priority: number = 0; | ||
|
||
constructor(index: number) { | ||
this.index = index; | ||
} | ||
constructor(index: number) { | ||
this.index = index; | ||
} | ||
|
||
public get image(): CanvasImageSource | undefined { | ||
return this.images.find(image => image.image !== undefined)?.image; | ||
} | ||
public get image(): CanvasImageSource | undefined { | ||
return this.images.find(image => image.image !== undefined)?.image; | ||
} | ||
|
||
public async getImage(): Promise<CanvasImageSource> { | ||
return new Promise(async (resolve, reject) => { | ||
if (this.image !== undefined) { | ||
resolve(this.image); | ||
} else { | ||
const lastImage = this.images[this.images.length - 1]; | ||
if (lastImage) { | ||
lastImage.fetchImage().then(img => resolve(img)).catch(() => reject()); | ||
} else { | ||
reject(); | ||
} | ||
} | ||
}); | ||
} | ||
public async getImage(): Promise<CanvasImageSource> { | ||
return new Promise(async (resolve, reject) => { | ||
if (this.image !== undefined) { | ||
resolve(this.image); | ||
} else { | ||
const lastImage = this.images[this.images.length - 1]; | ||
if (lastImage) { | ||
lastImage.fetchImage().then(img => resolve(img)).catch(() => reject()); | ||
} else { | ||
reject(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public async fetchImage(): Promise<CanvasImageSource | undefined> { | ||
return this.images.find(image => image.available)?.fetchImage(); | ||
} | ||
public async fetchImage(): Promise<CanvasImageSource | undefined> { | ||
return this.images.find(image => image.available)?.fetchImage(); | ||
} | ||
|
||
public releaseImage() { | ||
this.images.forEach(image => image.releaseImage()); | ||
} | ||
public releaseImage() { | ||
this.images.forEach(image => image.releaseImage()); | ||
} | ||
|
||
public reset() { | ||
this.images.forEach(image => image.reset()); | ||
} | ||
public reset() { | ||
this.images.forEach(image => image.reset()); | ||
} | ||
} |