"use strict";
function is_solid(x){
	if(x == 1 || x == 2 || x == 4) return 1;
	return 0;
}

			/*if(mask == parseInt('1111',2)) t.tiles[a] = ["tile_test_plane", 0, 0];
			else if(mask == parseInt('1100',2)) t.tiles[a] = ["tile_test_inverted_corner", 0, 2];
			else if(mask == parseInt('0110',2)) t.tiles[a] = ["tile_test_inverted_corner", 0, 1];
			else if(mask == parseInt('0011',2)) t.tiles[a] = ["tile_test_inverted_corner", 0, 0];
			else if(mask == parseInt('1001',2)) t.tiles[a] = ["tile_test_inverted_corner", 0, 3];
			else if(mask == parseInt('0111',2)) t.tiles[a] = ["tile_test_wall", 0, 0];
			else if(mask == parseInt('1011',2)) t.tiles[a] = ["tile_test_wall", 0, 3];
			else if(mask == parseInt('1101',2)) t.tiles[a] = ["tile_test_wall", 0, 2];
			else if(mask == parseInt('1110',2)) t.tiles[a] = ["tile_test_wall", 0, 1];
			
			else if(mask == parseInt('1010',2)) t.tiles[a] = ["tile_test_corridor", 0, 1];
			else if(mask == parseInt('0101',2)) t.tiles[a] = ["tile_test_corridor", 0, 0];*/
			

function edge_resolver(input,t,size){
	var sx = size[0];
	var sy = size[1];
	
	var x;
	var y;
	
	//var t = new Array(sx*sy);
	
	//for(x in t) t[x] = [null, 0, 0];
	
	for(y=1; y<sy -1; y+=1)
	for(x=1; x<sx -1; x+=1){
		var a = x + sx * y;
		if(!is_solid(input[a])){
			var mask = 0;
			// UP LEFT RIGHT DOWN
			mask |= is_solid(input[a - sx]) << 0;
			mask |= is_solid(input[a - 1]) << 1;
			mask |= is_solid(input[a + sx]) << 2;
			mask |= is_solid(input[a + 1]) << 3;

			mask |= is_solid(input[a - sx + 1]) << 4;
			mask |= is_solid(input[a - sx - 1]) << 5;
			mask |= is_solid(input[a + sx + 1]) << 6;
			mask |= is_solid(input[a + sx - 1]) << 7;
			

			
			if(mask) t.tiles[a] = ["tile_test_block", 0, 0, "tile_test_wall", 0, 0];
			
			//console.log(mask);
		}else t.tiles[a] = ["tile_test_plane", 0, 0];
	}
	return t;
}