2019-09-26 01:59:16 +00:00
|
|
|
import { CanvasHandler } from './canvas_handler';
|
2019-09-25 03:16:07 +00:00
|
|
|
import { FileHandler } from './file_handler';
|
|
|
|
import { FrameHandler } from './frame_handler';
|
2019-09-26 01:59:16 +00:00
|
|
|
import { IAnimationData } from './Interfaces/IAnimationData';
|
|
|
|
import { IFrame } from './Interfaces/IFrame';
|
2019-09-25 03:16:07 +00:00
|
|
|
|
2019-09-25 00:01:54 +00:00
|
|
|
export class Page {
|
2019-09-25 03:16:07 +00:00
|
|
|
private static handleDragOver(evt: DragEvent) {
|
|
|
|
if (evt !== null) {
|
|
|
|
evt.stopPropagation();
|
|
|
|
evt.preventDefault();
|
|
|
|
evt.dataTransfer!.dropEffect = 'copy'; // Explicitly show this is a copy.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-26 01:59:16 +00:00
|
|
|
private frameHandler: FrameHandler;
|
|
|
|
private canvasHandler: CanvasHandler;
|
|
|
|
private animationData: IAnimationData;
|
2019-09-25 03:16:07 +00:00
|
|
|
|
2019-09-25 00:01:54 +00:00
|
|
|
public Load() {
|
2019-09-26 01:59:16 +00:00
|
|
|
// defining blank slate animation data
|
|
|
|
this.animationData = {
|
|
|
|
pins: [],
|
|
|
|
originX: 0,
|
|
|
|
originY: 0,
|
|
|
|
frameRate: 30,
|
|
|
|
loop: true,
|
|
|
|
frames: [
|
|
|
|
{
|
|
|
|
filename: '',
|
|
|
|
pinData: []
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.canvasHandler = new CanvasHandler(document.getElementById('currentImage') as HTMLElement);
|
2019-09-26 22:05:37 +00:00
|
|
|
// this.canvasHandler.currentImageDiv.addEventListener('onmousedown', ClickOnCanvas);
|
2019-09-26 01:59:16 +00:00
|
|
|
|
|
|
|
this.frameHandler = new FrameHandler(
|
|
|
|
document.getElementById('currentImage') as HTMLElement,
|
|
|
|
document.getElementById('frameNumber') as HTMLElement
|
|
|
|
);
|
2019-09-25 03:16:07 +00:00
|
|
|
|
|
|
|
const dropZone = document.getElementById('dropZone') as HTMLElement;
|
|
|
|
|
|
|
|
dropZone.addEventListener('dragover', Page.handleDragOver, false);
|
|
|
|
dropZone.addEventListener('drop', this.handleFileSelect, false);
|
2019-09-25 00:42:35 +00:00
|
|
|
|
2019-09-25 03:16:07 +00:00
|
|
|
const keyDown = (event: KeyboardEvent) => {
|
|
|
|
switch (event.keyCode) {
|
|
|
|
case 39: {
|
|
|
|
// right_arrow
|
|
|
|
console.log('next frame action');
|
2019-09-26 01:59:16 +00:00
|
|
|
this.frameHandler.AdvanceFrames(1);
|
2019-09-25 03:16:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 37: {
|
|
|
|
// left arrow
|
|
|
|
console.log('previous frame action');
|
2019-09-26 01:59:16 +00:00
|
|
|
this.frameHandler.AdvanceFrames(-1);
|
2019-09-25 03:16:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-09-25 00:42:35 +00:00
|
|
|
};
|
2019-09-25 03:16:07 +00:00
|
|
|
|
|
|
|
document.addEventListener('keydown', keyDown);
|
2019-09-25 00:01:54 +00:00
|
|
|
}
|
2019-09-25 03:16:07 +00:00
|
|
|
|
2019-09-26 01:59:16 +00:00
|
|
|
private handleFileSelect = async (event: DragEvent) => {
|
2019-09-25 03:16:07 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
2019-09-26 01:59:16 +00:00
|
|
|
const filenames = await FileHandler.ProcessImages(event.dataTransfer!.files);
|
|
|
|
this.frameHandler.loadFrames(filenames);
|
|
|
|
|
|
|
|
const newFrames: IFrame[] = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < event.dataTransfer!.files.length; i++) {
|
|
|
|
newFrames.push({
|
|
|
|
filename: event.dataTransfer!.files[i].name,
|
|
|
|
pinData: []
|
|
|
|
});
|
|
|
|
}
|
2019-09-25 03:16:07 +00:00
|
|
|
|
2019-09-26 01:59:16 +00:00
|
|
|
this.animationData.frames = newFrames;
|
|
|
|
console.log(this.animationData);
|
2019-09-25 03:16:07 +00:00
|
|
|
};
|
2019-09-25 00:01:54 +00:00
|
|
|
}
|