summaryrefslogtreecommitdiffstats
path: root/nametable.js
blob: 92a09a5e1de7ea552d3066c6537dca6d5c744273 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function NameTable(width, height, name) {	
	this.name = name;
	
	this.tile = new Array(width*height);
	this.attrib = new Array(width*height);
	
	this.width = width;
	this.height = height;
}

NameTable.prototype.getTileIndex = function(x, y){
	return this.tile[y*this.width+x];
}

NameTable.prototype.getAttrib = function(x, y){
	return this.attrib[y*this.width+x];
}

NameTable.prototype.writeAttrib = function(index, value){
	var basex,basey;
	var add;
	var tx,ty;
	var attindex;
	basex = index%8;
	basey = parseInt(index/8);
	basex *= 4;
	basey *= 4;
	
	for(var sqy=0;sqy<2;sqy++){
		for(var sqx=0;sqx<2;sqx++){
			add = (value>>(2*(sqy*2+sqx)))&3;
			for(var y=0;y<2;y++){
				for(var x=0;x<2;x++){
					tx = basex+sqx*2+x;
					ty = basey+sqy*2+y;
					attindex = ty*this.width+tx;
					this.attrib[ty*this.width+tx] = (add<<2)&12;
					////System.out.println("x="+tx+" y="+ty+" value="+attrib[ty*width+tx]+" index="+attindex);
				}
			}
		}
	}
}