package level;

import dummy.Screen;
import lib.Colors;

public abstract class Tile {
	protected static final Tile[] tilesRegistry = new Tile[64]; //Allows for 64 Main Game Tiles
	protected static final Tile[] modTilesRegistry = new Tile[64]; //Allow for 64 Modded Tiles
	
	protected byte id;
	protected boolean solid;
	private int color;
	
	public void registerTiles() {
		new BasicSolidTile(0, 0, 0, Colors.BLACK, 0xff000000); //Void Tile
		new BasicTile(1, 1, 0, Colors.WHITE, 0xff555555); //Road Tile
	}
	
	public Tile(int id, boolean isSolid, int color) {
		this.id = (byte)id;
		
		
		this.solid = isSolid;
		this.color = color;
		
		if (id <= 64) {
			if (tilesRegistry[id] != null) throw new RuntimeException("Duplicate Tile id on " + id + "\n" + "IDs (1-64) are reserved for non-modded tiles!");
			tilesRegistry[id] = this;
		} if (id > 64 && id <= 128) {
			if (modTilesRegistry[id] != null) throw new RuntimeException("Duplicate Tile id on " + id + "\n" + "Please use IDs (65-128) for modded tiles!");
			modTilesRegistry[id] = this;
		} if (id > 128) {
			throw new RuntimeException("Tile ID outside of allowed range. Please use 65-128 for modded tiles!");
		}
	}
	
	public byte getId() {
		return id;
	}
	
	public boolean isSolid() {
		return solid;
	}
	
	public int getColor() {
		return color;
	}
	
	public abstract void tick();
	public abstract void render(Screen screen, Level level, int x, int y);
}
