jocly
Version:
Board games 3D/2D UI and AI web library
1 lines • 28.3 kB
JavaScript
exports.view=View={Game:{},Board:{},Move:{}},function(){var e,a,t;View.Game.cbTargetMesh="/res/ring-target.js",View.Game.cbTargetSelectColor=16777215,View.Game.cbTargetCancelColor=16746496,View.Game.cbPromoSize=2e3,View.Game.xdInit=function(t){this.g.fullPath=this.mViewOptions.fullPath,this.cbPieceByType={},e=this.cbVar,a=this.cbDefineView(),this.cbView=a,this.cbClearPieces(),this.cbCreateLights(t),this.cbCreateScreens(t),this.cbCreateBoard(t),this.cbCreatePromo(t),this.cbCreatePieces(t),this.cbCreateCells(t)},View.Game.cbMakeDummyMesh=function(e){return"undefined"!=typeof THREE?new THREE.Mesh(new THREE.CubeGeometry(1e-4,1e-4,1e-4),new THREE.MeshLambertMaterial):null},View.Game.cbCurrentGame=function(){return t},View.Game.cbCreatePieces=function(e){for(var a=this.cbMakeDummyMesh(e),t=0;t<this.cbPiecesCount;t++)e.createGadget("piece#"+t,{base:{},"2d":{type:"sprite"},"3d":{type:"custommesh3d",create:function(e,t,i){return a}}})},View.Game.cbCreateBoard=function(e){var a=this.cbMakeDummyMesh(e);e.createGadget("board",{base:{},"2d":{type:"canvas",width:12e3,height:12e3,draw:function(e){console.warn("board draw must be overridden")}},"3d":{type:"custommesh3d",receiveShadow:!0,create:function(e,t,i){return a}}})},View.Game.cbCreateCells=function(e){for(var a=this,t=0;t<this.g.boardSize;t++)!function(t){e.createGadget("cell#"+t,{"2d":{z:101,type:"element",initialClasses:a.cbCellClass(e,t),width:1300,height:1300}}),e.createGadget("clicker#"+t,$.extend(!0,{"2d":{z:103,type:"element",initialClasses:"cb-clicker"},"3d":{type:"meshfile",file:a.g.fullPath+a.cbTargetMesh,flatShading:!0,castShadow:!0,smooth:0,scale:[.9,.9,.9],materials:{square:{transparent:!0,opacity:0},ring:{color:a.cbTargetSelectColor,opacity:1}}}},a.cbView.clicker))}(t)},View.Game.cbCreatePromo=function(e){e.createGadget("promo-board",{base:{type:"element",x:0,y:0,width:2e3,height:2e3,z:108,css:{"background-color":"White"}}}),e.createGadget("promo-cancel",{base:{type:"image",file:this.g.fullPath+"/res/images/cancel.png",x:0,y:0,width:800,height:800,z:109}});for(var a=0;a<this.g.pTypes.length;a++)e.createGadget("promo#"+a,{base:{y:0,z:109,type:"sprite",clipwidth:100,clipheight:100,width:1200,height:1200}})},View.Game.xdBuildScene=function(i){t=this,e=this.cbVar,a=this.cbDefineView(),this.cbView=a;for(var r=0;r<this.cbExtraLights.length;r++)i.updateGadget("extralights#"+r,{"3d":{visible:!0}});i.updateGadget("board",$.extend({base:{visible:!0}},this.cbView.board));for(var n=0;n<this.g.boardSize;n++)!function(e){var a=t.cbMakeDisplaySpec(e,0),r=$.extend(!0,{},a,{base:{visible:!0}},t.cbView.clicker,t.cbView.cell);i.updateGadget("cell#"+e,r),$.extend(!0,a,t.cbView.clicker),i.updateGadget("clicker#"+e,a)}(n);i.updateGadget("videoa",{"3d":{visible:!0,playerSide:1,z:3e3,y:1==this.mViewAs?1e4:-1e4,rotate:1==this.mViewAs?-180:-0,rotateX:1==this.mViewAs?25:-25,scale:[3,3,3]}}),i.updateGadget("videoabis",{"3d":{visible:!0,playerSide:-1,z:1500,x:1==this.mViewAs?-5500:5500,y:1==this.mViewAs?8900:-8900,rotate:1==this.mViewAs?-180:-0,rotateX:1==this.mViewAs?25:-25,scale:[.75,.75,.75]}}),i.updateGadget("videob",{"3d":{visible:!0,playerSide:-1,z:3e3,y:1==this.mViewAs?-1e4:1e4,rotate:1==this.mViewAs?-0:-180,rotateX:1==this.mViewAs?-25:25,scale:[3,3,3]}}),i.updateGadget("videobbis",{"3d":{visible:!0,playerSide:1,z:1500,x:1==this.mViewAs?5500:-5500,y:1==this.mViewAs?-8900:8900,rotate:1==this.mViewAs?-0:-180,rotateX:1==this.mViewAs?-25:25,scale:[.75,.75,.75]}}),i.updateGadget("promo-board",{base:{visible:!1}}),i.updateGadget("promo-cancel",{base:{visible:!1}});for(var r=0;r<this.g.pTypes.length;r++)i.updateGadget("promo#"+r,{base:{visible:!1}})},View.Game.cbDisplayBoardFn=function(e){var a=this;return function(i,r,n){var s=e.style+"_"+e.margins.x+"_"+e.margins.y+"_"+a.mNotation+"_"+a.mViewAs,o=this;s!=this._cbKey&&(this._cbKey=s,e.display.call(t,e,o,function(e){o.replaceMesh(e,r,n)}))}},View.Game.cbDrawBoardFn=function(e){return function(a){e.draw.call(t,e,this,a)}},View.Game.cbMakeDisplaySpec=function(e,a){var t={};for(var i in this.cbView.coords){var r=this.cbView.coords[i],n=r.call(this,e);t[i]={x:n.x||0,y:n.y||0,z:n.z||0,rotateX:n.rx||0,rotateY:(n.ry||0)*("3d"==i?this.mViewAs*a<0?-1:1:0),rotate:(n.rz||0)+("3d"==i&&this.mViewAs*a<0?180:0)}}return t},View.Game.cbMakeDisplaySpecForPiece=function(t,i,r){function n(e,a,t){return a?$.extend(!0,e,a.default,a[t]):{}}var s=this.cbMakeDisplaySpec(i,r.s);if(void 0===e.pieceTypes[r.t])return void console.warn("Piece type",r.t,"not defined in model");var o=e.pieceTypes[r.t].aspect||e.pieceTypes[r.t].name;return o?(a.pieces&&(s=n(s,a.pieces,o),a.pieces[r.s]&&(s=n(s,a.pieces[r.s],o))),s):void console.warn("Piece type",r.t,"has no aspect defined")},View.Board.xdDisplay=function(e,a){for(var t=0;t<this.pieces.length;t++){var i=this.pieces[t];if(i.p<0)e.updateGadget("piece#"+t,{base:{visible:!1}});else{var r=a.cbMakeDisplaySpecForPiece(a,i.p,i);r=$.extend(!0,{base:{visible:!0},"2d":{opacity:1},"3d":{positionEasingUpdate:null}},r),e.updateGadget("piece#"+t,r)}}for(;t<a.cbPiecesCount;t++)e.updateGadget("piece#"+t,{base:{visible:!1}})},View.Game.cbExtraLights=[{color:16777215,intensity:.8,position:[9,14,-9],props:{shadowCameraNear:10,shadowCameraFar:25,castShadow:!0,shadowMapWidth:2048,shadowMapHeight:2048}}],View.Game.cbCreateLights=function(e){for(var a=0;a<this.cbExtraLights.length;a++)!function(a,t){e.createGadget("extralights#"+t,{"3d":{type:"custommesh3d",create:function(e){var t=new THREE.SpotLight(a.color,a.intensity);t.shadow.camera.far=a.props.shadowCameraFar,t.shadow.camera.near=a.props.shadowCameraNear,t.shadow.mapSize.width=a.props.shadowMapWidth,t.shadow.mapSize.height=a.props.shadowMapHeight,t.position.set.apply(t.position,a.position);var i=new THREE.Mesh;i.add(t);var r=new THREE.Object3D;i.add(r),t.target=r,e(i)}}})}(this.cbExtraLights[a],a)},View.Game.cbCreateScreen=function(e){var a=new THREE.PlaneGeometry(4,3,1,1),t=new THREE.MeshPhongMaterial({color:16777215,map:e,shading:THREE.FlatShading,emissive:{r:1,g:1,b:1}}),i=new THREE.Mesh(a,t);return this.objectReady(i),null},View.Game.cbCreateScreens=function(e){var a=this;e.createGadget("videoa",{"3d":{type:"video3d",makeMesh:function(e){return a.cbCreateScreen.call(this,e)}}}),e.createGadget("videoabis",{"3d":{type:"video3d",makeMesh:function(e){return a.cbCreateScreen.call(this,e)}}}),e.createGadget("videob",{"3d":{type:"video3d",makeMesh:function(e){return a.cbCreateScreen.call(this,e)}}}),e.createGadget("videobbis",{"3d":{type:"video3d",makeMesh:function(e){return a.cbCreateScreen.call(this,e)}}})},View.Board.xdInput=function(a,t){function i(){a.updateGadget("promo-board",{base:{visible:!1}}),a.updateGadget("promo-cancel",{base:{visible:!1}})}return{initial:{f:null,t:null,pr:null},getActions:function(r,n){var s={};if(null==n.f)r.forEach(function(e){void 0===s[e.f]&&(s[e.f]={f:e.f,moves:[],click:["piece#"+this.board[e.f],"clicker#"+e.f],view:["clicker#"+e.f],highlight:function(i){a.updateGadget("cell#"+e.f,{"2d":{classes:"select"==i?"cb-cell-select":"cb-cell-cancel",opacity:t.mShowMoves||"cancel"==i?1:0}}),a.updateGadget("clicker#"+e.f,{"3d":{materials:{ring:{color:"select"==i?t.cbTargetSelectColor:t.cbTargetCancelColor,opacity:t.mShowMoves||"cancel"==i?1:0,transparent:!t.mShowMoves&&"cancel"!=i}},castShadow:t.mShowMoves||"cancel"==i}})},unhighlight:function(){a.updateGadget("cell#"+e.f,{"2d":{classes:""}})},validate:{f:e.f}}),s[e.f].moves.push(e)},this);else if(null==n.t)r.forEach(function(r){var n=void 0===r.cg?r.t:r.cg;void 0===s[n]&&(s[n]={t:r.t,moves:[],click:["piece#"+this.board[n],"clicker#"+n],view:["clicker#"+n],highlight:function(e){a.updateGadget("cell#"+n,{"2d":{classes:"select"==e?"cb-cell-select":"cb-cell-cancel",opacity:t.mShowMoves||"cancel"==e?1:0}}),a.updateGadget("clicker#"+n,{"3d":{materials:{ring:{color:"select"==e?t.cbTargetSelectColor:t.cbTargetCancelColor,opacity:t.mShowMoves||"cancel"==e?1:0,transparent:!t.mShowMoves&&"cancel"!=e}},castShadow:t.mShowMoves||"cancel"==e}})},unhighlight:function(e){a.updateGadget("cell#"+n,{"2d":{classes:""}})},validate:{t:r.t},execute:function(i){var n=this;this.cbAnimate(a,t,r,function(){var o=s[r.t].moves;o.length>1&&(a.updateGadget("promo-board",{base:{visible:!0,width:t.cbPromoSize*(o.length+1)}}),a.updateGadget("promo-cancel",{base:{visible:!0,x:o.length*t.cbPromoSize/2}}),o.forEach(function(i,r){var n=e.pieceTypes[i.pr].aspect||e.pieceTypes[i.pr].name,s=$.extend(!0,{},t.cbView.pieces.default,t.cbView.pieces[n]);t.cbView.pieces[this.mWho]&&(s=$.extend(!0,s,t.cbView.pieces[this.mWho].default,t.cbView.pieces[this.mWho][n])),a.updateGadget("promo#"+i.pr,{base:$.extend(s["2d"],{x:(r-o.length/2)*t.cbPromoSize})})},n)),i()})},unexecute:function(){if(null!=r.c){var e=this.pieces[r.c],n=t.cbMakeDisplaySpecForPiece(t,e.p,e);n=$.extend(!0,{base:{visible:!0},"2d":{opacity:1},"3d":{positionEasingUpdate:null}},n),a.updateGadget("piece#"+r.c,n)}var s=this.pieces[this.board[r.f]],o=t.cbMakeDisplaySpecForPiece(t,s.p,s);a.updateGadget("piece#"+s.i,o),i()}}),void 0!==r.cg&&(s[n].validate.cg=r.cg,s[n].execute=function(e){this.cbAnimate(a,t,r,function(){e()})}),s[n].moves.push(r)},this);else if(null==n.pr){var o=[];r.forEach(function(e){void 0!==e.pr&&(void 0===s[e.pr]&&(s[e.pr]={pr:e.pr,moves:[],click:["promo#"+e.pr],validate:{pr:e.pr},cancel:["promo-cancel"],post:i,skipable:!0},o.push(e.pr)),s[e.pr].moves.push(e))},this),o.length>1&&o.forEach(function(e){s[e].view=["promo#"+e]})}return s}}},View.Game.cbCellClass=function(e,a){return"classic-cell "+((a+(a-a%this.g.NBCOLS)/this.g.ROWS)%2?"classic-cell-black":"classic-cell-white")},View.Board.xdPlayedMove=function(e,a,t){a.mOldBoard.cbAnimate(e,a,t,function(){a.MoveShown()})},View.Board.cbAnimate=function(e,a,t,i){function r(){0==--s&&(o&&a.PlaySound("tac"+(1+Math.floor(3*Math.random()))),i())}var n=this,s=1,o=!1,c=this.pieces[this.board[t.f]],l=a.cbMakeDisplaySpec(t.f,c.s),d=a.cbMakeDisplaySpecForPiece(a,t.t,c);for(var h in l){var u=l[h];void 0!==u.z&&function(e){var i=u.z,r=d[e].z,s=n.cbMoveMidZ(a,t,i,r,e),c=i,l=c-s,h=c-r;s!=(i+r)/2&&(o=!0);var p=4*l-2*h,m=-h*h,f=Math.abs(p*p- -4*m),g=(-p-Math.sqrt(f))/-2,b=(-p+Math.sqrt(f))/-2,v=g,w=-v-h;(0==v||-w/(2*v)<0||-w/(2*v)>1)&&(v=b,w=-v-h),d[e].positionEasingUpdate=function(e){var a=(v*e*e+w*e+c)*this.SCALE3D;this.object3d.position.y=a}}(h)}if(o||a.PlaySound("move"+(1+Math.floor(4*Math.random()))),e.updateGadget("piece#"+c.i,d,600,function(){r()}),null!=t.c){s++;var p={positionEasingUpdate:null};switch(a.cbView.captureAnim3d||"movedown"){case"movedown":p.z=-2e3;break;case"scaledown":p.scale=[0,0,0]}var m=this.pieces[t.c];e.updateGadget("piece#"+m.i,{"2d":{opacity:0},"3d":p},600,r)}if(void 0!==t.cg){var u=a.cbVar.castle[t.f+"/"+t.cg],f=u.r[u.r.length-1],c=this.pieces[this.board[t.cg]],d=a.cbMakeDisplaySpecForPiece(a,f,c);s++,e.updateGadget("piece#"+c.i,d,600,function(){r()})}},View.Board.cbMoveMidZ=function(e,a,t,i){return(t+i)/2}}(),function(){View.Game.cbBaseBoard={TEXTURE_CANVAS_CX:1024,TEXTURE_CANVAS_CY:1024,display:function(e,a,t){var i=this;e.getResource=a.getResource,e.createGeometry.call(this,e,function(a){e.createTextureImages.call(i,e,function(r){var n=["diffuse"].concat(e.extraChannels||[]),s={};n.forEach(function(a){var t=document.createElement("canvas");t.width=e.TEXTURE_CANVAS_CX,t.height=e.TEXTURE_CANVAS_CY,s[a]=t}),e.createMaterial.call(i,e,s,function(n){var o=new THREE.Mesh(a,n);e.modifyMesh.call(i,e,o,function(a){e.paint.call(i,e,s,r,function(){t(a)})})})})})},createTextureImages:function(e,a){var t=this,i={},r=0,n=e.texturesImg||{};for(var s in n)r++;if(0==r)a(i);else for(var s in n)!function(s){e.getResource("image|"+t.g.fullPath+n[s],function(e){i[s]=e,0==--r&&a(i)})}(s)},createMaterial:function(e,a,t){var i=new THREE.Texture(a.diffuse);i.needsUpdate=!0;var r={specular:"#050505",shininess:30,map:i};if(a.bump){var n=new THREE.Texture(a.bump);n.needsUpdate=!0,r.bumpMap=n,r.bumpScale=.05}t(new THREE.MeshPhongMaterial(r))},modifyMesh:function(e,a,t){t(a)},prePaint:function(e,a,t,i,r){r()},paint:function(e,a,t,i,r){r()},postPaint:function(e,a,t,i,r){r()},paintChannel:function(e,a,t,i){},draw:function(e,a,t){var i=this;e.getResource=a.getResource,e.createTextureImages.call(this,e,function(a){e.paintChannel.call(i,e,t,a,"diffuse")})}}}(),function(){function e(e){for(var a=JSON.stringify(e),t=0,i=0;i<a.length;i++)t=(t<<5)-t+a.charCodeAt(i),t&=t;return t}var a,t={};View.Game.cbDisplayPieceFn=function(t){var i=this,r=e(t);return function(e,n,s){a=this.getResource;var o=/^piece#([0-9]+)$/.exec(this.gadget.id);if(!o)return null;var c=parseInt(o[1]),l=i.cbCurrentGame();if(c>=l.mBoard.pieces.length)return null;var d=l.mBoard.pieces[c],h=l.cbVar.pieceTypes[d.t].aspect||l.cbVar.pieceTypes[d.t].name,u=h+"_"+r+"_"+d.s,p=this;u!=this._cbKey&&(this._cbKey=u,p.options=n,l.cbMakePiece(t,h,d.s,function(e){p.replaceMesh(e,p.options,s)}))}},View.Game.cbMakePiece=function(a,i,r,n){function s(e,a,t){return a?$.extend(!0,e,a.default,a[t]):{}}if(!a)return void console.error("piece-view: style is not defined");var o=s({},a,i);a[r]&&(o=s(o,a[r],i));var c=e(o),l=t[c];Array.isArray(l)?l.push(n):l?n(new THREE.Mesh(l.geometry,l.material)):(t[c]=[n],o.loadResources.call(this,o,function(e){o.displayPiece.call(this,o,e,function(){var a=t[c];t[c]={geometry:e.geometry,material:e.material},a.forEach(function(a){a(new THREE.Mesh(e.geometry,e.material))})})}))},View.Game.cbClearPieces=function(){t={}},View.Game.cbBasePieceStyle={default:{mesh:{jsFile:function(e,a){a(new THREE.CubeGeometry(1,1,1),new THREE.MeshPhongMaterial({}))},smooth:0,rotateZ:0},loadMesh:function(e,t){"function"==typeof e.mesh.jsFile?e.mesh.jsFile(e,t):a("smoothedfilegeo|"+e.mesh.smooth+"|"+this.g.fullPath+e.mesh.jsFile,t)},loadImages:function(e,t){function i(){0==--n&&t(s)}var r=this,n=1,s={};for(var o in e.materials){var c=e.materials[o].channels;for(var l in c)if(c[l].texturesImg)for(var d in c[l].texturesImg)!function(e,t){n++,a("image|"+r.g.fullPath+t,function(a){s[e]=a,i()})}(d,c[l].texturesImg[d])}i()},loadResources:function(e,a){function t(){0==--s&&a({geometry:r,images:i,textures:{},loadedMaterials:n})}var i,r,n,s=2;e.loadMesh.call(this,e,function(a,i){if(!a._cbZRotated){var s=new THREE.Matrix4;s.makeRotationY(e.mesh.rotateZ*Math.PI/180),a.applyMatrix(s),a._cbZRotated=!0}r=a,n=i,t()}),e.loadImages.call(this,e,function(e){i=e,t()})},displayPiece:function(e,a,t){e.makeMaterials.call(this,e,a),t()},paintTextureImageClip:function(e,a,t,i,r,n,s,o,c){var l=a.canvas.width,d=a.canvas.height;if(r.patternFill&&r.patternFill[n]){var h=r.patternFill[n];a.save();var u=document.createElement("canvas");u.width=l,u.height=d,ctxTmp=u.getContext("2d"),ctxTmp.fillStyle=h,ctxTmp.fillRect(0,0,l,d),ctxTmp.globalCompositeOperation="destination-in",ctxTmp.drawImage(s,o.x,o.y,o.cx,o.cy,0,0,l,d),a.drawImage(u,0,0,l,d,0,0,l,d),a.restore()}else a.drawImage(s,o.x,o.y,o.cx,o.cy,0,0,l,d)},paintTextureImage:function(e,a,t,i,r,n,s,o){var c;c=r.clipping&&r.clipping[n]?r.clipping[n]:{x:0,y:0,cx:s.width,cy:s.height},e.paintTextureImageClip.call(this,e,a,t,i,r,n,s,c,o)},paintTexture:function(e,a,t,i,r){var n=e.materials[t].channels[i];for(var s in n.texturesImg){var o=r.images[s];e.paintTextureImage.call(this,e,a,t,i,n,s,o,r)}},makeMaterialTextures:function(e,a,t){for(var i in e.materials[a].channels){var r=e.materials[a].channels[i],n=document.createElement("canvas");n.width=r.size.cx,n.height=r.size.cy;var s=n.getContext("2d");e.paintTexture.call(this,e,s,a,i,t);var o=new THREE.Texture(n);o.needsUpdate=!0,t.textures[a][i]=o}},makeMaterials:function(e,a){a.textures={};for(var t in e.materials)a.textures[t]={},e.makeMaterialTextures.call(this,e,t,a),e.makeMaterial.call(this,e,t,a)}}},View.Game.cbTokenPieceStyle3D=$.extend(!0,{},View.Game.cbBasePieceStyle,{default:{makeMaterials:function(e,a){a.textures={};for(var t in e.materials)a.textures[t]={},e.makeMaterialTextures.call(this,e,t,a);var i=[];for(var r in a.loadedMaterials){var n=a.loadedMaterials[r].clone(),s=n.name;if(e.materials[s]){$.extend(!0,n,e.materials[s].params);for(var o in e.materials[s].channels)switch(o){case"diffuse":n.map=a.textures[s][o];break;case"bump":n.bumpMap=a.textures[s][o]}}i.push(n)}var c=new THREE.MultiMaterial(i);a.material=c}}}),View.Game.cbUniformPieceStyle3D=$.extend(!0,{},View.Game.cbBasePieceStyle,{default:{makeMaterial:function(e,a,t){var i=e.materials[a].params;i.map=t.textures[a].diffuse,i.normalMap=t.textures[a].normal;var r=e.materials[a].channels.normal.normalScale||1;i.normalScale=new THREE.Vector2(r,r);var n=new THREE.MeshPhongMaterial(i);t.material=n,t.geometry.mergeVertices(),t.geometry.computeVertexNormals()}}}),View.Game.cbPhongPieceStyle3D=$.extend(!0,{},View.Game.cbBasePieceStyle,{default:{phongProperties:{color:"#ffffff",shininess:300,specular:"#ffffff",emissive:"#222222",shading:"undefined"!=typeof THREE?THREE.FlatShading:0},makeMaterials:function(e,a){var t=new THREE.MeshPhongMaterial(e.phongProperties);a.material=t}}})}(),function(){var e=0,a=0,t=0,i={};View.Game.cbTargetMesh="/res/ring-target-square-v2.js",View.Game.cbEnsureConstants=function(){t||(t=this.cbView.boardLayout.length),a||(a=this.cbView.boardLayout[0].length),e||(e=this.cbView.boardLayout[0][0].length)},View.Game.cbCSize=function(t,r){var n=t.margins;void 0!==r&&void 0!==t.boardFloorMargins&&void 0!==t.boardFloorMargins[r]&&(n=t.boardFloorMargins[r]);var s=i[t.flat+"_"+n.x+"_"+n.y];if(!s){this.cbEnsureConstants();var o,c,l=e+2*t.margins.x,d=a+2*t.margins.y;o=l/d,c=o<1?12e3*o/l:12e3/o/d,(e+2*t.margins.x)*c,(a+2*t.margins.y)*c,t.flat&&(c=t.boardFloorSize/Math.max(e+2*n.x,e+2*n.y)),s={cx:c,cy:c,pieceCx:c,pieceCy:c,ratio:o,width:(e+2*n.x)*c,height:(a+2*n.y)*c},i[t.flat+"_"+n.x+"_"+n.y]=s}return s},View.Game.cbMultiplanBoard=$.extend({},View.Game.cbBaseBoard,{notationMode:"out",interFloorsDist:2500,coordsFn:function(t){return t=t||{},t.margins=t.margins||{x:0,y:0},function(i,r){this.cbEnsureConstants();var n=Math.floor(i/(e*a)),s=i%e,o=(i%(e*a)-s)/e,c=this.cbCSize(t,r);1==this.mViewAs&&(o=a-1-o),-1==this.mViewAs&&(s=e-1-s);var l={x:(s-(e-1)/2)*c.cx,y:(o-(a-1)/2)*c.cy};if(t.flat){var d=t.boardFloor2dPos[n];l.x+=d.x,l.y+=d.y}else l.z=n*t.interFloorsDist;return l}},createGeometry:function(e,a,t){var i=this.cbCSize(e);console.log("geometry",a,i);var r=i.width/1e3,n=i.height/1e3,s=new THREE.PlaneGeometry(r,n),o=new THREE.Matrix4;o.makeRotationX(-Math.PI/2),s.applyMatrix(o);for(var c=s.faceVertexUvs[0],l=0;l<c.length;l++)for(var d=0;d<c[l].length;d++)i.ratio<1&&(c[l][d].x=c[l][d].x*i.ratio+(1-i.ratio)/2),i.ratio>1&&(c[l][d].y=c[l][d].y/i.ratio+(1-1/i.ratio)/2);t(s)},paintBackground:function(e,a,t,i,r,n,s,o,c){t.boardBG&&a.drawImage(t.boardBG,o-n/2,c-s/2,n,s)},paintChannel:function(e,a,t,i,r,n,s){var o=this.cbCSize(e);e.paintBackground.call(this,e,a,t,i,r,o.width,o.height,n,s)},paint:function(e,a,t,i,r){for(var n in a){var s=a[n].getContext("2d");s.scale(e.TEXTURE_CANVAS_CX/12e3,e.TEXTURE_CANVAS_CY/12e3),s.translate(6e3,6e3),e.paintChannel.call(this,e,s,t,i,n,0,0)}r()},display:function(e,a,t){function i(a,i){if(a.visible=!0,s[i]=a,0==--n){for(var o=new THREE.Object3D,i=0;i<r.cbView.boardLayout.length;i++){var a=s[i];o.add(a),a.translateY(i*e.interFloorsDist/1e3)}t(o)}}var r=this;e.getResource=a.getResource;for(var n=this.cbView.boardLayout.length,s={},o=0;o<this.cbView.boardLayout.length;o++)!function(a){e.createGeometry.call(r,e,a,function(t){e.createTextureImages.call(r,e,function(n){var s=["diffuse"].concat(e.extraChannels||[]),o={};s.forEach(function(a){var t=document.createElement("canvas");t.width=e.TEXTURE_CANVAS_CX,t.height=e.TEXTURE_CANVAS_CY,o[a]=t}),e.createMaterial.call(r,e,o,function(s){if(void 0!==e.boardFloorOpacity&&void 0!==e.boardFloorOpacity[a]){var c=e.boardFloorOpacity[a];1!=c&&(s.opacity=c,s.transparent=!0)}s.side=THREE.DoubleSide;var l=new THREE.Mesh(t,s);e.modifyMesh.call(r,e,l,a,function(t){e.paint.call(r,e,o,n,a,function(){i(t,a)})})})})})}(o)},draw:function(e,a,t){var i=this;e.getResource=a.getResource,t.save(),e.createTextureImages.call(this,e,function(a){for(var r=0;r<i.cbView.boardLayout.length;r++){var n=e.boardFloor2dPos[r];e.paintChannel.call(i,e,t,a,r,"diffuse",n.x,n.y)}t.restore()})}}),View.Game.cbMultiplanBoardClassic=$.extend({},View.Game.cbMultiplanBoard,{colorFill:{".":"rgba(160,150,150,0.9)","#":"rgba(0,0,0,1)"," ":"rgba(0,0,0,0)"},texturesImg:{boardBG:"/res/images/wood.jpg"},modifyMesh:function(e,a,t,i){function r(e,a){var t=new THREE.Shape;return t.moveTo(-e/2,-a/2),t.lineTo(e/2,-a/2),t.lineTo(e/2,a/2),t.lineTo(-e/2,a/2),t}if(void 0!==e.boardFloorFrames&&void 0!==e.boardFloorFrames[t]&&0==e.boardFloorFrames[t])return void i(a);var n=this.cbCSize(e),s=n.width/1e3,o=n.height/1e3,c=r(s+.5+.1,o+.5+.1),l=r(s+.1,o+.1);c.holes.push(l);var d={amount:.4,steps:1,bevelSize:.1,bevelThickness:.04,bevelSegments:1},h=new THREE.ExtrudeGeometry(c,d),u=new THREE.Matrix4;u.makeRotationX(-Math.PI/2),h.applyMatrix(u),blackMat=new THREE.MeshPhongMaterial({color:"#000000",shininess:500,specular:"#888888",emissive:"#000000"});var p=new THREE.Mesh(h,blackMat);p.position.y=-d.amount-.01,a.add(p);var m=new THREE.Mesh(new THREE.BoxGeometry(s,o,.1),blackMat);m.rotation.x=Math.PI/2,m.position.y=-.1,a.add(m),i(a)},paintCell:function(e,a,t,i,r,n,s,o,c,l){a.strokeStyle="rgba(0,0,0,1)",a.lineWidth=15,a.fillStyle="bump"==r?"#ffffff":e.colorFill[n],a.fillRect(s-c/2,o-l/2,c,l),a.rect(s-c/2,o-l/2,c,l)},paintCells:function(t,i,r,n,s,o,c){for(var l=this.cbCSize(t,n),d=t.coordsFn(t),h=0;h<a;h++)for(var u=0;u<e;u++){var p=1==this.mViewAs?u+h*e+n*e*a:e*a-(1+u+h*e),m=d.call(this,p,n),f=this.cbView.boardLayout[n][a-h-1][u],g=m.x,b=m.y,v=l.cx,w=l.cy;t.paintCell.call(this,t,i,r,n,s,f,g,b,v,w)}},paintLines:function(t,i,r,n,s,o,c){var l=this.cbCSize(t);i.strokeStyle="#000000",i.lineWidth=40,i.strokeRect(o-e*l.cx/2,c-a*l.cy/2,e*l.cx,a*l.cy)},paintChannel:function(e,a,t,i,r,n,s){var o=this.cbCSize(e,i);(void 0===e.boardFloorFrames||e.boardFloorFrames[i])&&e.paintBackground.call(this,e,a,t,r,i,o.width,o.height,n,s),e.paintCells.call(this,e,a,t,i,r,n,s),e.paintLines.call(this,e,a,t,i,r,n,s),this.mNotation&&e.paintNotation.call(this,e,a,i,r,n,s)},paintNotation:function(e,a,t,i,r,n){var s=this.cbCSize(e,t);switch(a.textAlign="center",a.textBaseline="middle",a.fillStyle="#000000",a.font=Math.ceil(s.cx/3)+"px Monospace",e.notationMode){case"out":e.paintOutNotation.apply(this,arguments);break;case"in":e.paintInNotation.apply(this,arguments)}},paintOutNotation:function(t,i,r,n,s,o){for(var c=this.cbCSize(t),l=0;l<a;l++){var d=a-l;this.mViewAs<0&&(d=l+1);var h=-(e/2+t.margins.x/2)*c.cx,u=(l-a/2+.5)*c.cy;i.fillText(d,h+s,u+o)}for(var p=0;p<e;p++){var m=p;this.mViewAs<0&&(m=e-p-1);var h=(p-e/2+.5)*c.cx,u=(a/2+t.margins.y/2)*c.cy;i.fillText(String.fromCharCode(97+m),h+s,u+o)}},paintInNotation:function(t,i,r,n,s,o){var c=this.cbCSize(t),l=t.coordsFn(t),d=t.colorFill;i.font=Math.ceil(c.cx/5)+"px Monospace";for(var h=0;h<a;h++)for(var u=0;u<e;u++){this.mViewAs<0?e-u-1:h+1;var p=1==this.mViewAs?u+h*e:e*a-(1+u+h*e);p+=r*e*a;var m;switch(t.flat?(m=l.call(this,p),m.x-=s,m.y-=o):m=l.call(this,p,r),i.fillStyle="rgba(0,0,0,0)","bump"==n&&(i.fillStyle=d["."]),this.cbView.boardLayout[r][a-h-1][u]){case".":i.fillStyle="bump"==n?d["."]:d["#"];break;case"#":i.fillStyle=d["."]}var f=m.x-c.cx/3.5,g=m.y-c.cy/3;t.notationDebug?i.fillText(p,f,g):i.fillText(this.cbVar.geometry.PosName(p),f+s,g+o)}}}),View.Game.cbMultiplanBoardClassic2D=$.extend({},View.Game.cbMultiplanBoardClassic,{colorFill:{".":"rgba(231,208,167,1)","#":"rgba(152,113,82,1)"," ":"rgba(0,0,0,0)"},flat:!0}),View.Game.cbMultiplanBoardClassic3D=$.extend({},View.Game.cbMultiplanBoardClassic,{flat:!1}),View.Game.cbMultiplanBoardClassic3DMargin=$.extend({},View.Game.cbMultiplanBoardClassic3D,{margins:{x:.67,y:.67},extraChannels:["bump"]}),View.Game.cbMultiplanBoardClassic2DMargin=$.extend({},View.Game.cbMultiplanBoardClassic2D,{margins:{x:.67,y:.67}}),View.Game.cbMultiplanBoardClassic2DNoMargin=$.extend({},View.Game.cbMultiplanBoardClassic2D,{margins:{x:0,y:0},notationMode:"in"})}(),function(){var e={cx:512,cy:512};View.Game.cbStauntonWoodenPieceStyle=function(e){return this.cbStauntonPieceStyle($.extend(!0,{default:{"2d":{file:this.mViewOptions.fullPath+"/res/images/woodenpieces2d2.png"}}},e))},View.Game.cbStauntonPieceStyle=function(e){return $.extend(!0,{1:{default:{"2d":{clipy:0}}},"-1":{default:{"2d":{clipy:100}}},default:{"3d":{display:this.cbDisplayPieceFn(this.cbStauntonPieceStyle3D)},"2d":{file:this.mViewOptions.fullPath+"/res/images/wikipedia.png",clipwidth:100,clipheight:100}},pawn:{"2d":{clipx:0}},knight:{"2d":{clipx:100}},bishop:{"2d":{clipx:200}},rook:{"2d":{clipx:300}},queen:{"2d":{clipx:400}},king:{"2d":{clipx:500}}},e)},View.Game.cbStauntonPieceStyle3D=$.extend(!0,{},View.Game.cbUniformPieceStyle3D,{default:{mesh:{normalScale:1,rotateZ:180},materials:{mat0:{channels:{diffuse:{size:e},normal:{size:e}}}}},1:{default:{materials:{mat0:{params:{specular:131586,shininess:150}}}}},"-1":{default:{materials:{mat0:{params:{specular:526344,shininess:100}}},paintTextureImageClip:function(e,a,t,i,r,n,s,o,c){var l=a.canvas.width,d=a.canvas.height;"diffuse"==i?(a.globalCompositeOperation="normal",a.drawImage(s,o.x,o.y,o.cx,o.cy,0,0,l,d),a.globalCompositeOperation="multiply",a.drawImage(s,o.x,o.y,o.cx,o.cy,0,0,l,d),a.drawImage(s,o.x,o.y,o.cx,o.cy,0,0,l,d),a.globalCompositeOperation="hue",a.fillStyle="rgba(0,0,0,0.7)",a.fillRect(0,0,512,512)):a.drawImage(s,o.x,o.y,o.cx,o.cy,0,0,l,d)}}},pawn:{mesh:{jsFile:"/res/staunton/pawn/pawn-classic.js"},materials:{mat0:{channels:{diffuse:{texturesImg:{diffImg:"/res/staunton/pawn/pawn-diffusemap.jpg"}},normal:{texturesImg:{normalImg:"/res/staunton/pawn/pawn-normalmap.jpg"}}}}}},knight:{mesh:{jsFile:"/res/staunton/knight/knight.js"},materials:{mat0:{channels:{diffuse:{texturesImg:{diffImg:"/res/staunton/knight/knight-diffusemap.jpg"}},normal:{texturesImg:{normalImg:"/res/staunton/knight/knight-normalmap.jpg"}}}}}},bishop:{mesh:{jsFile:"/res/staunton/bishop/bishop.js"},materials:{mat0:{channels:{diffuse:{texturesImg:{diffImg:"/res/staunton/bishop/bishop-diffusemap.jpg"}},normal:{texturesImg:{normalImg:"/res/staunton/bishop/bishop-normalmap.jpg"}}}}}},rook:{mesh:{jsFile:"/res/staunton/rook/rook.js"},materials:{mat0:{channels:{diffuse:{texturesImg:{diffImg:"/res/staunton/rook/rook-diffusemap.jpg"}},normal:{texturesImg:{normalImg:"/res/staunton/rook/rook-normalmap.jpg"}}}}}},queen:{mesh:{jsFile:"/res/staunton/queen/queen.js"},materials:{mat0:{channels:{diffuse:{texturesImg:{diffImg:"/res/staunton/queen/queen-diffusemap.jpg"}},normal:{texturesImg:{normalImg:"/res/staunton/queen/queen-normalmap.jpg"}}}}}},king:{mesh:{jsFile:"/res/staunton/king/king.js"},materials:{mat0:{channels:{diffuse:{texturesImg:{diffImg:"/res/staunton/king/king-diffusemap.jpg"}},normal:{texturesImg:{normalImg:"/res/staunton/king/king-normalmap.jpg"}}}}}}})}(),function(){View.Game.cbExtraLights=[{color:16777215,intensity:1,position:[9,14,-9],props:{shadowCameraNear:10,shadowCameraFar:25,castShadow:!0,shadowDarkness:.25,shadowMapWidth:2048,shadowMapHeight:2048}}],View.Game.cbDefineView=function(){var e=$.extend(!0,{},this.cbMultiplanBoardClassic3DMargin,{notationMode:"in",boardFloorFrames:[!0,!1,!1],boardFloorMargins:[{x:.67,y:.67},{x:0,y:0},{x:0,y:0}],boardFloorOpacity:[1,.3,.3],interFloorsDist:3e3}),a=$.extend(!0,{},this.cbMultiplanBoardClassic2DNoMargin,{notationMode:"in",boardFloorFrames:[!1,!1,!1],margins:{x:.3,y:.3},boardFloorMargins:[{x:.3,y:.3},{x:.3,y:.3},{x:.3,y:.3}],boardFloor2dPos:[{x:-4e3,y:3300},{x:0,y:0},{x:4e3,y:-3300}],boardFloorSize:4100});return{coords:{"2d":this.cbMultiplanBoard.coordsFn.call(this,a),"3d":this.cbMultiplanBoard.coordsFn.call(this,e)},boardLayout:[[".#.#.#","#.#.#.",".#.#.#","#.#.#.",".#.#.#","#.#.#.",".#.#.#","#.#.#."],["#.#.#.",".#.#.#","#.#.#.",".#.#.#","#.#.#.",".#.#.#","#.#.#.",".#.#.#"],[".#.#.#","#.#.#.",".#.#.#","#.#.#.",".#.#.#","#.#.#.",".#.#.#","#.#.#."]],board:{"2d":{draw:this.cbDrawBoardFn(a)},"3d":{display:this.cbDisplayBoardFn(e)}},clicker:{"2d":{width:650,height:650},"3d":{scale:[.7,.7,.7]}},pieces:this.cbStauntonPieceStyle({default:{"2d":{width:600,height:600},"3d":{scale:[.6,.6,.6]}}}),captureAnim3d:"scaledown"}},View.Board.cbMoveMidZ=function(e,a,t,i){return"N"==a.a||t!=i?Math.max(t,i)+1500:(t+i)/2}}();