'use strict';var d=document.getElementById("debug"),miniGlCanvas=document.getElementById("miniGlCanvas"),simulation_timestep=30,stats=null,tilesData=null,spriteData=null,gameData=null,powerData=null,isMobile=!1,trans=!1,newup=!1,powerup=!1,cityWorker=new Worker("js/worker.city.js"),view3d,hub,im,isWithMiniMap=!1,storage;function debug(a){d.innerHTML+="
"+a}
function testMobile(){return navigator.userAgent.match(/Android/i)||navigator.userAgent.match(/webOS/i)||navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/BlackBerry/i)||navigator.userAgent.match(/Windows Phone/i)?!0:!1}function init(){isMobile=testMobile();storage=window.localStorage;hub=new HUB.Base;view3d=new V3D.Base(isMobile);isWithMiniMap&&view3d.initMiniRender()}
function loop(){requestAnimationFrame(loop);newup&&(view3d.paintMap(),view3d.moveSprite(),newup=!1);powerup&&(view3d.showPower(),powerup=!1);view3d.mouse.dragView||3===view3d.mouse.button?view3d.dragCenterposition():isMobile||view3d.updateKey();view3d.renderer.render(view3d.scene,view3d.camera);view3d.isWithStats&&view3d.runStats();isWithMiniMap&&(view3d.miniCheck(),view3d.miniRenderer.render(view3d.miniScene,view3d.topCamera))}
function saveGame(){var a=[];view3d.saveCityBuild(a);a=JSON.stringify(a);cityWorker.postMessage({tell:"SAVEGAME",saveCity:a})}function loadGame(a){cityWorker.postMessage({tell:"LOADGAME",isStart:a||!1})}function makeGameSave(a,b){window.localStorage.setItem(b,a);console.log("game is save")}
function makeLoadGame(a,b){var c=b||!1;b&&hub.initGameHub();var e=window.localStorage.getItem(a);e?(cityWorker.postMessage({tell:"MAKELOADGAME",savegame:e,isStart:c}),console.log("game is load")):console.log("No loading game found")}function newGameMap(){console.log("new map")}function displayStats(){view3d.isWithStats=!0}function hideStats(){view3d.isWithStats=!1}var ARRAY_TYPE;ARRAY_TYPE||(ARRAY_TYPE="undefined"!==typeof Float32Array?Float32Array:Array);function start(){initCity()}
function setTimeColors(a){view3d.setTimeColors(a)}function newMap(){view3d.isWithHeight&&view3d.resetHeight();cityWorker.postMessage({tell:"NEWMAP"})}function newHeightMap(){view3d.isWithHeight=!0;cityWorker.postMessage({tell:"NEWMAP"})}function playMap(){hub.initGameHub();view3d.startZoom();cityWorker.postMessage({tell:"PLAYMAP"})}function selectTool(a){view3d.selectTool(a)}function sendTool(a){cityWorker.postMessage({tell:"TOOL",name:a})}
function setDifficulty(a){cityWorker.postMessage({tell:"DIFFICULTY",n:a})}function setSpeed(a){cityWorker.postMessage({tell:"SPEED",n:a})}function getBudjet(){cityWorker.postMessage({tell:"BUDGET"})}function setBudjet(a){cityWorker.postMessage({tell:"NEWBUDGET",budgetData:a})}function getEval(){cityWorker.postMessage({tell:"EVAL"})}function setDisaster(a){console.log(a);cityWorker.postMessage({tell:"DISASTER",disaster:a})}function setOverlays(a){}
function destroy(a,b){cityWorker.postMessage({tell:"DESTROY",x:a,y:b})}function mapClick(){var a=view3d.pos;0this.f[0]&&(this.f[0]=this.f[1],hub.upStats(this.f[2],this.renderer.info.memory.geometries),this.f[2]=0);this.f[2]++},render:function(){this.isWithStats&&this.runStats();this.renderer.render(this.scene,this.camera);this.deepthTest&&this.miniRender()},initMiniRender:function(){this.minibuilding=this.miniTree=null;this.miniTreeUpdate=0;this.townHeigth=this.customShader();this.miniScene=new THREE.Scene;
this.topCamera=new THREE.OrthographicCamera(-5,5,5,-5,0.1,200);this.topCameraDistance=10;this.miniScene.add(this.topCamera);this.miniRenderer=new THREE.WebGLRenderer({canvas:miniGlCanvas,precision:"lowp",antialias:!1});this.miniRenderer.setSize(this.miniSize.w,this.miniSize.h,!0);this.miniRenderer.sortObjects=!1;this.miniRenderer.sortElements=!1;this.deepthTest=!0},customShader:function(){return new THREE.ShaderMaterial({uniforms:{deep:{type:"f",value:0.1}},attributes:{},vertexShader:"uniform float deep;\nvarying float dy;\nvarying vec4 vc;\nvoid main(void) {\ngl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\ndy = position.y*deep;\nvc = vec4(dy,dy,dy, 1.0);\n}",
fragmentShader:"precision lowp float;\nvarying vec4 vc;\nvoid main(void) { gl_FragColor = vc; }"})},miniClear:function(){for(var a=this.miniScene.children.length,b;a--;)b=this.miniScene.children[a],b.geometry&&(b.geometry.dispose(),this.miniScene.remove(b))},miniClearMesh:function(a){a.geometry.dispose();this.miniScene.remove(a)},miniCheck:function(){var a=this.findLayer(this.center.x,this.center.z);a!==this.currentLayer?(this.currentLayer=a,this.miniUpTree(a),this.miniUpBuilding(a)):1==this.miniTreeUpdate&&
(this.miniUpTree(a),this.miniTreeUpdate=0)},miniUpTree:function(a){null!==this.miniTree&&this.miniClearMesh(this.miniTree);this.miniTree=new THREE.Mesh(this.treeMeshs[a].geometry.clone(),this.townHeigth);this.miniScene.add(this.miniTree)},miniUpBuilding:function(a){this.buildingMeshs[a]&&(null!==this.minibuilding&&this.miniClearMesh(this.minibuilding),this.minibuilding=new THREE.Mesh(this.buildingMeshs[a].geometry.clone(),this.townHeigth),this.miniScene.add(this.minibuilding))},miniRender:function(){this.deepthTest&&
(this.miniCheck(),this.miniRenderer.render(this.miniScene,this.topCamera))},resize:function(){this.vsize={x:window.innerWidth,y:window.innerHeight,z:window.innerWidth/window.innerHeight};this.camera.aspect=this.vsize.z;this.camera.updateProjectionMatrix();this.renderer.setSize(this.vsize.x,this.vsize.y)},startZoom:function(){this.timer=setInterval(this.faddingZoom,1E3/60,this)},faddingZoom:function(a){20a?b["r_0"+a].geometry:b["r_"+a].geometry;for(a=21;a--;)this.commercialGeo[a]=10>a?b["c_0"+a].geometry:b["c_"+a].geometry;for(a=12;a--;)this.houseGeo[a]=10>a?b["rh_0"+
a].geometry:b["rh_"+a].geometry;this.spriteGeo=[];this.spriteGeo[0]=b.train.geometry;this.spriteGeo[1]=b.elico.geometry.clone();this.spriteGeo[2]=b.plane.geometry.clone();this.treeGeo=[];this.treeGeo[0]=b.ttt3.geometry;this.treeGeo[1]=b.ttt3.geometry.clone();this.treeGeo[2]=b.ttt4.geometry;this.treeGeo[3]=b.ttt4.geometry.clone();this.treeGeo[4]=b.ttt0.geometry;this.treeGeo[5]=b.ttt1.geometry;this.treeGeo[6]=b.ttt2.geometry;this.treeGeo[7]=b.ttt5.geometry;this.init()},getRandomObject:function(){var a,
b;switch(this.randRange(0,6)){case 0:a=this.buildingGeo[this.randRange(4,12)];b=this.townMaterial;break;case 1:a=this.residentialGeo[this.randRange(1,this.residentialGeo.length-1)];b=this.buildingMaterial;break;case 2:a=this.commercialGeo[this.randRange(1,this.commercialGeo.length-1)];b=this.buildingMaterial;break;case 3:a=this.industrialGeo[this.randRange(1,this.industrialGeo.length-1)];b=this.buildingMaterial;break;case 4:a=this.houseGeo[this.randRange(0,this.houseGeo.length-1)];b=this.buildingMaterial;
break;case 5:a=this.spriteGeo[this.randRange(0,this.spriteGeo.length-1)];b=this.townMaterial;break;case 6:a=this.randRange(0,2),b=0,1==a&&(b=4),2==a&&(b=6),a=this.treeGeo[b],b=this.townMaterial}b=new THREE.Mesh(a.clone(),b.clone());b.name=a.name;return b},randRange:function(a,b){return Math.floor(Math.random()*(b-a+1))+a},buildMeshLayer:function(a,b){b=b||"tree";var c=0;"tree"===b&&(c=0);"town"===b&&(c=1);"house"===b&&(c=2);"building"===b&&(c=3);var e=this.M_list[c],f=this.M_temp[c],h=this.M_geom[c],
g=this.M_mesh[c],l=this.M_mats[c],k,p,q,n,m,v,s,t,u,r,w=0;if(this[e][a]){v=this[e][a].length;p=[];n=[];for(q=[];v--;){r=this[e][a][v];if(3===c){for(m=this.R.length;m--;)r[3]===this.R[m]&&(k=this.residentialGeo[m],0===m&&0===r[5]?(this.buildingLists[a][v][5]=1,this.addBaseHouse(r[0],r[1],r[2])):0e;e++)for(var f=0;8>f;f++){var h;h=this.isWithHeight?new THREE.PlaneBufferGeometry(16,16,16,16):new THREE.PlaneBufferGeometry(16,16,1,1);h.rotateX(0.5*
-Math.PI);for(var g=h.attributes.position.array,l=g.length/3;l--;){var k=3*l;g[k]+=8+16*f-0.5;g[k+2]+=8+16*e-0.5}this.miniTerrain[a]=this.isColorTest?new THREE.Mesh(h,new THREE.MeshBasicMaterial({color:b[e]+c[f]})):this.isWithLight?new THREE.Mesh(h,new THREE.MeshStandardMaterial({color:16777215,metalness:this.metalness,roughness:this.roughness,wireframe:this.wireframe})):new THREE.Mesh(h,new THREE.MeshBasicMaterial({color:16777215}));this.isWithEnv&&(this.miniTerrain[a].material.envMap=this.environment);
this.land.add(this.miniTerrain[a]);a++}}for(a=this.miniTerrain.length;a--;)b=new THREE.Texture(this.miniCanvas[a]),b.needsUpdate=!0,this.miniTerrain[a].material.map=b,this.isWithNormal&&(c=new THREE.Texture(this.miniCanvasN[a]),c.needsUpdate=!0,this.miniTerrain[a].material.normalMap=c),this.terrainTxt[a]=b;this.isWithHeight?(this.applyHeight(),this.center.y=this.heightData[this.findHeightId(this.center.x,this.center.z)]):this.center.y=0;this.moveCamera();this.back.position.copy(this.center)},generateHeight:function(){if(0!=
this.miniTerrain.length){for(var a=this.miniTerrain.length;a--;)this.land.remove(this.miniTerrain[a]);this.miniTerrain=[]}this.bigG=new THREE.PlaneBufferGeometry(128,128,128,128);this.bigG.rotateX(0.5*-Math.PI);for(var a=this.bigG.attributes.position.array,b=a.length/3;b--;){var c=3*b;a[c]+=this.center.x;a[c+2]+=this.center.z}for(var e,f,b=new ARRAY_TYPE(16641),c=new Perlin,h=1/129,g=3+2*Math.random(),a=16641;a--;)e=a%129,f=~~(a*h),e=c.noise(0.05*e,0.05*f),b[a]=(0.5+0.5*e)*g;return b},resetHeight:function(){for(var a=
this.heightData.length;a--;)this.heightData[a]=0;this.applyHeight();this.isWithHeight=!1},findHeightId:function(a,b){return this.findSamePoint(a,b)},findSamePoint:function(a,b){var c;c=this.bigG?this.bigG.attributes.position.array:this.positionRef;for(var e=c.length/3,f,h=0;e--;)if(f=3*e,c[f]===a&&c[f+2]===b){h=e;break}return h},applyHeight:function(){var a,b,c,e,f,h;this.Gtmp=[];c=this.bigG.attributes.position.array;for(a=c.length/3;a--;)f=3*a,c[f+1]=this.heightData[a];this.bigG.attributes.position.needUpdate=
!0;this.bigG.computeVertexNormals();this.positionRef=new Float32Array(c.length);for(a=c.length;a--;)this.positionRef[a]=c[a];var g=this.bigG.attributes.normal.array;for(a=64;a--;)this.Gtmp[a]=new ARRAY_TYPE(289);for(a=64;a--;){c=this.miniTerrain[a].geometry.attributes.position.array;e=this.miniTerrain[a].geometry.attributes.normal.array;for(b=c.length/3;b--;)f=3*b,h=this.findSamePoint(c[f]+0.5,c[f+2]+0.5),this.Gtmp[b]=this.heightData[h],c[f+1]=this.Gtmp[b],h*=3,e[f]=g[h],e[f+1]=g[h+1],e[f+2]=g[h+
2];this.miniTerrain[a].geometry.attributes.position.needUpdate=!0;this.miniTerrain[a].geometry.attributes.normal.needUpdate=!0}this.bigG.dispose();this.bigG=null},makePlanar:function(a,b){},updateVertices:function(a,b){for(var c=a.attributes.position.array,e=b.length,f;e--;)f=3*e,c[f+1]=b[e];a.attributes.position.needUpdate=!0},findPositionDisp:function(a){var b=Math.floor(a/129);return[a-Math.floor(129*b),b]},findLayerDisp:function(a,b){return Math.floor(a/16)+8*Math.floor(b/16)},findVerticesDisp:function(a,
b){var c=0,c=Math.floor(a/8);return c=b[0]-16*Math.floor(a-8*c)+16*(b[1]-16*c)},findLayer:function(a,b){return Math.floor(a/16)+8*Math.floor(b/16)},findLayerPos:function(a,b,c){var e=Math.floor(c/8);return[a-16*Math.floor(c-8*e),b-16*e]},findPosition:function(a){var b=Math.floor(a/this.mapSize[1]);return[a-b*this.mapSize[1],b]},findId:function(a,b){return a+b*this.mapSize[1]},findVertices:function(a,b){var c=0,c=Math.floor(a/8);return c=b[0]-16*Math.floor(a-8*c)+16*(b[1]-16*c)},rayTest:function(){this.raycaster.setFromCamera(this.rayVector,
this.camera);if(0c&&0!==c&&(this.addBaseBuilding(a,e,b,c,f),this.snd_layzone.play());if(8==c||9==c||4==c||5==c||7==c||10==c||11==c||12==c)this.addBaseTown(a,e,b,c,f),this.snd_layzone.play()}else this.removeTree(a,b),this.isWithHeight&&(e=this.heightData[this.findHeightId(a,b)],this.makePlanar([[a,b]],e)),"bulldozer"==this.currentTool.tool&&(this.forceUpdate.x=a,
this.forceUpdate.y=b,this.testDestruct(a,b))},removeTool:function(){this.scene.remove(this.tool);this.tool.geometry.dispose();this.currentTool=this.tool=null},testLayer:function(a,b){var c=this.findLayer(a,b),e=[c],f=this.findLayerPos(a,b,c),h=0,g=0;4>f[0]?h=1:13f[1]?g=1:13c+8&&e.push(c+8);1==h&&-1c+1&&e.push(c+1);1==h&&1==g&&-1c+9&&e.push(c+9);1==h&&2==g&&64>c+7&&e.push(c+7);
2==h&&1==g&&-1c&&(c=1);c*=this.ToRad;b*=this.ToRad;f.x=e*Math.sin(c)*Math.cos(b)+a.x;f.z=e*Math.sin(c)*Math.sin(b)+a.z;f.y=e*Math.cos(c)+a.y;return f},
unwrapDegrees:function(a){a%=360;180a&&(a+=360);return a},moveCamera:function(){this.camera.position.copy(this.Orbit(this.center,this.cam.horizontal,this.cam.vertical,this.cam.distance));this.camera.lookAt(this.center);this.isWithFog&&(this.fog.far=4*this.cam.distance,20>this.fog.far&&(this.fog.far=20));this.deepthTest&&(this.topCamera.position.set(this.center.x,this.topCameraDistance,this.center.z),this.topCamera.lookAt(this.center))},dragCenterposition:function(){if(0!=this.ease.x||
0!=this.ease.z)this.easeRot.y=this.cam.horizontal*this.ToRad,this.unwrapDegrees(Math.round(this.cam.horizontal)),this.easeRot.x=Math.sin(this.easeRot.y)*this.ease.x+Math.cos(this.easeRot.y)*this.ease.z,this.easeRot.z=Math.cos(this.easeRot.y)*this.ease.x-Math.sin(this.easeRot.y)*this.ease.z,this.center.x+=this.easeRot.x,this.center.z-=this.easeRot.z,0>this.center.x&&(this.center.x=0),128this.center.z&&(this.center.z=0),128this.mouse.button&&(this.mouse.click=!0,this.currentTool.drag&&(this.mouse.drag=!0))},onMouseUp:function(a){a.preventDefault();
this.mouse.button=0;this.mouse.down=!1;this.mouse.drag=!1;null==this.currentTool&&(this.mouse.move=!0);this.ease.x=0;this.ease.z=0;document.body.style.cursor="auto"},onMouseMove:function(a){a.preventDefault();var b;a.touches?(b=a.clientX||a.touches[0].pageX,a=a.clientY||a.touches[0].pageY):(b=a.clientX,a=a.clientY);if(this.mouse.down){if(this.mouse.move||2===this.mouse.button)this.mouse.dragView=!1,document.body.style.cursor="crosshair",this.cam.horizontal=0.3*(b-this.mouse.ox)+this.mouse.h,this.cam.vertical=
0.3*-(a-this.mouse.oy)+this.mouse.v,this.moveCamera();if(this.mouse.dragView||3===this.mouse.button)document.body.style.cursor="move",this.mouse.move=!1,this.ease.x=(b-this.mouse.ox)/1E3,this.ease.z=(a-this.mouse.oy)/1E3}null!==this.currentTool&&(this.rayVector.x=b/this.vsize.x*2-1,this.rayVector.y=2*-(a/this.vsize.y)+1,this.rayTest())},onMouseWheel:function(a){a.preventDefault();var b=0;a.wheelDelta?b=-1*a.wheelDelta:a.detail&&(b=20*a.detail);this.cam.distance+=b/80;1>this.cam.distance&&(this.cam.distance=
1);150g&&this.isWithHeight&&(this.heightData[this.findHeightId(h,e)]=-0.1),5g&&this.isWithHeight&&(this.heightData[this.findHeightId(h,e)]*=0.5),20g&&(this.isWithHeight&&(m=this.heightData[this.findHeightId(h,e)]-0.1),l=Math.floor(4*Math.random()),36<=g&&(l+=4),c&&this.addTree(h,m,e,l,n),g=this.isWithTree?21+l:29+l,this.treeValue[p]=
g)),this.fullRedraw&&20g&&(g=this.treeValue[p]),l=g%32*16,k=16*Math.floor(g/32),c||this.fullRedraw)this.miniCtx[n].drawImage(this.imageSrc,l*this.mu,k*this.mu,16*this.mu,16*this.mu,16*(h-16*q)*this.mu,16*(e-16*f)*this.mu,16*this.mu,16*this.mu),this.isWithNormal&&this.miniCtxN[n].drawImage(this.ground_n,l*this.mu,k*this.mu,16*this.mu,16*this.mu,16*(h-16*q)*this.mu,16*(e-16*f)*this.mu,16*this.mu,16*this.mu);else if(h===this.forceUpdate.x&&e===this.forceUpdate.y&&(a=!0,this.forceUpdate.x=-1,this.forceUpdate.y=
-1),43g||a)a&&(a=!1,20g&&(k=l=0)),this.miniCtx[n].drawImage(this.imageSrc,l*this.mu,k*this.mu,16*this.mu,16*this.mu,16*(h-16*q)*this.mu,16*(e-16*f)*this.mu,16*this.mu,16*this.mu),this.isWithNormal&&this.miniCtxN[n].drawImage(this.ground_n,l*this.mu,k*this.mu,16*this.mu,16*this.mu,16*(h-16*q)*this.mu,16*(e-16*f)*this.mu,16*this.mu,16*this.mu),this.txtNeedUpdate[n]=1;else if(240g||0==g){if(this.houseLists[n])for(f=this.houseLists[n].length;f--;)q=this.houseLists[n][f],
q[0]===h&&q[2]===e&&q[3]!==g&&(this.houseLists[n][f][3]=g,this.tempHouseLayers[n]=1)}else if(this.buildingLists[n])for(f=this.buildingLists[n].length;f--;)q=this.buildingLists[n][f],q[0]===h&&q[2]===e&&q[3]!==g&&(this.buildingLists[n][f][3]=g,this.tempBuildingLayers[n]=1);if(c)this.updateTerrain(b),this.populateTree();else{for(f=this.nlayers;f--;)if(this.txtNeedUpdate[f]||this.fullRedraw)this.terrainTxt[f].needsUpdate=!0,this.txtNeedUpdate[f]=0;for(f=this.tempHouseLayers.length;f--;)1===this.tempHouseLayers[f]&&
this.rebuildHouseLayer(f);for(f=this.tempBuildingLayers.length;f--;)1===this.tempBuildingLayers[f]&&this.rebuildBuildingLayer(f)}this.fullRedraw&&(this.fullRedraw=!1)}},moveSprite:function(){if(spriteData)for(var a=spriteData.length,b=new THREE.Vector3,c=0,e=0;a--;){var f=spriteData[a],c=f[1],e=f[0];b.x=Math.round((f[2]-8)/16);b.z=Math.round((f[3]-8)/16);b.y=0;this.isWithHeight&&(b.y=this.heightData[this.findHeightId(b.x,b.z)]);2==f[0]&&(b.y+=5);3==f[0]&&(b.y=11==c?b.y+0:10==c?b.y+1:9==c?b.y+3:b.y+
6);null==this.spriteObjs[this.spriteLists[e]]&&(this.spriteObjs[this.spriteLists[e]]=this.addSprite(e,b));this.spriteObjs[this.spriteLists[e]].visible=1===e&&5===c?!1:!0;this.spriteObjs[this.spriteLists[e]].position.lerp(b,0.6);this.spriteObjs[this.spriteLists[e]].rotation.y=this.rotationSprite(f[0],c)}},rotationSprite:function(a,b){var c=0;if(1===a)1===b?c=0:2===b?c=90*this.ToRad:3===b?c=45*this.ToRad:4===b&&(c=-45*this.ToRad);else if(2===a||3===a)1===b?c=0:2===b?c=-45*this.ToRad:3===b?c=-90*this.ToRad:
4===b?c=-135*this.ToRad:5===b?c=-180*this.ToRad:6===b?c=-225*this.ToRad:7===b?c=-270*this.ToRad:8===b?c=-315*this.ToRad:9===b?c=-90*this.ToRad:10===b?c=-90*this.ToRad:11===b&&(c=-90*this.ToRad);return c},addSprite:function(a,b){var c;c=1===a?new THREE.Mesh(this.spriteGeo[0],this.townMaterial):2===a?new THREE.Mesh(this.spriteGeo[1],this.townMaterial):3===a?new THREE.Mesh(this.spriteGeo[2],this.townMaterial):new THREE.Mesh(new THREE.BoxGeometry(1,1,1),this.townMaterial);c.position.copy(b);this.scene.add(c);
return c},showPower:function(){if(powerData)for(var a=powerData.length;a--;)2==powerData[a]?null==this.powerMeshs[a]&&this.addPowerMesh(a,this.findPosition(a)):1==powerData[a]&&null!==this.powerMeshs[a]&&this.removePowerMesh(a)},addPowerMesh:function(a,b){var c=0;this.isWithHeight&&(c=this.heightData[this.findHeightId(b[0],b[1])]);var e=new THREE.Sprite(this.powerMaterial);e.position.set(b[0],c+1,b[1]);this.scene.add(e);this.powerMeshs[a]=e},removePowerMesh:function(a){this.scene.remove(this.powerMeshs[a]);
this.powerMeshs[a]=null},powerTexture:function(){var a=document.createElement("canvas"),b=a.getContext("2d");a.width=a.height=64;var c=b.createLinearGradient(0,0,64,64);c.addColorStop(0.3,"yellow");c.addColorStop(1,"red");b.beginPath();b.moveTo(44,0);b.lineTo(10,34);b.lineTo(34,34);b.lineTo(20,64);b.lineTo(54,30);b.lineTo(30,30);b.lineTo(44,0);b.closePath();b.strokeStyle="red";b.stroke();b.fillStyle=c;b.fill();a=new THREE.Texture(a);a.needsUpdate=!0;return a},gradTexture:function(a){var b=document.createElement("canvas"),
c=b.getContext("2d");b.width=16;b.height=256;for(var e=c.createLinearGradient(0,0,0,256),f=a[0].length;f--;)e.addColorStop(a[0][f],a[1][f]);c.fillStyle=e;c.fillRect(0,0,16,256);return b},tint:function(a,b,c){var e,f,h=a.width*a.height,g=a.getContext("2d"),l=null,l=null;if(c&&0!==this.dayTime&&1!==this.dayTime){g.clearRect(0,0,a.width,a.height);g.drawImage(c,0,0);l=g.getImageData(0,0,a.width,a.height);c=l.data;for(e=h;e--;)f=e<<2,0!==c[f+3]&&(0==c[f+0]&&0==c[f+1]&&0==c[f+2]&&(c[f+3]=60),0==c[f+1]&&
(3==this.dayTime&&(c[f+1]=255),2==this.dayTime&&(c[f+0]=0,c[f+3]=60)));g.putImageData(l,0,0);l=document.createElement("img");l.src=a.toDataURL("image/png")}b?(g.clearRect(0,0,a.width,a.height),g.drawImage(b,0,0)):g.drawImage(this.skyCanvasBasic,0,0);if(0!==this.dayTime){a=g.getImageData(0,0,a.width,a.height);c=a.data;e=h;for(h=this.tcolor;e--;)f=e<<2,c[f+0]=c[f+0]*(1-h.a)+h.r*h.a,c[f+1]=c[f+1]*(1-h.a)+h.g*h.a,c[f+2]=c[f+2]*(1-h.a)+h.b*h.a;g.putImageData(a,0,0);l&&g.drawImage(l,0,0)}},updateKey:function(){var a=
!1;1==this.key[0]||1==this.key[1]?(1==this.key[0]&&(this.ease.z=-0.3),1==this.key[1]&&(this.ease.z=0.3),a=!0):this.ease.z=0;1==this.key[2]||1==this.key[3]?(1==this.key[2]&&(this.ease.x=-0.3),1==this.key[3]&&(this.ease.x=0.3),a=!0):this.ease.x=0;a&&this.dragCenterposition()},bindKeys:function(){var a=this;document.onkeydown=function(b){b=b||window.event;switch(b.keyCode){case 38:case 87:case 90:a.key[0]=1;break;case 40:case 83:a.key[1]=1;break;case 37:case 65:case 81:a.key[2]=1;break;case 39:case 68:a.key[3]=
1}};document.onkeyup=function(b){b=b||window.event;switch(b.keyCode){case 38:case 87:case 90:a.key[0]=0;break;case 40:case 83:a.key[1]=0;break;case 37:case 65:case 81:a.key[2]=0;break;case 39:case 68:a.key[3]=0}};self.focus()}};var HUB={REVISION:"1",round:'',roundSelected:'',roundSelect:'',
Base:function(){this.hub=document.getElementById("hub");this.title=this.full=null;this.isIntro=!0;this.timer=null;this.bg=1;this.I=this.C=this.R=null;this.colors="rgba(255,255,255,1) rgba(0,0,0,0.2) rgba(0,0,0,1) rgba(0,0,0,0.5) rgba(0,0,0,0.8) rgba(255,255,255,0.5)".split(" ");this.radius="-moz-border-radius: 6px; -webkit-border-radius: 6px; border-radius: 6px;";this.radiusL="-moz-border-top-left-radius: 6px; -webkit-border-top-left-radius: 6px; border-top-left-radius: 6px;";this.radiusL+="-moz-border-bottom-left-radius: 6px; -webkit-border-bottom-left-radius: 6px; border-bottom-left-radius: 6px;";
this.radiusR="-moz-border-top-right-radius: 6px; -webkit-border-top-right-radius: 6px; border-top-right-radius: 6px;";this.radiusR+="-moz-border-bottom-right-radius: 6px; -webkit-border-bottom-right-radius: 6px; border-bottom-right-radius: 6px;";this.radiusB="-moz-border-bottom-left-radius: 6px; -webkit-border-bottom-left-radius: 6px; border-bottom-left-radius: 6px;";this.radiusB+="-moz-border-bottom-right-radius: 6px; -webkit-border-bottom-right-radius: 6px; border-bottom-right-radius: 6px;";this.windowsStyle=
" top:40px; left:10px; border:1px solid "+this.colors[1]+"; background:"+this.colors[3]+";";this.select=this.selector=this.aboutWindow=this.overlaysWindow=this.queryWindow=this.exitWindow=this.disasterWindow=this.evaluationWindow=this.budgetWindow=null;this.currentToolName=0;this.disasterTypes="None Monster Fire Flood Crash Meltdown Tornado".split(" ");this.disasterButtons=[];this.overlaysTypes="None;Density;Growth;Land value;Crime Rate;Pollution;Traffic;Power Grid;Fire;Police".split(";");this.overlaysButtons=
[];this.intro()}};
HUB.Base.prototype={constructor:HUB.Base,init:function(){},intro:function(){this.full=document.createElement("div");this.full.style.cssText="position:absolute; top:0px; left:0px; width:100%; height:100%; pointer-events:none; display:block; background:rgba(102,102,230,1); ";this.fullMid=document.createElement("div");this.fullMid.style.cssText="position:absolute; top:10px; left:50%; width:300px; height:300px; margin-left:-150px; pointer-events:none; display:block;";this.title=document.createElement("div");this.title.innerHTML=
"3D.CITY";this.title.style.cssText="position:absolute; font-size:44px; top:50%; left:0; margin-top:-30px; width:300px; height:60px; pointer-events:none; text-align:center;";this.subtitle=document.createElement("div");this.subtitle.style.cssText="position:absolute; font-size:14px; top:50%; left:0; margin-top:20px; width:300px; height:80px; pointer-events:none; text-align:center;";this.subtitle.innerHTML="Generating world...";this.logo=document.getElementById("logo");this.logo.style.display="block";
this.full.appendChild(this.fullMid);this.fullMid.appendChild(this.logo);this.fullMid.appendChild(this.title);this.fullMid.appendChild(this.subtitle);this.hub.appendChild(this.full)},start:function(){this.isIntro&&(this.timer=setInterval(this.fadding,100,this))},fadding:function(a){a.bg-=0.1;a.full.style.background="rgba(102,102,230,"+a.bg+")";0>=a.bg&&(clearInterval(a.timer),a.full.removeChild(a.fullMid),a.fullMid.removeChild(a.logo),a.fullMid.removeChild(a.title),a.fullMid.removeChild(a.subtitle),
a.hub.removeChild(a.full),a.initStartHub(),a.isIntro=!1)},initStartHub:function(){this.full=document.createElement("div");this.full.style.cssText="position:absolute; top:10px; left:50%; margin-left:-150px; width:300px; height:300px; pointer-events:none;";this.full.id="fullStart";this.hub.appendChild(this.full);var a=this.addButton(this.full,"Play Game",[276,48,40],"position:absolute; top:10px; left:0px;"),b=this.addButton(this.full,"New Map",[120,26,22],"position:absolute; top:150px; left:0px;"),
c=this.addButton(this.full,"Height Map",[120,26,22],"position:absolute; top:150px; right:0px;"),e=this.addButton(this.full,"Load Map",[276,26,22],"position:absolute; top:90px; left:0px;");this.addSelector("DIFFICULTY",["LOW","MEDIUM","HARD"],setDifficulty,0);a.addEventListener("click",function(a){a.preventDefault();playMap()},!1);b.addEventListener("click",function(a){a.preventDefault();newMap()},!1);c.addEventListener("click",function(a){a.preventDefault();newHeightMap()},!1);e.addEventListener("click",
function(a){a.preventDefault();loadGame(!0)},!1)},initGameHub:function(){var a=this;this.removeSelector("DIFFICULTY");this.clearElement("fullStart");this.toolSet=document.createElement("div");this.toolSet.style.cssText="position:absolute; margin:0px; padding:0px; top:60px; right:12px; width:198px; height:456px; pointer-events:none;";this.hub.appendChild(this.toolSet);this.toolInfo=document.createElement("div");this.toolInfo.style.cssText="position:absolute; top:15px; right:12px; width:198px; height:50px; pointer-events:none; font-size:16px;";
this.hub.appendChild(this.toolInfo);this.toolInfo.innerHTML="Selecte
Tool";for(var b,c=0;18>c;c++)b=this.addSVGButton(this.toolSet),b.name=c+1;this.selector=document.createElement("div");this.selector.style.cssText="position:absolute; top:0px; left:0px; pointer-events:none; display:none;";this.selector.innerHTML=HUB.roundSelected;this.toolSet.appendChild(this.selector);this.select=document.createElement("div");this.select.style.cssText="position:absolute; top:0px; left:0px; pointer-events:none; display:none;";
this.select.innerHTML=HUB.roundSelect;this.toolSet.appendChild(this.select);c=document.createElement("img");c.src="img/interface.png";this.toolSet.appendChild(c);c.style.cssText="position:absolute; margin:0px; padding:0px; top:0px; right:0px; width:198px; height:396px; pointer-events:none;";this.addSelector("Speed",["II",">",">>",">>>",">>>"],setSpeed,2,[20,20,20,20,20]);this.addButton(this.hub,"Budget",[75,16,14],"position:absolute; left:10px; top:-7px; font-weight:bold;",!0).addEventListener("click",
function(a){a.preventDefault();getBudjet()},!1);this.addButton(this.hub,"Eval",[75,16,14],"position:absolute; left:110px; top:-7px; font-weight:bold;",!0).addEventListener("click",function(a){a.preventDefault();getEval()},!1);this.addButton(this.hub,"Exit",[75,16,14],"position:absolute; left:310px; top:-7px; font-weight:bold;",!0).addEventListener("click",function(b){b.preventDefault();a.openExit()},!1);this.addButton(this.hub,"About",[75,16,14],"position:absolute; left:410px; top:-7px; font-weight:bold;",
!0).addEventListener("click",function(b){b.preventDefault();a.openAbout()},!1);this.H=[];this.roo=document.createElement("div");this.roo.style.cssText="position:absolute; bottom:11px; left:10px; width:60px; height:60px; pointer-events:none; transform:rotate(45deg); ";this.roo.style.cssText+="-moz-border-radius: 30px; -webkit-border-radius: 30px; border-radius: 30px; overflow:hidden; ";this.hub.appendChild(this.roo);for(c=0;4>c;c++)b=document.createElement("div"),0==c&&(b.style.cssText="position:absolute; top:0px; left:0px; width:30px; height:30px; pointer-events:auto; cursor:pointer; background:#ffffff;"),
1==c&&(b.style.cssText="position:absolute; top:0px; right:0px; width:30px; height:30px; pointer-events:auto; cursor:pointer;"),2==c&&(b.style.cssText="position:absolute; bottom:0px; right:0px; width:30px; height:30px; pointer-events:auto; cursor:pointer;"),3==c&&(b.style.cssText="position:absolute; bottom:0px; left:0px; width:30px; height:30px; pointer-events:auto; cursor:pointer;"),b.name=c,this.roo.appendChild(b),b.addEventListener("click",function(b){b.preventDefault();a.hideoldSel();a.H[this.name].style.background=
"#ffffff";setTimeColors(this.name)},!1),this.H[c]=b;c=document.createElement("div");c.style.cssText="position:absolute; bottom:80px; left:25px; width:30px; height:30px; pointer-events:auto; cursor:pointer; background:rgba(0,0,0,0); ";c.style.cssText+="-moz-border-radius: 30px; -webkit-border-radius: 30px; border-radius: 30px; ";this.hub.appendChild(c);c.addEventListener("click",function(a){view3d.winterSwitch();this.style.background=view3d.isWinter?"rgba(255,255,255,0.5);":"rgba(0,0,0,0);"},!1);c=
document.createElement("img");c.src="img/basemenu.png";this.hub.appendChild(c);c.style.cssText="position:absolute; margin:0px; padding:0px; bottom:0px; left:0px; width:630px; height:120px; pointer-events:none;";this.initCITYinfo()},hideoldSel:function(){for(var a=0;4>a;a++)this.H[a].style.background="none"},initCITYinfo:function(){this.date=document.createElement("div");this.date.style.cssText="font-size:14px; position:absolute; width:70px; height:19px; bottom:15px; left:65px; text-align:right; font-weight:bold;";
this.money=document.createElement("div");this.money.style.cssText="font-size:14px; position:absolute; width:70px; height:19px; bottom:15px; left:295px; text-align:right; font-weight:bold;";this.population=document.createElement("div");this.population.style.cssText="font-size:14px; position:absolute; width:70px; height:19px; bottom:15px; left:180px; text-align:right; font-weight:bold;";this.score=document.createElement("div");this.score.style.cssText="font-size:14px; position:absolute; width:70px; height:19px; bottom:15px; left:410px; text-align:right; font-weight:bold;";
this.msg=document.createElement("div");this.msg.style.cssText="font-size:14px; letter-spacing:0.02em; position:absolute; width:420px; height:20px; bottom:44px; left:76px; text-align:left; color:"+this.colors[4]+"; font-weight:bold;";this.hub.appendChild(this.date);this.hub.appendChild(this.money);this.hub.appendChild(this.population);this.hub.appendChild(this.score);this.hub.appendChild(this.msg);this.initRCI()},updateCITYinfo:function(a){this.date.innerHTML=a[0];this.money.innerHTML=a[4];this.population.innerHTML=
a[3];this.score.innerHTML=a[2];this.msg.innerHTML=a[8];this.updateRCI(a[5],a[6],a[7])},testOpen:function(){var a="";null!==this.budgetWindow&&"open"==this.budgetWindow.className&&(this.closeBudget(),a="budget");null!==this.evaluationWindow&&"open"==this.evaluationWindow.className&&(this.closeEval(),a="evaluation");null!==this.disasterWindow&&"open"==this.disasterWindow.className&&(this.closeDisaster(),a="disaster");null!==this.exitWindow&&"open"==this.exitWindow.className&&(this.closeExit(),a="exit");
null!==this.queryWindow&&"open"==this.queryWindow.className&&(this.closeQuery(),a="query");null!==this.overlaysWindow&&"open"==this.overlaysWindow.className&&(this.closeOverlays(),a="overlays");null!==this.aboutWindow&&"open"==this.aboutWindow.className&&(this.closeAbout(),a="about");return a},openAbout:function(a){var b=this;"about"!=this.testOpen()&&(null==this.aboutWindow?(this.aboutWindow=document.createElement("div"),this.aboutWindow.style.cssText=this.radius+"position:absolute; width:200px; height:210px; pointer-events:none; display:block;"+
this.windowsStyle,this.hub.appendChild(this.aboutWindow),this.addButton(this.aboutWindow,"X",[16,16,14],"position:absolute; left:10px; top:10px;").addEventListener("click",function(a){a.preventDefault();b.closeAbout()},!1),this.fps=document.createElement("div"),this.fps.style.cssText="position:absolute; top:20px; left:60px; width:120px; height:20px; pointer-events:none; font-size:12px; text-align:center; color:"+this.colors[0]+";",this.aboutWindow.appendChild(this.fps),this.abb=document.createElement("div"),
this.abb.style.cssText="position:absolute; top:60px; left:10px; width:180px; height:180px; pointer-events:none; font-size:12px; text-align:center; color:"+this.colors[0]+";",this.aboutWindow.appendChild(this.abb),this.linke=document.createElement("div"),this.linke.style.cssText="position:absolute; top:160px; left:10px; width:180px; height:20px; pointer-events:auto; font-size:12px; text-align:center; color:"+this.colors[0]+";",this.aboutWindow.appendChild(this.linke),this.abb.innerHTML="3D CITY
All 3d side made by Lo.th
Simulation from MicropolisJS
",
this.linke.innerHTML="https://WebOas.is"):this.aboutWindow.style.display="block",displayStats(),this.aboutWindow.className="open")},upStats:function(a,b){this.fps.innerHTML="Fps: "+a+"
geometry: "+b},closeAbout:function(){hideStats();this.aboutWindow.style.display="none";this.aboutWindow.className="close"},openOverlays:function(a){if("overlays"!=this.testOpen()){if(null==this.overlaysWindow)for(this.overlaysWindow=document.createElement("div"),
this.overlaysWindow.style.cssText=this.radius+"position:absolute; width:140px; height:420px; pointer-events:none; display:block;"+this.windowsStyle,this.hub.appendChild(this.overlaysWindow),a=0;aPublic opinion
Is the mayor doing a good job ?
What are the worst problems ?
"):
this.evaluationWindow.style.display="block",this.evaltYes.innerHTML="YES:"+a[0]+"%",this.evaltNo.innerHTML="NO:"+(100-a[0])+"%",this.evaltProb.innerHTML=a[1],this.evaluationWindow.className="open")},closeEval:function(){this.evaluationWindow.style.display="none";this.evaluationWindow.className="close"},openExit:function(a){var b=this;if("exit"!=this.testOpen()){if(null==this.exitWindow){this.exitWindow=document.createElement("div");this.exitWindow.style.cssText=this.radius+"position:absolute; width:140px; height:180px; pointer-events:none; display:block;"+
this.windowsStyle;this.hub.appendChild(this.exitWindow);a=this.addButton(this.exitWindow,"X",[16,16,14],"position:absolute; left:50px; top:10px;");var c=this.addButton(this.exitWindow,"NEW MAP",[96,16,14],"position:absolute; left:10px; top:50px;"),e=this.addButton(this.exitWindow,"SAVE",[96,16,14],"position:absolute; left:10px; top:90px;"),f=this.addButton(this.exitWindow,"LOAD",[96,16,14],"position:absolute; left:10px; top:130px;");a.addEventListener("click",function(a){a.preventDefault();b.closeExit()},
!1);c.addEventListener("click",function(a){a.preventDefault();newGameMap()},!1);e.addEventListener("click",function(a){a.preventDefault();saveGame()},!1);f.addEventListener("click",function(a){a.preventDefault();loadGame()},!1)}else this.exitWindow.style.display="block";this.exitWindow.className="open"}},closeExit:function(){this.exitWindow.style.display="none";this.exitWindow.className="close"},openBudget:function(a){var b=this;if("budget"!=this.testOpen()){this.dataKeys="roadFund roadRate fireFund fireRate policeFund policeRate taxRate totalFunds taxesCollected".split(" ");
for(var c=this.dataKeys.length;c--;)this[this.dataKeys[c]]=a[this.dataKeys[c]];a=a.taxesCollected;c=a-this.roadFund-this.fireFund-this.policeFund;if(null==this.budgetWindow){this.budgetWindow=document.createElement("div");this.budgetWindow.style.cssText=this.radius+"position:absolute; width:200px; height:300px; pointer-events:none; display:block;"+this.windowsStyle;this.hub.appendChild(this.budgetWindow);this.addSlider(this.budgetWindow,10,"Tax",this.taxRate,null,"green",20);this.addSlider(this.budgetWindow,
70,"Roads",this.roadRate,this.roadFund,"red",100);this.addSlider(this.budgetWindow,110,"Fire",this.fireRate,this.fireFund,"red",100);this.addSlider(this.budgetWindow,150,"Police",this.policeRate,this.policeFund,"red",100);this.budgetResult=document.createElement("div");this.budgetResult.style.cssText="position:absolute; top:200px; left:10px; width:180px; height:300px; pointer-events:none; color:"+this.colors[0]+";";this.budgetWindow.appendChild(this.budgetResult);var e=this.addButton(this.budgetWindow,
"CLOSE",[70,16,14],"position:absolute; left:10px; bottom:10px;"),f=this.addButton(this.budgetWindow,"APPLY",[70,16,14],"position:absolute; rigth:10px; bottom:10px;");e.addEventListener("click",function(a){a.preventDefault();b.closeBudget()},!1);f.addEventListener("click",function(a){a.preventDefault();b.applyBudget()},!1)}else this.budgetWindow.style.display="block",this.setBudgetValue();this.budgetResult.innerHTML="Annual receipts:"+c+"$
Taxes collected:"+a+"$";this.budgetWindow.className="open"}},
applyBudget:function(){this.budgetWindow.style.display="none";this.budgetWindow.className="close";setBudjet([this.taxRate,this.roadRate,this.fireRate,this.policeRate])},closeBudget:function(){this.budgetWindow.style.display="none";this.budgetWindow.className="close"},setBudgetValue:function(){this.setSliderValue("Tax",this.taxRate,20,null);this.setSliderValue("Roads",this.roadRate,100,this.roadFund);this.setSliderValue("Fire",this.fireRate,100,this.fireFund);this.setSliderValue("Police",this.policeRate,
100,this.policeFund)},openDisaster:function(){if("disaster"!=this.testOpen()){if(null==this.disasterWindow){this.disasterWindow=document.createElement("div");this.disasterWindow.style.cssText=this.radius+"position:absolute; width:140px; height:300px; pointer-events:none; display:block;"+this.windowsStyle;this.hub.appendChild(this.disasterWindow);for(var a=0;ab&&(b=0);b>c&&(b=c);e[0].style.width=b/c*170+"px";switch(a.name){case "Tax":e[1].innerHTML=a.name+" "+b+"%";this.taxRate=b;break;case "Roads":e[1].innerHTML=a.name+" "+b+"% of "+this.roadFund+"$ = "+Math.floor(b/100*this.roadFund)+"$";this.roadRate=b;break;case "Fire":e[1].innerHTML=a.name+" "+b+"% of "+this.fireFund+"$ = "+Math.floor(b/100*this.fireFund)+"$";this.fireRate=b;break;case "Police":e[1].innerHTML=a.name+" "+b+"% of "+this.policeFund+"$ = "+Math.floor(b/100*this.policeFund)+"$",
this.policeRate=b}}},initRCI:function(){var a=document.createElement("div");a.id="RCI";a.style.cssText="font-size:10px; position:absolute; width:70px; height:70px; bottom:20px; right:20px;";var b=document.createElement("div");b.style.cssText="font-size:10px; position:absolute; width:46px; height:14px; bottom:28px; left:10px; background:#cccccc; padding:0px 2px; letter-spacing:12px; text-align:center; color:#000000;";b.innerHTML="RCI";this.R=document.createElement("div");this.R.id="R";this.R.style.cssText=
"position:absolute; width:10px; height:20px; bottom:42px; left:10px; background:#30ff30;";a.appendChild(this.R);this.C=document.createElement("div");this.C.id="C";this.C.style.cssText="position:absolute; width:10px; height:20px; bottom:42px; left:30px; background:#3030ff;";a.appendChild(this.C);this.I=document.createElement("div");this.I.id="I";this.I.style.cssText="position:absolute; width:10px; height:20px; bottom:42px; left:50px; background:#ffff30;";a.appendChild(this.I);a.appendChild(b);this.hub.appendChild(a)},
updateRCI:function(a,b,c){this.R.style.height=a/100+"px";this.C.style.height=b/100+"px";this.I.style.height=c/100+"px";this.R.style.bottom=0";g.id=a;for(var l=[],k=0;k!==b.length;k++)l[k]=document.createElement("div"),l[k].style.cssText="font-size:14px; border:1px solid "+this.colors[5]+"; background:"+this.colors[1]+"; color:"+this.colors[0]+";",l[k].style.cssText="Speed"==a?l[k].style.cssText+" width:70px; height:16px; margin-left:2px; padding:6px; pointer-events:auto; cursor:pointer; display:inline-block; ":l[k].style.cssText+" width:70px; height:16px; margin:2px; padding:7px; pointer-events:auto; cursor:pointer; display:inline-block; ",
0==k&&(l[k].style.cssText+=this.radiusL),k==b.length-1&&(l[k].style.cssText+=this.radiusR),f?f[k]?(l[k].style.width=f[k]+"px",l[k].style.height=f[k]+"px",l[k].style.padding="0px"):l[k].style.width="60px":l[k].style.width="60px",l[k].className="none","Speed"!==a&&(l[k].textContent=b[k]),k==e&&(l[k].style.backgroundColor=this.colors[5],l[k].style.color=this.colors[2],l[k].className="select"),l[k].name=k,l[k].id=a+k,g.appendChild(l[k]),l[k].addEventListener("mouseover",function(a){a.preventDefault();
this.style.border="1px solid "+h.colors[0]},!1),l[k].addEventListener("mouseout",function(a){a.preventDefault();this.style.border="1px solid "+h.colors[5]},!1),l[k].addEventListener("click",function(b){b.preventDefault();c(this.name);h.setActiveSelector(this.name,a)},!1);"DIFFICULTY"==a?(this.full.appendChild(g),g.style.position="absolute",g.style.top="200px",g.style.width="300px"):this.hub.appendChild(g)},setActiveSelector:function(a,b){for(var c=10,e;c--;)document.getElementById(b+c)&&(e=document.getElementById(b+
c),e.style.color=this.colors[0],e.style.backgroundColor=this.colors[1],e.className="none");c=document.getElementById(b+a);c.style.backgroundColor=this.colors[5];c.style.color=this.colors[2];c.className="select"},removeSelector:function(a){for(var b=10,c,e=document.getElementById(a);b--;)document.getElementById(a+b)&&(c=document.getElementById(a+b),e.removeChild(c));this.full.removeChild(e)},showToolSelect:function(a){if(a.name!==this.currentToolName){this.currentToolName=a.name;var b=a.getBoundingClientRect().left-
this.toolSet.getBoundingClientRect().left;a=a.getBoundingClientRect().top-this.toolSet.getBoundingClientRect().top;this.select.style.left=b+"px";this.select.style.top=a+"px";this.select.style.display="block"}else this.select.style.display="none",this.currentToolName=0;selectTool(this.currentToolName)},showToolInfo:function(a,b){var c=view3d.toolSet[a.name].tool,c=c.charAt(0).toUpperCase()+c.substring(1).toLowerCase();b.toolInfo.innerHTML=16===a.name?"Drag view":178===a.name?"Get info":18===a.name?
"Rotate view":c+"
"+view3d.toolSet[a.name].price+"$"},addSVGButton:function(a){var b=this,c=document.createElement("div");c.style.cssText=" margin:0px; padding:0px; width:66px; height:66px; pointer-events:auto; cursor:pointer; display:inline-block; line-height:0px; vertical-align: top;";c.innerHTML=HUB.round;c.addEventListener("mouseover",function(a){a.preventDefault();a=this.getBoundingClientRect().left-b.toolSet.getBoundingClientRect().left;var c=this.getBoundingClientRect().top-b.toolSet.getBoundingClientRect().top;
b.selector.style.left=a+"px";b.selector.style.top=c+"px";b.selector.style.display="block";b.showToolInfo(this,b)},!1);c.addEventListener("mouseout",function(a){a.preventDefault();b.selector.style.display="none"},!1);c.addEventListener("click",function(a){a.preventDefault();b.showToolSelect(this)},!1);a.appendChild(c);return c},addButton:function(a,b,c,e,f){var h=this;c||(c=[128,30,22]);var g=document.createElement("div");c="font-size:"+c[2]+"px; border:1px solid "+this.colors[5]+"; background:"+
this.colors[1]+"; width:"+c[0]+"px; height:"+c[1]+"px; color:"+this.colors[0]+";";c=f?c+("margin:4px; padding:7px; pointer-events:auto; cursor:pointer; display:inline-block; "+this.radiusB):c+("margin:4px; padding:7px; pointer-events:auto; cursor:pointer; display:inline-block; "+this.radius);g.textContent=b;g.style.cssText=e?c+e:c+"margin-top:20px;";g.addEventListener("mouseover",function(a){a.preventDefault();this.style.backgroundColor=h.colors[5];this.style.color=h.colors[2]},!1);g.addEventListener("mouseout",
function(a){a.preventDefault();this.style.backgroundColor=h.colors[1];this.style.color=h.colors[0]},!1);a.appendChild(g);return g},clearElement:function(a){a=document.getElementById(a);for(var b=a.childNodes,c=b.length;c--;)a.removeChild(b[c]);this.hub.removeChild(a)}};var ARRAY8="undefined"!==typeof Uint8Array?Uint8Array:Array,Perlin=function(){this.F2=0.5*(Math.sqrt(3)-1);this.G2=(3-Math.sqrt(3))/6;var a=Math.random;this.p=new ARRAY8(256);this.perm=new ARRAY8(512);this.permMod12=new ARRAY8(512);for(var b=0;256>b;b++)this.p[b]=256*a();for(b=0;512>b;b++)this.perm[b]=this.p[b&255],this.permMod12[b]=this.perm[b]%12};
Perlin.prototype={grad3:new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),noise:function(a,b){var c=this.permMod12,e=this.perm,f=this.grad3,h=0,g=0,l=0,k=(a+b)*this.F2,p=Math.floor(a+k),q=Math.floor(b+k),k=(p+q)*this.G2,n=a-(p-k),m=b-(q-k),v,s;n>m?(v=1,s=0):(v=0,s=1);var t=n-v+this.G2,u=m-s+this.G2,k=n-1+2*this.G2,r=m-1+2*this.G2,p=p&255,q=q&255,w=0.5-n*n-m*m;0<=w&&(h=3*c[p+e[q]],w*=w,h=w*w*(f[h]*n+f[h+1]*m));n=0.5-t*t-u*u;0<=n&&(g=3*c[p+v+e[q+
s]],n*=n,g=n*n*(f[g]*t+f[g+1]*u));t=0.5-k*k-r*r;0<=t&&(c=3*c[p+1+e[q+1]],t*=t,l=t*t*(f[c]*k+f[c+1]*r));return 70*(h+g+l)}};