
import * as c from ".././constants.js"

class GameArea {
	keys: string[] = [];
	handleInputInterval: number = 0;
	gameLoopInterval: number = 0;
	drawLoopInterval: number = 0;
	canvas: HTMLCanvasElement;
	ctx: CanvasRenderingContext2D;
	constructor() {
		this.canvas = document.createElement("canvas");
		this.ctx = this.canvas.getContext("2d") as CanvasRenderingContext2D;
		this.canvas.width = c.CanvasWidth;
		this.canvas.height = c.CanvasWidth / c.CanvasRatio;
		let container = document.getElementById("canvas_container");
		if (container)
			container.insertBefore(this.canvas, container.childNodes[0]);
	}
	addKey(key: string) {
		key = key.toLowerCase();
		var i = this.keys.indexOf(key);
		if (i == -1)
			this.keys.push(key);
	}
	deleteKey(key: string) {
		key = key.toLowerCase();
		var i = this.keys.indexOf(key);
		if (i != -1) {
			this.keys.splice(i, 1);
		}
	}
	clear() {
		this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
	}
}

export {GameArea}
