refactor: inline fromJSON for resources
This commit is contained in:
parent
ad317f1cd6
commit
ab4fd16b37
|
@ -12,8 +12,7 @@ export class Resource extends decorate(class {}) {
|
|||
|
||||
static load(uri) {
|
||||
return this.read(uri).then((json) => {
|
||||
const instance = new this();
|
||||
return instance.fromJSON(json);
|
||||
return new this(json);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,7 @@ export class Sound extends Resource {
|
|||
return this.loadCache[uri];
|
||||
}
|
||||
return this.loadCache[uri] = this.read(uri).then((json) => {
|
||||
const instance = new this();
|
||||
instance.fromJSON(json);
|
||||
const instance = new Sound(json);
|
||||
let lastTime = performance.now();
|
||||
instance.tickHandle = setInterval(() => {
|
||||
const now = performance.now();
|
||||
|
@ -36,7 +35,7 @@ export class Sound extends Resource {
|
|||
});
|
||||
}
|
||||
|
||||
constructor() {
|
||||
constructor(json) {
|
||||
super();
|
||||
this.interval = 0;
|
||||
this.lastPlayHandle = undefined;
|
||||
|
@ -45,6 +44,9 @@ export class Sound extends Resource {
|
|||
this.remaining = 0;
|
||||
this.sound = undefined;
|
||||
this.tickHandle = undefined;
|
||||
if ('undefined' !== typeof json) {
|
||||
this.fromJSON(json);
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
|
|
@ -21,9 +21,12 @@ const decorate = compose(
|
|||
|
||||
export class Animation extends decorate(Resource) {
|
||||
|
||||
constructor() {
|
||||
constructor(json) {
|
||||
super();
|
||||
this.imageUri = undefined;
|
||||
if ('undefined' !== typeof json) {
|
||||
this.fromJSON(json);
|
||||
}
|
||||
}
|
||||
|
||||
get sourceRectangle() {
|
||||
|
|
|
@ -16,10 +16,13 @@ const decorate = compose(
|
|||
|
||||
export class Tileset extends decorate(Resource) {
|
||||
|
||||
constructor() {
|
||||
constructor(json) {
|
||||
super();
|
||||
this._geometry = {};
|
||||
this.subimages = [];
|
||||
if ('undefined' !== typeof json) {
|
||||
this.fromJSON(json);
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user