refactor: safer fromJSON
This commit is contained in:
parent
07491fabdf
commit
ab689beee9
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user