revise anim format
parent
c5b7a35f1d
commit
01fe18d3ee
|
@ -2,5 +2,5 @@ import { IFramePinData } from './IFramePinData';
|
||||||
|
|
||||||
export interface IFrame {
|
export interface IFrame {
|
||||||
filename: string;
|
filename: string;
|
||||||
[index: number]: IFramePinData;
|
pinData: IFramePinData;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
export interface IFramePinData {
|
export interface IFramePinData {
|
||||||
id: number;
|
[id: number]: {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,13 +63,12 @@ export class CanvasHandler {
|
||||||
this.animationData.originY = pixelY;
|
this.animationData.originY = pixelY;
|
||||||
} else {
|
} else {
|
||||||
// console.log('current pin id = ' + this.projectData.currentlySelectedPin);
|
// console.log('current pin id = ' + this.projectData.currentlySelectedPin);
|
||||||
const newPinData: IFramePinData = {
|
const newPinData = {
|
||||||
id: this.projectData.currentlySelectedPin,
|
|
||||||
x: pixelX,
|
x: pixelX,
|
||||||
y: pixelY
|
y: pixelY
|
||||||
};
|
};
|
||||||
|
|
||||||
this.animationData.frames[this.projectData.currentFrame][
|
this.animationData.frames[this.projectData.currentFrame].pinData[
|
||||||
this.projectData.currentlySelectedPin
|
this.projectData.currentlySelectedPin
|
||||||
] = newPinData;
|
] = newPinData;
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ export class FrameHandler {
|
||||||
const pinIDtoCheck = this.animationData.pins[p].id;
|
const pinIDtoCheck = this.animationData.pins[p].id;
|
||||||
// console.log('checking frame ' + f + ' for pinID ' + this.animationData.pins[p].name);
|
// console.log('checking frame ' + f + ' for pinID ' + this.animationData.pins[p].name);
|
||||||
if (this.frameViewer.children[f] !== undefined) {
|
if (this.frameViewer.children[f] !== undefined) {
|
||||||
if (this.animationData.frames[f][pinIDtoCheck] === undefined) {
|
if (this.animationData.frames[f].pinData[pinIDtoCheck] === undefined) {
|
||||||
this.frameViewer.children[f].classList.add('warning');
|
this.frameViewer.children[f].classList.add('warning');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -186,9 +186,7 @@ export class FrameHandler {
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
this.canvasContext.strokeStyle = '#FF0000';
|
this.canvasContext.strokeStyle = '#FF0000';
|
||||||
if (this.animationData.frames[this.projectData.currentFrame] !== undefined) {
|
if (this.animationData.frames[this.projectData.currentFrame] !== undefined) {
|
||||||
const currentSelectedPinData: IFramePinData = this.animationData.frames[
|
const currentSelectedPinData = this.animationData.frames[this.projectData.currentFrame].pinData[i];
|
||||||
this.projectData.currentFrame
|
|
||||||
][i];
|
|
||||||
if (currentSelectedPinData !== null && currentSelectedPinData !== undefined) {
|
if (currentSelectedPinData !== null && currentSelectedPinData !== undefined) {
|
||||||
this.DrawCrossHair(50, this.canvasContext, currentSelectedPinData.x, currentSelectedPinData.y);
|
this.DrawCrossHair(50, this.canvasContext, currentSelectedPinData.x, currentSelectedPinData.y);
|
||||||
}
|
}
|
||||||
|
|
28
app/page.ts
28
app/page.ts
|
@ -44,7 +44,8 @@ export class Page {
|
||||||
frameRate: 30,
|
frameRate: 30,
|
||||||
frames: [
|
frames: [
|
||||||
{
|
{
|
||||||
filename: ''
|
filename: '',
|
||||||
|
pinData: {}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
loop: true,
|
loop: true,
|
||||||
|
@ -211,15 +212,29 @@ export class Page {
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
// name of project
|
// name of project
|
||||||
const name = this.filenameInput.value;
|
const name = this.filenameInput.value;
|
||||||
|
|
||||||
|
// generate output filenames
|
||||||
|
var outputFilenames = [];
|
||||||
|
for (let i = 0; i < this.animationData.frames.length; i++) {
|
||||||
|
const padding = i.toString().padStart(3, '0');
|
||||||
|
const filename = name + '_' + padding.toString() + '.png';
|
||||||
|
outputFilenames[i] = filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < this.animationData.frames.length; i++) {
|
||||||
|
this.animationData.frames[i].filename = outputFilenames[i];
|
||||||
|
}
|
||||||
|
|
||||||
// .anim file
|
// .anim file
|
||||||
zip.file(name + '.anim', JSON.stringify(this.animationData));
|
zip.file(name + '.anim', JSON.stringify(this.animationData));
|
||||||
|
|
||||||
// pngs
|
// pngs
|
||||||
const filenames = this.frameHandler.GetFilenames();
|
const filenames = this.frameHandler.GetFilenames();
|
||||||
for (let i = 0; i < filenames.length; i++) {
|
for (let i = 0; i < filenames.length; i++) {
|
||||||
const filedata = filenames[i].split('base64,')[1];
|
const filedata = filenames[i].split('base64,')[1];
|
||||||
const padding = i.toString().padStart(3, '0');
|
zip.file(outputFilenames[i], filedata, { base64: true });
|
||||||
zip.file(name + '_' + padding.toString() + '.png', filedata, { base64: true });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// save zip
|
// save zip
|
||||||
zip.generateAsync({ type: 'blob' }).then((content) => {
|
zip.generateAsync({ type: 'blob' }).then((content) => {
|
||||||
// see FileSaver.js
|
// see FileSaver.js
|
||||||
|
@ -253,7 +268,7 @@ export class Page {
|
||||||
if (this.animationData.pins[p] !== undefined) {
|
if (this.animationData.pins[p] !== undefined) {
|
||||||
const pinIDtoCheck = this.animationData.pins[p].id;
|
const pinIDtoCheck = this.animationData.pins[p].id;
|
||||||
// console.log('checking frame ' + f + ' for pinID ' + this.animationData.pins[p].name);
|
// console.log('checking frame ' + f + ' for pinID ' + this.animationData.pins[p].name);
|
||||||
if (this.animationData.frames[f][pinIDtoCheck] === undefined) {
|
if (this.animationData.frames[f].pinData[pinIDtoCheck] === undefined) {
|
||||||
if (!errorOnFrame) {
|
if (!errorOnFrame) {
|
||||||
pinDataErrorString += f + ' :\n';
|
pinDataErrorString += f + ' :\n';
|
||||||
}
|
}
|
||||||
|
@ -300,7 +315,8 @@ export class Page {
|
||||||
|
|
||||||
for (let i = 0; i < originalFilenames.length; i++) {
|
for (let i = 0; i < originalFilenames.length; i++) {
|
||||||
newFrames.push({
|
newFrames.push({
|
||||||
filename: originalFilenames[i].toString()
|
filename: originalFilenames[i].toString(),
|
||||||
|
pinData: {}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,7 +341,7 @@ export class Page {
|
||||||
this.animationData.originY = null;
|
this.animationData.originY = null;
|
||||||
this.animationData.frameRate = 30;
|
this.animationData.frameRate = 30;
|
||||||
this.animationData.loop = true;
|
this.animationData.loop = true;
|
||||||
this.animationData.frames = [ { filename: '' } ];
|
this.animationData.frames = [ { filename: '', pinData: {} } ];
|
||||||
|
|
||||||
// blank slate canvas data
|
// blank slate canvas data
|
||||||
this.projectData.currentFrame = 0;
|
this.projectData.currentFrame = 0;
|
||||||
|
|
|
@ -46,7 +46,7 @@ export class PinHandler {
|
||||||
const pinNumber = this.GetPinNumberFromID(pinDiv.id);
|
const pinNumber = this.GetPinNumberFromID(pinDiv.id);
|
||||||
for (let f = 0; f < this.animationData.frames.length; f++) {
|
for (let f = 0; f < this.animationData.frames.length; f++) {
|
||||||
if (this.animationData.frames[f] !== undefined) {
|
if (this.animationData.frames[f] !== undefined) {
|
||||||
if (this.animationData.frames[f][pinNumber] === undefined) {
|
if (this.animationData.frames[f].pinData[pinNumber] === undefined) {
|
||||||
pinDiv.classList.add('warning');
|
pinDiv.classList.add('warning');
|
||||||
// console.log('added warning');
|
// console.log('added warning');
|
||||||
break;
|
break;
|
||||||
|
@ -203,8 +203,8 @@ export class PinHandler {
|
||||||
|
|
||||||
// delete pin data from each frame
|
// delete pin data from each frame
|
||||||
for (let f = 0; f < this.animationData.frames.length; f++) {
|
for (let f = 0; f < this.animationData.frames.length; f++) {
|
||||||
if (this.animationData.frames[f][pinID] !== undefined) {
|
if (this.animationData.frames[f].pinData[pinID] !== undefined) {
|
||||||
delete this.animationData.frames[f][pinID];
|
delete this.animationData.frames[f].pinData[pinID];
|
||||||
// console.log('deleting pinID ' + pinID + ' data from frame ' + f);
|
// console.log('deleting pinID ' + pinID + ' data from frame ' + f);
|
||||||
} else {
|
} else {
|
||||||
// console.log('tried to delete pinID ' + pinID + ' data from frame ' + f + ' but it doesnt exist');
|
// console.log('tried to delete pinID ' + pinID + ' data from frame ' + f + ' but it doesnt exist');
|
||||||
|
|
Loading…
Reference in New Issue