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