2019-09-25 03:16:07 +00:00
|
|
|
export class FrameHandler {
|
2019-09-26 01:59:16 +00:00
|
|
|
private frameNumberDiv: HTMLElement;
|
|
|
|
|
2019-09-25 03:16:07 +00:00
|
|
|
private filenames: string[] = [];
|
|
|
|
private currentFrame: number = 0;
|
|
|
|
private currentImageDiv: HTMLElement;
|
|
|
|
|
2019-09-26 01:59:16 +00:00
|
|
|
constructor(currentImageDiv: HTMLElement, frameNumberDiv: HTMLElement) {
|
2019-09-25 03:16:07 +00:00
|
|
|
this.currentImageDiv = currentImageDiv;
|
2019-09-26 01:59:16 +00:00
|
|
|
this.frameNumberDiv = frameNumberDiv;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GetCurrentFrame(): number {
|
|
|
|
return this.currentFrame;
|
2019-09-25 03:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public loadFrames(filenames: string[]) {
|
|
|
|
this.filenames = filenames;
|
|
|
|
this.currentFrame = 0;
|
2019-09-26 01:59:16 +00:00
|
|
|
this.SetCurrentImageDiv();
|
2019-09-25 03:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public AdvanceFrames(amount: number) {
|
|
|
|
this.currentFrame += amount;
|
|
|
|
this.currentFrame %= this.filenames.length;
|
|
|
|
if (this.currentFrame < 0) {
|
|
|
|
this.currentFrame = this.filenames.length - 1;
|
|
|
|
}
|
|
|
|
this.GoToFrame(this.currentFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
public GoToFrame(frame: number) {
|
|
|
|
this.currentFrame = frame;
|
2019-09-26 01:59:16 +00:00
|
|
|
this.SetCurrentImageDiv();
|
|
|
|
}
|
|
|
|
|
|
|
|
private SetCurrentImageDiv() {
|
2019-09-25 03:16:07 +00:00
|
|
|
this.currentImageDiv.innerHTML = `<img src="${this.filenames[this.currentFrame]}"></img>`;
|
2019-09-26 01:59:16 +00:00
|
|
|
if (this.filenames.length === 0) {
|
|
|
|
this.frameNumberDiv.innerText = 'No images uploaded yet. Drag images onto the page to upload them';
|
|
|
|
} else {
|
|
|
|
this.frameNumberDiv.innerText = 'Current Frame: ' + this.currentFrame.toString();
|
|
|
|
}
|
2019-09-25 03:16:07 +00:00
|
|
|
}
|
|
|
|
}
|