import { AnimatedSprite } from 'pixi';
import GameItem from './game-item.js';

export default class WeaponShot extends GameItem
{
	constructor(sheet, id, model)
	{
		super();

		this.id = id;

		// Pick the animation by weapon model name (e.g. "Torpedo" -> torpedo, "Mine" -> mine),
		// so new weapons can be added just by adding their frames and an animation named after them.
		// A single-frame animation (like the mine) simply renders static.
		const frames = sheet.animations[model?.toLowerCase()] ?? sheet.animations.torpedo;

		this.sprite = new AnimatedSprite(frames);
		this.sprite.animationSpeed = 0.5;
		this.sprite.play();

		this.sprite.anchor.set(0.5);
		this.container.addChild(this.sprite);
	}

	render()
	{
		this.updatePosition();
	}
}
