Trade-Winds/Oversimplified.js

2 lines
39 KiB
JavaScript
Raw Normal View History

2016-04-21 06:10:17 +02:00
function IsInternetExplorer(){var e=window.navigator.userAgent,i=e.indexOf("MSIE ");return!!(i>0||navigator.userAgent.match(/Trident.*rv\:11\./))}var Oversimplified={},OS=Oversimplified;Oversimplified.canvas=null,Oversimplified.context=null,Oversimplified.nextID=0,Oversimplified.loadingScripts=[],Oversimplified.loadedScripts=[],Oversimplified.emptyImage=new Image,Oversimplified.emptyImage.src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=",Oversimplified.emptyImage.width=1,Oversimplified.emptyImage.height=1,Oversimplified.Settings={defaultStep:1/30,numberOfScriptsToLoad:0,soundVolume:.75,musicVolume:.75,preventRightClick:!0},Oversimplified.S=Oversimplified.Settings,Oversimplified.timestamp=function(){return window.performance&&window.performance.now?window.performance.now():(new Date).getTime()},Oversimplified.now=null,Oversimplified.dateTime=0,Oversimplified.lastFrame=Oversimplified.timestamp(),Oversimplified.step=Oversimplified.Settings.defaultStep,Oversimplified.camera={x:0,y:0,width:640,height:480,hBorder:64,vBorder:64,following:"",Follow:function(e){this.following=e.name}},Oversimplified.SetCamera=function(e){Oversimplified.camera.width="undefined"!=typeof e.width?e.width:Oversimplified.camera.width,Oversimplified.camera.height="undefined"!=typeof e.height?e.height:Oversimplified.camera.height,Oversimplified.SetCanvasToCameraSize(),Oversimplified.camera.x="undefined"!=typeof e.x?e.x:Oversimplified.camera.x,Oversimplified.camera.y="undefined"!=typeof e.y?e.y:Oversimplified.camera.y,"undefined"!=typeof e.objectToFollow&&(e.objectToFollow.name?Oversimplified.camera.Follow(e.objectToFollow):Oversimplified.DEBUG.showMessages&&console.log("Oversimplified.Settings.SetCamera()'s objectToFollow argument must be a Oversimplified.GameObject.")),Oversimplified.camera.hBorder="undefined"!=typeof e.hBorder?e.hBorder:Oversimplified.camera.hBorder,Oversimplified.camera.vBorder="undefined"!=typeof e.vBorder?e.vBorder:Oversimplified.camera.vBorder},Oversimplified.mouse={x:0,y:0,leftCode:IsInternetExplorer()?1:0,middleCode:IsInternetExplorer()?4:1,rightCode:2,leftDown:!1,left:!1,leftUp:!1,middleDown:!1,middle:!1,middleUp:!1,rightDown:!1,right:!1,rightUp:!1,wheel:0},Oversimplified.heldKeys=[],Oversimplified.pressedKeys=[],Oversimplified.releasedKeys=[],Oversimplified.Key={37:"left arrow",38:"up arrow",39:"right arrow",40:"down arrow",45:"insert",46:"delete",8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"caps lock",27:"escape",32:"space",33:"page up",34:"page down",35:"end",91:"left win/special key",92:"right win/special key",93:"select key",96:"numpad 0",97:"numpad 1",98:"numpad 2",99:"numpad 3",100:"numpad 4",101:"numpad 5",102:"numpad 6",103:"numpad 7",104:"numpad 8",105:"numpad 9",106:"numpad asterisk",107:"numpad plus",109:"numpad dash",110:"numpad period",111:"numpad slash",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"num lock",145:"scroll lock",186:"semicolon",187:"equal",188:"comma",189:"dash",190:"period",191:"slash",192:"grave accent",219:"open bracket",220:"backslash",221:"close bracket",222:"quote"},Oversimplified.Keycode={backspace:8,tab:9,enter:13,shift:16,ctrl:17,alt:18,pausebreak:19,capslock:20,escape:27,space:32,pageup:33,pagedown:34,end:35,home:36,left:37,up:38,right:39,down:40,insert:45,del:46,zero:48,one:49,two:50,three:51,four:52,five:53,six:54,seven:55,eight:56,nine:57,a:65,b:66,c:67,d:68,e:69,f:70,g:71,h:72,i:73,j:74,k:75,l:76,m:77,n:78,o:79,p:80,q:81,r:82,s:83,t:84,u:85,v:86,w:87,x:88,y:89,z:90,leftwinkey:91,rightwinkey:92,selectkey:93,numpad_0:96,numpad_1:97,numpad_2:98,numpad_3:99,numpad_4:100,numpad_5:101,numpad_6:102,numpad_7:103,numpad_8:104,numpad_9:105,numpad_asterisk:106,numpad_plus:107,numpad_dash:109,numpad_period:110,numpad_slash:111,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123,numlock:144,scrolllock:145,semicolon:186,equal:187,comma:188,dash:189,period:190,slash:191,grave:192,openbracket:219,backslash:220,closebraket:221,quote:222},Oversimplified.Con
Oversimplified.canvas.height=Oversimplified.camera.height)},Oversimplified.Frame=function(){if(Oversimplified.Settings.numberOfScriptsToLoad>0&&Oversimplified.loadedScripts.length==Oversimplified.Settings.numberOfScriptsToLoad||Oversimplified.Settings.numberOfScriptsToLoad<=0&&0==Oversimplified.loadingScripts.length){for(Oversimplified.now=Oversimplified.timestamp(),Oversimplified.dateTime=Oversimplified.dateTime+Math.min(1,(Oversimplified.now-Oversimplified.lastFrame)/1e3);Oversimplified.dateTime>Oversimplified.step;)Oversimplified.dateTime=Oversimplified.dateTime-Oversimplified.step,Oversimplified.Update(),Oversimplified.Draw(),Oversimplified.EndFrame();Oversimplified.lastFrame=Oversimplified.now}else{if(Oversimplified.DEBUG.showMessages){var e="Loaded "+Oversimplified.loadedScripts.length.toString();e+=Oversimplified.Settings.numberOfScriptsToLoad>0?" of "+Oversimplified.Settings.numberOfScriptsToLoad.toString():"",e+=" scripts:\n"+Oversimplified.loadedScripts.toString()+".\nWaiting for:\n"+Oversimplified.loadingScripts.toString(),console.log(e)}if(Oversimplified.Settings.numberOfScriptsToLoad>0){var i=Oversimplified.loadedScripts.length/Oversimplified.Settings.numberOfScriptsToLoad,s=32,t=Math.round(.6*Oversimplified.camera.width),o=Math.round(t*i),r=Math.round(.2*Oversimplified.camera.width),d=Math.round(.5*Oversimplified.camera.height)-Math.round(s/2),n=OS.context.fillStyle,m=OS.context.strokeStyle;OS.context.fillStyle="#DD5511",OS.context.fillRect(r,d,o,s),OS.context.strokeStyle="#882200",OS.context.lineWidth=5,OS.context.strokeRect(r,d,t,s),OS.context.fillStyle=n,OS.context.strokeStyle=m}}requestAnimationFrame(Oversimplified.Frame)},Oversimplified.Update=function(){Oversimplified.Controls.CheckAll(),Oversimplified.Rooms.AllBeforeDo(),Oversimplified.Rooms.AllDo(),"undefined"!=typeof Oversimplified.Rooms[Oversimplified.Rooms.currentRoom]?Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].Update():Oversimplified.DEBUG.showMessages&&console.log("There is no current room. Please add one or make sure you are referencing the correct room with Oversimplified.Rooms.SetRoom()."),Oversimplified.Rooms.AllAfterDo(),""!=Oversimplified.camera.following&&(Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].x-Oversimplified.camera.x>Oversimplified.camera.width-Oversimplified.camera.hBorder&&(Oversimplified.camera.x=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].x-(Oversimplified.camera.width-Oversimplified.camera.hBorder)),Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].x-Oversimplified.camera.x<Oversimplified.camera.hBorder&&(Oversimplified.camera.x=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].x-Oversimplified.camera.hBorder),Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].y-Oversimplified.camera.y>Oversimplified.camera.height-Oversimplified.camera.vBorder&&(Oversimplified.camera.y=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].y-(Oversimplified.camera.height-Oversimplified.camera.vBorder)),Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].y-Oversimplified.camera.y<Oversimplified.camera.vBorder&&(Oversimplified.camera.y=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].y-Oversimplified.camera.vBorder)),Oversimplified.camera.x<0&&(Oversimplified.camera.x=0),Oversimplified.camera.x+Oversimplified.camera.width>Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].width&&(Oversimplified.camera.x=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].width-Oversimplified.camera.width),Oversimplified.camera.y<0&&(Oversimplified.camera.y=0),Oversimplified.camera.y+Oversimplified.camera.height>Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].height&&(Oversimplified.camera.y=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].height-Oversimplified.c