2021-05-13 04:09:46 +00:00
|
|
|
import { AnimatableTile } from './animatable_tile.js';
|
2021-05-12 04:48:16 +00:00
|
|
|
import { Tile } from './tile.js';
|
|
|
|
|
|
2021-05-13 04:09:46 +00:00
|
|
|
export class SequenceTile extends AnimatableTile {
|
|
|
|
|
constructor(width: number, height: number, animations: Map<string, [Keyframe[], object]>, tiles: Tile[], delay: number, repeat: boolean) {
|
|
|
|
|
super(width, height, animations);
|
2021-05-12 04:48:16 +00:00
|
|
|
|
|
|
|
|
this.elem.style.position = 'relative';
|
|
|
|
|
|
|
|
|
|
const tile_chunk = 1 / tiles.length;
|
|
|
|
|
let animation = null;
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < tiles.length; i++) {
|
|
|
|
|
const tile = tiles[i];
|
|
|
|
|
|
|
|
|
|
this.elem.appendChild(tile.elem);
|
|
|
|
|
tile.elem.style.width = '100%';
|
|
|
|
|
tile.elem.style.height = '100%';
|
|
|
|
|
tile.elem.style.position = 'absolute';
|
|
|
|
|
tile.elem.style.top = '0';
|
|
|
|
|
tile.elem.style.left = '0';
|
2021-05-13 05:02:05 +00:00
|
|
|
tile.elem.style.visibility = 'hidden';
|
2021-05-12 04:48:16 +00:00
|
|
|
|
|
|
|
|
animation = tile.elem.animate(
|
|
|
|
|
[
|
|
|
|
|
{
|
2021-05-13 05:00:18 +00:00
|
|
|
'offset': 0,
|
|
|
|
|
'easing': 'step-end',
|
2021-05-13 05:02:05 +00:00
|
|
|
'visibility': 'hidden',
|
2021-05-12 04:48:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
2021-05-13 05:00:18 +00:00
|
|
|
'offset': i * tile_chunk,
|
|
|
|
|
'easing': 'step-end',
|
2021-05-13 05:02:05 +00:00
|
|
|
'visibility': 'visible',
|
2021-05-12 04:48:16 +00:00
|
|
|
},
|
2021-05-13 05:00:18 +00:00
|
|
|
{
|
|
|
|
|
'offset': (i + 1) * tile_chunk,
|
2021-05-13 05:02:05 +00:00
|
|
|
'visibility': 'hidden',
|
2021-05-13 05:00:18 +00:00
|
|
|
},
|
2021-05-12 04:48:16 +00:00
|
|
|
],
|
|
|
|
|
{
|
2021-05-13 05:00:18 +00:00
|
|
|
'duration': tiles.length * delay,
|
2021-05-12 04:48:16 +00:00
|
|
|
'iterations': repeat ? Infinity : 1,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!repeat) {
|
|
|
|
|
animation!.finished.then(() => this.elem.remove());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
play(_: string): Animation | undefined {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|