-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch.js
More file actions
85 lines (81 loc) · 1.87 KB
/
patch.js
File metadata and controls
85 lines (81 loc) · 1.87 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var patches = [];
class Patch
{
lump;
width;
height;
xOffset;
yOffset;
img;
columns;
constructor(lump)
{
this.lump = lump;
this.width = lump.lumpDataView.getUint16(0, true);
this.height = lump.lumpDataView.getUint16(2, true);
this.xOffset = lump.lumpDataView.getInt16(4, true);
this.yOffset = lump.lumpDataView.getInt16(6, true);
this.img = [];
this.columns = [];
for(var i = 0; i < this.width; i++)
{
this.img[i] = [];
for(var y = 0; y < this.height; y++)
{
this.img[i][y] = -1; //transparency
}
this.columns[i] = [];
this.columns[i].offset = lump.lumpDataView.getUint32(8+(i*4), true);
var topdelta = 0x00;
var length = 0;
for(var k = 0; topdelta < 0xFF; k++)
{
topdelta = lump.lumpDataView.getUint8(this.columns[i].offset+length);
if(topdelta >= 0xFF) break;
this.columns[i][k] = {};
this.columns[i][k].topdelta = topdelta;
this.columns[i][k].size = lump.lumpDataView.getUint8(this.columns[i].offset+length+1);
this.columns[i][k].data = [];
for(var j = 0; j < this.columns[i][k].size; j++)
{
this.columns[i][k].data[j] = lump.lumpDataView.getUint8(this.columns[i].offset+length+3+j);
if(topdelta+j < this.height)
this.img[i][topdelta+j] = this.columns[i][k].data[j];
}
length += this.columns[i][k].size+4
}
if(topdelta >= 0xFF) continue;
}
}
static precachePatch(lump)
{
if(!patches[lump] && wad)
{
var l = wad.getLastLump(lump);
if(l) patches[lump] = new Patch(l);
}
return patches[lump];
}
static getPatch(patch)
{
return Patch.precachePatch(patch);
}
static drawPatch(patch, x, y)
{
var p = Patch.getPatch(patch);
if(p)
{
for(var w = 0; w < p.width; w++)
{
for(var h = 0; h < p.height; h++)
{
if(p.img[w][h] >= 0)
{
graphics.drawPixel(p.img[w][h],x+w-p.xOffset,y+h-p.yOffset)
}
}
}
}
return p;
}
}