jocly
Version:
Board games 3D/2D UI and AI web library
1 lines • 28.7 kB
JavaScript
exports.view=View={Game:{},Board:{},Move:{}},function(){var e,i,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,i=this.cbDefineView(),this.cbView=i,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 i=this.cbMakeDummyMesh(e),a=0;a<this.cbPiecesCount;a++)e.createGadget("piece#"+a,{base:{},"2d":{type:"sprite"},"3d":{type:"custommesh3d",create:function(e,a,t){return i}}})},View.Game.cbCreateBoard=function(e){var i=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,t){return i}}})},View.Game.cbCreateCells=function(e){for(var i=this,a=0;a<this.g.boardSize;a++)!function(a){e.createGadget("cell#"+a,{"2d":{z:101,type:"element",initialClasses:i.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:i.g.fullPath+i.cbTargetMesh,flatShading:!0,castShadow:!0,smooth:0,scale:[.9,.9,.9],materials:{square:{transparent:!0,opacity:0},ring:{color:i.cbTargetSelectColor,opacity:1}}}},i.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 i=0;i<this.g.pTypes.length;i++)e.createGadget("promo#"+i,{base:{y:0,z:109,type:"sprite",clipwidth:100,clipheight:100,width:1200,height:1200}})},View.Game.xdBuildScene=function(t){a=this,e=this.cbVar,i=this.cbDefineView(),this.cbView=i;for(var r=0;r<this.cbExtraLights.length;r++)t.updateGadget("extralights#"+r,{"3d":{visible:!0}});t.updateGadget("board",$.extend({base:{visible:!0}},this.cbView.board));for(var n=0;n<this.g.boardSize;n++)!function(e){var i=a.cbMakeDisplaySpec(e,0),r=$.extend(!0,{},i,{base:{visible:!0}},a.cbView.clicker,a.cbView.cell);t.updateGadget("cell#"+e,r),$.extend(!0,i,a.cbView.clicker),t.updateGadget("clicker#"+e,i)}(n);t.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]}}),t.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]}}),t.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]}}),t.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]}}),t.updateGadget("promo-board",{base:{visible:!1}}),t.updateGadget("promo-cancel",{base:{visible:!1}});for(var r=0;r<this.g.pTypes.length;r++)t.updateGadget("promo#"+r,{base:{visible:!1}})},View.Game.cbDisplayBoardFn=function(e){var i=this;return function(t,r,n){var c=e.style+"_"+e.margins.x+"_"+e.margins.y+"_"+i.mNotation+"_"+i.mViewAs,s=this;c!=this._cbKey&&(this._cbKey=c,e.display.call(a,e,s,function(e){s.replaceMesh(e,r,n)}))}},View.Game.cbDrawBoardFn=function(e){return function(i){e.draw.call(a,e,this,i)}},View.Game.cbMakeDisplaySpec=function(e,i){var a={};for(var t in this.cbView.coords){var r=this.cbView.coords[t],n=r.call(this,e);a[t]={x:n.x||0,y:n.y||0,z:n.z||0,rotateX:n.rx||0,rotateY:(n.ry||0)*("3d"==t?this.mViewAs*i<0?-1:1:0),rotate:(n.rz||0)+("3d"==t&&this.mViewAs*i<0?180:0)}}return a},View.Game.cbMakeDisplaySpecForPiece=function(a,t,r){function n(e,i,a){return i?$.extend(!0,e,i.default,i[a]):{}}var c=this.cbMakeDisplaySpec(t,r.s);if(void 0===e.pieceTypes[r.t])return void console.warn("Piece type",r.t,"not defined in model");var s=e.pieceTypes[r.t].aspect||e.pieceTypes[r.t].name;return s?(i.pieces&&(c=n(c,i.pieces,s),i.pieces[r.s]&&(c=n(c,i.pieces[r.s],s))),c):void console.warn("Piece type",r.t,"has no aspect defined")},View.Board.xdDisplay=function(e,i){for(var a=0;a<this.pieces.length;a++){var t=this.pieces[a];if(t.p<0)e.updateGadget("piece#"+a,{base:{visible:!1}});else{var r=i.cbMakeDisplaySpecForPiece(i,t.p,t);r=$.extend(!0,{base:{visible:!0},"2d":{opacity:1},"3d":{positionEasingUpdate:null}},r),e.updateGadget("piece#"+a,r)}}for(;a<i.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 i=0;i<this.cbExtraLights.length;i++)!function(i,a){e.createGadget("extralights#"+a,{"3d":{type:"custommesh3d",create:function(e){var a=new THREE.SpotLight(i.color,i.intensity);a.shadow.camera.far=i.props.shadowCameraFar,a.shadow.camera.near=i.props.shadowCameraNear,a.shadow.mapSize.width=i.props.shadowMapWidth,a.shadow.mapSize.height=i.props.shadowMapHeight,a.position.set.apply(a.position,i.position);var t=new THREE.Mesh;t.add(a);var r=new THREE.Object3D;t.add(r),a.target=r,e(t)}}})}(this.cbExtraLights[i],i)},View.Game.cbCreateScreen=function(e){var i=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}}),t=new THREE.Mesh(i,a);return this.objectReady(t),null},View.Game.cbCreateScreens=function(e){var i=this;e.createGadget("videoa",{"3d":{type:"video3d",makeMesh:function(e){return i.cbCreateScreen.call(this,e)}}}),e.createGadget("videoabis",{"3d":{type:"video3d",makeMesh:function(e){return i.cbCreateScreen.call(this,e)}}}),e.createGadget("videob",{"3d":{type:"video3d",makeMesh:function(e){return i.cbCreateScreen.call(this,e)}}}),e.createGadget("videobbis",{"3d":{type:"video3d",makeMesh:function(e){return i.cbCreateScreen.call(this,e)}}})},View.Board.xdInput=function(i,a){function t(){i.updateGadget("promo-board",{base:{visible:!1}}),i.updateGadget("promo-cancel",{base:{visible:!1}})}return{initial:{f:null,t:null,pr:null},getActions:function(r,n){var c={};if(null==n.f)r.forEach(function(e){void 0===c[e.f]&&(c[e.f]={f:e.f,moves:[],click:["piece#"+this.board[e.f],"clicker#"+e.f],view:["clicker#"+e.f],highlight:function(t){i.updateGadget("cell#"+e.f,{"2d":{classes:"select"==t?"cb-cell-select":"cb-cell-cancel",opacity:a.mShowMoves||"cancel"==t?1:0}}),i.updateGadget("clicker#"+e.f,{"3d":{materials:{ring:{color:"select"==t?a.cbTargetSelectColor:a.cbTargetCancelColor,opacity:a.mShowMoves||"cancel"==t?1:0,transparent:!a.mShowMoves&&"cancel"!=t}},castShadow:a.mShowMoves||"cancel"==t}})},unhighlight:function(){i.updateGadget("cell#"+e.f,{"2d":{classes:""}})},validate:{f:e.f}}),c[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===c[n]&&(c[n]={t:r.t,moves:[],click:["piece#"+this.board[n],"clicker#"+n],view:["clicker#"+n],highlight:function(e){i.updateGadget("cell#"+n,{"2d":{classes:"select"==e?"cb-cell-select":"cb-cell-cancel",opacity:a.mShowMoves||"cancel"==e?1:0}}),i.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){i.updateGadget("cell#"+n,{"2d":{classes:""}})},validate:{t:r.t},execute:function(t){var n=this;this.cbAnimate(i,a,r,function(){var s=c[r.t].moves;s.length>1&&(i.updateGadget("promo-board",{base:{visible:!0,width:a.cbPromoSize*(s.length+1)}}),i.updateGadget("promo-cancel",{base:{visible:!0,x:s.length*a.cbPromoSize/2}}),s.forEach(function(t,r){var n=e.pieceTypes[t.pr].aspect||e.pieceTypes[t.pr].name,c=$.extend(!0,{},a.cbView.pieces.default,a.cbView.pieces[n]);a.cbView.pieces[this.mWho]&&(c=$.extend(!0,c,a.cbView.pieces[this.mWho].default,a.cbView.pieces[this.mWho][n])),i.updateGadget("promo#"+t.pr,{base:$.extend(c["2d"],{x:(r-s.length/2)*a.cbPromoSize})})},n)),t()})},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),i.updateGadget("piece#"+r.c,n)}var c=this.pieces[this.board[r.f]],s=a.cbMakeDisplaySpecForPiece(a,c.p,c);i.updateGadget("piece#"+c.i,s),t()}}),void 0!==r.cg&&(c[n].validate.cg=r.cg,c[n].execute=function(e){this.cbAnimate(i,a,r,function(){e()})}),c[n].moves.push(r)},this);else if(null==n.pr){var s=[];r.forEach(function(e){void 0!==e.pr&&(void 0===c[e.pr]&&(c[e.pr]={pr:e.pr,moves:[],click:["promo#"+e.pr],validate:{pr:e.pr},cancel:["promo-cancel"],post:t,skipable:!0},s.push(e.pr)),c[e.pr].moves.push(e))},this),s.length>1&&s.forEach(function(e){c[e].view=["promo#"+e]})}return c}}},View.Game.cbCellClass=function(e,i){return"classic-cell "+((i+(i-i%this.g.NBCOLS)/this.g.ROWS)%2?"classic-cell-black":"classic-cell-white")},View.Board.xdPlayedMove=function(e,i,a){i.mOldBoard.cbAnimate(e,i,a,function(){i.MoveShown()})},View.Board.cbAnimate=function(e,i,a,t){function r(){0==--c&&(s&&i.PlaySound("tac"+(1+Math.floor(3*Math.random()))),t())}var n=this,c=1,s=!1,o=this.pieces[this.board[a.f]],l=i.cbMakeDisplaySpec(a.f,o.s),d=i.cbMakeDisplaySpecForPiece(i,a.t,o);for(var p in l){var h=l[p];void 0!==h.z&&function(e){var t=h.z,r=d[e].z,c=n.cbMoveMidZ(i,a,t,r,e),o=t,l=o-c,p=o-r;c!=(t+r)/2&&(s=!0);var u=4*l-2*p,f=-p*p,m=Math.abs(u*u- -4*f),g=(-u-Math.sqrt(m))/-2,b=(-u+Math.sqrt(m))/-2,w=g,x=-w-p;(0==w||-x/(2*w)<0||-x/(2*w)>1)&&(w=b,x=-w-p),d[e].positionEasingUpdate=function(e){var i=(w*e*e+x*e+o)*this.SCALE3D;this.object3d.position.y=i}}(p)}if(s||i.PlaySound("move"+(1+Math.floor(4*Math.random()))),e.updateGadget("piece#"+o.i,d,600,function(){r()}),null!=a.c){c++;var u={positionEasingUpdate:null};switch(i.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 h=i.cbVar.castle[a.f+"/"+a.cg],m=h.r[h.r.length-1],o=this.pieces[this.board[a.cg]],d=i.cbMakeDisplaySpecForPiece(i,m,o);c++,e.updateGadget("piece#"+o.i,d,600,function(){r()})}},View.Board.cbMoveMidZ=function(e,i,a,t){return(a+t)/2}}(),function(){View.Game.cbBaseBoard={TEXTURE_CANVAS_CX:1024,TEXTURE_CANVAS_CY:1024,display:function(e,i,a){var t=this;e.getResource=i.getResource,e.createGeometry.call(this,e,function(i){e.createTextureImages.call(t,e,function(r){var n=["diffuse"].concat(e.extraChannels||[]),c={};n.forEach(function(i){var a=document.createElement("canvas");a.width=e.TEXTURE_CANVAS_CX,a.height=e.TEXTURE_CANVAS_CY,c[i]=a}),e.createMaterial.call(t,e,c,function(n){var s=new THREE.Mesh(i,n);e.modifyMesh.call(t,e,s,function(i){e.paint.call(t,e,c,r,function(){a(i)})})})})})},createTextureImages:function(e,i){var a=this,t={},r=0,n=e.texturesImg||{};for(var c in n)r++;if(0==r)i(t);else for(var c in n)!function(c){e.getResource("image|"+a.g.fullPath+n[c],function(e){t[c]=e,0==--r&&i(t)})}(c)},createMaterial:function(e,i,a){var t=new THREE.Texture(i.diffuse);t.needsUpdate=!0;var r={specular:"#050505",shininess:30,map:t};if(i.bump){var n=new THREE.Texture(i.bump);n.needsUpdate=!0,r.bumpMap=n,r.bumpScale=.05}a(new THREE.MeshPhongMaterial(r))},modifyMesh:function(e,i,a){a(i)},prePaint:function(e,i,a,t,r){r()},paint:function(e,i,a,t,r){r()},postPaint:function(e,i,a,t,r){r()},paintChannel:function(e,i,a,t){},draw:function(e,i,a){var t=this;e.getResource=i.getResource,e.createTextureImages.call(this,e,function(i){e.paintChannel.call(t,e,a,i,"diffuse")})}}}(),function(){function e(e){for(var i=JSON.stringify(e),a=0,t=0;t<i.length;t++)a=(a<<5)-a+i.charCodeAt(t),a&=a;return a}var i,a={};View.Game.cbDisplayPieceFn=function(a){var t=this,r=e(a);return function(e,n,c){i=this.getResource;var s=/^piece#([0-9]+)$/.exec(this.gadget.id);if(!s)return null;var o=parseInt(s[1]),l=t.cbCurrentGame();if(o>=l.mBoard.pieces.length)return null;var d=l.mBoard.pieces[o],p=l.cbVar.pieceTypes[d.t].aspect||l.cbVar.pieceTypes[d.t].name,h=p+"_"+r+"_"+d.s,u=this;h!=this._cbKey&&(this._cbKey=h,u.options=n,l.cbMakePiece(a,p,d.s,function(e){u.replaceMesh(e,u.options,c)}))}},View.Game.cbMakePiece=function(i,t,r,n){function c(e,i,a){return i?$.extend(!0,e,i.default,i[a]):{}}if(!i)return void console.error("piece-view: style is not defined");var s=c({},i,t);i[r]&&(s=c(s,i[r],t));var o=e(s),l=a[o];Array.isArray(l)?l.push(n):l?n(new THREE.Mesh(l.geometry,l.material)):(a[o]=[n],s.loadResources.call(this,s,function(e){s.displayPiece.call(this,s,e,function(){var i=a[o];a[o]={geometry:e.geometry,material:e.material},i.forEach(function(i){i(new THREE.Mesh(e.geometry,e.material))})})}))},View.Game.cbClearPieces=function(){a={}},View.Game.cbBasePieceStyle={default:{mesh:{jsFile:function(e,i){i(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):i("smoothedfilegeo|"+e.mesh.smooth+"|"+this.g.fullPath+e.mesh.jsFile,a)},loadImages:function(e,a){function t(){0==--n&&a(c)}var r=this,n=1,c={};for(var s in e.materials){var o=e.materials[s].channels;for(var l in o)if(o[l].texturesImg)for(var d in o[l].texturesImg)!function(e,a){n++,i("image|"+r.g.fullPath+a,function(i){c[e]=i,t()})}(d,o[l].texturesImg[d])}t()},loadResources:function(e,i){function a(){0==--c&&i({geometry:r,images:t,textures:{},loadedMaterials:n})}var t,r,n,c=2;e.loadMesh.call(this,e,function(i,t){if(!i._cbZRotated){var c=new THREE.Matrix4;c.makeRotationY(e.mesh.rotateZ*Math.PI/180),i.applyMatrix(c),i._cbZRotated=!0}r=i,n=t,a()}),e.loadImages.call(this,e,function(e){t=e,a()})},displayPiece:function(e,i,a){e.makeMaterials.call(this,e,i),a()},paintTextureImageClip:function(e,i,a,t,r,n,c,s,o){var l=i.canvas.width,d=i.canvas.height;if(r.patternFill&&r.patternFill[n]){var p=r.patternFill[n];i.save();var h=document.createElement("canvas");h.width=l,h.height=d,ctxTmp=h.getContext("2d"),ctxTmp.fillStyle=p,ctxTmp.fillRect(0,0,l,d),ctxTmp.globalCompositeOperation="destination-in",ctxTmp.drawImage(c,s.x,s.y,s.cx,s.cy,0,0,l,d),i.drawImage(h,0,0,l,d,0,0,l,d),i.restore()}else i.drawImage(c,s.x,s.y,s.cx,s.cy,0,0,l,d)},paintTextureImage:function(e,i,a,t,r,n,c,s){var o;o=r.clipping&&r.clipping[n]?r.clipping[n]:{x:0,y:0,cx:c.width,cy:c.height},e.paintTextureImageClip.call(this,e,i,a,t,r,n,c,o,s)},paintTexture:function(e,i,a,t,r){var n=e.materials[a].channels[t];for(var c in n.texturesImg){var s=r.images[c];e.paintTextureImage.call(this,e,i,a,t,n,c,s,r)}},makeMaterialTextures:function(e,i,a){for(var t in e.materials[i].channels){var r=e.materials[i].channels[t],n=document.createElement("canvas");n.width=r.size.cx,n.height=r.size.cy;var c=n.getContext("2d");e.paintTexture.call(this,e,c,i,t,a);var s=new THREE.Texture(n);s.needsUpdate=!0,a.textures[i][t]=s}},makeMaterials:function(e,i){i.textures={};for(var a in e.materials)i.textures[a]={},e.makeMaterialTextures.call(this,e,a,i),e.makeMaterial.call(this,e,a,i)}}},View.Game.cbTokenPieceStyle3D=$.extend(!0,{},View.Game.cbBasePieceStyle,{default:{makeMaterials:function(e,i){i.textures={};for(var a in e.materials)i.textures[a]={},e.makeMaterialTextures.call(this,e,a,i);var t=[];for(var r in i.loadedMaterials){var n=i.loadedMaterials[r].clone(),c=n.name;if(e.materials[c]){$.extend(!0,n,e.materials[c].params);for(var s in e.materials[c].channels)switch(s){case"diffuse":n.map=i.textures[c][s];break;case"bump":n.bumpMap=i.textures[c][s]}}t.push(n)}var o=new THREE.MultiMaterial(t);i.material=o}}}),View.Game.cbUniformPieceStyle3D=$.extend(!0,{},View.Game.cbBasePieceStyle,{default:{makeMaterial:function(e,i,a){var t=e.materials[i].params;t.map=a.textures[i].diffuse,t.normalMap=a.textures[i].normal;var r=e.materials[i].channels.normal.normalScale||1;t.normalScale=new THREE.Vector2(r,r);var n=new THREE.MeshPhongMaterial(t);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,i){var a=new THREE.MeshPhongMaterial(e.phongProperties);i.material=a}}})}(),function(){var e=0,i=0,a={};View.Game.cbEnsureConstants=function(){i||(i=this.cbVar.geometry.height,e=this.cbVar.geometry.width)},View.Game.cbCSize=function(t){this.cbEnsureConstants();var r=a[t.margins.x+"_"+t.margins.y];if(!r){var n,c,s,o,l=e+2*t.margins.x,d=i+2*t.margins.y;n=l/d,o=n<1?12e3*n/l:12e3/n/d,c=(e+2*t.margins.x)*o,s=(i+2*t.margins.y)*o,r={cx:o,cy:o,pieceCx:o,pieceCy:o,ratio:n,width:c,height:s},a[t.margins.x+"_"+t.margins.y]=r}return r},View.Game.cbGridBoard=$.extend({},View.Game.cbBaseBoard,{notationMode:"out",coordsFn:function(a){return a=a||{},a.margins=a.margins||{x:0,y:0},function(t){var r=this.cbCSize(a),n=t%e,c=(t-n)/e;return 1==this.mViewAs&&(c=i-1-c),-1==this.mViewAs&&(n=e-1-n),{x:(n-(e-1)/2)*r.cx,y:(c-(i-1)/2)*r.cy,z:0}}},createGeometry:function(e,i){var a=this.cbCSize(e),t=a.width/1e3,r=a.height/1e3,n=new THREE.PlaneGeometry(t,r),c=new THREE.Matrix4;c.makeRotationX(-Math.PI/2),n.applyMatrix(c);for(var s=n.faceVertexUvs[0],o=0;o<s.length;o++)for(var l=0;l<s[o].length;l++)a.ratio<1&&(s[o][l].x=s[o][l].x*a.ratio+(1-a.ratio)/2),a.ratio>1&&(s[o][l].y=s[o][l].y/a.ratio+(1-1/a.ratio)/2);i(n)},paintBackground:function(e,i,a,t,r,n){a.boardBG&&i.drawImage(a.boardBG,-r/2,-n/2,r,n)},paintChannel:function(e,i,a,t){var r=this.cbCSize(e);e.paintBackground.call(this,e,i,a,t,r.width,r.height)},paint:function(e,i,a,t){for(var r in i){var n=i[r].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,a,r),n.restore()}t()}}),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,i,a){function t(e,i){var a=new THREE.Shape;return a.moveTo(-e/2,-i/2),a.lineTo(e/2,-i/2),a.lineTo(e/2,i/2),a.lineTo(-e/2,i/2),a}var r=this.cbCSize(e),n=r.width/1e3,c=r.height/1e3,s=t(n+.5+.1,c+.5+.1),o=t(n+.1,c+.1);s.holes.push(o);var l={amount:.4,steps:1,bevelSize:.1,bevelThickness:.04,bevelSegments:1},d=new THREE.ExtrudeGeometry(s,l),p=new THREE.Matrix4;p.makeRotationX(-Math.PI/2),d.applyMatrix(p),blackMat=new THREE.MeshPhongMaterial({color:"#000000",shininess:500,specular:"#888888",emissive:"#000000"});var h=new THREE.Mesh(d,blackMat);h.position.y=-l.amount-.01,i.add(h);var u=new THREE.Mesh(new THREE.BoxGeometry(n,c,.1),blackMat);u.rotation.x=Math.PI/2,u.position.y=-.1,i.add(u),a(i)},paintCell:function(e,i,a,t,r,n,c,s,o){i.strokeStyle="rgba(0,0,0,1)",i.lineWidth=15,i.fillStyle="bump"==t?"#ffffff":e.colorFill[r],i.fillRect(n-s/2,c-o/2,s,o),i.rect(n-s/2,c-o/2,s,o)},paintCells:function(a,t,r,n){for(var c=this.cbCSize(a),s=a.coordsFn(a),o=0;o<i;o++)for(var l=0;l<e;l++){var d=1==this.mViewAs?l+o*e:e*i-(1+l+o*e),p=s.call(this,d),h=this.cbView.boardLayout[i-o-1][l],u=p.x,f=p.y,m=c.cx,g=c.cy;a.paintCell.call(this,a,t,r,n,h,u,f,m,g)}},paintLines:function(a,t,r,n){var c=this.cbCSize(a);t.strokeStyle="#000000",t.lineWidth=40,t.strokeRect(-e*c.cx/2,-i*c.cy/2,e*c.cx,i*c.cy)},paintChannel:function(e,i,a,t){var r=this.cbCSize(e);e.paintBackground.call(this,e,i,a,t,r.width,r.height),e.paintCells.call(this,e,i,a,t),e.paintLines.call(this,e,i,a,t),this.mNotation&&e.paintNotation.call(this,e,i,t)},paintNotation:function(e,i,a){var t=this.cbCSize(e);switch(i.textAlign="center",i.textBaseline="middle",i.fillStyle="#000000",i.font=Math.ceil(t.cx/3)+"px Monospace",e.notationMode){case"out":e.paintOutNotation.apply(this,arguments);break;case"in":e.paintInNotation.apply(this,arguments)}},paintOutNotation:function(a,t,r){for(var n=this.cbCSize(a),c=0;c<i;c++){var s=i-c;this.mViewAs<0&&(s=c+1);var o=-(e/2+a.margins.x/2)*n.cx,l=(c-i/2+.5)*n.cy;t.fillText(s,o,l)}for(var d=0;d<e;d++){var p=d;this.mViewAs<0&&(p=e-d-1);var o=(d-e/2+.5)*n.cx,l=(i/2+a.margins.y/2)*n.cy;t.fillText(String.fromCharCode(97+p),o,l)}},paintInNotation:function(a,t,r){var n=this.cbCSize(a),c=a.coordsFn(a),s=a.colorFill;t.font=Math.ceil(n.cx/5)+"px Monospace";for(var o=0;o<i;o++)for(var l=0;l<e;l++){var d=i-o,p=l;this.mViewAs<0?p=e-l-1:d=o+1;var h=1==this.mViewAs?l+o*e:e*i-(1+l+o*e),u=c.call(this,h);switch(t.fillStyle="rgba(0,0,0,0)","bump"==r&&(t.fillStyle=s["."]),this.cbView.boardLayout[i-o-1][l]){case".":t.fillStyle="bump"==r?s["."]:s["#"];break;case"#":t.fillStyle=s["."]}var f=u.x-n.cx/3,m=u.y-n.cy/3;a.notationDebug?t.fillText(h,f,m):t.fillText(String.fromCharCode(97+p)+d,f,m)}}}),View.Board.cbMoveMidZ=function(e,i,a,t){var r=e.cbVar.geometry,n=r.C(i.f),c=r.C(i.t),s=r.R(i.f),o=r.R(i.t);return c-n==0||o-s==0||Math.abs(c-n)==Math.abs(o-s)?(a+t)/2:Math.max(a,t)+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(){View.Game.cbXiangqiBoard=$.extend({},View.Game.cbGridBoardClassic,{colorFill:{".":"rgba(0,0,0,0)"},texturesImg:{boardBG:"/res/xiangqi/wood2.jpg",boarddeco1:"/res/xiangqi/decoration-cross.png"},paintCell:function(e,i,a,t,r,n,c,s,o){},paintBackground:function(e,i,a,t,r,n){"diffuse"==t&&i.drawImage(a.boardBG,-r/2,-n/2,r,n)},paintLines:function(e,i,a,t){function r(e,i){return 1==s.mViewAs?e+i*l:l*o-(1+e+i*l)}function n(e,a){var t=p.call(s,r(e.col,e.row)),n=p.call(s,r(a.col,a.row));i.beginPath(),i.moveTo(t.x,t.y),i.lineTo(n.x,n.y),i.stroke()}function c(e){var t=p.call(s,r(e.col,e.row)),n=d.cx/2,c=d.cy/2;if(a.boarddeco1){var o=a.boarddeco1;switch(e.col){default:i.drawImage(o,t.x-n/2,t.y-c/2,n,c);break;case 0:i.drawImage(o,o.width/2,0,o.width/2,o.height,t.x,t.y-c/2,n/2,c);break;case 8:i.drawImage(o,0,0,o.width/2,o.height,t.x-n/2,t.y-c/2,n/2,c)}}}var s=this,o=10,l=9,d=this.cbCSize(e),p=e.coordsFn(e);i.strokeStyle="rgba(0,0,0,1)",i.lineWidth=15;var h=p.call(s,r(0,o-1));i.save(),i.lineWidth=60,i.fillStyle="rgba(231,208,167,0.0)",i.rect(h.x,h.y,(l-1)*d.cx,(o-1)*d.cy),i.fill(),i.stroke(),i.restore();for(var u=1;u<o;u++){var f=r(0,u),m=p.call(s,f);i.strokeRect(m.x,m.y,(l-1)*d.cx,d.cy)}for(var u=4;u<o;u+=5)for(var g=0;g<l-1;g++){var f=r(g,u),m=p.call(s,f);i.strokeRect(m.x,m.y,d.cx,4*d.cy)}n({col:3,row:0},{col:5,row:2}),n({col:5,row:0},{col:3,row:2}),n({col:3,row:9},{col:5,row:7}),n({col:5,row:9},{col:3,row:7}),c({col:1,row:2}),c({col:7,row:2}),c({col:1,row:7}),c({col:7,row:7});for(var g=0;g<9;g+=2)c({col:g,row:3}),c({col:g,row:6})}}),View.Game.cbXiangqiBoard3DMargin=$.extend({},View.Game.cbXiangqiBoard,{"3D":!0,margins:{x:.35,y:.35},extraChannels:["bump"]}),View.Game.cbXiangqiBoard2DMargin=$.extend({},View.Game.cbXiangqiBoard,{margins:{x:.35,y:.35}}),View.Game.cbXiangqiBoard2DNoMargin=$.extend({},View.Game.cbXiangqiBoard,{margins:{x:0,y:0}})}(),function(){var e={shininess:1e3,bumpScale:.05,specular:{r:.1,g:.1,b:.1}};View.Game.cbXiangqiPieceStyle=function(e){return $.extend(!0,{1:{default:{"2d":{clipy:0}}},"-1":{default:{"2d":{clipy:300}}},default:{"3d":{display:this.cbDisplayPieceFn(this.cbXiangqiPieceStyle3D)},"2d":{file:this.mViewOptions.fullPath+"/res/xiangqi/xiangqi-pieces-sprites.png",clipwidth:300,clipheight:300}},"xq-pawn":{"2d":{clipx:1800}},"xq-horse":{"2d":{clipx:600}},"xq-chariot":{"2d":{clipx:1200}},"xq-cannon":{"2d":{clipx:1500}},"xq-general":{"2d":{clipx:0}},"xq-advisor":{"2d":{clipx:300}},"xq-elephant":{"2d":{clipx:900}}},e)},View.Game.cbXiangqiPieceStyle3D=$.extend(!0,{},View.Game.cbTokenPieceStyle3D,{1:{default:{materials:{piecetop:{channels:{bump:{texturesImg:{bumpTexturePattern:"/res/xiangqi/xiangqi-pieces-sprites-playera.png"}},diffuse:{texturesImg:{mainDiffuse:"/res/xiangqi/whitebg.png",faceDiffuse:"/res/xiangqi/xiangqi-pieces-sprites-playera.png"},patternFill:{faceDiffuse:"rgba(255,0,0,1)"}}}}}}},"-1":{default:{materials:{piecetop:{channels:{bump:{texturesImg:{bumpTexturePattern:"/res/xiangqi/xiangqi-pieces-sprites-playerb.png"}},diffuse:{texturesImg:{mainDiffuse:"/res/xiangqi/whitebg.png",faceDiffuse:"/res/xiangqi/xiangqi-pieces-sprites-playerb.png"},patternFill:{faceDiffuse:"rgba(0,0,0,1)"}}}}}}},default:{mesh:{jsFile:"/res/xiangqi/token.js"},materials:{pieceborders:{params:e,channels:{diffuse:{size:{cx:1024,cy:1024},texturesImg:{mainDiffuse:"/res/xiangqi/whitebg.png"},patternFill:{mainDiffuse:"rgb(255,255,255)"}}}},piecetop:{params:e,channels:{bump:{size:{cx:512,cy:512},texturesImg:{bumpTexture:"/res/xiangqi/piecebump.jpg"},clipping:{bumpTexturePattern:{y:0,cx:300,cy:300}},patternFill:{bumpTexturePattern:"rgba(0,0,0,0.2)"}},diffuse:{size:{cx:1024,cy:1024},clipping:{faceDiffuse:{y:0,cx:300,cy:300}},patternFill:{mainDiffuse:"rgb(255,255,255)"}}}}}},"xq-pawn":{materials:{piecetop:{channels:{diffuse:{clipping:{faceDiffuse:{x:1800}}},bump:{clipping:{bumpTexturePattern:{x:1800}}}}}}},"xq-horse":{materials:{piecetop:{channels:{diffuse:{clipping:{faceDiffuse:{x:600}}},bump:{clipping:{bumpTexturePattern:{x:600}}}}}}},"xq-chariot":{materials:{piecetop:{channels:{diffuse:{clipping:{faceDiffuse:{x:1200}}},bump:{clipping:{bumpTexturePattern:{x:1200}}}}}}},"xq-cannon":{materials:{piecetop:{channels:{diffuse:{clipping:{faceDiffuse:{x:1500}}},bump:{clipping:{bumpTexturePattern:{x:1500}}}}}}},"xq-general":{materials:{piecetop:{channels:{diffuse:{clipping:{faceDiffuse:{x:0}}},bump:{clipping:{bumpTexturePattern:{x:0}}}}}}},"xq-advisor":{materials:{piecetop:{channels:{diffuse:{clipping:{faceDiffuse:{x:300}}},bump:{clipping:{bumpTexturePattern:{x:300}}}}}}},"xq-elephant":{materials:{piecetop:{channels:{diffuse:{clipping:{faceDiffuse:{x:900}}},bump:{clipping:{bumpTexturePattern:{x:900}}}}}}}}),View.Game.cbXiangqiWesternPieceStyle=function(e){return $.extend(!0,this.cbXiangqiPieceStyle(),{default:{"3d":{display:this.cbDisplayPieceFn(this.cbXiangqiWesternPieceStyle3D)},"2d":{file:this.mViewOptions.fullPath+"/res/xiangqi/xiangqi-pieces-sprites-western.png"}}},e)},View.Game.cbXiangqiWesternPieceStyle3D=$.extend(!0,{},View.Game.cbXiangqiPieceStyle3D,{1:{default:{materials:{piecetop:{channels:{diffuse:{texturesImg:{faceDiffuse:"/res/xiangqi/xiangqi-pieces-sprites-western-player.png"}},bump:{texturesImg:{bumpTexturePattern:"/res/xiangqi/xiangqi-pieces-sprites-western-player.png"}}}}}}},"-1":{default:{materials:{piecetop:{channels:{diffuse:{texturesImg:{faceDiffuse:"/res/xiangqi/xiangqi-pieces-sprites-western-player.png"}},bump:{texturesImg:{bumpTexturePattern:"/res/xiangqi/xiangqi-pieces-sprites-western-player.png"}}}}}}}})}(),function(){View.Game.cbDefineView=function(){return{coords:{"2d":this.cbGridBoard.coordsFn.call(this,this.cbXiangqiBoard2DMargin),"3d":this.cbGridBoard.coordsFn.call(this,this.cbXiangqiBoard3DMargin)},boardLayout:[".........",".........",".........",".........",".........",".........",".........",".........",".........","........."],board:{"2d":{draw:this.cbDrawBoardFn(this.cbXiangqiBoard2DMargin)},"3d":{display:this.cbDisplayBoardFn(this.cbXiangqiBoard3DMargin)}},clicker:{"2d":{width:1100,height:1100},"3d":{scale:[.75,.75,.7]}},pieces:this.cbXiangqiPieceStyle({default:{"3d":{scale:[.5,.5,.5]},skin3dwall:{rotate:0},skin3dwestern:{display:this.cbXiangqiWesternPieceStyle().default["3d"].display},skin3dwallwestern:{display:this.cbXiangqiWesternPieceStyle().default["3d"].display,rotate:0},skin2dwestern:this.cbXiangqiWesternPieceStyle().default["2d"]}})}},View.Board.cbMoveMidZ=function(e,i,a,t){if("H"==i.a||"C"==i.a&&null!=i.c)return Math.max(a,t)+1500;var r=e.cbVar.geometry,n=r.C(i.f),c=r.C(i.t),s=r.R(i.f),o=r.R(i.t);return n==c||s==o?(a+t)/2:Math.max(a,t)+800}}();