UNPKG

jocly

Version:

Board games 3D/2D UI and AI web library

2 lines 32.5 kB
exports.view=View={Game:{},Board:{},Move:{}},function(){var e,t,a;View.Game.cbTargetMesh="/res/ring-target.js",View.Game.cbTargetSelectColor=16777215,View.Game.cbTargetCancelColor=16746496,View.Game.cbPromoSize=2e3,View.Game.xdInit=function(a){this.g.fullPath=this.mViewOptions.fullPath,this.cbPieceByType={},e=this.cbVar,t=this.cbDefineView(),this.cbView=t,this.cbClearPieces(),this.cbCreateLights(a),this.cbCreateScreens(a),this.cbCreateBoard(a),this.cbCreatePromo(a),this.cbCreatePieces(a),this.cbCreateCells(a)},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 a},View.Game.cbCreatePieces=function(e){for(var t=this.cbMakeDummyMesh(e),a=0;a<this.cbPiecesCount;a++)e.createGadget("piece#"+a,{base:{},"2d":{type:"sprite"},"3d":{type:"custommesh3d",create:function(e,a,i){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,a,i){return t}}})},View.Game.cbCreateCells=function(e){for(var t=this,a=0;a<this.g.boardSize;a++)!function(a){e.createGadget("cell#"+a,{"2d":{z:101,type:"element",initialClasses:t.cbCellClass(e,a),width:1300,height:1300}}),e.createGadget("clicker#"+a,$.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))}(a)},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(i){a=this,e=this.cbVar,t=this.cbDefineView(),this.cbView=t;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 t=a.cbMakeDisplaySpec(e,0),r=$.extend(!0,{},t,{base:{visible:!0}},a.cbView.clicker,a.cbView.cell);i.updateGadget("cell#"+e,r),$.extend(!0,t,a.cbView.clicker),i.updateGadget("clicker#"+e,t)}(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 t=this;return function(i,r,n){var s=e.style+"_"+e.margins.x+"_"+e.margins.y+"_"+t.mNotation+"_"+t.mViewAs,c=this;s!=this._cbKey&&(this._cbKey=s,e.display.call(a,e,c,function(e){c.replaceMesh(e,r,n)}))}},View.Game.cbDrawBoardFn=function(e){return function(t){e.draw.call(a,e,this,t)}},View.Game.cbMakeDisplaySpec=function(e,t){var a={};for(var i in this.cbView.coords){var r=this.cbView.coords[i],n=r.call(this,e);a[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*t<0?-1:1:0),rotate:(n.rz||0)+("3d"==i&&this.mViewAs*t<0?180:0)}}return a},View.Game.cbMakeDisplaySpecForPiece=function(a,i,r){function n(e,t,a){return t?$.extend(!0,e,t.default,t[a]):{}}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 c=e.pieceTypes[r.t].aspect||e.pieceTypes[r.t].name;return c?(t.pieces&&(s=n(s,t.pieces,c),t.pieces[r.s]&&(s=n(s,t.pieces[r.s],c))),s):void console.warn("Piece type",r.t,"has no aspect defined")},View.Board.xdDisplay=function(e,t){for(var a=0;a<this.pieces.length;a++){var i=this.pieces[a];if(i.p<0)e.updateGadget("piece#"+a,{base:{visible:!1}});else{var r=t.cbMakeDisplaySpecForPiece(t,i.p,i);r=$.extend(!0,{base:{visible:!0},"2d":{opacity:1},"3d":{positionEasingUpdate:null}},r),e.updateGadget("piece#"+a,r)}}for(;a<t.cbPiecesCount;a++)e.updateGadget("piece#"+a,{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,a){e.createGadget("extralights#"+a,{"3d":{type:"custommesh3d",create:function(e){var a=new THREE.SpotLight(t.color,t.intensity);a.shadow.camera.far=t.props.shadowCameraFar,a.shadow.camera.near=t.props.shadowCameraNear,a.shadow.mapSize.width=t.props.shadowMapWidth,a.shadow.mapSize.height=t.props.shadowMapHeight,a.position.set.apply(a.position,t.position);var i=new THREE.Mesh;i.add(a);var r=new THREE.Object3D;i.add(r),a.target=r,e(i)}}})}(this.cbExtraLights[t],t)},View.Game.cbCreateScreen=function(e){var t=new THREE.PlaneGeometry(4,3,1,1),a=new THREE.MeshPhongMaterial({color:16777215,map:e,shading:THREE.FlatShading,emissive:{r:1,g:1,b:1}}),i=new THREE.Mesh(t,a);return this.objectReady(i),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,a){function i(){t.updateGadget("promo-board",{base:{visible:!1}}),t.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){t.updateGadget("cell#"+e.f,{"2d":{classes:"select"==i?"cb-cell-select":"cb-cell-cancel",opacity:a.mShowMoves||"cancel"==i?1:0}}),t.updateGadget("clicker#"+e.f,{"3d":{materials:{ring:{color:"select"==i?a.cbTargetSelectColor:a.cbTargetCancelColor,opacity:a.mShowMoves||"cancel"==i?1:0,transparent:!a.mShowMoves&&"cancel"!=i}},castShadow:a.mShowMoves||"cancel"==i}})},unhighlight:function(){t.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){t.updateGadget("cell#"+n,{"2d":{classes:"select"==e?"cb-cell-select":"cb-cell-cancel",opacity:a.mShowMoves||"cancel"==e?1:0}}),t.updateGadget("clicker#"+n,{"3d":{materials:{ring:{color:"select"==e?a.cbTargetSelectColor:a.cbTargetCancelColor,opacity:a.mShowMoves||"cancel"==e?1:0,transparent:!a.mShowMoves&&"cancel"!=e}},castShadow:a.mShowMoves||"cancel"==e}})},unhighlight:function(e){t.updateGadget("cell#"+n,{"2d":{classes:""}})},validate:{t:r.t},execute:function(i){var n=this;this.cbAnimate(t,a,r,function(){var c=s[r.t].moves;c.length>1&&(t.updateGadget("promo-board",{base:{visible:!0,width:a.cbPromoSize*(c.length+1)}}),t.updateGadget("promo-cancel",{base:{visible:!0,x:c.length*a.cbPromoSize/2}}),c.forEach(function(i,r){var n=e.pieceTypes[i.pr].aspect||e.pieceTypes[i.pr].name,s=$.extend(!0,{},a.cbView.pieces.default,a.cbView.pieces[n]);a.cbView.pieces[this.mWho]&&(s=$.extend(!0,s,a.cbView.pieces[this.mWho].default,a.cbView.pieces[this.mWho][n])),t.updateGadget("promo#"+i.pr,{base:$.extend(s["2d"],{x:(r-c.length/2)*a.cbPromoSize})})},n)),i()})},unexecute:function(){if(null!=r.c){var e=this.pieces[r.c],n=a.cbMakeDisplaySpecForPiece(a,e.p,e);n=$.extend(!0,{base:{visible:!0},"2d":{opacity:1},"3d":{positionEasingUpdate:null}},n),t.updateGadget("piece#"+r.c,n)}var s=this.pieces[this.board[r.f]],c=a.cbMakeDisplaySpecForPiece(a,s.p,s);t.updateGadget("piece#"+s.i,c),i()}}),void 0!==r.cg&&(s[n].validate.cg=r.cg,s[n].execute=function(e){this.cbAnimate(t,a,r,function(){e()})}),s[n].moves.push(r)},this);else if(null==n.pr){var c=[];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},c.push(e.pr)),s[e.pr].moves.push(e))},this),c.length>1&&c.forEach(function(e){s[e].view=["promo#"+e]})}return s}}},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,a){t.mOldBoard.cbAnimate(e,t,a,function(){t.MoveShown()})},View.Board.cbAnimate=function(e,t,a,i){function r(){0==--s&&(c&&t.PlaySound("tac"+(1+Math.floor(3*Math.random()))),i())}var n=this,s=1,c=!1,o=this.pieces[this.board[a.f]],l=t.cbMakeDisplaySpec(a.f,o.s),h=t.cbMakeDisplaySpecForPiece(t,a.t,o);for(var d in l){var p=l[d];void 0!==p.z&&function(e){var i=p.z,r=h[e].z,s=n.cbMoveMidZ(t,a,i,r,e),o=i,l=o-s,d=o-r;s!=(i+r)/2&&(c=!0);var u=4*l-2*d,f=-d*d,m=Math.abs(u*u- -4*f),g=(-u-Math.sqrt(m))/-2,b=(-u+Math.sqrt(m))/-2,y=g,w=-y-d;(0==y||-w/(2*y)<0||-w/(2*y)>1)&&(y=b,w=-y-d),h[e].positionEasingUpdate=function(e){var t=(y*e*e+w*e+o)*this.SCALE3D;this.object3d.position.y=t}}(d)}if(c||t.PlaySound("move"+(1+Math.floor(4*Math.random()))),e.updateGadget("piece#"+o.i,h,600,function(){r()}),null!=a.c){s++;var u={positionEasingUpdate:null};switch(t.cbView.captureAnim3d||"movedown"){case"movedown":u.z=-2e3;break;case"scaledown":u.scale=[0,0,0]}var f=this.pieces[a.c];e.updateGadget("piece#"+f.i,{"2d":{opacity:0},"3d":u},600,r)}if(void 0!==a.cg){var p=t.cbVar.castle[a.f+"/"+a.cg],m=p.r[p.r.length-1],o=this.pieces[this.board[a.cg]],h=t.cbMakeDisplaySpecForPiece(t,m,o);s++,e.updateGadget("piece#"+o.i,h,600,function(){r()})}},View.Board.cbMoveMidZ=function(e,t,a,i){return(a+i)/2}}(),function(){View.Game.cbBaseBoard={TEXTURE_CANVAS_CX:1024,TEXTURE_CANVAS_CY:1024,display:function(e,t,a){var i=this;e.getResource=t.getResource,e.createGeometry.call(this,e,function(t){e.createTextureImages.call(i,e,function(r){var n=["diffuse"].concat(e.extraChannels||[]),s={};n.forEach(function(t){var a=document.createElement("canvas");a.width=e.TEXTURE_CANVAS_CX,a.height=e.TEXTURE_CANVAS_CY,s[t]=a}),e.createMaterial.call(i,e,s,function(n){var c=new THREE.Mesh(t,n);e.modifyMesh.call(i,e,c,function(t){e.paint.call(i,e,s,r,function(){a(t)})})})})})},createTextureImages:function(e,t){var a=this,i={},r=0,n=e.texturesImg||{};for(var s in n)r++;if(0==r)t(i);else for(var s in n)!function(s){e.getResource("image|"+a.g.fullPath+n[s],function(e){i[s]=e,0==--r&&t(i)})}(s)},createMaterial:function(e,t,a){var i=new THREE.Texture(t.diffuse);i.needsUpdate=!0;var r={specular:"#050505",shininess:30,map:i};if(t.bump){var n=new THREE.Texture(t.bump);n.needsUpdate=!0,r.bumpMap=n,r.bumpScale=.05}a(new THREE.MeshPhongMaterial(r))},modifyMesh:function(e,t,a){a(t)},prePaint:function(e,t,a,i,r){r()},paint:function(e,t,a,i,r){r()},postPaint:function(e,t,a,i,r){r()},paintChannel:function(e,t,a,i){},draw:function(e,t,a){var i=this;e.getResource=t.getResource,e.createTextureImages.call(this,e,function(t){e.paintChannel.call(i,e,a,t,"diffuse")})}}}(),function(){function e(e){for(var t=JSON.stringify(e),a=0,i=0;i<t.length;i++)a=(a<<5)-a+t.charCodeAt(i),a&=a;return a}var t,a={};View.Game.cbDisplayPieceFn=function(a){var i=this,r=e(a);return function(e,n,s){t=this.getResource;var c=/^piece#([0-9]+)$/.exec(this.gadget.id);if(!c)return null;var o=parseInt(c[1]),l=i.cbCurrentGame();if(o>=l.mBoard.pieces.length)return null;var h=l.mBoard.pieces[o],d=l.cbVar.pieceTypes[h.t].aspect||l.cbVar.pieceTypes[h.t].name,p=d+"_"+r+"_"+h.s,u=this;p!=this._cbKey&&(this._cbKey=p,u.options=n,l.cbMakePiece(a,d,h.s,function(e){u.replaceMesh(e,u.options,s)}))}},View.Game.cbMakePiece=function(t,i,r,n){function s(e,t,a){return t?$.extend(!0,e,t.default,t[a]):{}}if(!t)return void console.error("piece-view: style is not defined");var c=s({},t,i);t[r]&&(c=s(c,t[r],i));var o=e(c),l=a[o];Array.isArray(l)?l.push(n):l?n(new THREE.Mesh(l.geometry,l.material)):(a[o]=[n],c.loadResources.call(this,c,function(e){c.displayPiece.call(this,c,e,function(){var t=a[o];a[o]={geometry:e.geometry,material:e.material},t.forEach(function(t){t(new THREE.Mesh(e.geometry,e.material))})})}))},View.Game.cbClearPieces=function(){a={}},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,a){"function"==typeof e.mesh.jsFile?e.mesh.jsFile(e,a):t("smoothedfilegeo|"+e.mesh.smooth+"|"+this.g.fullPath+e.mesh.jsFile,a)},loadImages:function(e,a){function i(){0==--n&&a(s)}var r=this,n=1,s={};for(var c in e.materials){var o=e.materials[c].channels;for(var l in o)if(o[l].texturesImg)for(var h in o[l].texturesImg)!function(e,a){n++,t("image|"+r.g.fullPath+a,function(t){s[e]=t,i()})}(h,o[l].texturesImg[h])}i()},loadResources:function(e,t){function a(){0==--s&&t({geometry:r,images:i,textures:{},loadedMaterials:n})}var i,r,n,s=2;e.loadMesh.call(this,e,function(t,i){if(!t._cbZRotated){var s=new THREE.Matrix4;s.makeRotationY(e.mesh.rotateZ*Math.PI/180),t.applyMatrix(s),t._cbZRotated=!0}r=t,n=i,a()}),e.loadImages.call(this,e,function(e){i=e,a()})},displayPiece:function(e,t,a){e.makeMaterials.call(this,e,t),a()},paintTextureImageClip:function(e,t,a,i,r,n,s,c,o){var l=t.canvas.width,h=t.canvas.height;if(r.patternFill&&r.patternFill[n]){var d=r.patternFill[n];t.save();var p=document.createElement("canvas");p.width=l,p.height=h,ctxTmp=p.getContext("2d"),ctxTmp.fillStyle=d,ctxTmp.fillRect(0,0,l,h),ctxTmp.globalCompositeOperation="destination-in",ctxTmp.drawImage(s,c.x,c.y,c.cx,c.cy,0,0,l,h),t.drawImage(p,0,0,l,h,0,0,l,h),t.restore()}else t.drawImage(s,c.x,c.y,c.cx,c.cy,0,0,l,h)},paintTextureImage:function(e,t,a,i,r,n,s,c){var o;o=r.clipping&&r.clipping[n]?r.clipping[n]:{x:0,y:0,cx:s.width,cy:s.height},e.paintTextureImageClip.call(this,e,t,a,i,r,n,s,o,c)},paintTexture:function(e,t,a,i,r){var n=e.materials[a].channels[i];for(var s in n.texturesImg){var c=r.images[s];e.paintTextureImage.call(this,e,t,a,i,n,s,c,r)}},makeMaterialTextures:function(e,t,a){for(var i in e.materials[t].channels){var r=e.materials[t].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,t,i,a);var c=new THREE.Texture(n);c.needsUpdate=!0,a.textures[t][i]=c}},makeMaterials:function(e,t){t.textures={};for(var a in e.materials)t.textures[a]={},e.makeMaterialTextures.call(this,e,a,t),e.makeMaterial.call(this,e,a,t)}}},View.Game.cbTokenPieceStyle3D=$.extend(!0,{},View.Game.cbBasePieceStyle,{default:{makeMaterials:function(e,t){t.textures={};for(var a in e.materials)t.textures[a]={},e.makeMaterialTextures.call(this,e,a,t);var i=[];for(var r in t.loadedMaterials){var n=t.loadedMaterials[r].clone(),s=n.name;if(e.materials[s]){$.extend(!0,n,e.materials[s].params);for(var c in e.materials[s].channels)switch(c){case"diffuse":n.map=t.textures[s][c];break;case"bump":n.bumpMap=t.textures[s][c]}}i.push(n)}var o=new THREE.MultiMaterial(i);t.material=o}}}),View.Game.cbUniformPieceStyle3D=$.extend(!0,{},View.Game.cbBasePieceStyle,{default:{makeMaterial:function(e,t,a){var i=e.materials[t].params;i.map=a.textures[t].diffuse,i.normalMap=a.textures[t].normal;var r=e.materials[t].channels.normal.normalScale||1;i.normalScale=new THREE.Vector2(r,r);var n=new THREE.MeshPhongMaterial(i);a.material=n,a.geometry.mergeVertices(),a.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 a=new THREE.MeshPhongMaterial(e.phongProperties);t.material=a}}})}(),function(){var e=0,t=0,a=0,i={};View.Game.cbCubicEnsureConstants=function(){t||(t=this.cbVar.geometry.height,e=this.cbVar.geometry.width,a=this.cbVar.geometry.depth)},View.Game.cbCSize=function(r){this.cbCubicEnsureConstants();var n=i[r.flat];if(!n){if(r.flat){var s=2*(e+t),c=e+t+a,o=Math.min(12e3/s,12e3/c),l=-(t-e)/2;console.warn("centerYAdj",l);var h=r.fenceRatio*o;n={cellSize:o,width:o*s,height:o*c,planes2d:[{x:-(e/2-.5)*o,y:(l-(a+t)/2+.5)*o},{x:-(e+t/2-.5)*o,y:(l+.5)*o},{x:-(e/2-.5)*o,y:(l+.5)*o},{x:(t+e/2+.5)*o,y:(l+.5)*o},{x:(t/2+.5)*o,y:(l+.5)*o},{x:(t/2+.5)*o,y:(l+a/2+e/2+.5)*o}],fenceWidth:h,fences2d:{"01":[{x0:-e*o,y0:(l-a/2)*o,x1:-e*o,y1:(l-a/2-t)*o},{x0:-e*o,y0:(l-a/2)*o,x1:(-e-t)*o,y1:(l-a/2)*o}],"02":[{x0:-e*o,y0:(l-a/2)*o,x1:0,y1:(l-a/2)*o}],"03":[{x0:-e*o,y0:(l-a/2-t)*o,x1:0,y1:(l-a/2-t)*o},{x0:t*o,y0:(l-a/2)*o,x1:(t+e)*o,y1:(l-a/2)*o}],"04":[{x0:0,y0:(l-a/2)*o,x1:0,y1:(l-a/2-t)*o},{x0:0,y0:(l-a/2)*o,x1:t*o,y1:(l-a/2)*o}],12:[{x0:-e*o,y0:(l-a/2)*o,x1:-e*o,y1:(l+a/2)*o}],13:[{x0:(-e-t)*o,y0:(l-a/2)*o,x1:(-e-t)*o,y1:(l+a/2)*o},{x0:(e+t)*o,y0:(l-a/2)*o,x1:(e+t)*o,y1:(l+a/2)*o}],15:[{x0:-e*o,y0:(l+a/2)*o,x1:(-e-t)*o,y1:(l+a/2)*o},{x0:0,y0:(l+a/2+e)*o,x1:t*o,y1:(l+a/2+e)*o}],24:[{x0:0,y0:(l-a/2)*o,x1:0,y1:(l+a/2)*o}],25:[{x0:-e*o,y0:(l+a/2)*o,x1:0,y1:(l+a/2)*o},{x0:0,y0:(l+a/2)*o,x1:0,y1:(l+a/2+e)*o}],34:[{x0:t*o,y0:(l-a/2)*o,x1:t*o,y1:(l+a/2)*o}],35:[{x0:t*o,y0:(l+a/2)*o,x1:(t+e)*o,y1:(l+a/2)*o},{x0:t*o,y0:(l+a/2)*o,x1:t*o,y1:(l+a/2+e)*o}],45:[{x0:0,y0:(l+a/2)*o,x1:t*o,y1:(l+a/2)*o}]}}}else{var o,d=Math.max(e,t,a),o=12e3/(d+3),h=r.fenceRatio*o;n={cellSize:o,widths:[e*o,t*o,e*o,e*o,t*o,e*o],heights:[t*o,a*o,a*o,a*o,a*o,t*o],orients:[{rotX:-90,rotZ:180,tranZ:-a/2*o,rx:0,ry:0,rz:0,dx:[1,0],dy:[0,1],dz:[0,0]},{rotZ:90,tranX:-e/2*o,rx:0,ry:-90,rz:0,dx:[0,0],dy:[1,0],dz:[0,1]},{rotZ:180,tranY:t/2*o,rx:-90,ry:0,rz:0,dx:[1,0],dy:[0,0],dz:[0,1]},{tranY:-t/2*o,rx:90,ry:0,rz:180,dx:[-1,0],dy:[0,0],dz:[0,1]},{rotZ:-90,tranX:e/2*o,rx:0,ry:90,rz:0,dx:[0,0],dy:[-1,0],dz:[0,1]},{rotX:90,rotZ:180,tranZ:a/2*o,rx:180,ry:0,rz:0,dx:[1,0],dy:[0,-1],dz:[0,0]}],fenceWidth:h,fences:{"01":{height:t*o+h,rx:90,ry:0,rz:0,tx:-e/2*o,ty:0,tz:-a/2*o},"02":{height:e*o+h,rx:0,ry:90,rz:0,tx:0,ty:t/2*o,tz:-a/2*o},"03":{height:e*o+h,rx:0,ry:90,rz:0,tx:0,ty:-t/2*o,tz:-a/2*o},"04":{height:t*o+h,rx:90,ry:0,rz:0,tx:e/2*o,ty:0,tz:-a/2*o},12:{height:a*o+h,rx:0,ry:0,rz:0,tx:-e/2*o,ty:t/2*o,tz:0},13:{height:a*o+h,rx:0,ry:0,rz:0,tx:-e/2*o,ty:-t/2*o,tz:0},15:{height:t*o+h,rx:90,ry:0,rz:0,tx:-e/2*o,ty:0,tz:a/2*o},25:{height:e*o+h,rx:0,ry:90,rz:0,tx:0,ty:t/2*o,tz:a/2*o},24:{height:a*o+h,rx:0,ry:0,rz:0,tx:e/2*o,ty:t/2*o,tz:0},34:{height:a*o+h,rx:0,ry:0,rz:0,tx:e/2*o,ty:-t/2*o,tz:0},35:{height:e*o+h,rx:0,ry:90,rz:0,tx:0,ty:-t/2*o,tz:a/2*o},45:{height:t*o+h,rx:90,ry:0,rz:0,tx:e/2*o,ty:0,tz:a/2*o}}}}i[r.flat]=n}return n},View.Game.cbCubicBoard=$.extend({},View.Game.cbBaseBoard,{notationMode:"in",fenceRatio:.08,coordsFn:function(e){return e=e||{},function(t){var a=this.cbCSize(e),i=this.cbVar.geometry,r=i.P(t),n=i.planes[r];if(e.flat){var s=a.planes2d[r],c=t-n.start,o=c%n.cols,l=Math.floor(c/n.cols);l=n.rows-l-1;var h;if(5==r){o=n.cols-o-1;var d=o;o=l,l=d,h={x:s.x+(o-n.rows/2)*a.cellSize,y:s.y+(l-n.cols/2)*a.cellSize}}else h={x:s.x+(o-n.cols/2)*a.cellSize,y:s.y+(l-n.rows/2)*a.cellSize};return h.xb=h.x,h.yb=h.y,h}var p=a.orients[r],u=t-n.start,o=u%n.cols,l=Math.floor(u/n.cols);1==this.mViewAs&&(l=n.rows-1-l,xb=(o-(n.cols-1)/2)*a.cellSize,yb=(l-(n.rows-1)/2)*a.cellSize);var h={xb:xb,yb:yb,x:-(p.tranX||0)-xb*p.dx[0]-yb*p.dx[1],y:-(p.tranY||0)-xb*p.dy[0]-yb*p.dy[1],z:-(p.tranZ||0)-xb*p.dz[0]-yb*p.dz[1],rx:p.rx,ry:p.ry,rz:p.rz};return h}},createGeometry:function(e,t,a){var i=this.cbCSize(e),r=new THREE.PlaneGeometry(i.widths[t]/1e3,i.heights[t]/1e3),n=i.orients[t],s=n.tranX?-n.tranX/1e3:0,c=n.tranZ?-n.tranZ/1e3:0,o=n.tranY?-n.tranY/1e3:0,l=new THREE.Matrix4;n.rotX&&(l.makeRotationX(n.rotX*Math.PI/180),r.applyMatrix(l)),n.rotY&&(l.makeRotationZ(n.rotY*Math.PI/180),r.applyMatrix(l)),n.rotZ&&(l.makeRotationY(n.rotZ*Math.PI/180),r.applyMatrix(l)),l.makeTranslation(s,c,o),r.applyMatrix(l);for(var h=(i.widths[t],i.heights[t],r.faceVertexUvs[0]),d=0;d<h.length;d++)for(var p=0;p<h[d].length;p++)i.ratio<1&&(h[d][p].x=h[d][p].x*i.ratio+(1-i.ratio)/2),i.ratio>1&&(h[d][p].y=h[d][p].y/i.ratio+(1-1/i.ratio)/2);a(r)},createFenceGeometry:function(e,t,a){var i=this.cbCSize(e),r=i.fences[t]||{},n=new THREE.CubeGeometry(i.fenceWidth/1e3,r.height/1e3,i.fenceWidth/1e3),s=new THREE.Matrix4;s.makeRotationX(r.rx*Math.PI/180),n.applyMatrix(s),s.makeRotationZ(r.ry*Math.PI/180),n.applyMatrix(s),s.makeRotationY(r.rz*Math.PI/180),n.applyMatrix(s),s.makeTranslation(-r.tx/1e3,-r.tz/1e3,-r.ty/1e3),n.applyMatrix(s),a(n)},paintBackground:function(e,t,a,i,r,n,s){a.boardBG&&t.drawImage(a.boardBG,-n/2,-s/2,n,s)},paintChannel:function(e,t,a,i,r){var n=this.cbCSize(e);e.paintBackground.call(this,e,t,a,i,r,n.widths[i],n.heights[i])},paint:function(e,t,a,i,r){var n=this.cbCSize(e),s=this.cbVar.geometry;for(var c in t){var o=t[c].getContext("2d");if(o.save(),e.flat)o.scale(e.TEXTURE_CANVAS_CX/n.width,e.TEXTURE_CANVAS_CY/n.height),o.translate(n.width/2,n.height/2);else{var l=Math.max(s.planes[i].cols,s.planes[i].rows)*n.cellSize;o.scale(e.TEXTURE_CANVAS_CX/l,e.TEXTURE_CANVAS_CY/l),o.translate(l/2,l/2)}e.paintChannel.call(this,e,o,a,i,c),o.restore()}r()},createInnerMesh:function(i,r){var n=this.cbCSize(i),s=new THREE.CubeGeometry(.99*e*n.cellSize/1e3,.99*a*n.cellSize/1e3,.99*t*n.cellSize/1e3),c=new THREE.Mesh(s,new THREE.MeshPhongMaterial({color:0,transparent:!0,opacity:.9}));c.castShadow=!0,r(c)},display:function(e,t,a){function i(t,i){if(t.visible=!0,o[i]=t,0==--c){for(var n=new THREE.Object3D,i=0;i<s;i++){var t=o[i];n.add(t)}e.createInnerMesh.call(r,e,function(e){n.add(e),a(n)})}}var r=this;e.getResource=t.getResource;for(var n=this.cbVar.geometry,s=6+n.fences.length,c=s,o={},l=0;l<6;l++)!function(t,a,n){e.createGeometry.call(r,e,t,function(a){e.createTextureImages.call(r,e,function(n){var s=["diffuse"].concat(e.extraChannels||[]),c={};s.forEach(function(t){var a=document.createElement("canvas");a.width=e.TEXTURE_CANVAS_CX,a.height=e.TEXTURE_CANVAS_CY,c[t]=a}),e.createMaterial.call(r,e,c,function(s){var o=new THREE.Mesh(a,s);o.receiveShadow=!0,e.paint.call(r,e,c,n,t,function(){i(o,t)})})})})}(l,n.planes[l].cols,n.planes[l].rows);for(var l=0;l<n.fences.length;l++)!function(t,a){e.createFenceGeometry.call(r,e,a,function(n){e.createTextureImages.call(r,e,function(s){var c=["diffuse"],o={};c.forEach(function(t){var a=document.createElement("canvas");a.width=e.TEXTURE_CANVAS_CX,a.height=e.TEXTURE_CANVAS_CY,o[t]=a}),e.createMaterial.call(r,e,o,function(c){c.emissive={r:0,g:0,b:0},r.cbView.fences&&r.cbView.fences[a]&&c.color.set(r.cbView.fences[a]);var l=new THREE.Mesh(n,c);e.paintFence.call(r,e,o,s,a,function(){i(l,t)})})})})}(l+6,n.fences[l])},paintFence:function(e,t,a,i,r){var n=this.cbCSize(e),s=(n.fenceWidth,n.fences[i].height,t.diffuse.getContext("2d"));a.diffusefence&&s.drawImage(a.diffusefence,0,0,s.canvas.width,s.canvas.height),r()},draw:function(e,t,a){var i=this;e.getResource=t.getResource,function(t){e.createTextureImages.call(i,e,function(a){for(var r=0;r<6;r++)e.paintChannel.call(i,e,t,a,r,"diffuse");e.drawFences.call(i,e,t)})}(a)},drawFences:function(e,t){var a=this.cbCSize(e),i=this.cbVar.geometry;t.strokeStyle="#000000",t.lineWidth=a.fenceWidth;for(var r=0;r<i.fences.length;r++){var n=i.fences[r],s=a.fences2d[n];if(s)for(var c=0;c<s.length;c++){var o=s[c];t.beginPath(),t.moveTo(o.x0,o.y0),t.lineTo(o.x1,o.y1),t.stroke()}}}}),View.Game.cbCubicBoardClassic=$.extend({},View.Game.cbCubicBoard,{margins:{x:0,y:0},colorFill:{".":"rgba(160,150,150,1)","#":"rgba(0,0,0,1)"," ":"rgba(0,0,0,0)"},texturesImg:{boardBG:"/res/images/wood.jpg",diffusefence:"/res/images/wood.jpg"},extraChannels:["bump"],paintCell:function(e,t,a,i,r,n,s,c,o,l){t.strokeStyle="rgba(0,0,0,1)",t.lineWidth=15,t.fillStyle="bump"==r?"#ffffff":e.colorFill[n],t.fillRect(s-o/2,c-l/2,o,l),t.rect(s-o/2,c-l/2,o,l)},paintCells:function(e,t,a,i,r){for(var n=this.cbCSize(e),s=this.cbVar.geometry,c=s.planes[i].cols,o=s.planes[i].rows,l=e.coordsFn(e),h=0;h<o;h++)for(var d=0;d<c;d++){var p=s.POS(d,h,i),u=l.call(this,p),f=this.cbView.boardLayout[i][h][d],m=u.xb,g=u.yb,b=n.cellSize,y=n.cellSize;e.paintCell.call(this,e,t,a,i,r,f,m,g,b,y)}},paintChannel:function(e,t,a,i,r){this.cbCSize(e);e.paintCells.call(this,e,t,a,i,r),this.mNotation&&e.paintNotation.call(this,e,t,i,r)},paintNotation:function(e,t,a,i){var r=this.cbCSize(e);t.textAlign="center",t.textBaseline="middle",t.fillStyle="#000000",t.font=Math.ceil(r.cellSize/5)+"px Monospace",e.paintInNotation.apply(this,arguments)},paintInNotation:function(e,t,a,i){for(var r=this.cbCSize(e),n=e.coordsFn(e),s=e.colorFill,c=this.cbVar.geometry,o=c.planes[a],l=0;l<o.rows;l++)for(var h=0;h<o.cols;h++){var d=h+l*o.cols+o.start,p=n.call(this,d);switch(t.fillStyle="rgba(0,0,0,0)","bump"==i&&(t.fillStyle=s["."]),this.cbView.boardLayout[a][l][h]){case".":t.fillStyle="bump"==i?s["."]:s["#"];break;case"#":t.fillStyle=s["."]}var u=p.xb-.3*r.cellSize,f=p.yb+.3*r.cellSize;e.notationDebug?t.fillText(d,u,f):t.fillText(c.PosName(d),u,f)}},createMaterial:function(e,t,a){var i=new THREE.Texture(t.diffuse);i.needsUpdate=!0;var r={specular:"#010101",shininess:200,map:i};if(t.bump){var n=new THREE.Texture(t.bump);n.needsUpdate=!0,r.bumpMap=n,r.bumpScale=.1}a(new THREE.MeshPhongMaterial(r))}}),View.Game.cbCubicBoardClassic2D=$.extend({},View.Game.cbCubicBoardClassic,{colorFill:{".":"rgba(231,208,167,1)","#":"rgba(152,113,82,1)"," ":"rgba(0,0,0,0)"},flat:!0}),View.Board.cbAnimate=function(e,t,a,i){function r(){0==--s&&(c&&t.PlaySound("tac"+(1+Math.floor(3*Math.random()))),i())}function n(e,t){for(;t<e;)t+=2*Math.PI;return t-e>Math.PI&&(t-=2*Math.PI),t}var s=1,c=!1,o=this.pieces[this.board[a.f]],l=t.cbMakeDisplaySpec(a.f,o.s),h=t.cbMakeDisplaySpecForPiece(t,a.t,o);for(var d in l){var p=l[d];void 0!==p.z&&function(e){var t=h[e],a=Math.atan2(p.y,p.x),i=Math.atan2(t.y,t.x);i=n(a,i);var r=(Math.sqrt(p.y*p.y+p.x*p.x),Math.sqrt(t.y*t.y+t.x*t.x),Math.sqrt(p.y*p.y+p.x*p.x+p.z*p.z)),s=Math.sqrt(t.y*t.y+t.x*t.x+t.z*t.z),o=Math.acos(p.z/r),l=Math.acos(t.z/s);l=n(o,l);var d=r+4e3,u=r,f=u-d,m=u-s;c=!0;var g=4*f-2*m,b=-m*m,y=Math.abs(g*g- -4*b),w=(-g-Math.sqrt(y))/-2,x=(-g+Math.sqrt(y))/-2,v=w,M=-v-m;(0==v||-M/(2*v)<0||-M/(2*v)>1)&&(v=x,M=-v-m),t.positionEasingUpdate=function(e){var t=v*e*e+M*e+u,r=a+(i-a)*e,n=o+(l-o)*e,s=t*Math.cos(n),c=s*this.SCALE3D,h=Math.sqrt(t*t-s*s),d=h*Math.cos(r)*this.SCALE3D,p=h*Math.sin(r)*this.SCALE3D;this.object3d.position.x=d,this.object3d.position.z=p,this.object3d.position.y=c}}(d)}if(c||t.PlaySound("move"+(1+Math.floor(4*Math.random()))),e.updateGadget("piece#"+o.i,h,600,function(){r()}),null!=a.c){s++;var u={positionEasingUpdate:null};switch(t.cbView.captureAnim3d||"movedown"){case"movedown":u.z=-2e3;break;case"scaledown":u.scale=[0,0,0]}var f=this.pieces[a.c];e.updateGadget("piece#"+f.i,{"2d":{opacity:0},"3d":u},600,r)}if(void 0!==a.cg){var p=t.cbVar.castle[a.f+"/"+a.cg],m=p.r[p.r.length-1],o=this.pieces[this.board[a.cg]],h=t.cbMakeDisplaySpecForPiece(t,m,o);s++,e.updateGadget("piece#"+o.i,h,600,function(){r()})}};View.Game.cbExtraLights=[{color:16777215,intensity:1,position:[-14,14,-14],props:{shadowCameraNear:15,shadowCameraFar:40,castShadow:!0,shadowDarkness:.25,shadowMapWidth:2048,shadowMapHeight:2048}},{color:16777215,intensity:1,position:[14,14,14],props:{shadowCameraNear:15,shadowCameraFar:40,castShadow:!1,shadowDarkness:.25,shadowMapWidth:2048,shadowMapHeight:2048}},{color:16777215,intensity:1,position:[14,-14,14],props:{shadowCameraNear:15,shadowCameraFar:40,castShadow:!0,shadowDarkness:.25,shadowMapWidth:2048,shadowMapHeight:2048}},{color:16777215,intensity:1,position:[-14,-14,-14],props:{shadowCameraNear:15,shadowCameraFar:40,castShadow:!1,shadowDarkness:.25,shadowMapWidth:2048,shadowMapHeight:2048}}]}(),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,a,i,r,n,s,c,o){var l=t.canvas.width,h=t.canvas.height;"diffuse"==i?(t.globalCompositeOperation="normal",t.drawImage(s,c.x,c.y,c.cx,c.cy,0,0,l,h),t.globalCompositeOperation="multiply",t.drawImage(s,c.x,c.y,c.cx,c.cy,0,0,l,h),t.drawImage(s,c.x,c.y,c.cx,c.cy,0,0,l,h),t.globalCompositeOperation="hue",t.fillStyle="rgba(0,0,0,0.7)",t.fillRect(0,0,512,512)):t.drawImage(s,c.x,c.y,c.cx,c.cy,0,0,l,h)}}},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.cbDefineView=function(){var e=$.extend(!0,{},this.cbCubicBoardClassic,{notationDebug:!0}),t=$.extend(!0,{},this.cbCubicBoardClassic2D,{notationDebug:!0});return{coords:{"2d":this.cbCubicBoard.coordsFn.call(this,t), "3d":this.cbCubicBoard.coordsFn.call(this,e)},boardLayout:[["#.#.",".#.#","#.#.",".#.#"],["#.#.",".#.#","#.#.",".#.#"],["#.#.",".#.#","#.#.",".#.#"],["#.#.",".#.#","#.#.",".#.#"],["#.#.",".#.#","#.#.",".#.#"],[".#.#","#.#.",".#.#","#.#."]],board:{"2d":{draw:this.cbDrawBoardFn(t)},"3d":{display:this.cbDisplayBoardFn(e)}},clicker:{"2d":{width:800,height:800},"3d":{scale:[1.2,1.2,1.2]}},pieces:this.cbStauntonPieceStyle({default:{"2d":{width:700,height:700},"3d":{scale:[.7,.7,.7]}}}),captureAnim3d:"scaledown",fences:{35:"#000000",25:"#000000"}}}}();