UNPKG

jocly

Version:

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

1 lines 25.9 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 s=0;s<this.cbExtraLights.length;s++)i.updateGadget("extralights#"+s,{"3d":{visible:!0}});i.updateGadget("board",$.extend({base:{visible:!0}},this.cbView.board));for(var r=0;r<this.g.boardSize;r++)!function(e){var t=a.cbMakeDisplaySpec(e,0),s=$.extend(!0,{},t,{base:{visible:!0}},a.cbView.clicker,a.cbView.cell);i.updateGadget("cell#"+e,s),$.extend(!0,t,a.cbView.clicker),i.updateGadget("clicker#"+e,t)}(r);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 s=0;s<this.g.pTypes.length;s++)i.updateGadget("promo#"+s,{base:{visible:!1}})},View.Game.cbDisplayBoardFn=function(e){var t=this;return function(i,s,r){var c=e.style+"_"+e.margins.x+"_"+e.margins.y+"_"+t.mNotation+"_"+t.mViewAs,n=this;c!=this._cbKey&&(this._cbKey=c,e.display.call(a,e,n,function(e){n.replaceMesh(e,s,r)}))}},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 s=this.cbView.coords[i],r=s.call(this,e);a[i]={x:r.x||0,y:r.y||0,z:r.z||0,rotateX:r.rx||0,rotateY:(r.ry||0)*("3d"==i?this.mViewAs*t<0?-1:1:0),rotate:(r.rz||0)+("3d"==i&&this.mViewAs*t<0?180:0)}}return a},View.Game.cbMakeDisplaySpecForPiece=function(a,i,s){function r(e,t,a){return t?$.extend(!0,e,t.default,t[a]):{}}var c=this.cbMakeDisplaySpec(i,s.s);if(void 0===e.pieceTypes[s.t])return void console.warn("Piece type",s.t,"not defined in model");var n=e.pieceTypes[s.t].aspect||e.pieceTypes[s.t].name;return n?(t.pieces&&(c=r(c,t.pieces,n),t.pieces[s.s]&&(c=r(c,t.pieces[s.s],n))),c):void console.warn("Piece type",s.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 s=t.cbMakeDisplaySpecForPiece(t,i.p,i);s=$.extend(!0,{base:{visible:!0},"2d":{opacity:1},"3d":{positionEasingUpdate:null}},s),e.updateGadget("piece#"+a,s)}}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 s=new THREE.Object3D;i.add(s),a.target=s,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(s,r){var c={};if(null==r.f)s.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(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}}),c[e.f].moves.push(e)},this);else if(null==r.t)s.forEach(function(s){var r=void 0===s.cg?s.t:s.cg;void 0===c[r]&&(c[r]={t:s.t,moves:[],click:["piece#"+this.board[r],"clicker#"+r],view:["clicker#"+r],highlight:function(e){t.updateGadget("cell#"+r,{"2d":{classes:"select"==e?"cb-cell-select":"cb-cell-cancel",opacity:a.mShowMoves||"cancel"==e?1:0}}),t.updateGadget("clicker#"+r,{"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#"+r,{"2d":{classes:""}})},validate:{t:s.t},execute:function(i){var r=this;this.cbAnimate(t,a,s,function(){var n=c[s.t].moves;n.length>1&&(t.updateGadget("promo-board",{base:{visible:!0,width:a.cbPromoSize*(n.length+1)}}),t.updateGadget("promo-cancel",{base:{visible:!0,x:n.length*a.cbPromoSize/2}}),n.forEach(function(i,s){var r=e.pieceTypes[i.pr].aspect||e.pieceTypes[i.pr].name,c=$.extend(!0,{},a.cbView.pieces.default,a.cbView.pieces[r]);a.cbView.pieces[this.mWho]&&(c=$.extend(!0,c,a.cbView.pieces[this.mWho].default,a.cbView.pieces[this.mWho][r])),t.updateGadget("promo#"+i.pr,{base:$.extend(c["2d"],{x:(s-n.length/2)*a.cbPromoSize})})},r)),i()})},unexecute:function(){if(null!=s.c){var e=this.pieces[s.c],r=a.cbMakeDisplaySpecForPiece(a,e.p,e);r=$.extend(!0,{base:{visible:!0},"2d":{opacity:1},"3d":{positionEasingUpdate:null}},r),t.updateGadget("piece#"+s.c,r)}var c=this.pieces[this.board[s.f]],n=a.cbMakeDisplaySpecForPiece(a,c.p,c);t.updateGadget("piece#"+c.i,n),i()}}),void 0!==s.cg&&(c[r].validate.cg=s.cg,c[r].execute=function(e){this.cbAnimate(t,a,s,function(){e()})}),c[r].moves.push(s)},this);else if(null==r.pr){var n=[];s.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:i,skipable:!0},n.push(e.pr)),c[e.pr].moves.push(e))},this),n.length>1&&n.forEach(function(e){c[e].view=["promo#"+e]})}return c}}},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 s(){0==--c&&(n&&t.PlaySound("tac"+(1+Math.floor(3*Math.random()))),i())}var r=this,c=1,n=!1,o=this.pieces[this.board[a.f]],l=t.cbMakeDisplaySpec(a.f,o.s),d=t.cbMakeDisplaySpecForPiece(t,a.t,o);for(var h in l){var p=l[h];void 0!==p.z&&function(e){var i=p.z,s=d[e].z,c=r.cbMoveMidZ(t,a,i,s,e),o=i,l=o-c,h=o-s;c!=(i+s)/2&&(n=!0);var m=4*l-2*h,u=-h*h,f=Math.abs(m*m- -4*u),g=(-m-Math.sqrt(f))/-2,b=(-m+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(n||t.PlaySound("move"+(1+Math.floor(4*Math.random()))),e.updateGadget("piece#"+o.i,d,600,function(){s()}),null!=a.c){c++;var m={positionEasingUpdate:null};switch(t.cbView.captureAnim3d||"movedown"){case"movedown":m.z=-2e3;break;case"scaledown":m.scale=[0,0,0]}var u=this.pieces[a.c];e.updateGadget("piece#"+u.i,{"2d":{opacity:0},"3d":m},600,s)}if(void 0!==a.cg){var p=t.cbVar.castle[a.f+"/"+a.cg],f=p.r[p.r.length-1],o=this.pieces[this.board[a.cg]],d=t.cbMakeDisplaySpecForPiece(t,f,o);c++,e.updateGadget("piece#"+o.i,d,600,function(){s()})}},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(s){var r=["diffuse"].concat(e.extraChannels||[]),c={};r.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(i,e,c,function(r){var n=new THREE.Mesh(t,r);e.modifyMesh.call(i,e,n,function(t){e.paint.call(i,e,c,s,function(){a(t)})})})})})},createTextureImages:function(e,t){var a=this,i={},s=0,r=e.texturesImg||{};for(var c in r)s++;if(0==s)t(i);else for(var c in r)!function(c){e.getResource("image|"+a.g.fullPath+r[c],function(e){i[c]=e,0==--s&&t(i)})}(c)},createMaterial:function(e,t,a){var i=new THREE.Texture(t.diffuse);i.needsUpdate=!0;var s={specular:"#050505",shininess:30,map:i};if(t.bump){var r=new THREE.Texture(t.bump);r.needsUpdate=!0,s.bumpMap=r,s.bumpScale=.05}a(new THREE.MeshPhongMaterial(s))},modifyMesh:function(e,t,a){a(t)},prePaint:function(e,t,a,i,s){s()},paint:function(e,t,a,i,s){s()},postPaint:function(e,t,a,i,s){s()},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,s=e(a);return function(e,r,c){t=this.getResource;var n=/^piece#([0-9]+)$/.exec(this.gadget.id);if(!n)return null;var o=parseInt(n[1]),l=i.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,p=h+"_"+s+"_"+d.s,m=this;p!=this._cbKey&&(this._cbKey=p,m.options=r,l.cbMakePiece(a,h,d.s,function(e){m.replaceMesh(e,m.options,c)}))}},View.Game.cbMakePiece=function(t,i,s,r){function c(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 n=c({},t,i);t[s]&&(n=c(n,t[s],i));var o=e(n),l=a[o];Array.isArray(l)?l.push(r):l?r(new THREE.Mesh(l.geometry,l.material)):(a[o]=[r],n.loadResources.call(this,n,function(e){n.displayPiece.call(this,n,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==--r&&a(c)}var s=this,r=1,c={};for(var n in e.materials){var o=e.materials[n].channels;for(var l in o)if(o[l].texturesImg)for(var d in o[l].texturesImg)!function(e,a){r++,t("image|"+s.g.fullPath+a,function(t){c[e]=t,i()})}(d,o[l].texturesImg[d])}i()},loadResources:function(e,t){function a(){0==--c&&t({geometry:s,images:i,textures:{},loadedMaterials:r})}var i,s,r,c=2;e.loadMesh.call(this,e,function(t,i){if(!t._cbZRotated){var c=new THREE.Matrix4;c.makeRotationY(e.mesh.rotateZ*Math.PI/180),t.applyMatrix(c),t._cbZRotated=!0}s=t,r=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,s,r,c,n,o){var l=t.canvas.width,d=t.canvas.height;if(s.patternFill&&s.patternFill[r]){var h=s.patternFill[r];t.save();var p=document.createElement("canvas");p.width=l,p.height=d,ctxTmp=p.getContext("2d"),ctxTmp.fillStyle=h,ctxTmp.fillRect(0,0,l,d),ctxTmp.globalCompositeOperation="destination-in",ctxTmp.drawImage(c,n.x,n.y,n.cx,n.cy,0,0,l,d),t.drawImage(p,0,0,l,d,0,0,l,d),t.restore()}else t.drawImage(c,n.x,n.y,n.cx,n.cy,0,0,l,d)},paintTextureImage:function(e,t,a,i,s,r,c,n){var o;o=s.clipping&&s.clipping[r]?s.clipping[r]:{x:0,y:0,cx:c.width,cy:c.height},e.paintTextureImageClip.call(this,e,t,a,i,s,r,c,o,n)},paintTexture:function(e,t,a,i,s){var r=e.materials[a].channels[i];for(var c in r.texturesImg){var n=s.images[c];e.paintTextureImage.call(this,e,t,a,i,r,c,n,s)}},makeMaterialTextures:function(e,t,a){for(var i in e.materials[t].channels){var s=e.materials[t].channels[i],r=document.createElement("canvas");r.width=s.size.cx,r.height=s.size.cy;var c=r.getContext("2d");e.paintTexture.call(this,e,c,t,i,a);var n=new THREE.Texture(r);n.needsUpdate=!0,a.textures[t][i]=n}},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 s in t.loadedMaterials){var r=t.loadedMaterials[s].clone(),c=r.name;if(e.materials[c]){$.extend(!0,r,e.materials[c].params);for(var n in e.materials[c].channels)switch(n){case"diffuse":r.map=t.textures[c][n];break;case"bump":r.bumpMap=t.textures[c][n]}}i.push(r)}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 s=e.materials[t].channels.normal.normalScale||1;i.normalScale=new THREE.Vector2(s,s);var r=new THREE.MeshPhongMaterial(i);a.material=r,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={};View.Game.cbEnsureConstants=function(){t||(t=this.cbVar.geometry.height,e=this.cbVar.geometry.width)},View.Game.cbCSize=function(i){this.cbEnsureConstants();var s=a[i.margins.x+"_"+i.margins.y];if(!s){var r,c,n,o,l=e+2*i.margins.x,d=t+2*i.margins.y;r=l/d,o=r<1?12e3*r/l:12e3/r/d,c=(e+2*i.margins.x)*o,n=(t+2*i.margins.y)*o,s={cx:o,cy:o,pieceCx:o,pieceCy:o,ratio:r,width:c,height:n},a[i.margins.x+"_"+i.margins.y]=s}return s},View.Game.cbGridBoard=$.extend({},View.Game.cbBaseBoard,{notationMode:"out",coordsFn:function(a){return a=a||{},a.margins=a.margins||{x:0,y:0},function(i){var s=this.cbCSize(a),r=i%e,c=(i-r)/e;return 1==this.mViewAs&&(c=t-1-c),-1==this.mViewAs&&(r=e-1-r),{x:(r-(e-1)/2)*s.cx,y:(c-(t-1)/2)*s.cy,z:0}}},createGeometry:function(e,t){var a=this.cbCSize(e),i=a.width/1e3,s=a.height/1e3,r=new THREE.PlaneGeometry(i,s),c=new THREE.Matrix4;c.makeRotationX(-Math.PI/2),r.applyMatrix(c);for(var n=r.faceVertexUvs[0],o=0;o<n.length;o++)for(var l=0;l<n[o].length;l++)a.ratio<1&&(n[o][l].x=n[o][l].x*a.ratio+(1-a.ratio)/2),a.ratio>1&&(n[o][l].y=n[o][l].y/a.ratio+(1-1/a.ratio)/2);t(r)},paintBackground:function(e,t,a,i,s,r){a.boardBG&&t.drawImage(a.boardBG,-s/2,-r/2,s,r)},paintChannel:function(e,t,a,i){var s=this.cbCSize(e);e.paintBackground.call(this,e,t,a,i,s.width,s.height)},paint:function(e,t,a,i){for(var s in t){var r=t[s].getContext("2d");r.save(),r.scale(e.TEXTURE_CANVAS_CX/12e3,e.TEXTURE_CANVAS_CY/12e3),r.translate(6e3,6e3),e.paintChannel.call(this,e,r,a,s),r.restore()}i()}}),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,a){function i(e,t){var a=new THREE.Shape;return a.moveTo(-e/2,-t/2),a.lineTo(e/2,-t/2),a.lineTo(e/2,t/2),a.lineTo(-e/2,t/2),a}var s=this.cbCSize(e),r=s.width/1e3,c=s.height/1e3,n=i(r+.5+.1,c+.5+.1),o=i(r+.1,c+.1);n.holes.push(o);var l={amount:.4,steps:1,bevelSize:.1,bevelThickness:.04,bevelSegments:1},d=new THREE.ExtrudeGeometry(n,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 p=new THREE.Mesh(d,blackMat);p.position.y=-l.amount-.01,t.add(p);var m=new THREE.Mesh(new THREE.BoxGeometry(r,c,.1),blackMat);m.rotation.x=Math.PI/2,m.position.y=-.1,t.add(m),a(t)},paintCell:function(e,t,a,i,s,r,c,n,o){t.strokeStyle="rgba(0,0,0,1)",t.lineWidth=15,t.fillStyle="bump"==i?"#ffffff":e.colorFill[s],t.fillRect(r-n/2,c-o/2,n,o),t.rect(r-n/2,c-o/2,n,o)},paintCells:function(a,i,s,r){for(var c=this.cbCSize(a),n=a.coordsFn(a),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=n.call(this,d),p=this.cbView.boardLayout[t-o-1][l],m=h.x,u=h.y,f=c.cx,g=c.cy;a.paintCell.call(this,a,i,s,r,p,m,u,f,g)}},paintLines:function(a,i,s,r){var c=this.cbCSize(a);i.strokeStyle="#000000",i.lineWidth=40,i.strokeRect(-e*c.cx/2,-t*c.cy/2,e*c.cx,t*c.cy)},paintChannel:function(e,t,a,i){var s=this.cbCSize(e);e.paintBackground.call(this,e,t,a,i,s.width,s.height),e.paintCells.call(this,e,t,a,i),e.paintLines.call(this,e,t,a,i),this.mNotation&&e.paintNotation.call(this,e,t,i)},paintNotation:function(e,t,a){var i=this.cbCSize(e);switch(t.textAlign="center",t.textBaseline="middle",t.fillStyle="#000000",t.font=Math.ceil(i.cx/3)+"px Monospace",e.notationMode){case"out":e.paintOutNotation.apply(this,arguments);break;case"in":e.paintInNotation.apply(this,arguments)}},paintOutNotation:function(a,i,s){for(var r=this.cbCSize(a),c=0;c<t;c++){var n=t-c;this.mViewAs<0&&(n=c+1);var o=-(e/2+a.margins.x/2)*r.cx,l=(c-t/2+.5)*r.cy;i.fillText(n,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)*r.cx,l=(t/2+a.margins.y/2)*r.cy;i.fillText(String.fromCharCode(97+h),o,l)}},paintInNotation:function(a,i,s){var r=this.cbCSize(a),c=a.coordsFn(a),n=a.colorFill;i.font=Math.ceil(r.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 p=1==this.mViewAs?l+o*e:e*t-(1+l+o*e),m=c.call(this,p);switch(i.fillStyle="rgba(0,0,0,0)","bump"==s&&(i.fillStyle=n["."]),this.cbView.boardLayout[t-o-1][l]){case".":i.fillStyle="bump"==s?n["."]:n["#"];break;case"#":i.fillStyle=n["."]}var u=m.x-r.cx/3,f=m.y-r.cy/3;a.notationDebug?i.fillText(p,u,f):i.fillText(String.fromCharCode(97+h)+d,u,f)}}}),View.Board.cbMoveMidZ=function(e,t,a,i){var s=e.cbVar.geometry,r=s.C(t.f),c=s.C(t.t),n=s.R(t.f),o=s.R(t.t);return c-r==0||o-n==0||Math.abs(c-r)==Math.abs(o-n)?(a+i)/2:Math.max(a,i)+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={shininess:10,bumpScale:.05,specular:{r:.1,g:.1,b:.1}};View.Game.cbSmessPieceStyle=function(e){return $.extend(!0,{1:{default:{"2d":{file:this.mViewOptions.fullPath+"/res/smess/smess-pieces-sprites-a.png",clipy:0}}},"-1":{default:{"2d":{file:this.mViewOptions.fullPath+"/res/smess/smess-pieces-sprites-b.png",clipy:0}}},default:{"3d":{display:this.cbDisplayPieceFn(this.cbSmessPieceStyle3D)},"2d":{clipwidth:300,clipheight:300}},"sm-pawn":{"2d":{clipx:0}},"sm-skull":{"2d":{clipx:300}},"sm-brain":{"2d":{clipx:600}}},e)},View.Game.cbSmessPieceStyle3D=$.extend(!0,{},View.Game.cbTokenPieceStyle3D,{1:{default:{materials:{piecetop:{channels:{bump:{texturesImg:{bumpTexturePattern:"/res/smess/smess-pieces-sprites.png"}},diffuse:{texturesImg:{mainDiffuse:"/res/smess/playera-bg.png",faceDiffuse:"/res/smess/smess-pieces-sprites.png"}}}}}}},"-1":{default:{materials:{piecetop:{channels:{bump:{texturesImg:{bumpTexturePattern:"/res/smess/smess-pieces-sprites.png"}},diffuse:{texturesImg:{mainDiffuse:"/res/smess/playerb-bg.png",faceDiffuse:"/res/smess/smess-pieces-sprites.png"}}}}}}},default:{mesh:{jsFile:"/res/smess/token.js"},materials:{pieceborders:{params:e,channels:{diffuse:{size:{cx:1024,cy:1024},texturesImg:{mainDiffuse:"/res/smess/playera-bg.png"}}}},piecetop:{params:e,channels:{bump:{size:{cx:512,cy:512},texturesImg:{},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}}}}}}},"sm-pawn":{materials:{piecetop:{channels:{diffuse:{clipping:{faceDiffuse:{x:0}}},bump:{clipping:{bumpTexturePattern:{x:0}}}}}}},"sm-skull":{materials:{piecetop:{channels:{diffuse:{clipping:{faceDiffuse:{x:300}}},bump:{clipping:{bumpTexturePattern:{x:300}}}}}}},"sm-brain":{materials:{piecetop:{channels:{diffuse:{clipping:{faceDiffuse:{x:600}}},bump:{clipping:{bumpTexturePattern:{x:600}}}}}}}})}(),function(){var e=[{img:"left",rot:0},{img:"",rot:0},{img:"left",rot:90},{img:"",rot:90},{img:"left",rot:180},{img:"",rot:180},{img:"left",rot:270},{img:"",rot:270}];View.Game.cbSmessBoard=$.extend({},View.Game.cbGridBoardClassic,{texturesImg:{promo:"/res/smess/promo.png",arrowtop:"/res/smess/arrow-top.png",arrowtopleft:"/res/smess/arrow-top-left.png",boardBG:"/res/images/wood-chipboard-4.jpg"},paintCell:function(t,a,i,s,r,c,n,o,l){a.strokeStyle="rgba(0,0,0,1)",a.lineWidth=15,a.rect(c-o/2,n-l/2,o,l),a.stroke();for(var d=r.charCodeAt(0)>>8,h=0;h<8;h++)if(d&1<<h){a.save(),a.translate(c,n);var p="arrowtop"+e[h].img;a.rotate(e[h].rot*Math.PI/180);var m=i[p];a.drawImage(m,0,0,m.width,m.height,-o/2,-l/2,o,l),a.restore()}if(1&r.charCodeAt(0)){var m=i.promo;a.drawImage(m,0,0,m.width,m.height,c-o/2,n-l/2,o,l)}}}),View.Game.cbSmessBoard3DMargin=$.extend({},View.Game.cbSmessBoard,{"3D":!0,margins:{x:.35,y:.35},extraChannels:["bump"]}),View.Game.cbSmessBoard2DMargin=$.extend({},View.Game.cbSmessBoard,{margins:{x:.35,y:.35}}),View.Game.cbSmessBoard2DNoMargin=$.extend({},View.Game.cbSmessBoard,{margins:{x:0,y:0}}),View.Game.cbDefineView=function(){for(var e=this.cbVar.geometry,t=[],a=0;a<e.height;a++){for(var i="",s=0;s<e.width;s++){var r=e.POS(s,a),c=this.cbSmessGraph[r]<<8;(this.cbSmessPromoPoss[1][r]||this.cbSmessPromoPoss[-1][r])&&(c|=1),i+=String.fromCharCode(c)}t.unshift(i)}return{coords:{"2d":this.cbGridBoard.coordsFn.call(this,this.cbSmessBoard2DMargin),"3d":this.cbGridBoard.coordsFn.call(this,this.cbSmessBoard3DMargin)},boardLayout:t,board:{"2d":{draw:this.cbDrawBoardFn(this.cbSmessBoard2DMargin)},"3d":{display:this.cbDisplayBoardFn(this.cbSmessBoard3DMargin)}},clicker:{"2d":{width:1300,height:1300},"3d":{scale:[.9,.9,.9]}},pieces:this.cbSmessPieceStyle({default:{"2d":{width:1e3,height:1e3},"3d":{scale:[.4,.4,.4]}}})}}}();