-
Notifications
You must be signed in to change notification settings - Fork 2
/
wad.min.js
2 lines (2 loc) · 26.7 KB
/
wad.min.js
1
2
function hexToRgb(a){var b=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);return b?{r:parseInt(b[1],16),g:parseInt(b[2],16),b:parseInt(b[3],16)}:null}function readName(a,b){for(output="",j=b;j<b+8;j++)0!=a.getUint8(j)&&(output+=String.fromCharCode(a.getUint8(j)));return output}function mus2midi(a){function b(){c(["M".charCodeAt(0),"T".charCodeAt(0),"h".charCodeAt(0),"d".charCodeAt(0),0,0,0,6,0,0,0,1,0,70,"M".charCodeAt(0),"T".charCodeAt(0),"r".charCodeAt(0),"k".charCodeAt(0),0,0,0,0])}function c(a){P=P.concat(a)}function d(){var a=new ArrayBuffer(P.length);t=new DataView(a);for(var b=0;b<P.length;b++)t.setUint8(O,P[b]),O+=1}function e(a){for(var b,d=127&a;0!=(a>>=7);)d<<=8,d|=127&a|128;for(;;){if(b=255&d,c([b]),s+=1,0==(128&d))return void(L=0);d>>=8}}function f(){endtrack=[255,47,0],e(L),c(endtrack),s+=3}function g(a,b,d){e(L);var f=B|a;c([f]),f=127&b,c([f]),f=127&d,c([f]),s+=3}function h(a,b){e(L);var d=A|a;c([d]),d=127&b,c([d]),d=0,c([d]),s+=3}function i(a,b){e(L);var d=E|a;c([d]),d=127&b,c([d]),d=b>>7&127,c([d]),s+=3}function j(a,b){e(L);var d=D|a;c([d]),d=127&b,c([d]),s+=2}function k(a,b,d){e(L);var f=C|a;c([f]),f=127&b,c([f]),f=128&d?127:d,c([f]),s+=3}function l(a,b){k(a,b,0)}function m(){var a,b,c;for(b=-1,c=0;c<G;++c)N[c]>b&&(b=N[c]);return a=b+1,a==I&&++a,a}function n(a){return a==H?I:(-1==N[a]&&(N[a]=m()),N[a])}function o(a){for(var b=Object.create(F),c=0;c<4;c++)b.id.push(a.getUint8(c));return b.scorelength=a.getUint16(4,!0),b.scorestart=a.getUint16(6,!0),b.primarychannels=a.getUint16(8,!0),b.secondarychannels=a.getUint16(10,!0),b.instrumentcount=a.getUint16(12,!0),b}function p(a){function c(){var a=q.getUint8(r);return r+=1,a}q=new DataView(a),r=0,console.log("start mus2midi");var e=Date.now(),m=new ArrayBuffer(0);t=new DataView(m);var p,A,B,C,D,E,F,H,I=0;for(B=0;B<G;++B)N[B]=-1;if(p=o(q),p.id[0]!="M".charCodeAt(0)||p.id[1]!="U".charCodeAt(0)||p.id[2]!="S".charCodeAt(0)||26!=p.id[3])return console.log("mus header fail"),!1;for(r=p.scorestart,b(),s=0;0==I;){for(;0==I;){switch(A=c(),B=n(15&A),112&A){case u:C=c(),h(B,C);break;case v:C=c(),128&C&&(K[B]=c(),K[B]&=127),g(B,C,K[B]);break;case w:C=c(),i(B,64*C);break;case x:if((D=c())<10||D>14)return console.log("controller number inaccurate 10-14:"+D),!1;l(B,M[D]);break;case y:if(D=c(),E=c(),0==D)j(B,E);else{if(D<1||D>9)return console.log("controller number inaccurate: "+D),!1;k(B,M[D],E)}break;case z:I=1;break;default:return!1}if(0!=(128&A))break}if(0==I){for(H=0;F=c(),H=128*H+(127&F),0!=(128&F););L+=H}}return console.log("finish writing"),console.log("time: "+(Date.now()-e)),f(),d(),t.setUint8(J+0,s>>24&255),t.setUint8(J+1,s>>16&255),t.setUint8(J+2,s>>8&255),t.setUint8(J+3,255&s),t.buffer}var q,r,s,t,u=0,v=16,w=32,x=48,y=64,z=96,A=128,B=144,C=176,D=192,E=224,F={id:[],scorelength:null,scorestart:null,primarychannels:null,secondarychannels:null,instrumentcount:null},G=16,H=15,I=9,J=18,K=[127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127],L=0,M=[0,32,1,7,10,11,91,93,64,67,120,123,126,127,121],N=[],O=0,P=[],Q=p(a);return 0!=Q?Q:(console.log("Failed to convert mus to midi. Sucks."),console.log(r),console.log(a.byteLength),console.log(Q),!1)}var TEXT="text",MAP="map",MAPDATA="mapdata",MUSIC="music",MIDI="midi",MP3="mp3",PNG="png",MUS="mus",GRAPHIC="graphic",FLAT="flat",MARKER="marker",PLAYPAL="PLAYPAL",COLORMAP="COLORMAP",ENDOOM="ENDOOM",PNAMES="PNAMES",TEXTUREx=["TEXTURE1","TEXTURE2"],GRAPHIC_MARKERS=["P_","PP_","P1_","P2_","P3_","S_","S2_","S3_","SS_"],FLAT_MARKERS=["F_","FF_","F1_","F2_","F3_"],MAPLUMPS=["THINGS","LINEDEFS","SIDEDEFS","VERTEXES","SEGS","TEXTMAP","SSECTORS","NODES","SECTORS","REJECT","BLOCKMAP","BEHAVIOR","ZNODES"],TEXTLUMPS=["DEHACKED","MAPINFO","ZMAPINFO","EMAPINFO","DMXGUS","DMXGUSC","WADINFO","EMENUS","MUSINFO","SNDINFO","GLDEFS","KEYCONF","SCRIPTS","LANGUAGE","DECORATE","SBARINFO","MENUDEF"],DATA_LUMPS=["PLAYPAL","COLORMAP","TEXTURE1","TEXTURE2","PNAMES","ENDOOM"],DEFAULT_EXTENSION="lmp",EXTENSIONS={text:"txt",mp3:"mp3",mus:"mus",midi:"mid",png:"png"},Wad={onProgress:null,onLoad:null,ident:"",numlumps:-1,dictpos:-1,data:null,lumps:[],playpal:null,errormsg:null,error:function(a){self.errormsg=a},loadURL:function(a){var b=new XMLHttpRequest;b.open("GET",a,!0),b.responseType="blob";var c=this;b.onload=function(a){if(200==this.status){var b=this.response;c.load(b)}},b.send()},load:function(a){var b=this;b.lumps=[];var c=0,d=-1,e=new FileReader;e.readAsArrayBuffer(a),e.onprogress=b.onProgress,e.onload=function(e){b.data=e.target.result;for(var f=new DataView(e.target.result),g=0;g<4;g++)b.ident+=String.fromCharCode(f.getUint8(g));"IWAD"!=b.ident&&"PWAD"!=b.ident?(b.error("Not a valid WAD file."),b.onLoad()):(b.numlumps=f.getInt32(4,!0),b.dictpos=f.getInt32(8,!0),c=b.dictpos,d=128,chunkReaderBlock(b.dictpos,d,a))};var f=function(e){c+=e.target.result.byteLength;for(var f=new DataView(e.target.result),g=0;g<f.byteLength/16;g++){var h=16*g,i=f.getInt32(h,!0),k=f.getInt32(h+4,!0),l="";for(j=h+8;j<h+16;j++)0!=f.getUint8(j)&&(l+=String.fromCharCode(f.getUint8(j)));lumpEntry={pos:i,size:k,name:l},b.lumps.push(lumpEntry)}if(c>=a.size)return b.onProgress(),b.onLoad(),b.playpal=Object.create(Playpal),void(b.lumpExists("PLAYPAL")&&b.playpal.load(wad.getLumpByName("PLAYPAL")));chunkReaderBlock(c,d,a)};chunkReaderBlock=function(a,c,d){var e=new FileReader,g=d.slice(a,a+c);e.onload=f,e.onprogress=b.onProgress,e.readAsArrayBuffer(g)}},save:function(){var a=prompt("Save as...","output.wad");if(null!=this.data){var b=new Blob([this.data],{type:"octet/stream"}),c=document.createElement("a");document.body.appendChild(c),c.style="display:none;";var d=window.URL.createObjectURL(b);c.href=d,c.download=a,c.click(),window.URL.revokeObjectURL(d)}},saveLump:function(a){var b=this.lumps[a].name+".lmp",c=new Blob([this.getLump(a)],{type:"octet/stream"}),d=document.createElement("a");document.body.appendChild(d),d.style="display:none;";var e=window.URL.createObjectURL(c);d.href=e,d.download=b,d.click(),window.URL.revokeObjectURL(e)},lumpExists:function(a){for(var b=0;b<this.numlumps;b++)if(this.lumps[b].name==a)return!0;return!1},getLumpByName:function(a){for(var b=0;b<this.numlumps;b++)if(this.lumps[b].name==a)return l=this.lumps[b],this.data.slice(l.pos,l.pos+l.size);return null},getLumpIndexByName:function(a){for(var b=this.numlumps-1;b>=0;b--)if(this.lumps[b].name==a)return b;return null},getLumpAsText:function(a){var b=this.getLump(a);return this.lumpDataToText(b)},lumpDataToText:function(a){output="";var b=new DataView(a);for(i=0;i<a.byteLength;i++)output+=String.fromCharCode(b.getUint8(i));return output},getLump:function(a){return l=this.lumps[a],this.data.slice(l.pos,l.pos+l.size)}},MapData={things:null,vertexes:null,linedefs:null,sidedefs:null,segs:null,ssectors:null,nodes:null,sectors:null,reject:null,blockmap:null,wad:null,thingTable:null,name:null,music:null,format:null,top:null,left:null,bottom:null,right:null,load:function(a,b){function c(b){return a.getLump(d+mapdatalumps.indexOf(b)+1)}var d=a.getLumpIndexByName(b);if(this.wad=a,this.reject=null,this.blockmap=null,this.nodesExist,"TEXTMAP"==a.lumps[d+1].name)this.format="UDMF";else{var e=1;for(mapdatalumps=[],nextLump=a.lumps[d+e].name;MAPLUMPS.indexOf(nextLump)>-1&&(mapdatalumps.push(nextLump),e+=1,a.lumps.length!=e+d);)nextLump=a.lumps[d+e].name;mapdatalumps.indexOf("BEHAVIOR")>-1?this.format="Hexen":this.format="Doom"}"Doom"==this.format&&(this.parseThings(c("THINGS")),this.parseLinedefs(c("LINEDEFS")),this.parseSidedefs(c("SIDEDEFS")),this.parseVertexes(c("VERTEXES")),this.parseSegs(c("SEGS")),this.parseSsectors(c("SSECTORS")),this.parseNodes(c("NODES")),this.parseSectors(c("SECTORS")),this.calculateBoundaries()),"Hexen"==this.format&&(this.parseHexenThings(c("THINGS")),this.parseHexenLinedefs(c("LINEDEFS")),this.parseSidedefs(c("SIDEDEFS")),this.parseVertexes(c("VERTEXES")),this.parseSegs(c("SEGS")),this.parseSsectors(c("SSECTORS")),this.parseNodes(c("NODES")),this.parseSectors(c("SECTORS")),this.calculateBoundaries()),this.name=b,/^E\dM\d/.test(b)&&(a.lumpExists("MUS_"+b)&&(this.music="MUS_"+b),a.lumpExists("D_"+b)&&(this.music="D_"+b)),null!=Doom2DefaultMusic[b]&&(this.music=Doom2DefaultMusic[b])},calculateBoundaries:function(){this.top=this.vertexes[0].y,this.left=this.vertexes[0].x,this.bottom=this.vertexes[0].y,this.right=this.vertexes[0].x;for(var a=1;a<this.vertexes.length;a++)this.vertexes[a].x<this.left&&(this.left=this.vertexes[a].x),this.vertexes[a].x>this.right&&(this.right=this.vertexes[a].x),this.vertexes[a].y<this.top&&(this.top=this.vertexes[a].y),this.vertexes[a].y>this.bottom&&(this.bottom=this.vertexes[a].y)},parseThings:function(a){this.things=[];for(var b=10,c=new DataView(a),d=c.byteLength/b,e=0;e<d;e++)r=Object.create(Thing),r.x=c.getInt16(e*b+0,!0),r.y=c.getInt16(e*b+2,!0),r.angle=c.getInt16(e*b+4,!0),r.type=c.getInt16(e*b+6,!0),r.flags=c.getInt16(e*b+8,!0),this.things.push(r)},parseVertexes:function(a){this.vertexes=[];for(var b=4,c=new DataView(a),d=c.byteLength/b,e=0;e<d;e++)r=Object.create(Vertex),r.x=c.getInt16(e*b+0,!0),r.y=c.getInt16(e*b+2,!0),this.vertexes.push(r)},parseLinedefs:function(a){this.linedefs=[];for(var b=14,c=new DataView(a),d=c.byteLength/b,e=0;e<d;e++)r=Object.create(Linedef),r.vx1=c.getUint16(e*b+0,!0),r.vx2=c.getUint16(e*b+2,!0),r.flags=c.getUint16(e*b+4,!0),r.action=c.getUint16(e*b+6,!0),r.tag=c.getUint16(e*b+8,!0),r.right=c.getUint16(e*b+10,!0),r.left=c.getUint16(e*b+12,!0),this.linedefs.push(r)},parseSidedefs:function(a){this.sidedefs=[];for(var b=30,c=new DataView(a),d=c.byteLength/b,e=0;e<d;e++)r=Object.create(Sidedef),r.xOffset=c.getUint16(e*b+0,!0),r.yOffset=c.getUint16(e*b+2,!0),r.upper=readName(c,e*b+4),r.lower=readName(c,e*b+12),r.middle=readName(c,e*b+20),r.sector=c.getUint16(e*b+28,!0),this.sidedefs.push(r)},parseSectors:function(a){this.sectors=[];for(var b=26,c=new DataView(a),d=c.byteLength/b,e=0;e<d;e++)r=Object.create(Sector),r.zFloor=c.getUint16(e*b+0,!0),r.zCeil=c.getUint16(e*b+2,!0),r.floorFlat=readName(c,e*b+4),r.ceilFlat=readName(c,e*b+12),r.light=c.getUint16(e*b+20,!0),r.type=c.getUint16(e*b+22,!0),r.tag=c.getUint16(e*b+24,!0),this.sectors.push(r)},parseSegs:function(a){this.segs=[];for(var b=12,c=new DataView(a),d=c.byteLength/b,e=0;e<d;e++)r=Object.create(Seg),r.vx1=c.getUint16(e*b+0,!0),r.vx2=c.getUint16(e*b+2,!0),r.angle=c.getUint16(e*b+4,!0),r.linedef=c.getUint16(e*b+6,!0),r.direction=c.getUint16(e*b+8,!0),r.offset=c.getUint16(e*b+10,!0),this.segs.push(r)},parseSsectors:function(a){this.ssectors=[];for(var b=4,c=new DataView(a),d=c.byteLength/b,e=0;e<d;e++)r=Object.create(Subsector),r.segCount=c.getUint16(e*b+0,!0),r.first=c.getUint16(e*b+2,!0),this.ssectors.push(r)},parseNodes:function(a){this.nodes=[];for(var b=28,c=new DataView(a),d=c.byteLength/b,e=0;e<d;e++)r=Object.create(Node),r.partitionX=c.getUint16(e*b+0,!0),r.partitionY=c.getUint16(e*b+2,!0),r.changeX=c.getUint16(e*b+4,!0),r.changeY=c.getUint16(e*b+6,!0),r.boundsRight={top:c.getUint16(e*b+8,!0),bottom:c.getUint16(e*b+10,!0),left:c.getUint16(e*b+12,!0),right:c.getUint16(e*b+14,!0)},r.boundsLeft={top:c.getUint16(e*b+16,!0),bottom:c.getUint16(e*b+18,!0),left:c.getUint16(e*b+20,!0),right:c.getUint16(e*b+22,!0)},r.childRight=c.getUint16(e*b+24,!0),r.childLeft=c.getUint16(e*b+26,!0),this.nodes.push(r)},parseHexenThings:function(a){this.things=[];for(var b=20,c=new DataView(a),d=c.byteLength/b,e=0;e<d;e++){r=Object.create(HexenThing),r.tid=c.getInt16(e*b+0,!0),r.x=c.getInt16(e*b+2,!0),r.y=c.getInt16(e*b+4,!0),r.z=c.getInt16(e*b+6,!0),r.angle=c.getInt16(e*b+8,!0),r.type=c.getInt16(e*b+10,!0),r.flags=c.getInt16(e*b+12,!0),r.special=c.getInt8(e*b+14);for(var f=0;f<5;f++)r.args[f]=c.getInt8(e*b+15+f);this.things.push(r)}},parseHexenLinedefs:function(a){this.linedefs=[];for(var b=16,c=new DataView(a),d=c.byteLength/b,e=0;e<d;e++){r=Object.create(HexenLinedef),r.vx1=c.getUint16(e*b+0,!0),r.vx2=c.getUint16(e*b+2,!0),r.flags=c.getUint16(e*b+4,!0),r.action=c.getUint8(e*b+6);for(var f=0;f<5;f++)r.args[f]=c.getInt8(e*b+7+f);r.right=c.getUint16(e*b+12,!0),r.left=c.getUint16(e*b+14,!0),this.linedefs.push(r)}},toCanvas:function(a,b){if("UDMF"==this.format){var c=document.createElement("div");return c.innerHTML="Unable to render "+this.format+" format maps.",c}var d,e=document.createElement("canvas"),f=this.right-this.left,g=this.bottom-this.top;b/a<f/g?(e.height=b+10,d=b/g,e.width=d*f+10):(e.width=a+10,d=a/f,e.height=d*g+10);var h=e.getContext("2d");h.fillStyle=this.wad.playpal.palettes[0][0],h.fillRect(0,0,e.width,e.height),h.imageSmoothingEnabled=!1;for(var i=0;i<this.linedefs.length;i++){l=this.linedefs[i];var j=l.getVx1(this).x,k=l.getVx1(this).y,m=l.getVx2(this).x,n=l.getVx2(this).y;if(j-=this.left,m-=this.left,k-=this.top,n-=this.top,j*=d,m*=d,k*=d,n*=d,h.strokeStyle=this.wad.playpal.palettes[0][96],65535!=l.left){var o=this.sidedefs[l.right],p=this.sidedefs[l.left];this.sectors[o.sector].zFloor!=this.sectors[p.sector].zFloor?h.strokeStyle=this.wad.playpal.palettes[0][64]:this.sectors[o.sector].zCeil!=this.sectors[p.sector].zCeil&&(h.strokeStyle=this.wad.playpal.palettes[0][231])}else h.strokeStyle=this.wad.playpal.palettes[0][176];h.beginPath(),h.moveTo(Math.floor(j)+5.5,Math.floor(e.height-k-5)+.5),h.lineTo(Math.floor(m)+5.5,Math.floor(e.height-n-5)+.5),h.stroke()}return e},getDoomThingName:function(a){for(var b in DoomThingTable)if(DoomThingTable.hasOwnProperty(b)&&DoomThingTable[b]===a)return b},getThingTable:function(){this.thingTable=[];for(var a=0;a<this.things.length;a++)void 0==this.thingTable[this.things[a].type]?this.thingTable[this.things[a].type]=1:this.thingTable[this.things[a].type]+=1;return this.thingTable},getThingCount:function(a){for(var b=0,c=0;c<this.things.length;c++)this.things[c].type==a&&(b+=1);return b}},Thing={x:null,y:null,angle:null,type:null,flags:null},Vertex={x:null,y:null},Linedef={vx1:null,vx2:null,flags:null,action:null,tag:null,right:null,left:null,getVx1:function(a){return a.vertexes[this.vx1]},getVx2:function(a){return a.vertexes[this.vx2]}},Sidedef={xOffset:null,yOffset:null,upper:null,lower:null,middle:null,sector:null},Seg={vx1:null,vx2:null,angle:null,linedef:null,direction:null,offset:null},Subsector={segCount:null,first:null},Node={partitionX:null,partitionY:null,changeX:null,changeY:null,boundsRight:null,boundsLeft:null,childRight:null,childLeft:null},Sector={zFloor:null,zCeil:null,floorFlat:null,ceilFlat:null,light:null,type:null,tag:null},Reject={},Blockmap={},HexenThing={tid:null,x:null,y:null,z:null,angle:null,type:null,flags:null,special:null,args:[]},HexenLinedef={vx1:null,vx2:null,flags:null,action:null,args:[],right:null,left:null,getVx1:function(a){return a.vertexes[this.vx1]},getVx2:function(a){return a.vertexes[this.vx2]}},DoomThingGroups={Monsters:[68,64,3003,3005,65,72,16,3002,3004,9,69,3001,67,71,66,58,7,84],Powerups:[2023,2026,2014,2024,2022,2045,83,2013,2015,2019,2018,2012,2025,2011],Weapons:[2006,2002,2005,2004,2003,2001,82],Ammunition:[2007,2048,2046,2049,2047,17,2010,2008,8],Keys:[5,40,13,38,6,39]},DoomThingTable={zombie:3004,sergeant:9,commando:65,imp:3001,demon:3002,spectre:58,"lost soul":3006,cacodemon:3005,"hell knight":69,"baron of hell":3003,revenant:66,mancubus:67,arachnotron:68,"pain elemental":71,archvile:64,cyberdemon:16,"spider mastermind":7,"ss guy":84,"spawn target":87,"spawn shooter":89,"romero head":88,"commander keen":72,shotgun:2001,"super shotgun":82,chaingun:2002,"rocket launcher":2003,"plasma gun":2004,chainsaw:2005,"bfg 9000":2006,"ammo clip":2007,"ammo box":2048,shells:2008,"shell box":2049,rocket:2010,"rocket box":2046,"cell charge":2047,"cell pack":17,backpack:8,stimpack:2011,medikit:2012,supercharge:2013,"health bonus":2014,"armor bonus":2015,"green armor":2018,"blue armor":2019,invulnerability:2022,berserk:2023,invisibility:2024,"radiation suit":2025,"computer map":2026,goggles:2048,megasphere:83,"red keycard":13,"yellow keycard":6,"blue keycard":5,"red skull key":38,"yellow skull key":39,"blue skull key":40,"player 1 start":1,"player 2 start":2,"player 3 start":3,"player 4 start":4,"deathmatch start":11,"teleport destination":14,"gibs 1":10,"gibs 2":12,"dead marine":15,"dead zombie":18,"dead sergeant":19,"dead imp":20,"dead demon":21,"dead cacodemon":22,"dead lost soul":23,"pool of blood":24,"impaled human 1":25,"impaled human 2":26,"skull on pole":27,"five skulls":28,"skull pile":29,"hangman 1":49,"hangman 2":50,"hangman 3":51,"hangman 4":52,"hangman 5":53,"hangman 2 (passable)":59,"hangman 4 (passable)":60,"hangman 3 (passable)":61,"hangman 5 (passable)":62,"hangman 1 (passable)":63,"green pillar":30,"short green pillar":31,"red pillar":32,"short red pillar":33,candle:34,candelabra:35,"green pillar with heart":36,"red pillar with skull":37,eye:41,"skull rock":42,"gray tree":43,"blue torch":44,"green torch":45,"red torch":46,scrub:47,"tech column":48,"brown tree":54,"short blue torch":55,"short green torch":56,"short red torch":57,"floor lamp":2028,barrel:2035},Doom2DefaultMusic={MAP01:"D_RUNNIN",MAP02:"D_STALKS",MAP03:"D_COUNTD",MAP04:"D_BETWEE",MAP05:"D_DOOM",MAP06:"D_THE_DA",MAP07:"D_SHAWN",MAP08:"D_DDTBLU",MAP09:"D_IN_CIT",MAP10:"D_DEAD",MAP11:"D_STLKS2",MAP12:"D_THE_DA2",MAP13:"D_DOOM2",MAP14:"D_DDTBL2",MAP15:"D_RUNNI2",MAP16:"D_DEAD2",MAP17:"D_STLKS3",MAP18:"D_ROMERO",MAP19:"D_SHAWN2",MAP20:"D_MESSAG",MAP21:"D_COUNT2",MAP22:"D_DDTBL3",MAP23:"D_AMPIE",MAP24:"D_THEDA3",MAP25:"D_ADRIAN",MAP26:"D_MESSG2",MAP27:"D_ROMER2",MAP28:"D_TENSE",MAP29:"D_SHAWN3",MAP30:"D_OPENIN",MAP31:"D_EVIL",MAP32:"D_ULTIMA"};Wad.detectLumpType=function(a){function b(a,b){for(var c=(b.split(""),0);c<b.length;c++)if(b.charCodeAt(c)!=a.getUint8(c))return!1;return!0}function c(a,b){if(a.getUint16(0,!0)>4096)return!1;if(a.getUint16(2,!0)>4096)return!1;if(a.getInt16(4,!0)>2e3||a.getInt16(4,!0)<-2e3)return!1;if(a.getInt16(6,!0)>2e3||a.getInt16(6,!0)<-2e3)return!1;if(255!=a.getUint8(b.size-1)){for(var c=!1,d=1;d<=4;d++)if(0==c)if(255==a.getUint8(b.size-d))c=!0;else if(0!=a.getUint8(b.size-d))return!1;if(0==c)return!1}return!0}if(0!=this.lumps[a].size){var d=new DataView(this.data,this.lumps[a].pos);if(b(d,"MThd"))return MIDI;if(b(d,"ID3"))return MP3;if(b(d,"MUS"))return MUS;if(b(d,String.fromCharCode(137)+"PNG"))return PNG}var e=this.lumps[a].name;if(TEXTLUMPS.indexOf(e)>=0)return TEXT;if(MAPLUMPS.indexOf(e)>=0)return MAPDATA;if(DATA_LUMPS.indexOf(e)>=0)return e;if(/^MAP\d\d/.test(e))return MAP;if(/^E\dM\d/.test(e))return MAP;if(/_START$/.test(e))return MARKER;if(/_END$/.test(e))return MARKER;if(0==this.lumps[a].size)return MARKER;for(var f=a;f>=0&&!/_END$/.test(this.lumps[f].name);f--)if(/_START$/.test(this.lumps[f].name)){if(pre=this.lumps[f].name.substr(0,this.lumps[f].name.indexOf("_")+1),GRAPHIC_MARKERS.indexOf(pre)>=0)return GRAPHIC;if(FLAT_MARKERS.indexOf(pre)>=0)return FLAT}return/^D_/.test(e)?MUSIC:c(d,this.lumps[a])?GRAPHIC:"..."};var Playpal={rgbToHex:function(a,b,c){return"#"+((1<<24)+(a<<16)+(b<<8)+c).toString(16).slice(1)},palettes:[["#000000","#1f170b","#170f07","#4b4b4b","#ffffff","#1b1b1b","#131313","#0b0b0b","#070707","#2f371f","#232b0f","#171f07","#0f1700","#4f3b2b","#473323","#3f2b1b","#ffb7b7","#f7abab","#f3a3a3","#eb9797","#e78f8f","#df8787","#db7b7b","#d37373","#cb6b6b","#c76363","#bf5b5b","#bb5757","#b34f4f","#af4747","#a73f3f","#a33b3b","#9b3333","#972f2f","#8f2b2b","#8b2323","#831f1f","#7f1b1b","#771717","#731313","#6b0f0f","#670b0b","#5f0707","#5b0707","#530707","#4f0000","#470000","#430000","#ffebdf","#ffe3d3","#ffdbc7","#ffd3bb","#ffcfb3","#ffc7a7","#ffbf9b","#ffbb93","#ffb383","#f7ab7b","#efa373","#e79b6b","#df9363","#d78b5b","#cf8353","#cb7f4f","#bf7b4b","#b37347","#ab6f43","#a36b3f","#9b633b","#8f5f37","#875733","#7f532f","#774f2b","#6b4727","#5f4323","#533f1f","#4b371b","#3f2f17","#332b13","#2b230f","#efefef","#e7e7e7","#dfdfdf","#dbdbdb","#d3d3d3","#cbcbcb","#c7c7c7","#bfbfbf","#b7b7b7","#b3b3b3","#ababab","#a7a7a7","#9f9f9f","#979797","#939393","#8b8b8b","#838383","#7f7f7f","#777777","#6f6f6f","#6b6b6b","#636363","#5b5b5b","#575757","#4f4f4f","#474747","#434343","#3b3b3b","#373737","#2f2f2f","#272727","#232323","#77ff6f","#6fef67","#67df5f","#5fcf57","#5bbf4f","#53af47","#4b9f3f","#439337","#3f832f","#37732b","#2f6323","#27531b","#1f4317","#17330f","#13230b","#0b1707","#bfa78f","#b79f87","#af977f","#a78f77","#9f876f","#9b7f6b","#937b63","#8b735b","#836b57","#7b634f","#775f4b","#6f5743","#67533f","#5f4b37","#574333","#533f2f","#9f8363","#8f7753","#836b4b","#775f3f","#675333","#5b472b","#4f3b23","#43331b","#7b7f63","#6f7357","#676b4f","#5b6347","#53573b","#474f33","#3f472b","#373f27","#ffff73","#ebdb57","#d7bb43","#c39b2f","#af7b1f","#9b5b13","#874307","#732b00","#ffffff","#ffdbdb","#ffbbbb","#ff9b9b","#ff7b7b","#ff5f5f","#ff3f3f","#ff1f1f","#ff0000","#ef0000","#e30000","#d70000","#cb0000","#bf0000","#b30000","#a70000","#9b0000","#8b0000","#7f0000","#730000","#670000","#5b0000","#4f0000","#430000","#e7e7ff","#c7c7ff","#ababff","#8f8fff","#7373ff","#5353ff","#3737ff","#1b1bff","#0000ff","#0000e3","#0000cb","#0000b3","#00009b","#000083","#00006b","#000053","#ffffff","#ffebdb","#ffd7bb","#ffc79b","#ffb37b","#ffa35b","#ff8f3b","#ff7f1b","#f37317","#eb6f0f","#df670f","#d75f0b","#cb5707","#c34f00","#b74700","#af4300","#ffffff","#ffffd7","#ffffb3","#ffff8f","#ffff6b","#ffff47","#ffff23","#ffff00","#a73f00","#9f3700","#932f00","#872300","#4f3b27","#432f1b","#372313","#2f1b0b","#000053","#000047","#00003b","#00002f","#000023","#000017","#00000b","#000000","#ff9f43","#ffe74b","#ff7bff","#ff00ff","#cf00cf","#9f009b","#6f006b","#a76b6b"]],load:function(a){var b=new DataView(a);this.palettes=[];for(var c=0;c<14;c++){palette=[];for(var d=0;d<256;d++){var e=b.getUint8(768*c+3*d+0),f=b.getUint8(768*c+3*d+1),g=b.getUint8(768*c+3*d+2);palette.push(this.rgbToHex(e,f,g))}this.palettes.push(palette)}},toCanvas:function(){var a=16,b=document.createElement("canvas");b.width=16*a,b.height=16*a;for(var c=b.getContext("2d"),d=c.createImageData(16,16),e=0;e<1024;e+=4)col=hexToRgb(this.palettes[0][e/4]),d.data[e]=col.r,d.data[e+1]=col.g,d.data[e+2]=col.b,d.data[e+3]=255;var f=document.createElement("CANVAS");return f.width=d.width,f.height=d.height,f.getContext("2d").putImageData(d,0,0),c.scale(a,a),c.mozImageSmoothingEnabled=!1,c.msImageSmoothingEnabled=!1,c.imageSmoothingEnabled=!1,c.drawImage(f,0,0),b}},Colormap={colormaps:null,load:function(a){var b=new DataView(a);this.colormaps=[];for(var c=0;c<34;c++){cm=[];for(var d=0;d<256;d++)cm.push(b.getUint8(256*c+d));this.colormaps.push(cm)}},toCanvas:function(a){var b=3,c=document.createElement("canvas");c.width=256*b,c.height=34*b;for(var d=c.getContext("2d"),e=d.createImageData(256,34),f=0;f<34;f++)for(var g=0;g<256;g++)col=hexToRgb(a.playpal.palettes[0][this.colormaps[f][g]]),e.data[4*(256*f+g)+0]=col.r,e.data[4*(256*f+g)+1]=col.g,e.data[4*(256*f+g)+2]=col.b,e.data[4*(256*f+g)+3]=255;var h=document.createElement("CANVAS");return h.width=e.width,h.height=e.height,h.getContext("2d").putImageData(e,0,0),d.scale(b,b),d.mozImageSmoothingEnabled=!1,d.msImageSmoothingEnabled=!1,d.imageSmoothingEnabled=!1,d.drawImage(h,0,0),c}},EndoomChar={charIndex:0,backColor:0,foreColor:0,blinking:!1},Endoom={ansiColDark:[[0,0,0],[0,0,170],[0,170,0],[0,170,170],[170,0,0],[170,0,170],[170,85,0],[170,170,170]],ansiColLight:[[85,85,85],[85,85,255],[85,255,85],[85,255,255],[255,85,85],[255,85,255],[255,255,85],[255,255,255]],charCanvas:[],charContext:[],setTile:function(a,b,c,d,e,f){var g=b%80+Math.floor(c/80);this.data[g].charIndex=d,this.data[g].backColor=e,this.data[g].foreColor=f,a.drawImage(this.getChar(d,e,f),8*b,16*c)},getChar:function(a,b,c){var d=document.createElement("canvas"),e=d.getContext("2d");e.drawImage(this.charCanvas[a],0,0),this.swapcolor(e,[0,0,0],this.ansiColDark[b]);var f=[];return f=c>=8?this.ansiColLight[c-8]:this.ansiColDark[c],this.swapcolor(e,[255,255,255],f),d},swapcolor:function(a,b,c){for(var d=a.getImageData(0,0,8,16),e=0;e<d.data.length;e+=4)d.data[e]==b[0]&&d.data[e+1]==b[1]&&d.data[e+2]==b[2]&&(d.data[e]=c[0],d.data[e+1]=c[1],d.data[e+2]=c[2]);a.putImageData(d,0,0)},data:[],load:function(a){if(this.data=[],null!=a)for(var b=new DataView(a),c=0;c<2e3;c++){var d=b.getUint8(2*c),e=b.getUint8(2*c+1),f=e&parseInt("00001111",2),g=e>>4,h=!1;g>=8&&(h=!0,g-=8);var i=Object.create(EndoomChar);i.charIndex=d,i.backColor=g,i.foreColor=f,i.blinking=h,this.data.push(i)}else for(var c=0;c<2e3;c++){var i=Object.create(EndoomChar);this.data.push(i)}charImage=document.createElement("img"),charImage.src="dos.png",charImage.onerror=function(){console.log("Image failed!")};var j=this;charImage.onload=function(){for(var a=0;a<256;a++){var b=document.createElement("canvas");b.width=8,b.height=16;var c=b.getContext("2d"),d=a%32*8,e=16*Math.floor(a/32);c.drawImage(charImage,d,e,8,16,0,0,8,16),j.charCanvas.push(b),j.charContext.push(c)}null!=j.onLoad&&j.onLoad()}},onLoad:null,toCanvasBlinked:function(){endoomDat=this.data;var a=document.createElement("canvas");a.width=640,a.height=400;for(var b=a.getContext("2d"),c=0;c<2e3;c++){var d=endoomDat[c].charIndex,e=endoomDat[c].foreColor;(endoomDat[c].blinking=!0)&&(e=endoomDat[c].backColor);var f=endoomDat[c].backColor;this.setTile(b,c%80,Math.floor(c/80),d,f,e)}return a},toCanvas:function(){endoomDat=this.data;var a=document.createElement("canvas");a.width=640,a.height=400;for(var b=a.getContext("2d"),c=0;c<2e3;c++){var d=endoomDat[c].charIndex,e=endoomDat[c].foreColor,f=endoomDat[c].backColor;this.setTile(b,c%80,Math.floor(c/80),d,f,e)}return a}},Flat={data:null,load:function(a){var b=new DataView(a);this.data=[];for(var c=0;c<4096;c++)this.data.push(b.getUint8(c))},toCanvas:function(a){var b=3,c=document.createElement("canvas");c.width=64*b,c.height=64*b;for(var d=c.getContext("2d"),e=d.createImageData(64,64),f=0;f<4096;f++)col=hexToRgb(a.playpal.palettes[0][this.data[f]]),e.data[4*f+0]=col.r,e.data[4*f+1]=col.g,e.data[4*f+2]=col.b,e.data[4*f+3]=255;var g=document.createElement("CANVAS");return g.width=e.width,g.height=e.height,g.getContext("2d").putImageData(e,0,0),d.scale(b,b),d.mozImageSmoothingEnabled=!1,d.msImageSmoothingEnabled=!1,d.imageSmoothingEnabled=!1,d.drawImage(g,0,0),c}},Graphic={data:null,width:null,height:null,xOffset:null,yOffset:null,load:function(a){var b,c,d=new DataView(a);for(this.data=[],this.width=d.getUint16(0,!0),this.height=d.getUint16(2,!0),this.xOffset=d.getUint16(4,!0),this.yOffset=d.getUint16(6,!0),b=0;b<this.width;b++)for(c=0;c<this.height;c++)this.data.push(-1);var e=[];for(b=0;b<this.width;b++)e[b]=d.getUint32(8+4*b,!0);var f=0,g=0;for(b=0;b<this.width;b++){f=e[b];for(var h=0;255!=h&&(h=d.getUint8(f),f+=1,255!=h);){for(g=d.getUint8(f),f+=2,c=0;c<g;c++)this.data[(h+c)*this.width+b]=d.getUint8(f),f+=1;f+=1}}},toCanvas:function(a){var b=3,c=document.createElement("canvas");c.width=this.width*b,c.height=this.height*b;for(var d=c.getContext("2d"),e=d.createImageData(this.width,this.height),f=this.width*this.height,g=0;g<f;g++)-1!=this.data[g]?(col=hexToRgb(a.playpal.palettes[0][this.data[g]]),e.data[4*g+0]=col.r,e.data[4*g+1]=col.g,e.data[4*g+2]=col.b,e.data[4*g+3]=255):(e.data[4*g+0]=0,e.data[4*g+1]=0,e.data[4*g+2]=0,e.data[4*g+3]=0);var h=document.createElement("CANVAS");return h.width=e.width,h.height=e.height,h.getContext("2d").putImageData(e,0,0),d.scale(b,b),d.mozImageSmoothingEnabled=!1,d.msImageSmoothingEnabled=!1,d.imageSmoothingEnabled=!1,d.drawImage(h,0,0),c}};
//# sourceMappingURL=../sourceMap.map