refactor: get rid of fromJSON promise return
This commit is contained in:
parent
e97aef03d1
commit
ad317f1cd6
|
@ -1,10 +1,14 @@
|
|||
import {compose} from '@avocado/core';
|
||||
import {compose, EventEmitter, Property} from '@avocado/core';
|
||||
import {hasGraphics, Image} from '@avocado/graphics';
|
||||
import {Rectangle, Vector} from '@avocado/math';
|
||||
import {shapeFromJSON} from '@avocado/physics';
|
||||
import {Resource} from '@avocado/resource';
|
||||
|
||||
const decorate = compose(
|
||||
EventEmitter,
|
||||
Property('image', {
|
||||
track: true,
|
||||
}),
|
||||
Vector.Mixin('tileSize', 'tileWidth', 'tileHeight', {
|
||||
default: [0, 0],
|
||||
}),
|
||||
|
@ -15,7 +19,6 @@ export class Tileset extends decorate(Resource) {
|
|||
constructor() {
|
||||
super();
|
||||
this._geometry = {};
|
||||
this._image = undefined;
|
||||
this.subimages = [];
|
||||
}
|
||||
|
||||
|
@ -38,13 +41,10 @@ export class Tileset extends decorate(Resource) {
|
|||
this.tileSize = json.tileSize;
|
||||
}
|
||||
if (hasGraphics && json.imageUri) {
|
||||
promise = Image.load(json.imageUri).then((image) => {
|
||||
Image.load(json.imageUri).then((image) => {
|
||||
this.image = image;
|
||||
});
|
||||
}
|
||||
return Promise.resolve(promise).then(() => {
|
||||
return this;
|
||||
});
|
||||
}
|
||||
|
||||
geometry(index) {
|
||||
|
@ -52,18 +52,20 @@ export class Tileset extends decorate(Resource) {
|
|||
}
|
||||
|
||||
get image() {
|
||||
return this._image;
|
||||
return super.image;
|
||||
}
|
||||
|
||||
set image(image) {
|
||||
this._image = image
|
||||
this.recalculateSubimages();
|
||||
this.recalculateSubimages(image);
|
||||
super.image = image;
|
||||
}
|
||||
|
||||
recalculateSubimages() {
|
||||
const image = this._image;
|
||||
recalculateSubimages(image) {
|
||||
if (!image) {
|
||||
return;
|
||||
}
|
||||
const tileSize = this.tileSize;
|
||||
if (!image || Vector.isZero(tileSize)) {
|
||||
if (Vector.isZero(tileSize)) {
|
||||
return;
|
||||
}
|
||||
this.destroy();
|
||||
|
@ -90,7 +92,7 @@ export class Tileset extends decorate(Resource) {
|
|||
|
||||
set tileSize(tileSize) {
|
||||
super.tileSize = tileSize;
|
||||
this.recalculateSubimages();
|
||||
this.recalculateSubimages(this.image);
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user