refactor: safer fromJSON

This commit is contained in:
cha0s 2019-03-21 23:40:03 -05:00
parent 07491fabdf
commit ab689beee9

View File

@ -82,11 +82,20 @@ export class Animation extends decorate(Resource) {
fromJSON(json) {
super.fromJSON(json);
this.directionCount = json.directionCount;
this.frameCount = json.frameCount;
this.ticker.frequency = json.frameRate;
this.frameSize = json.frameSize;
this.imageUri = json.imageUri;
if (json.frameRate) {
this.ticker.frequency = json.frameRate;
}
const keys = [
'directionCount',
'frameCount',
'frameSize',
'imageUri',
];
for (const key of keys) {
if (json[key]) {
this[key] = json[key];
}
}
return this;
}