class Sprite {
	private readonly defines = new Map();

	constructor(private img: HTMLImageElement) {}

	define(name: string, x: number, y: number, w: number, h: number) {
		this.defines.set(name, { x, y, w, h });
	}

	draw(ctx: CanvasRenderingContext2D, x: number, y: number, name: string) {
		const def = this.params(name);
		if (def) {
			ctx.drawImage(
				this.img,
				def.x,
				def.y,
				def.w,
				def.h,
				Math.round(x),
				Math.round(y),
				def.w,
				def.h,
			);
		}
	}

	params(name: string) {
		return this.defines.get(name);
	}
}

export default Sprite;
