Factor out AnimatableTile{Factory}

This commit is contained in:
Ian Gulliver
2021-05-11 05:28:20 +00:00
parent 4e65819183
commit 8f76317ccc
16 changed files with 80 additions and 51 deletions

View File

@@ -1,24 +1,11 @@
import { Tile } from './tile.js';
export class SimpleTile extends Tile {
animations: Map<string, [Keyframe[], object]>;
import { AnimatableTile } from './animatable_tile.js';
export class SimpleTile extends AnimatableTile {
constructor(width: number, height: number, image_url: string, animations: Map<string, [Keyframe[], object]>) {
super(width, height);
super(width, height, animations);
this.elem.style.backgroundImage = `url('${encodeURIComponent(image_url)}')`;
this.elem.style.backgroundSize = 'cover';
this.animations = animations;
}
play(name: string): Animation | undefined {
const animation = this.animations.get(name);
if (animation) {
return this.elem.animate(...animation);
} else {
return undefined;
}
}
}