diff --git a/dist/diagram.js b/dist/diagram.js index 5039b53..28e1f39 100644 --- a/dist/diagram.js +++ b/dist/diagram.js @@ -1,4 +1,4 @@ -"use strict";(self.webpackChunkbilliards=self.webpackChunkbilliards||[]).push([[465],{"./src/container/container.ts":(e,t,n)=>{n.d(t,{W:()=>ec});var r=n("./src/events/stationaryevent.ts"),i=n("./node_modules/three/build/three.module.js"),o=n("./src/utils/utils.ts"),s=n("./src/view/cameratop.ts"),a=n("./src/model/physics/constants.ts");function l(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:.08,n=this.height,r=this.camera.aspect<.8;if(this.camera.fov=r?60:40,n<10*a.R){var i=100*(10*a.R-n);this.camera.fov-=i*(r?3:1)}this.camera.position.lerp(e.pos.clone().addScaledVector((0,o.AA)(e.angle),-(18*a.R)),t),this.camera.position.z=n,this.camera.up=o.up,this.camera.lookAt(e.pos.clone().addScaledVector(o.up,n/2))}},{key:"adjustHeight",value:function(e){e=this.height<10*a.R?e/8:e,this.height=i.M8C.clamp(this.height+e,6*a.R,120*a.R),this.height>110*a.R&&this.suggestMode(this.topView),this.height<105*a.R&&this.suggestMode(this.aimView)}},{key:"suggestMode",value:function(e){this.mainMode===this.aimView&&(this.mode=e)}},{key:"forceMode",value:function(e){this.mode=e,this.mainMode=e}},{key:"forceMove",value:function(e){this.mode===this.aimView&&this.aimView(e,1)}},{key:"toggleMode",value:function(){this.mode===this.topView?this.mode=this.aimView:this.mode=this.topView,this.mainMode=this.mode}}],l(n.prototype,e),t&&l(n,t),n}(),h=n("./src/view/tablegeometry.ts");function f(e,t){for(var n=0;n0&&(null===(t=this.cuePowerElement)||void 0===t?void 0:t.value)&&(this.cuePowerElement.value=e)}}],_(n.prototype,e),t&&_(n,t),n}(),j=n("./src/controller/aim.ts"),N=n("./src/controller/playshot.ts"),B=n("./src/controller/watchshot.ts"),L=n("./src/controller/end.ts");function H(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function F(e,t){for(var n=0;nthis.sentTime+this.period||e.type!==z.t.AIM){this.flush(),this.apply(e),this.sentTime=performance.now();return}this.pending=e}}]),e&&K(t,e),t}(),W=n("./src/view/sliders.ts"),Y=n("./src/model/outcome.ts"),Z=n("./node_modules/jsoncrush/JSONCrush.js"),Q=n("./src/events/rerackevent.ts");function J(e,t){for(var n=0;n0&&"RERACK"===this.shots[e].type&&e--,e}},{key:"lastShot",value:function(){var e=this.last();return this.state(this.states[e],[this.shots[e]])}},{key:"currentBreak",value:function(){if(void 0!==this.breakStart)return this.state(this.states[this.breakStart],this.shots.slice(this.breakStart),this.breakStartTime,this.container.rules.previousBreak)}},{key:"state",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;return{init:e,shots:t,start:n,now:Date.now(),score:r}}},{key:"updateBreak",value:function(e){var t=this.container.rules.isPartOfBreak(e),n=this.container.rules.isEndOfGame(e),r=Y.k.potCount(e);if(t||this.breakLink(n),this.lastShotLink(t||n,r,Y.k.pots(e)),n&&this.breakLink(n),!t){this.breakStart=void 0;return}void 0===this.breakStart&&(this.breakStart=this.last(),this.breakStartTime=Date.now())}},{key:"lastShotLink",value:function(e,t,n){var r=this.container.rules.currentBreak>0?" "+this.container.rules.currentBreak:"",i="#000000";n.length>0&&n.forEach(function(e){i="#"+e.ballmesh.color.getHexString()});var o="⚈".repeat(t>1?t-1:0)+(e?"⚈":"⚆")+r,s=JSON.stringify(this.lastShot());this.generateLink(o,s,i)}},{key:"breakLink",value:function(e){var t=this.currentBreak();if(t&&(e||t.shots.pop(),1!==t.shots.length)){var n=this.container.rules.previousBreak>0?this.container.rules.previousBreak:t.shots.length,r=JSON.stringify(t),i=Z.Z.crush(r);this.generateLink("break(".concat(n,")"),i,"black")}}},{key:"wholeGameLink",value:function(){var e=this.wholeGame(),t="frame(".concat(e.shots.length," shots)"),n=JSON.stringify(e),r=Z.Z.crush(n);this.generateLink(t,r,"black")}},{key:"generateLink",value:function(e,t,n){var r="".concat(this.replayUrl).concat(encodeURIComponent(t)),i='').concat(e,"");this.container.eventQueue.push(new G.s(null,"".concat(i)))}}],J(n.prototype,e),t&&J(n,t),n}(),ee=n("./src/controller/rules/rulefactory.ts"),et=n("./src/events/breakevent.ts");function en(e,t){for(var n=0;n').concat(e,"")));r.push(new G.s(null,s))})},this.redo.onclick=function(e){var r=new et.l(t.init,t.shots);r.retry=!0,n.interuptEventQueue(r)},this.replay.onclick=function(e){n.interuptEventQueue(t)}}}},{key:"interuptEventQueue",value:function(e){this.container.table.halt();var t=this.container.eventQueue;t.length=0,t.push(new r.I),t.push(e)}},{key:"getElement",value:function(e){return document.getElementById(e)}}],en(n.prototype,e),t&&en(n,t),n}();function eo(e,t){for(var n=0;n0?this.element.innerHTML="Break
"+e:this.element.innerHTML="")}},{key:"getElement",value:function(e){return document.getElementById(e)}}]),e&&eo(t,e),t}();function ea(e,t){for(var n=0;n0;){this.lastEventTime=this.last;var t=this.inputQueue.shift();t&&this.updateController(this.controller.handleInput(t))}if(this.table.allStationary()){var n=this.eventQueue.shift();n&&(this.lastEventTime=performance.now(),this.updateController(n.applyToController(this.controller)))}}},{key:"animate",value:function(e){var t=this;this.advance((e-this.last)/1e3),this.last=e,this.processEvents(),(e{n.d(t,{h:()=>u});var r=n("./src/controller/controller.ts"),i=n("./src/controller/controllerbase.ts"),o=n("./src/controller/playshot.ts"),s=n("./src/controller/replay.ts");function a(e,t){for(var n=0;n{n.d(t,{II:()=>i.I,OF:()=>r.O,Qr:()=>s}),n("./src/events/beginevent.ts"),n("./src/events/aimevent.ts");var r=n("./src/events/hitevent.ts"),i=n("./src/events/input.ts");function o(e,t){for(var n=0;n{n.d(t,{r:()=>f});var r=n("./src/controller/controller.ts"),i=n("./src/controller/end.ts"),o=n("./src/utils/gltf.ts"),s=n("./src/model/outcome.ts"),a=n("./node_modules/three/build/three.module.js");function l(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function c(e,t){for(var n=0;n{function r(e,t){for(var n=0;ns});var s=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}(a,e);var t,n,s=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n,r=i(a);if(t){var o=i(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(e=n)&&("object"==(e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)||"function"==typeof e)?e:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this)});function a(){return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),s.apply(this,arguments)}return r(a.prototype,[{key:"handleChat",value:function(e){var t=e.sender?"".concat(e.sender,":"):"",n="".concat(t," ").concat(e.message);return this.container.chat.showMessage(n),this}}]),n&&r(a,n),a}(n("./src/controller/controller.ts").Qr)},"./src/controller/placeball.ts":(e,t,n)=>{n.d(t,{a:()=>v});var r=n("./src/controller/controllerbase.ts"),i=n("./src/controller/controller.ts"),o=n("./src/controller/aim.ts"),s=n("./src/events/breakevent.ts"),a=n("./src/model/physics/constants.ts"),l=n("./node_modules/three/build/three.module.js"),c=n("./src/view/cuemesh.ts"),u=n("./src/utils/utils.ts");function h(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(e,t){for(var n=0;n{function r(e,t){for(var n=0;ns});var s=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}(l,e);var t,n,s,a=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n,r=i(l);if(t){var o=i(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(e=n)&&("object"==(e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)||"function"==typeof e)?e:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this)});function l(e){var t;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,l),(t=a.call(this,e)).hit(),t}return n=[{key:"handleStationary",value:function(e){var t=this.container.table,n=t.outcome,r=this.container.rules.update(n);return this.container.recorder.updateBreak(n),t.cue.aimAtNext(t.cueball,this.container.rules.nextCandidateBall()),r}},{key:"handleInput",value:function(e){return this.commonKeyHandler(e),this}}],r(l.prototype,n),s&&r(l,s),l}(n("./src/controller/controllerbase.ts").r)},"./src/controller/replay.ts":(e,t,n)=>{n.d(t,{U:()=>y});var r=n("./src/events/hitevent.ts"),i=n("./src/controller/controllerbase.ts"),o=n("./src/events/aimevent.ts"),s=n("./src/events/breakevent.ts"),a=n("./src/controller/aim.ts"),l=n("./src/events/eventtype.ts"),c=n("./src/events/rerackevent.ts");function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1500;if(!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,u),p(h(r=i.call(this,e)),"delay",void 0),p(h(r),"shots",void 0),p(h(r),"firstShot",void 0),p(h(r),"timer",void 0),p(h(r),"init",void 0),r.init=t,r.shots=m(n),r.firstShot=r.shots[0],r.delay=a,r.container.table.showTraces(!0),r.container.table.updateFromShortSerialised(r.init),o){var l=new s.l(t,n);l.retry=!0,r.container.eventQueue.push(l)}else r.container.view.camera.forceMode(r.container.view.camera.topView),r.playNextShot(1.5*r.delay);return r}return f(u.prototype,[{key:"playNextShot",value:function(e){var t=this,n=this.shots.shift();if((null==n?void 0:n.type)===l.t.RERACK){c.K.fromJson(n.ballinfo).applyToController(this),this.shots.length>0&&this.playNextShot(e);return}var i=o.f.fromJson(n);this.container.table.cueball=this.container.table.balls[i.i],this.container.table.cueball.pos.copy(i.pos),this.container.table.cue.aim=i,this.container.table.cue.updateAimInput(),this.container.table.cue.t=1,clearTimeout(this.timer),this.timer=setTimeout(function(){t.container.eventQueue.push(new r.O(t.container.table.cue.aim)),t.timer=void 0},e)}},{key:"handleHit",value:function(e){return this.hit(),this}},{key:"handleStationary",value:function(e){return this.shots.length>0&&void 0===this.timer&&this.playNextShot(this.delay),this}},{key:"handleInput",value:function(e){return this.commonKeyHandler(e),this}},{key:"handleBreak",value:function(e){return(this.container.table.updateFromShortSerialised(e.init),this.shots=m(e.shots),this.container.table.showSpin(!0),e.retry)?this.retry():(this.playNextShot(this.delay),this)}},{key:"retry",value:function(){clearTimeout(this.timer),this.timer=void 0,this.container.table.updateFromShortSerialised(this.init);var e=o.f.fromJson(this.firstShot);return this.container.table.cueball=this.container.table.balls[e.i],this.container.rules.cueball=this.container.table.cueball,this.container.table.cueball.pos.copy(e.pos),this.container.table.cue.aim=e,this.container.view.camera.forceMode(this.container.view.camera.aimView),new a.h(this.container)}}]),n&&f(u,n),u}(i.r)},"./src/controller/rules/rulefactory.ts":(e,t,n)=>{n.d(t,{N:()=>I});var r=n("./src/events/watchevent.ts"),i=n("./src/utils/rack.ts"),o=n("./node_modules/three/build/three.module.js"),s=n("./src/controller/aim.ts"),a=n("./src/controller/placeball.ts"),l=n("./src/controller/watchaim.ts"),c=n("./src/events/chatevent.ts"),u=n("./src/events/placeballevent.ts"),h=n("./src/model/outcome.ts"),f=n("./src/model/table.ts"),p=n("./src/utils/utils.ts"),d=n("./src/controller/end.ts"),v=n("./src/model/physics/constants.ts"),m=n("./src/utils/respot.ts"),y=n("./src/view/tablegeometry.ts"),b=n("./src/events/startaimevent.ts");function g(e,t){for(var n=0;n{n.d(t,{x:()=>T});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/events/watchevent.ts"),o=n("./src/model/outcome.ts"),s=n("./src/utils/rack.ts"),a=n("./src/utils/respot.ts"),l=n("./src/controller/aim.ts"),c=n("./src/controller/watchaim.ts"),u=n("./src/events/chatevent.ts"),h=n("./src/controller/end.ts"),f=n("./src/model/table.ts"),p=n("./src/view/tablegeometry.ts"),d=n("./src/controller/placeball.ts"),v=n("./src/events/placeballevent.ts"),m=n("./src/utils/utils.ts"),y=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"shotInfo",value:function(e,n,r){var i=o.k.firstCollision(n);return{pots:o.k.potCount(n),firstCollision:i,legalFirstCollision:t.isLegalFirstCollision(e,r,i),whitePotted:o.k.isCueBallPotted(e.cueball,n)}}},{key:"isLegalFirstCollision",value:function(e,n,r){if(!r)return!1;var i=r.ballB.id,o=t.coloursOnTable(e).filter(function(e){return e.id0;return n?i>=7:!o}},{key:"respotAllPottedColours",value:function(e,t){return o.k.pots(t).filter(function(e){return e.id<7}).filter(function(e){return 0!==e.id}).map(function(t){return a.s.respot(t,e)})}},{key:"redsOnTable",value:function(e){return e.balls.slice(7).filter(function(e){return e.onTable()})}},{key:"coloursOnTable",value:function(e){return e.balls.slice(1,7).filter(function(e){return e.onTable()})}}],function(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=Array(t);n0,this.switchPlayer()}return this.targetIsRed?this.targetRedRule(e,t):this.targetColourRule(e,t)}},{key:"targetRedRule",value:function(e,t){return(console.log("applying target red rule"),t.legalFirstCollision&&o.k.onlyRedsPotted(e))?(this.currentBreak+=t.pots,this.targetIsRed=!1,this.previousPotRed=!0,this.container.hud.updateBreak(this.currentBreak),this.continueBreak()):(this.foulPoints=this.foulCalculation(e,t),this.respot(e),t.whitePotted)?this.whiteInHand():this.switchPlayer()}},{key:"targetColourRule",value:function(e,t){if(console.log("applying target colour rule"),t.whitePotted)return this.respot(e),this.whiteInHand();if(t.pots>1)return this.foulPoints=this.foulCalculation(e,t),this.respot(e),this.switchPlayer();if(o.k.pots(e)[0].id>6)return this.foulPoints=this.foulCalculation(e,t),this.switchPlayer();this.targetIsRed=y.redsOnTable(this.container.table).length>0;var n=o.k.pots(e)[0].id;if(!this.previousPotRed){var r=y.coloursOnTable(this.container.table).filter(function(e){return e.id0;if(!t.legalFirstCollision||r)return this.foulPoints=this.foulCalculation(e,t),this.respot(e),this.switchPlayer()}return this.previousPotRed&&this.respot(e),this.currentBreak+=n+1,this.previousPotRed=!1,this.container.hud.updateBreak(this.currentBreak),this.continueBreak()}},{key:"foulCalculation",value:function(e,t){var n,r,i,s,a=o.k.pots(e).map(function(e){return e.id}).filter(function(e){return e<7}),l=null!==(s=null===(i=t.firstCollision)||void 0===i?void 0:null===(r=i.ballB)||void 0===r?void 0:r.id)&&void 0!==s?s:0;return l>6&&(l=0),(n=Math).max.apply(n,[3,l].concat(function(e){if(Array.isArray(e))return g(e)}(a)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(a)||function(e,t){if(e){if("string"==typeof e)return g(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return g(e,t)}}(a)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()))+1}},{key:"tableGeometry",value:function(){p.H.hasPockets=!0}},{key:"table",value:function(){var e=new f.i(this.rack());return this.cueball=e.cueball,e}},{key:"otherPlayersCueBall",value:function(){return this.cueball}},{key:"secondToPlay",value:function(){}},{key:"isPartOfBreak",value:function(e){return this.currentBreak>0}},{key:"isEndOfGame",value:function(e){return o.k.isClearTable(this.container.table)&&this.currentBreak>0}},{key:"allowsPlaceBall",value:function(){return!0}},{key:"asset",value:function(){return n.tablemodel}},{key:"startTurn",value:function(){this.previousPotRed=!1,this.targetIsRed=y.redsOnTable(this.container.table).length>0,this.previousBreak=this.currentBreak,this.currentBreak=0,this.container.hud.updateBreak(this.currentBreak)}},{key:"rack",value:function(){return s.F.snooker()}},{key:"nextCandidateBall",value:function(){var e=this.container.table,t=y.redsOnTable(e),n=y.coloursOnTable(e);return this.previousPotRed?a.s.closest(e.cueball,n):t.length>0?a.s.closest(e.cueball,t):n.length>0?n[0]:void 0}},{key:"placeBall",value:function(e){if(e){var t=new r.Pa4(s.F.baulk,s.F.sixth),n=new r.Pa4(s.F.baulk-s.F.sixth,-s.F.sixth);return e.clamp(n,t)}return new r.Pa4(s.F.baulk,-s.F.sixth/3,0)}},{key:"switchPlayer",value:function(){this.foulPoints>0&&console.log("foul, ".concat(this.foulPoints," to opponent")),console.log("end of break, switch player");var e=this.container.table;return(console.log(e.cue.aim),this.container.sendEvent(new b.H(this.foulPoints)),this.container.isSinglePlayer)?(this.container.sendEvent(new i.g(e.serialise())),this.startTurn(),new l.h(this.container)):new c.Q(this.container)}},{key:"continueBreak",value:function(){var e=this.container.table;return(this.container.sound.playSuccess(e.inPockets()),o.k.isClearTable(e))?(this.container.eventQueue.push(new u.s(null,"game over")),this.container.recorder.wholeGameLink(),new h.C(this.container)):(this.container.sendEvent(new i.g(e.serialise())),new l.h(this.container))}},{key:"whiteInHand",value:function(){return(this.foulPoints>0&&console.log("foul, ".concat(this.foulPoints," to opponent")),this.startTurn(),this.container.isSinglePlayer)?new d.a(this.container):(this.container.sendEvent(new v.I(m.bM,!0)),new c.Q(this.container))}},{key:"update",value:function(e){return this.snookerrule(e)}},{key:"respot",value:function(e){var t=y.respotAllPottedColours(this.container.table,e);if(t.length>0){var n={balls:t.map(function(e){return e.serialise()}),rerack:!0},r=new i.g(n);this.container.sendEvent(r),this.container.recorder.record(r)}}}],w(n.prototype,e),t&&w(n,t),n}();k(T,"tablemodel","models/snooker.min.gltf")},"./src/controller/watchaim.ts":(e,t,n)=>{n.d(t,{Q:()=>a});var r=n("./src/controller/watchshot.ts");function i(e,t){for(var n=0;n{n.d(t,{O:()=>u});var r=n("./src/controller/aim.ts"),i=n("./src/controller/watchaim.ts"),o=n("./src/controller/controllerbase.ts"),s=n("./src/controller/placeball.ts");function a(e,t){for(var n=0;n{var r,i,o,s,a,l,c,u,h,f=n("./src/model/physics/physics.ts"),p=n("./node_modules/three/build/three.module.js");function d(e,t){for(var n=0;n4&&void 0!==arguments[4]?arguments[4]:.9,o={dx:n-e,dy:r-t},s={x:o.dx*i+e,y:o.dy*i+t},a={dx:n-s.x,dy:r-s.y};this.context.beginPath(),this.context.moveTo(e,t),this.context.lineTo(s.x,s.y),this.context.moveTo(s.x+.5*a.dy,s.y-.5*a.dx),this.context.lineTo(s.x-.5*a.dy,s.y+.5*a.dx),this.context.lineTo(n,r),this.context.closePath(),this.context.stroke()}}],d(n.prototype,e),t&&d(n,t),n}();function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n{n.d(t,{Y:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{f:()=>f});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts"),s=n("./node_modules/three/build/three.module.js");function a(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){for(var n=0;n{n.d(t,{Z:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{l:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{s:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{var r;n.d(t,{t:()=>r}),function(e){e.BEGIN="BEGIN",e.BREAK="BREAK",e.WATCHAIM="WATCHAIM",e.AIM="AIM",e.HIT="HIT",e.STATIONARY="STATIONARY",e.CHAT="CHAT",e.ABORT="ABORT",e.PLACEBALL="PLACEBALL",e.REJOIN="REJOIN",e.RERACK="RERACK",e.STARTAIM="STARTAIM"}(r||(r={}))},"./src/events/gameevent.ts":(e,t,n)=>{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{Z:()=>i});var i=function e(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"type",void 0),r(this,"sequence",void 0)}},"./src/events/hitevent.ts":(e,t,n)=>{n.d(t,{O:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{I:()=>i});var i=function e(t,n){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"t",void 0),r(this,"key",void 0),this.t=t,this.key=n}},"./src/events/keyboard.ts":(e,t,n)=>{n.d(t,{N:()=>l});var r=n("./src/events/input.ts"),i=n("./node_modules/interactjs/dist/interact.min.js"),o=n.n(i);function s(e,t){for(var n=0;nMath.abs(i.movementY)&&(i.movementY=0)}),this.addHandlers(e),/Android|iPhone/i.test(navigator.userAgent)||(e.contentEditable="true")}return e=[{key:"getEvents",value:function(){var e=this,t=Object.keys(this.pressed).filter(function(e){return!/Shift/.test(e)}).filter(function(e){return!/Control/.test(e)}),n=Object.keys(this.pressed).some(function(e){return/Shift/.test(e)}),i=Object.keys(this.pressed).some(function(e){return/Control/.test(e)}),o=[];return t.forEach(function(t){var s=performance.now()-e.pressed[t];o.push(new r.I(i?s/3:s,n?"Shift"+t:t)),"Space"!=t&&(e.pressed[t]=performance.now())}),Object.keys(this.released).forEach(function(t){return o.push(new r.I(e.released[t],t+"Up"))}),this.released={},o}},{key:"addHandlers",value:function(e){var t=this;e.addEventListener("keydown",this.keydown),e.addEventListener("keyup",this.keyup),e.focus(),o()(e).draggable({listeners:{move:function(e){t.mousetouch(e)}}}),o()(e).gesturable({onmove:function(e){e.dx/=3,t.mousetouch(e)}})}}],s(n.prototype,e),t&&s(n,t),n}()},"./src/events/placeballevent.ts":(e,t,n)=>{n.d(t,{I:()=>h});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts");function s(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(e,t){for(var n=0;n{n.d(t,{K:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{H:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:0;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,u),(t="foul")in(e=o(n=c.call(this)))?Object.defineProperty(e,t,{value:0,enumerable:!0,configurable:!0,writable:!0}):e[t]=0,n.type=i.t.STARTAIM,n.foul=r,n}return n=[{key:"applyToController",value:function(e){return e.handleStartAim(this)}}],r=[{key:"fromJson",value:function(e){return new u(e.foul)}}],n&&s(u.prototype,n),r&&s(u,r),u}(r.Z)},"./src/events/stationaryevent.ts":(e,t,n)=>{n.d(t,{I:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{g:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{e:()=>m,Z:()=>r});var r,i=n("./src/utils/utils.ts"),o=n("./src/model/physics/physics.ts"),s=n("./node_modules/three/build/three.module.js"),a=n("./src/model/physics/constants.ts");function l(e,t){for(var n=0;nMath.PI/32?.01*a.R:a.R,i=this.lastPos.distanceTo(e);this.addTraceGiven(e,t,i,r,n)}}},{key:"addTraceGiven",value:function(e,t,n,r,i){var o=this.geometry.drawRange.count;0!==o&&n1&&i<1e-4&&o--,this.lastPos.copy(e),this.lastVel.copy(t),this.addPoint(e,o))}},{key:"addPoint",value:function(e,t){var n=3*t;n>this.positions.length||(this.positions[n++]=e.x,this.positions[n++]=e.y,this.positions[n]=e.z,this.geometry.setDrawRange(0,t+1),this.line.geometry.attributes.position.needsUpdate=!0)}}],l(n.prototype,e),t&&l(n,t),n}();function h(e,t){for(var n=0;nMath.abs(this.rvel.z))&&(this.setStationary(),!0)}},{key:"setStationary",value:function(){this.vel.copy(i.bM),this.rvel.copy(i.bM),this.state="Stationary"}},{key:"isRolling",value:function(){return 0!==this.vel.lengthSq()&&0!==this.rvel.lengthSq()&&(0,o.E9)(this.vel,this.rvel).length(){function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{k:()=>o}),function(e){e.Pot="Pot",e.Cushion="Cushion",e.Collision="Collision",e.Hit="Hit"}(i||(i={}));var i,o=function(){var e;function t(e,n,i,o){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),r(this,"type",void 0),r(this,"timestamp",void 0),r(this,"ballA",null),r(this,"ballB",null),r(this,"incidentSpeed",void 0),this.type=e,this.ballA=n,this.ballB=i,this.incidentSpeed=o,this.timestamp=Date.now()}return e=[{key:"pot",value:function(e,n){return new t("Pot",e,e,n)}},{key:"cushion",value:function(e,n){return new t("Cushion",e,e,n)}},{key:"collision",value:function(e,n,r){return new t("Collision",e,n,r)}},{key:"hit",value:function(e,n){return new t("Hit",e,e,n)}},{key:"isCueBallPotted",value:function(e,t){return t.some(function(t){return"Pot"==t.type&&t.ballA===e})}},{key:"isBallPottedNoFoul",value:function(e,n){return n.some(function(e){return"Pot"==e.type&&null!==e.ballA})&&!t.isCueBallPotted(e,n)}},{key:"pots",value:function(e){return e.filter(function(e){return"Pot"==e.type}).map(function(e){return e.ballA})}},{key:"potCount",value:function(e){return this.pots(e).length}},{key:"onlyRedsPotted",value:function(e){return this.pots(e).every(function(e){return e.id>6})}},{key:"firstCollision",value:function(e){var t=e.filter(function(e){return"Collision"===e.type});return t.length>0?t[0]:void 0}},{key:"isClearTable",value:function(e){var t=e.balls.filter(function(e){return e.onTable()});return 1===t.length&&t[0]===e.cueball}},{key:"isThreeCushionPoint",value:function(e,n){n=t.cueBallFirst(e,n).filter(function(t){return t.ballA===e});var r=new Set,i=0,o=!0,s=!1,a=void 0;try{for(var l,c=n[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){var u=l.value;if("Cushion"===u.type&&i++,"Collision"===u.type&&(r.add(u.ballB),2===r.size))return i>=3}}catch(e){s=!0,a=e}finally{try{o||null==c.return||c.return()}finally{if(s)throw a}}return!1}},{key:"cueBallFirst",value:function(e,t){return t.forEach(function(t){"Collision"===t.type&&t.ballB===e&&(t.ballB=t.ballA,t.ballA=e)}),t}}],function(e,t){for(var n=0;n{n.d(t,{Dt:()=>c,Ew:()=>v,G3:()=>w,Hz:()=>i,I:()=>o,Mz:()=>r,R:()=>f,Xm:()=>k,_5:()=>u,dE:()=>y,e:()=>p,f7:()=>g,fN:()=>m,g:()=>s,m:()=>h,mu:()=>a,zq:()=>b,zv:()=>l});var r,i,o,s=9.8,a=.00985,l=.15,c=.8,u=.024,h=.23,f=.03275,p=.86;function d(){r=a*h*s*2/3*u,i=7/(5*Math.sqrt(2))*f*a*h*s,o=.4*h*f*f}function v(e){f=e,d()}function m(e){h=e,d()}function y(e){a=e,d()}function b(e){u=e,d()}function g(e){l=e}function w(e){p=e}function k(e){c=e}d()},"./src/model/physics/knuckle.ts":(e,t,n)=>{n.d(t,{T:()=>a});var r=n("./src/model/physics/constants.ts"),i=n("./src/view/pocketgeometry.ts");function o(e,t){for(var n=0;n{n.d(t,{E9:()=>a,Fn:()=>R,IT:()=>h,NP:()=>g,QC:()=>u,Vp:()=>c,WL:()=>E,ZI:()=>f,al:()=>b,c0:()=>y,h_:()=>A,s0:()=>m,vZ:()=>w});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/utils/utils.ts"),o=n("./src/model/physics/constants.ts"),s=new r.Pa4;function a(e,t){return s.copy(e).addScaledVector((0,i.a1)(t),o.R)}var l={v:new r.Pa4,w:new r.Pa4};function c(e,t){var n=a(e,t).setZ(0);return l.v.copy((0,i.KO)(n).multiplyScalar(-o.zv*o.g)),l.w.copy((0,i.KO)((0,i.a1)(n)).multiplyScalar(2.5*o.zv*o.g/o.R)),l.w.setZ(-2.5*(o.Mz/(o.m*o.R*o.R))*Math.sign(t.z)),l}function u(e){var t=new r.Pa4(e.x,e.y,0).length(),n=5/7*o.Hz/(o.m*o.R)/t,i=5/7*o.Hz/(o.m*o.R*o.R)/t;return l.v.set(-n*e.y,n*e.x,0),l.w.set(-i*e.x,-i*e.y,-2.5*(o.Mz/(o.m*o.R*o.R))*Math.sign(e.z)),l}function h(e,t){var n=t.z;t.copy((0,i.a1)(e).multiplyScalar(1/o.R)),t.setZ(n)}function f(e,t,n,r){var o=r(t.clone().applyAxisAngle(i.up,e),n.clone().applyAxisAngle(i.up,e));return o.v.applyAxisAngle(i.up,-e),o.w.applyAxisAngle(i.up,-e),o}Object.freeze(l);var p=Math.asin(.1*o.R/o.R),d=Math.sin(p),v=Math.cos(p);function m(e,t){return new r.Pa4(e.x*d-e.z*v+o.R*t.y,-e.y-o.R*t.z*v+o.R*t.x*d)}function y(e){return e.x*v}function b(e){var t=3.5/o.m;return e.length()/t}function g(e){var t,n=1/o.m,i=.39+.257*(t=new r.Pa4(e/v,0,0)).x-.044*t.x*t.x;return o.Dt*((1+i)*e)/n}function w(e,t){var n=g(y(e));return b(m(e,t))<=n}function k(e,t){return{c:y(e),s:m(e,t),A:3.5/o.m,B:1/o.m}}function T(e,t){var n=k(e,t),r=n.c,i=n.s,s=n.A,a=n.B,l=(1+o.e)*(r/a);return P(-i.x/s*d-l*v,i.y/s,i.x/s*v-l*d)}function x(e,t){var n=k(e,t),r=n.c,i=n.B,s=(1+o.e)*(r/i),a=.471-.241*Math.atan2(Math.abs(e.y),e.x),l=Math.atan2(e.y,e.x),c=Math.cos(l);return P(-a*s*c*v-s*v,a*s*Math.sin(l),a*s*c*v-s*d)}function R(e,t){return w(e,t)?T(e,t):x(e,t)}function A(e,t){var n=T(e,t),r=x(e,t),i=Math.sign(e.y)===Math.sign(t.z)?Math.cos(Math.atan2(e.y,e.x)):1;return{v:r.v.lerp(n.v,i),w:r.w.lerp(n.w,i)}}function P(e,t,n){return{v:new r.Pa4(e/o.m,t/o.m),w:new r.Pa4(-o.R/o.I*t*d,o.R/o.I*(e*d-n*v),o.R/o.I*t*v)}}function E(e,t){var n=Math.atan2(-e.x,e.y),r=2.5*t.length()*(e.length()*o.R)/(o.R*o.R),s=t.clone().normalize();return(0,i.a1)(s).applyAxisAngle(s,n).multiplyScalar(r)}},"./src/model/physics/pocket.ts":(e,t,n)=>{n.d(t,{f:()=>l});var r=n("./src/model/ball.ts"),i=n("./src/model/physics/constants.ts"),o=n("./src/utils/utils.ts");function s(e,t){for(var n=0;nthis.radius-i.R){var s=this.pos.clone().sub(e.pos).normalize().setZ(0);n>-i.R/2&&e.vel.addScaledVector(s,7*i.R*t*i.g),0>e.vel.dot(s)&&(e.ballmesh.trace.forceTrace(e.pos),e.vel.x=s.x*e.vel.length()/2,e.vel.y=s.y*e.vel.length()/2)}var a=this.restingDepth(e);n{n.d(t,{i:()=>b});var r=n("./src/view/tablegeometry.ts"),i=n("./src/model/physics/physics.ts"),o=n("./src/view/pocketgeometry.ts"),s=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"bounceAny",value:function(e,n){var o=!(arguments.length>2)||void 0===arguments[2]||arguments[2],s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:i.h_,a=e.futurePosition(n);if(t.willBounceLong(a,o)){var l=a.y>r.H.tableY?-Math.PI/2:Math.PI/2;return t.bounceIn(l,e,s)}if(t.willBounceShort(a,o)){var c=a.x>r.H.tableX?0:Math.PI;return t.bounceIn(c,e,s)}}},{key:"willBounceShort",value:function(e,n){return n?t.willBounceShortSegment(o.u.pockets.pocketNW.knuckleSW.pos.y,o.u.pockets.pocketSW.knuckleNW.pos.y,e):t.willBounceShortSegment(r.H.Y,-r.H.Y,e)}},{key:"willBounceLong",value:function(e,n){return n?t.willBounceLongSegment(o.u.pockets.pocketNW.knuckleNE.pos.x,o.u.pockets.pocketN.knuckleNW.pos.x,e)||t.willBounceLongSegment(o.u.pockets.pocketN.knuckleNE.pos.x,o.u.pockets.pocketNE.knuckleNW.pos.x,e):t.willBounceLongSegment(-r.H.X,r.H.X,e)}},{key:"willBounceLongSegment",value:function(e,t,n){return n.x>e&&n.xr.H.tableY}},{key:"willBounceShortSegment",value:function(e,t,n){return n.y>t&&n.yr.H.tableX}},{key:"bounceIn",value:function(e,t,n){t.ballmesh.trace.forceTrace(t.futurePos);var r=(0,i.ZI)(e,t.vel,t.rvel,n);return t.vel.add(r.v),t.rvel.add(r.w),r.v.length()}}],function(e,t){for(var n=0;n100)throw Error("Depth exceeded resolving collisions");this.balls.forEach(function(t){t.update(e)})}},{key:"prepareAdvanceAll",value:function(e){var t=this;return this.pairs.every(function(n){return t.prepareAdvancePair(n.a,n.b,e)})&&this.balls.every(function(n){return t.prepareAdvanceToCushions(n,e)})}},{key:"prepareAdvancePair",value:function(e,t,n){if(c.willCollide(e,t,n)){var r=c.collide(e,t);return this.outcome.push(d.k.collision(e,t,r)),!1}return!0}},{key:"prepareAdvanceToCushions",value:function(e,t){if(!e.onTable())return!0;var n=e.futurePosition(t);if(Math.abs(n.y)1&&void 0!==arguments[1]?arguments[1]:this.cueball;return this.balls.filter(function(e){return e!==t}).some(function(t){return t.pos.distanceTo(e)<2*l.R})}}],t=[{key:"fromSerialised",value:function(e){var t=new n(e.balls.map(function(e){return a.e.fromSerialised(e)}));return t.updateFromSerialised(e),t}}],e&&m(n.prototype,e),t&&m(n,t),n}()},"./src/utils/gltf.ts":(e,t,n)=>{let r,i,o,s;n.d(t,{pC:()=>eE,MR:()=>eS});var a=n("./node_modules/three/build/three.module.js");function l(e,t=1/0,n=null){i||(i=new a._12(2,2,1,1)),o||(o=new a.jyz({uniforms:{blitTexture:new a.xWb(e)},vertexShader:` +"use strict";(self.webpackChunkbilliards=self.webpackChunkbilliards||[]).push([[465],{"./src/container/container.ts":(e,t,n)=>{n.d(t,{W:()=>ec});var r=n("./src/events/stationaryevent.ts"),i=n("./node_modules/three/build/three.module.js"),o=n("./src/utils/utils.ts"),s=n("./src/view/cameratop.ts"),a=n("./src/model/physics/constants.ts");function l(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:.08,n=this.height,r=this.camera.aspect<.8;if(this.camera.fov=r?60:40,n<10*a.R){var i=100*(10*a.R-n);this.camera.fov-=i*(r?3:1)}this.camera.position.lerp(e.pos.clone().addScaledVector((0,o.AA)(e.angle),-(18*a.R)),t),this.camera.position.z=n,this.camera.up=o.up,this.camera.lookAt(e.pos.clone().addScaledVector(o.up,n/2))}},{key:"adjustHeight",value:function(e){e=this.height<10*a.R?e/8:e,this.height=i.M8C.clamp(this.height+e,6*a.R,120*a.R),this.height>110*a.R&&this.suggestMode(this.topView),this.height<105*a.R&&this.suggestMode(this.aimView)}},{key:"suggestMode",value:function(e){this.mainMode===this.aimView&&(this.mode=e)}},{key:"forceMode",value:function(e){this.mode=e,this.mainMode=e}},{key:"forceMove",value:function(e){this.mode===this.aimView&&this.aimView(e,1)}},{key:"toggleMode",value:function(){this.mode===this.topView?this.mode=this.aimView:this.mode=this.topView,this.mainMode=this.mode}}],l(n.prototype,e),t&&l(n,t),n}(),h=n("./src/view/tablegeometry.ts");function f(e,t){for(var n=0;n0&&(null===(t=this.cuePowerElement)||void 0===t?void 0:t.value)&&(this.cuePowerElement.value=e)}}],_(n.prototype,e),t&&_(n,t),n}(),j=n("./src/controller/aim.ts"),N=n("./src/controller/playshot.ts"),B=n("./src/controller/watchshot.ts"),L=n("./src/controller/end.ts");function H(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function F(e,t){for(var n=0;nthis.sentTime+this.period||e.type!==z.t.AIM){this.flush(),this.apply(e),this.sentTime=performance.now();return}this.pending=e}}]),e&&K(t,e),t}(),W=n("./src/view/sliders.ts"),Y=n("./src/model/outcome.ts"),Z=n("./node_modules/jsoncrush/JSONCrush.js"),Q=n("./src/events/rerackevent.ts");function J(e,t){for(var n=0;n0&&"RERACK"===this.shots[e].type&&e--,e}},{key:"lastShot",value:function(){var e=this.last();return this.state(this.states[e],[this.shots[e]])}},{key:"currentBreak",value:function(){if(void 0!==this.breakStart)return this.state(this.states[this.breakStart],this.shots.slice(this.breakStart),this.breakStartTime,this.container.rules.previousBreak)}},{key:"state",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];return{init:e,shots:t,start:n,now:Date.now(),score:r,wholeGame:i}}},{key:"updateBreak",value:function(e){var t=this.container.rules.isPartOfBreak(e),n=this.container.rules.isEndOfGame(e),r=Y.k.potCount(e);if(t||this.breakLink(n),this.lastShotLink(t||n,r,Y.k.pots(e)),n&&this.breakLink(n),!t){this.breakStart=void 0;return}void 0===this.breakStart&&(this.breakStart=this.last(),this.breakStartTime=Date.now())}},{key:"lastShotLink",value:function(e,t,n){var r="#000000";n.length>0&&n.forEach(function(e){r="#"+e.ballmesh.color.getHexString()});var i="⚈".repeat(t>1?t-1:0)+(e?"⚈":"⚆"),o=JSON.stringify(this.lastShot());this.generateLink(i,o,r)}},{key:"breakLink",value:function(e){var t=this.currentBreak();if(t&&(e||t.shots.pop(),1!==t.shots.length)){var n=this.container.rules.previousBreak>0?this.container.rules.previousBreak:t.shots.length,r=JSON.stringify(t),i=Z.Z.crush(r);this.generateLink("break(".concat(n,")"),i,"black")}}},{key:"wholeGameLink",value:function(){var e=this.wholeGame(),t="frame(".concat(e.shots.length," shots)"),n=JSON.stringify(e),r=Z.Z.crush(n);this.generateLink(t,r,"black")}},{key:"generateLink",value:function(e,t,n){var r="".concat(this.replayUrl).concat(encodeURIComponent(t)),i='').concat(e,"");this.container.eventQueue.push(new G.s(null,"".concat(i)))}}],J(n.prototype,e),t&&J(n,t),n}(),ee=n("./src/controller/rules/rulefactory.ts"),et=n("./src/events/breakevent.ts");function en(e,t){for(var n=0;n').concat(e,"")));r.push(new G.s(null,s))})},this.redo.onclick=function(e){var r=new et.l(t.init,t.shots);r.retry=!0,n.interuptEventQueue(r)},this.replay.onclick=function(e){n.interuptEventQueue(t)}}}},{key:"interuptEventQueue",value:function(e){this.container.table.halt();var t=this.container.eventQueue;t.length=0,t.push(new r.I),t.push(e)}},{key:"getElement",value:function(e){return document.getElementById(e)}}],en(n.prototype,e),t&&en(n,t),n}();function eo(e,t){for(var n=0;n0?this.element.innerHTML="Break
"+e:this.element.innerHTML="")}},{key:"getElement",value:function(e){return document.getElementById(e)}}]),e&&eo(t,e),t}();function ea(e,t){for(var n=0;n0;){this.lastEventTime=this.last;var t=this.inputQueue.shift();t&&this.updateController(this.controller.handleInput(t))}if(this.table.allStationary()){var n=this.eventQueue.shift();n&&(this.lastEventTime=performance.now(),this.updateController(n.applyToController(this.controller)))}}},{key:"animate",value:function(e){var t=this;this.advance((e-this.last)/1e3),this.last=e,this.processEvents(),(e{n.d(t,{h:()=>u});var r=n("./src/controller/controller.ts"),i=n("./src/controller/controllerbase.ts"),o=n("./src/controller/playshot.ts"),s=n("./src/controller/replay.ts");function a(e,t){for(var n=0;n{n.d(t,{II:()=>i.I,OF:()=>r.O,Qr:()=>s}),n("./src/events/beginevent.ts"),n("./src/events/aimevent.ts");var r=n("./src/events/hitevent.ts"),i=n("./src/events/input.ts");function o(e,t){for(var n=0;n{n.d(t,{r:()=>f});var r=n("./src/controller/controller.ts"),i=n("./src/controller/end.ts"),o=n("./src/utils/gltf.ts"),s=n("./src/model/outcome.ts"),a=n("./node_modules/three/build/three.module.js");function l(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function c(e,t){for(var n=0;n{function r(e,t){for(var n=0;ns});var s=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}(a,e);var t,n,s=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n,r=i(a);if(t){var o=i(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(e=n)&&("object"==(e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)||"function"==typeof e)?e:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this)});function a(){return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),s.apply(this,arguments)}return r(a.prototype,[{key:"handleChat",value:function(e){var t=e.sender?"".concat(e.sender,":"):"",n="".concat(t," ").concat(e.message);return this.container.chat.showMessage(n),this}}]),n&&r(a,n),a}(n("./src/controller/controller.ts").Qr)},"./src/controller/placeball.ts":(e,t,n)=>{n.d(t,{a:()=>v});var r=n("./src/controller/controllerbase.ts"),i=n("./src/controller/controller.ts"),o=n("./src/controller/aim.ts"),s=n("./src/events/breakevent.ts"),a=n("./src/model/physics/constants.ts"),l=n("./node_modules/three/build/three.module.js"),c=n("./src/view/cuemesh.ts"),u=n("./src/utils/utils.ts");function h(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(e,t){for(var n=0;n{function r(e,t){for(var n=0;ns});var s=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}(l,e);var t,n,s,a=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n,r=i(l);if(t){var o=i(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(e=n)&&("object"==(e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)||"function"==typeof e)?e:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this)});function l(e){var t;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,l),(t=a.call(this,e)).hit(),t}return n=[{key:"handleStationary",value:function(e){var t=this.container.table,n=t.outcome,r=this.container.rules.update(n);return this.container.recorder.updateBreak(n),t.cue.aimAtNext(t.cueball,this.container.rules.nextCandidateBall()),r}},{key:"handleInput",value:function(e){return this.commonKeyHandler(e),this}}],r(l.prototype,n),s&&r(l,s),l}(n("./src/controller/controllerbase.ts").r)},"./src/controller/replay.ts":(e,t,n)=>{n.d(t,{U:()=>y});var r=n("./src/events/hitevent.ts"),i=n("./src/controller/controllerbase.ts"),o=n("./src/events/aimevent.ts"),s=n("./src/events/breakevent.ts"),a=n("./src/controller/aim.ts"),l=n("./src/events/eventtype.ts"),c=n("./src/events/rerackevent.ts");function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1500;if(!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,u),p(h(r=i.call(this,e)),"delay",void 0),p(h(r),"shots",void 0),p(h(r),"firstShot",void 0),p(h(r),"timer",void 0),p(h(r),"init",void 0),r.init=t,r.shots=m(n),r.firstShot=r.shots[0],r.delay=a,r.container.table.showTraces(!0),r.container.table.updateFromShortSerialised(r.init),o){var l=new s.l(t,n);l.retry=!0,r.container.eventQueue.push(l)}else r.container.view.camera.forceMode(r.container.view.camera.topView),r.playNextShot(1.5*r.delay);return r}return f(u.prototype,[{key:"playNextShot",value:function(e){var t=this,n=this.shots.shift();if((null==n?void 0:n.type)===l.t.RERACK){c.K.fromJson(n.ballinfo).applyToController(this),this.shots.length>0&&this.playNextShot(e);return}var i=o.f.fromJson(n);this.container.table.cueball=this.container.table.balls[i.i],this.container.table.cueball.pos.copy(i.pos),this.container.table.cue.aim=i,this.container.table.cue.updateAimInput(),this.container.table.cue.t=1,clearTimeout(this.timer),this.timer=setTimeout(function(){t.container.eventQueue.push(new r.O(t.container.table.cue.aim)),t.timer=void 0},e)}},{key:"handleHit",value:function(e){return this.hit(),this}},{key:"handleStationary",value:function(e){return this.shots.length>0&&void 0===this.timer&&this.playNextShot(this.delay),this}},{key:"handleInput",value:function(e){return this.commonKeyHandler(e),this}},{key:"handleBreak",value:function(e){return(this.container.table.updateFromShortSerialised(e.init),this.shots=m(e.shots),this.container.table.showSpin(!0),e.retry)?this.retry():(this.playNextShot(this.delay),this)}},{key:"retry",value:function(){clearTimeout(this.timer),this.timer=void 0,this.container.table.updateFromShortSerialised(this.init);var e=o.f.fromJson(this.firstShot);return this.container.table.cueball=this.container.table.balls[e.i],this.container.rules.cueball=this.container.table.cueball,this.container.table.cueball.pos.copy(e.pos),this.container.table.cue.aim=e,this.container.view.camera.forceMode(this.container.view.camera.aimView),new a.h(this.container)}}]),n&&f(u,n),u}(i.r)},"./src/controller/rules/rulefactory.ts":(e,t,n)=>{n.d(t,{N:()=>I});var r=n("./src/events/watchevent.ts"),i=n("./src/utils/rack.ts"),o=n("./node_modules/three/build/three.module.js"),s=n("./src/controller/aim.ts"),a=n("./src/controller/placeball.ts"),l=n("./src/controller/watchaim.ts"),c=n("./src/events/chatevent.ts"),u=n("./src/events/placeballevent.ts"),h=n("./src/model/outcome.ts"),f=n("./src/model/table.ts"),p=n("./src/utils/utils.ts"),d=n("./src/controller/end.ts"),v=n("./src/model/physics/constants.ts"),m=n("./src/utils/respot.ts"),y=n("./src/view/tablegeometry.ts"),b=n("./src/events/startaimevent.ts");function g(e,t){for(var n=0;n{n.d(t,{x:()=>T});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/events/watchevent.ts"),o=n("./src/model/outcome.ts"),s=n("./src/utils/rack.ts"),a=n("./src/utils/respot.ts"),l=n("./src/controller/aim.ts"),c=n("./src/controller/watchaim.ts"),u=n("./src/events/chatevent.ts"),h=n("./src/controller/end.ts"),f=n("./src/model/table.ts"),p=n("./src/view/tablegeometry.ts"),d=n("./src/controller/placeball.ts"),v=n("./src/events/placeballevent.ts"),m=n("./src/utils/utils.ts"),y=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"shotInfo",value:function(e,n,r){var i=o.k.firstCollision(n);return{pots:o.k.potCount(n),firstCollision:i,legalFirstCollision:t.isLegalFirstCollision(e,r,i),whitePotted:o.k.isCueBallPotted(e.cueball,n)}}},{key:"isLegalFirstCollision",value:function(e,n,r){if(!r)return!1;var i=r.ballB.id,o=t.coloursOnTable(e).filter(function(e){return e.id0;return n?i>=7:!o}},{key:"respotAllPottedColours",value:function(e,t){return o.k.pots(t).filter(function(e){return e.id<7}).filter(function(e){return 0!==e.id}).map(function(t){return a.s.respot(t,e)})}},{key:"redsOnTable",value:function(e){return e.balls.slice(7).filter(function(e){return e.onTable()})}},{key:"coloursOnTable",value:function(e){return e.balls.slice(1,7).filter(function(e){return e.onTable()})}}],function(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=Array(t);n0,this.switchPlayer()}return this.targetIsRed?this.targetRedRule(e,t):this.targetColourRule(e,t)}},{key:"targetRedRule",value:function(e,t){return(console.log("applying target red rule"),t.legalFirstCollision&&o.k.onlyRedsPotted(e))?(this.currentBreak+=t.pots,this.targetIsRed=!1,this.previousPotRed=!0,this.container.hud.updateBreak(this.currentBreak),this.continueBreak()):(this.foulPoints=this.foulCalculation(e,t),this.respot(e),t.whitePotted)?this.whiteInHand():this.switchPlayer()}},{key:"targetColourRule",value:function(e,t){if(console.log("applying target colour rule"),t.whitePotted)return this.respot(e),this.whiteInHand();if(t.pots>1)return this.foulPoints=this.foulCalculation(e,t),this.respot(e),this.switchPlayer();if(o.k.pots(e)[0].id>6)return this.foulPoints=this.foulCalculation(e,t),this.switchPlayer();this.targetIsRed=y.redsOnTable(this.container.table).length>0;var n=o.k.pots(e)[0].id;if(!this.previousPotRed){var r=y.coloursOnTable(this.container.table).filter(function(e){return e.id0;if(!t.legalFirstCollision||r)return this.foulPoints=this.foulCalculation(e,t),this.respot(e),this.switchPlayer()}return this.previousPotRed&&this.respot(e),this.currentBreak+=n+1,this.previousPotRed=!1,this.container.hud.updateBreak(this.currentBreak),this.continueBreak()}},{key:"foulCalculation",value:function(e,t){var n,r,i,s,a=o.k.pots(e).map(function(e){return e.id}).filter(function(e){return e<7}),l=null!==(s=null===(i=t.firstCollision)||void 0===i?void 0:null===(r=i.ballB)||void 0===r?void 0:r.id)&&void 0!==s?s:0;return l>6&&(l=0),(n=Math).max.apply(n,[3,l].concat(function(e){if(Array.isArray(e))return g(e)}(a)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(a)||function(e,t){if(e){if("string"==typeof e)return g(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return g(e,t)}}(a)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()))+1}},{key:"tableGeometry",value:function(){p.H.hasPockets=!0}},{key:"table",value:function(){var e=new f.i(this.rack());return this.cueball=e.cueball,e}},{key:"otherPlayersCueBall",value:function(){return this.cueball}},{key:"secondToPlay",value:function(){}},{key:"isPartOfBreak",value:function(e){return this.currentBreak>0}},{key:"isEndOfGame",value:function(e){return o.k.isClearTable(this.container.table)&&this.currentBreak>0}},{key:"allowsPlaceBall",value:function(){return!0}},{key:"asset",value:function(){return n.tablemodel}},{key:"startTurn",value:function(){this.previousPotRed=!1,this.targetIsRed=y.redsOnTable(this.container.table).length>0,this.previousBreak=this.currentBreak,this.currentBreak=0,this.container.hud.updateBreak(this.currentBreak)}},{key:"rack",value:function(){return s.F.snooker()}},{key:"nextCandidateBall",value:function(){var e=this.container.table,t=y.redsOnTable(e),n=y.coloursOnTable(e);return this.previousPotRed?a.s.closest(e.cueball,n):t.length>0?a.s.closest(e.cueball,t):n.length>0?n[0]:void 0}},{key:"placeBall",value:function(e){if(e){var t=new r.Pa4(s.F.baulk,s.F.sixth),n=new r.Pa4(s.F.baulk-s.F.sixth,-s.F.sixth);return e.clamp(n,t)}return new r.Pa4(s.F.baulk,-s.F.sixth/3,0)}},{key:"switchPlayer",value:function(){this.foulPoints>0&&console.log("foul, ".concat(this.foulPoints," to opponent")),console.log("end of break, switch player");var e=this.container.table;return(console.log(e.cue.aim),this.container.sendEvent(new b.H(this.foulPoints)),this.container.isSinglePlayer)?(this.container.sendEvent(new i.g(e.serialise())),this.startTurn(),new l.h(this.container)):new c.Q(this.container)}},{key:"continueBreak",value:function(){var e=this.container.table;return(this.container.sound.playSuccess(e.inPockets()),o.k.isClearTable(e))?(this.container.eventQueue.push(new u.s(null,"game over")),this.container.recorder.wholeGameLink(),new h.C(this.container)):(this.container.sendEvent(new i.g(e.serialise())),new l.h(this.container))}},{key:"whiteInHand",value:function(){return(this.foulPoints>0&&console.log("foul, ".concat(this.foulPoints," to opponent")),this.startTurn(),this.container.isSinglePlayer)?new d.a(this.container):(this.container.sendEvent(new v.I(m.bM,!0)),new c.Q(this.container))}},{key:"update",value:function(e){return this.snookerrule(e)}},{key:"respot",value:function(e){var t=y.respotAllPottedColours(this.container.table,e);if(t.length>0){var n={balls:t.map(function(e){return e.serialise()}),rerack:!0},r=new i.g(n);this.container.sendEvent(r),this.container.recorder.record(r)}}}],w(n.prototype,e),t&&w(n,t),n}();k(T,"tablemodel","models/snooker.min.gltf")},"./src/controller/watchaim.ts":(e,t,n)=>{n.d(t,{Q:()=>a});var r=n("./src/controller/watchshot.ts");function i(e,t){for(var n=0;n{n.d(t,{O:()=>u});var r=n("./src/controller/aim.ts"),i=n("./src/controller/watchaim.ts"),o=n("./src/controller/controllerbase.ts"),s=n("./src/controller/placeball.ts");function a(e,t){for(var n=0;n{var r,i,o,s,a,l,c,u,h,f=n("./src/model/physics/physics.ts"),p=n("./node_modules/three/build/three.module.js");function d(e,t){for(var n=0;n4&&void 0!==arguments[4]?arguments[4]:.9,o={dx:n-e,dy:r-t},s={x:o.dx*i+e,y:o.dy*i+t},a={dx:n-s.x,dy:r-s.y};this.context.beginPath(),this.context.moveTo(e,t),this.context.lineTo(s.x,s.y),this.context.moveTo(s.x+.5*a.dy,s.y-.5*a.dx),this.context.lineTo(s.x-.5*a.dy,s.y+.5*a.dx),this.context.lineTo(n,r),this.context.closePath(),this.context.stroke()}}],d(n.prototype,e),t&&d(n,t),n}();function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n{n.d(t,{Y:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{f:()=>f});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts"),s=n("./node_modules/three/build/three.module.js");function a(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){for(var n=0;n{n.d(t,{Z:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{l:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{s:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{var r;n.d(t,{t:()=>r}),function(e){e.BEGIN="BEGIN",e.BREAK="BREAK",e.WATCHAIM="WATCHAIM",e.AIM="AIM",e.HIT="HIT",e.STATIONARY="STATIONARY",e.CHAT="CHAT",e.ABORT="ABORT",e.PLACEBALL="PLACEBALL",e.REJOIN="REJOIN",e.RERACK="RERACK",e.STARTAIM="STARTAIM"}(r||(r={}))},"./src/events/gameevent.ts":(e,t,n)=>{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{Z:()=>i});var i=function e(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"type",void 0),r(this,"sequence",void 0)}},"./src/events/hitevent.ts":(e,t,n)=>{n.d(t,{O:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{I:()=>i});var i=function e(t,n){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"t",void 0),r(this,"key",void 0),this.t=t,this.key=n}},"./src/events/keyboard.ts":(e,t,n)=>{n.d(t,{N:()=>l});var r=n("./src/events/input.ts"),i=n("./node_modules/interactjs/dist/interact.min.js"),o=n.n(i);function s(e,t){for(var n=0;nMath.abs(i.movementY)&&(i.movementY=0)}),this.addHandlers(e),/Android|iPhone/i.test(navigator.userAgent)||(e.contentEditable="true")}return e=[{key:"getEvents",value:function(){var e=this,t=Object.keys(this.pressed).filter(function(e){return!/Shift/.test(e)}).filter(function(e){return!/Control/.test(e)}),n=Object.keys(this.pressed).some(function(e){return/Shift/.test(e)}),i=Object.keys(this.pressed).some(function(e){return/Control/.test(e)}),o=[];return t.forEach(function(t){var s=performance.now()-e.pressed[t];o.push(new r.I(i?s/3:s,n?"Shift"+t:t)),"Space"!=t&&(e.pressed[t]=performance.now())}),Object.keys(this.released).forEach(function(t){return o.push(new r.I(e.released[t],t+"Up"))}),this.released={},o}},{key:"addHandlers",value:function(e){var t=this;e.addEventListener("keydown",this.keydown),e.addEventListener("keyup",this.keyup),e.focus(),o()(e).draggable({listeners:{move:function(e){t.mousetouch(e)}}}),o()(e).gesturable({onmove:function(e){e.dx/=3,t.mousetouch(e)}})}}],s(n.prototype,e),t&&s(n,t),n}()},"./src/events/placeballevent.ts":(e,t,n)=>{n.d(t,{I:()=>h});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts");function s(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(e,t){for(var n=0;n{n.d(t,{K:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{H:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:0;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,u),(t="foul")in(e=o(n=c.call(this)))?Object.defineProperty(e,t,{value:0,enumerable:!0,configurable:!0,writable:!0}):e[t]=0,n.type=i.t.STARTAIM,n.foul=r,n}return n=[{key:"applyToController",value:function(e){return e.handleStartAim(this)}}],r=[{key:"fromJson",value:function(e){return new u(e.foul)}}],n&&s(u.prototype,n),r&&s(u,r),u}(r.Z)},"./src/events/stationaryevent.ts":(e,t,n)=>{n.d(t,{I:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{g:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{e:()=>m,Z:()=>r});var r,i=n("./src/utils/utils.ts"),o=n("./src/model/physics/physics.ts"),s=n("./node_modules/three/build/three.module.js"),a=n("./src/model/physics/constants.ts");function l(e,t){for(var n=0;nMath.PI/32?.01*a.R:a.R,i=this.lastPos.distanceTo(e);this.addTraceGiven(e,t,i,r,n)}}},{key:"addTraceGiven",value:function(e,t,n,r,i){var o=this.geometry.drawRange.count;0!==o&&n1&&i<1e-4&&o--,this.lastPos.copy(e),this.lastVel.copy(t),this.addPoint(e,o))}},{key:"addPoint",value:function(e,t){var n=3*t;n>this.positions.length||(this.positions[n++]=e.x,this.positions[n++]=e.y,this.positions[n]=e.z,this.geometry.setDrawRange(0,t+1),this.line.geometry.attributes.position.needsUpdate=!0)}}],l(n.prototype,e),t&&l(n,t),n}();function h(e,t){for(var n=0;nMath.abs(this.rvel.z))&&(this.setStationary(),!0)}},{key:"setStationary",value:function(){this.vel.copy(i.bM),this.rvel.copy(i.bM),this.state="Stationary"}},{key:"isRolling",value:function(){return 0!==this.vel.lengthSq()&&0!==this.rvel.lengthSq()&&(0,o.E9)(this.vel,this.rvel).length(){function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{k:()=>o}),function(e){e.Pot="Pot",e.Cushion="Cushion",e.Collision="Collision",e.Hit="Hit"}(i||(i={}));var i,o=function(){var e;function t(e,n,i,o){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),r(this,"type",void 0),r(this,"timestamp",void 0),r(this,"ballA",null),r(this,"ballB",null),r(this,"incidentSpeed",void 0),this.type=e,this.ballA=n,this.ballB=i,this.incidentSpeed=o,this.timestamp=Date.now()}return e=[{key:"pot",value:function(e,n){return new t("Pot",e,e,n)}},{key:"cushion",value:function(e,n){return new t("Cushion",e,e,n)}},{key:"collision",value:function(e,n,r){return new t("Collision",e,n,r)}},{key:"hit",value:function(e,n){return new t("Hit",e,e,n)}},{key:"isCueBallPotted",value:function(e,t){return t.some(function(t){return"Pot"==t.type&&t.ballA===e})}},{key:"isBallPottedNoFoul",value:function(e,n){return n.some(function(e){return"Pot"==e.type&&null!==e.ballA})&&!t.isCueBallPotted(e,n)}},{key:"pots",value:function(e){return e.filter(function(e){return"Pot"==e.type}).map(function(e){return e.ballA})}},{key:"potCount",value:function(e){return this.pots(e).length}},{key:"onlyRedsPotted",value:function(e){return this.pots(e).every(function(e){return e.id>6})}},{key:"firstCollision",value:function(e){var t=e.filter(function(e){return"Collision"===e.type});return t.length>0?t[0]:void 0}},{key:"isClearTable",value:function(e){var t=e.balls.filter(function(e){return e.onTable()});return 1===t.length&&t[0]===e.cueball}},{key:"isThreeCushionPoint",value:function(e,n){n=t.cueBallFirst(e,n).filter(function(t){return t.ballA===e});var r=new Set,i=0,o=!0,s=!1,a=void 0;try{for(var l,c=n[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){var u=l.value;if("Cushion"===u.type&&i++,"Collision"===u.type&&(r.add(u.ballB),2===r.size))return i>=3}}catch(e){s=!0,a=e}finally{try{o||null==c.return||c.return()}finally{if(s)throw a}}return!1}},{key:"cueBallFirst",value:function(e,t){return t.forEach(function(t){"Collision"===t.type&&t.ballB===e&&(t.ballB=t.ballA,t.ballA=e)}),t}}],function(e,t){for(var n=0;n{n.d(t,{Dt:()=>c,Ew:()=>v,G3:()=>w,Hz:()=>i,I:()=>o,Mz:()=>r,R:()=>f,Xm:()=>k,_5:()=>u,dE:()=>y,e:()=>p,f7:()=>g,fN:()=>m,g:()=>s,m:()=>h,mu:()=>a,zq:()=>b,zv:()=>l});var r,i,o,s=9.8,a=.00985,l=.15,c=.8,u=.024,h=.23,f=.03275,p=.86;function d(){r=a*h*s*2/3*u,i=7/(5*Math.sqrt(2))*f*a*h*s,o=.4*h*f*f}function v(e){f=e,d()}function m(e){h=e,d()}function y(e){a=e,d()}function b(e){u=e,d()}function g(e){l=e}function w(e){p=e}function k(e){c=e}d()},"./src/model/physics/knuckle.ts":(e,t,n)=>{n.d(t,{T:()=>a});var r=n("./src/model/physics/constants.ts"),i=n("./src/view/pocketgeometry.ts");function o(e,t){for(var n=0;n{n.d(t,{E9:()=>a,Fn:()=>R,IT:()=>h,NP:()=>g,QC:()=>u,Vp:()=>c,WL:()=>E,ZI:()=>f,al:()=>b,c0:()=>y,h_:()=>A,s0:()=>m,vZ:()=>w});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/utils/utils.ts"),o=n("./src/model/physics/constants.ts"),s=new r.Pa4;function a(e,t){return s.copy(e).addScaledVector((0,i.a1)(t),o.R)}var l={v:new r.Pa4,w:new r.Pa4};function c(e,t){var n=a(e,t).setZ(0);return l.v.copy((0,i.KO)(n).multiplyScalar(-o.zv*o.g)),l.w.copy((0,i.KO)((0,i.a1)(n)).multiplyScalar(2.5*o.zv*o.g/o.R)),l.w.setZ(-2.5*(o.Mz/(o.m*o.R*o.R))*Math.sign(t.z)),l}function u(e){var t=new r.Pa4(e.x,e.y,0).length(),n=5/7*o.Hz/(o.m*o.R)/t,i=5/7*o.Hz/(o.m*o.R*o.R)/t;return l.v.set(-n*e.y,n*e.x,0),l.w.set(-i*e.x,-i*e.y,-2.5*(o.Mz/(o.m*o.R*o.R))*Math.sign(e.z)),l}function h(e,t){var n=t.z;t.copy((0,i.a1)(e).multiplyScalar(1/o.R)),t.setZ(n)}function f(e,t,n,r){var o=r(t.clone().applyAxisAngle(i.up,e),n.clone().applyAxisAngle(i.up,e));return o.v.applyAxisAngle(i.up,-e),o.w.applyAxisAngle(i.up,-e),o}Object.freeze(l);var p=Math.asin(.1*o.R/o.R),d=Math.sin(p),v=Math.cos(p);function m(e,t){return new r.Pa4(e.x*d-e.z*v+o.R*t.y,-e.y-o.R*t.z*v+o.R*t.x*d)}function y(e){return e.x*v}function b(e){var t=3.5/o.m;return e.length()/t}function g(e){var t,n=1/o.m,i=.39+.257*(t=new r.Pa4(e/v,0,0)).x-.044*t.x*t.x;return o.Dt*((1+i)*e)/n}function w(e,t){var n=g(y(e));return b(m(e,t))<=n}function k(e,t){return{c:y(e),s:m(e,t),A:3.5/o.m,B:1/o.m}}function T(e,t){var n=k(e,t),r=n.c,i=n.s,s=n.A,a=n.B,l=(1+o.e)*(r/a);return P(-i.x/s*d-l*v,i.y/s,i.x/s*v-l*d)}function x(e,t){var n=k(e,t),r=n.c,i=n.B,s=(1+o.e)*(r/i),a=.471-.241*Math.atan2(Math.abs(e.y),e.x),l=Math.atan2(e.y,e.x),c=Math.cos(l);return P(-a*s*c*v-s*v,a*s*Math.sin(l),a*s*c*v-s*d)}function R(e,t){return w(e,t)?T(e,t):x(e,t)}function A(e,t){var n=T(e,t),r=x(e,t),i=Math.sign(e.y)===Math.sign(t.z)?Math.cos(Math.atan2(e.y,e.x)):1;return{v:r.v.lerp(n.v,i),w:r.w.lerp(n.w,i)}}function P(e,t,n){return{v:new r.Pa4(e/o.m,t/o.m),w:new r.Pa4(-o.R/o.I*t*d,o.R/o.I*(e*d-n*v),o.R/o.I*t*v)}}function E(e,t){var n=Math.atan2(-e.x,e.y),r=2.5*t.length()*(e.length()*o.R)/(o.R*o.R),s=t.clone().normalize();return(0,i.a1)(s).applyAxisAngle(s,n).multiplyScalar(r)}},"./src/model/physics/pocket.ts":(e,t,n)=>{n.d(t,{f:()=>l});var r=n("./src/model/ball.ts"),i=n("./src/model/physics/constants.ts"),o=n("./src/utils/utils.ts");function s(e,t){for(var n=0;nthis.radius-i.R){var s=this.pos.clone().sub(e.pos).normalize().setZ(0);n>-i.R/2&&e.vel.addScaledVector(s,7*i.R*t*i.g),0>e.vel.dot(s)&&(e.ballmesh.trace.forceTrace(e.pos),e.vel.x=s.x*e.vel.length()/2,e.vel.y=s.y*e.vel.length()/2)}var a=this.restingDepth(e);n{n.d(t,{i:()=>b});var r=n("./src/view/tablegeometry.ts"),i=n("./src/model/physics/physics.ts"),o=n("./src/view/pocketgeometry.ts"),s=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"bounceAny",value:function(e,n){var o=!(arguments.length>2)||void 0===arguments[2]||arguments[2],s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:i.h_,a=e.futurePosition(n);if(t.willBounceLong(a,o)){var l=a.y>r.H.tableY?-Math.PI/2:Math.PI/2;return t.bounceIn(l,e,s)}if(t.willBounceShort(a,o)){var c=a.x>r.H.tableX?0:Math.PI;return t.bounceIn(c,e,s)}}},{key:"willBounceShort",value:function(e,n){return n?t.willBounceShortSegment(o.u.pockets.pocketNW.knuckleSW.pos.y,o.u.pockets.pocketSW.knuckleNW.pos.y,e):t.willBounceShortSegment(r.H.Y,-r.H.Y,e)}},{key:"willBounceLong",value:function(e,n){return n?t.willBounceLongSegment(o.u.pockets.pocketNW.knuckleNE.pos.x,o.u.pockets.pocketN.knuckleNW.pos.x,e)||t.willBounceLongSegment(o.u.pockets.pocketN.knuckleNE.pos.x,o.u.pockets.pocketNE.knuckleNW.pos.x,e):t.willBounceLongSegment(-r.H.X,r.H.X,e)}},{key:"willBounceLongSegment",value:function(e,t,n){return n.x>e&&n.xr.H.tableY}},{key:"willBounceShortSegment",value:function(e,t,n){return n.y>t&&n.yr.H.tableX}},{key:"bounceIn",value:function(e,t,n){t.ballmesh.trace.forceTrace(t.futurePos);var r=(0,i.ZI)(e,t.vel,t.rvel,n);return t.vel.add(r.v),t.rvel.add(r.w),r.v.length()}}],function(e,t){for(var n=0;n100)throw Error("Depth exceeded resolving collisions");this.balls.forEach(function(t){t.update(e)})}},{key:"prepareAdvanceAll",value:function(e){var t=this;return this.pairs.every(function(n){return t.prepareAdvancePair(n.a,n.b,e)})&&this.balls.every(function(n){return t.prepareAdvanceToCushions(n,e)})}},{key:"prepareAdvancePair",value:function(e,t,n){if(c.willCollide(e,t,n)){var r=c.collide(e,t);return this.outcome.push(d.k.collision(e,t,r)),!1}return!0}},{key:"prepareAdvanceToCushions",value:function(e,t){if(!e.onTable())return!0;var n=e.futurePosition(t);if(Math.abs(n.y)1&&void 0!==arguments[1]?arguments[1]:this.cueball;return this.balls.filter(function(e){return e!==t}).some(function(t){return t.pos.distanceTo(e)<2*l.R})}}],t=[{key:"fromSerialised",value:function(e){var t=new n(e.balls.map(function(e){return a.e.fromSerialised(e)}));return t.updateFromSerialised(e),t}}],e&&m(n.prototype,e),t&&m(n,t),n}()},"./src/utils/gltf.ts":(e,t,n)=>{let r,i,o,s;n.d(t,{pC:()=>eE,MR:()=>eS});var a=n("./node_modules/three/build/three.module.js");function l(e,t=1/0,n=null){i||(i=new a._12(2,2,1,1)),o||(o=new a.jyz({uniforms:{blitTexture:new a.xWb(e)},vertexShader:` varying vec2 vUv; void main(){ vUv = uv; diff --git a/dist/index.js b/dist/index.js index 44eb793..d22b11f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,4 +1,4 @@ -"use strict";(self.webpackChunkbilliards=self.webpackChunkbilliards||[]).push([[826],{"./src/container/container.ts":(e,t,n)=>{n.d(t,{W:()=>ec});var r=n("./src/events/stationaryevent.ts"),i=n("./node_modules/three/build/three.module.js"),o=n("./src/utils/utils.ts"),s=n("./src/view/cameratop.ts"),a=n("./src/model/physics/constants.ts");function l(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:.08,n=this.height,r=this.camera.aspect<.8;if(this.camera.fov=r?60:40,n<10*a.R){var i=100*(10*a.R-n);this.camera.fov-=i*(r?3:1)}this.camera.position.lerp(e.pos.clone().addScaledVector((0,o.AA)(e.angle),-(18*a.R)),t),this.camera.position.z=n,this.camera.up=o.up,this.camera.lookAt(e.pos.clone().addScaledVector(o.up,n/2))}},{key:"adjustHeight",value:function(e){e=this.height<10*a.R?e/8:e,this.height=i.M8C.clamp(this.height+e,6*a.R,120*a.R),this.height>110*a.R&&this.suggestMode(this.topView),this.height<105*a.R&&this.suggestMode(this.aimView)}},{key:"suggestMode",value:function(e){this.mainMode===this.aimView&&(this.mode=e)}},{key:"forceMode",value:function(e){this.mode=e,this.mainMode=e}},{key:"forceMove",value:function(e){this.mode===this.aimView&&this.aimView(e,1)}},{key:"toggleMode",value:function(){this.mode===this.topView?this.mode=this.aimView:this.mode=this.topView,this.mainMode=this.mode}}],l(n.prototype,e),t&&l(n,t),n}(),h=n("./src/view/tablegeometry.ts");function f(e,t){for(var n=0;n0&&(null===(t=this.cuePowerElement)||void 0===t?void 0:t.value)&&(this.cuePowerElement.value=e)}}],_(n.prototype,e),t&&_(n,t),n}(),j=n("./src/controller/aim.ts"),N=n("./src/controller/playshot.ts"),B=n("./src/controller/watchshot.ts"),L=n("./src/controller/end.ts");function H(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function F(e,t){for(var n=0;nthis.sentTime+this.period||e.type!==z.t.AIM){this.flush(),this.apply(e),this.sentTime=performance.now();return}this.pending=e}}]),e&&K(t,e),t}(),W=n("./src/view/sliders.ts"),Y=n("./src/model/outcome.ts"),Z=n("./node_modules/jsoncrush/JSONCrush.js"),J=n("./src/events/rerackevent.ts");function q(e,t){for(var n=0;n0&&"RERACK"===this.shots[e].type&&e--,e}},{key:"lastShot",value:function(){var e=this.last();return this.state(this.states[e],[this.shots[e]])}},{key:"currentBreak",value:function(){if(void 0!==this.breakStart)return this.state(this.states[this.breakStart],this.shots.slice(this.breakStart),this.breakStartTime,this.container.rules.previousBreak)}},{key:"state",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;return{init:e,shots:t,start:n,now:Date.now(),score:r}}},{key:"updateBreak",value:function(e){var t=this.container.rules.isPartOfBreak(e),n=this.container.rules.isEndOfGame(e),r=Y.k.potCount(e);if(t||this.breakLink(n),this.lastShotLink(t||n,r,Y.k.pots(e)),n&&this.breakLink(n),!t){this.breakStart=void 0;return}void 0===this.breakStart&&(this.breakStart=this.last(),this.breakStartTime=Date.now())}},{key:"lastShotLink",value:function(e,t,n){var r=this.container.rules.currentBreak>0?" "+this.container.rules.currentBreak:"",i="#000000";n.length>0&&n.forEach(function(e){i="#"+e.ballmesh.color.getHexString()});var o="⚈".repeat(t>1?t-1:0)+(e?"⚈":"⚆")+r,s=JSON.stringify(this.lastShot());this.generateLink(o,s,i)}},{key:"breakLink",value:function(e){var t=this.currentBreak();if(t&&(e||t.shots.pop(),1!==t.shots.length)){var n=this.container.rules.previousBreak>0?this.container.rules.previousBreak:t.shots.length,r=JSON.stringify(t),i=Z.Z.crush(r);this.generateLink("break(".concat(n,")"),i,"black")}}},{key:"wholeGameLink",value:function(){var e=this.wholeGame(),t="frame(".concat(e.shots.length," shots)"),n=JSON.stringify(e),r=Z.Z.crush(n);this.generateLink(t,r,"black")}},{key:"generateLink",value:function(e,t,n){var r="".concat(this.replayUrl).concat(encodeURIComponent(t)),i='').concat(e,"");this.container.eventQueue.push(new G.s(null,"".concat(i)))}}],q(n.prototype,e),t&&q(n,t),n}(),ee=n("./src/controller/rules/rulefactory.ts"),et=n("./src/events/breakevent.ts");function en(e,t){for(var n=0;n').concat(e,"")));r.push(new G.s(null,s))})},this.redo.onclick=function(e){var r=new et.l(t.init,t.shots);r.retry=!0,n.interuptEventQueue(r)},this.replay.onclick=function(e){n.interuptEventQueue(t)}}}},{key:"interuptEventQueue",value:function(e){this.container.table.halt();var t=this.container.eventQueue;t.length=0,t.push(new r.I),t.push(e)}},{key:"getElement",value:function(e){return document.getElementById(e)}}],en(n.prototype,e),t&&en(n,t),n}();function eo(e,t){for(var n=0;n0?this.element.innerHTML="Break
"+e:this.element.innerHTML="")}},{key:"getElement",value:function(e){return document.getElementById(e)}}]),e&&eo(t,e),t}();function ea(e,t){for(var n=0;n0;){this.lastEventTime=this.last;var t=this.inputQueue.shift();t&&this.updateController(this.controller.handleInput(t))}if(this.table.allStationary()){var n=this.eventQueue.shift();n&&(this.lastEventTime=performance.now(),this.updateController(n.applyToController(this.controller)))}}},{key:"animate",value:function(e){var t=this;this.advance((e-this.last)/1e3),this.last=e,this.processEvents(),(e{n.d(t,{h:()=>u});var r=n("./src/controller/controller.ts"),i=n("./src/controller/controllerbase.ts"),o=n("./src/controller/playshot.ts"),s=n("./src/controller/replay.ts");function a(e,t){for(var n=0;n{n.d(t,{II:()=>i.I,OF:()=>r.O,Qr:()=>s}),n("./src/events/beginevent.ts"),n("./src/events/aimevent.ts");var r=n("./src/events/hitevent.ts"),i=n("./src/events/input.ts");function o(e,t){for(var n=0;n{n.d(t,{r:()=>f});var r=n("./src/controller/controller.ts"),i=n("./src/controller/end.ts"),o=n("./src/utils/gltf.ts"),s=n("./src/model/outcome.ts"),a=n("./node_modules/three/build/three.module.js");function l(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function c(e,t){for(var n=0;n{function r(e,t){for(var n=0;ns});var s=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}(a,e);var t,n,s=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n,r=i(a);if(t){var o=i(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(e=n)&&("object"==(e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)||"function"==typeof e)?e:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this)});function a(){return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),s.apply(this,arguments)}return r(a.prototype,[{key:"handleChat",value:function(e){var t=e.sender?"".concat(e.sender,":"):"",n="".concat(t," ").concat(e.message);return this.container.chat.showMessage(n),this}}]),n&&r(a,n),a}(n("./src/controller/controller.ts").Qr)},"./src/controller/placeball.ts":(e,t,n)=>{n.d(t,{a:()=>v});var r=n("./src/controller/controllerbase.ts"),i=n("./src/controller/controller.ts"),o=n("./src/controller/aim.ts"),s=n("./src/events/breakevent.ts"),a=n("./src/model/physics/constants.ts"),l=n("./node_modules/three/build/three.module.js"),c=n("./src/view/cuemesh.ts"),u=n("./src/utils/utils.ts");function h(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(e,t){for(var n=0;n{function r(e,t){for(var n=0;ns});var s=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}(l,e);var t,n,s,a=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n,r=i(l);if(t){var o=i(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(e=n)&&("object"==(e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)||"function"==typeof e)?e:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this)});function l(e){var t;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,l),(t=a.call(this,e)).hit(),t}return n=[{key:"handleStationary",value:function(e){var t=this.container.table,n=t.outcome,r=this.container.rules.update(n);return this.container.recorder.updateBreak(n),t.cue.aimAtNext(t.cueball,this.container.rules.nextCandidateBall()),r}},{key:"handleInput",value:function(e){return this.commonKeyHandler(e),this}}],r(l.prototype,n),s&&r(l,s),l}(n("./src/controller/controllerbase.ts").r)},"./src/controller/replay.ts":(e,t,n)=>{n.d(t,{U:()=>y});var r=n("./src/events/hitevent.ts"),i=n("./src/controller/controllerbase.ts"),o=n("./src/events/aimevent.ts"),s=n("./src/events/breakevent.ts"),a=n("./src/controller/aim.ts"),l=n("./src/events/eventtype.ts"),c=n("./src/events/rerackevent.ts");function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1500;if(!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,u),p(h(r=i.call(this,e)),"delay",void 0),p(h(r),"shots",void 0),p(h(r),"firstShot",void 0),p(h(r),"timer",void 0),p(h(r),"init",void 0),r.init=t,r.shots=m(n),r.firstShot=r.shots[0],r.delay=a,r.container.table.showTraces(!0),r.container.table.updateFromShortSerialised(r.init),o){var l=new s.l(t,n);l.retry=!0,r.container.eventQueue.push(l)}else r.container.view.camera.forceMode(r.container.view.camera.topView),r.playNextShot(1.5*r.delay);return r}return f(u.prototype,[{key:"playNextShot",value:function(e){var t=this,n=this.shots.shift();if((null==n?void 0:n.type)===l.t.RERACK){c.K.fromJson(n.ballinfo).applyToController(this),this.shots.length>0&&this.playNextShot(e);return}var i=o.f.fromJson(n);this.container.table.cueball=this.container.table.balls[i.i],this.container.table.cueball.pos.copy(i.pos),this.container.table.cue.aim=i,this.container.table.cue.updateAimInput(),this.container.table.cue.t=1,clearTimeout(this.timer),this.timer=setTimeout(function(){t.container.eventQueue.push(new r.O(t.container.table.cue.aim)),t.timer=void 0},e)}},{key:"handleHit",value:function(e){return this.hit(),this}},{key:"handleStationary",value:function(e){return this.shots.length>0&&void 0===this.timer&&this.playNextShot(this.delay),this}},{key:"handleInput",value:function(e){return this.commonKeyHandler(e),this}},{key:"handleBreak",value:function(e){return(this.container.table.updateFromShortSerialised(e.init),this.shots=m(e.shots),this.container.table.showSpin(!0),e.retry)?this.retry():(this.playNextShot(this.delay),this)}},{key:"retry",value:function(){clearTimeout(this.timer),this.timer=void 0,this.container.table.updateFromShortSerialised(this.init);var e=o.f.fromJson(this.firstShot);return this.container.table.cueball=this.container.table.balls[e.i],this.container.rules.cueball=this.container.table.cueball,this.container.table.cueball.pos.copy(e.pos),this.container.table.cue.aim=e,this.container.view.camera.forceMode(this.container.view.camera.aimView),new a.h(this.container)}}]),n&&f(u,n),u}(i.r)},"./src/controller/rules/rulefactory.ts":(e,t,n)=>{n.d(t,{N:()=>I});var r=n("./src/events/watchevent.ts"),i=n("./src/utils/rack.ts"),o=n("./node_modules/three/build/three.module.js"),s=n("./src/controller/aim.ts"),a=n("./src/controller/placeball.ts"),l=n("./src/controller/watchaim.ts"),c=n("./src/events/chatevent.ts"),u=n("./src/events/placeballevent.ts"),h=n("./src/model/outcome.ts"),f=n("./src/model/table.ts"),p=n("./src/utils/utils.ts"),d=n("./src/controller/end.ts"),v=n("./src/model/physics/constants.ts"),m=n("./src/utils/respot.ts"),y=n("./src/view/tablegeometry.ts"),b=n("./src/events/startaimevent.ts");function g(e,t){for(var n=0;n{n.d(t,{x:()=>T});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/events/watchevent.ts"),o=n("./src/model/outcome.ts"),s=n("./src/utils/rack.ts"),a=n("./src/utils/respot.ts"),l=n("./src/controller/aim.ts"),c=n("./src/controller/watchaim.ts"),u=n("./src/events/chatevent.ts"),h=n("./src/controller/end.ts"),f=n("./src/model/table.ts"),p=n("./src/view/tablegeometry.ts"),d=n("./src/controller/placeball.ts"),v=n("./src/events/placeballevent.ts"),m=n("./src/utils/utils.ts"),y=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"shotInfo",value:function(e,n,r){var i=o.k.firstCollision(n);return{pots:o.k.potCount(n),firstCollision:i,legalFirstCollision:t.isLegalFirstCollision(e,r,i),whitePotted:o.k.isCueBallPotted(e.cueball,n)}}},{key:"isLegalFirstCollision",value:function(e,n,r){if(!r)return!1;var i=r.ballB.id,o=t.coloursOnTable(e).filter(function(e){return e.id0;return n?i>=7:!o}},{key:"respotAllPottedColours",value:function(e,t){return o.k.pots(t).filter(function(e){return e.id<7}).filter(function(e){return 0!==e.id}).map(function(t){return a.s.respot(t,e)})}},{key:"redsOnTable",value:function(e){return e.balls.slice(7).filter(function(e){return e.onTable()})}},{key:"coloursOnTable",value:function(e){return e.balls.slice(1,7).filter(function(e){return e.onTable()})}}],function(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=Array(t);n0,this.switchPlayer()}return this.targetIsRed?this.targetRedRule(e,t):this.targetColourRule(e,t)}},{key:"targetRedRule",value:function(e,t){return(console.log("applying target red rule"),t.legalFirstCollision&&o.k.onlyRedsPotted(e))?(this.currentBreak+=t.pots,this.targetIsRed=!1,this.previousPotRed=!0,this.container.hud.updateBreak(this.currentBreak),this.continueBreak()):(this.foulPoints=this.foulCalculation(e,t),this.respot(e),t.whitePotted)?this.whiteInHand():this.switchPlayer()}},{key:"targetColourRule",value:function(e,t){if(console.log("applying target colour rule"),t.whitePotted)return this.respot(e),this.whiteInHand();if(t.pots>1)return this.foulPoints=this.foulCalculation(e,t),this.respot(e),this.switchPlayer();if(o.k.pots(e)[0].id>6)return this.foulPoints=this.foulCalculation(e,t),this.switchPlayer();this.targetIsRed=y.redsOnTable(this.container.table).length>0;var n=o.k.pots(e)[0].id;if(!this.previousPotRed){var r=y.coloursOnTable(this.container.table).filter(function(e){return e.id0;if(!t.legalFirstCollision||r)return this.foulPoints=this.foulCalculation(e,t),this.respot(e),this.switchPlayer()}return this.previousPotRed&&this.respot(e),this.currentBreak+=n+1,this.previousPotRed=!1,this.container.hud.updateBreak(this.currentBreak),this.continueBreak()}},{key:"foulCalculation",value:function(e,t){var n,r,i,s,a=o.k.pots(e).map(function(e){return e.id}).filter(function(e){return e<7}),l=null!==(s=null===(i=t.firstCollision)||void 0===i?void 0:null===(r=i.ballB)||void 0===r?void 0:r.id)&&void 0!==s?s:0;return l>6&&(l=0),(n=Math).max.apply(n,[3,l].concat(function(e){if(Array.isArray(e))return g(e)}(a)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(a)||function(e,t){if(e){if("string"==typeof e)return g(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return g(e,t)}}(a)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()))+1}},{key:"tableGeometry",value:function(){p.H.hasPockets=!0}},{key:"table",value:function(){var e=new f.i(this.rack());return this.cueball=e.cueball,e}},{key:"otherPlayersCueBall",value:function(){return this.cueball}},{key:"secondToPlay",value:function(){}},{key:"isPartOfBreak",value:function(e){return this.currentBreak>0}},{key:"isEndOfGame",value:function(e){return o.k.isClearTable(this.container.table)&&this.currentBreak>0}},{key:"allowsPlaceBall",value:function(){return!0}},{key:"asset",value:function(){return n.tablemodel}},{key:"startTurn",value:function(){this.previousPotRed=!1,this.targetIsRed=y.redsOnTable(this.container.table).length>0,this.previousBreak=this.currentBreak,this.currentBreak=0,this.container.hud.updateBreak(this.currentBreak)}},{key:"rack",value:function(){return s.F.snooker()}},{key:"nextCandidateBall",value:function(){var e=this.container.table,t=y.redsOnTable(e),n=y.coloursOnTable(e);return this.previousPotRed?a.s.closest(e.cueball,n):t.length>0?a.s.closest(e.cueball,t):n.length>0?n[0]:void 0}},{key:"placeBall",value:function(e){if(e){var t=new r.Pa4(s.F.baulk,s.F.sixth),n=new r.Pa4(s.F.baulk-s.F.sixth,-s.F.sixth);return e.clamp(n,t)}return new r.Pa4(s.F.baulk,-s.F.sixth/3,0)}},{key:"switchPlayer",value:function(){this.foulPoints>0&&console.log("foul, ".concat(this.foulPoints," to opponent")),console.log("end of break, switch player");var e=this.container.table;return(console.log(e.cue.aim),this.container.sendEvent(new b.H(this.foulPoints)),this.container.isSinglePlayer)?(this.container.sendEvent(new i.g(e.serialise())),this.startTurn(),new l.h(this.container)):new c.Q(this.container)}},{key:"continueBreak",value:function(){var e=this.container.table;return(this.container.sound.playSuccess(e.inPockets()),o.k.isClearTable(e))?(this.container.eventQueue.push(new u.s(null,"game over")),this.container.recorder.wholeGameLink(),new h.C(this.container)):(this.container.sendEvent(new i.g(e.serialise())),new l.h(this.container))}},{key:"whiteInHand",value:function(){return(this.foulPoints>0&&console.log("foul, ".concat(this.foulPoints," to opponent")),this.startTurn(),this.container.isSinglePlayer)?new d.a(this.container):(this.container.sendEvent(new v.I(m.bM,!0)),new c.Q(this.container))}},{key:"update",value:function(e){return this.snookerrule(e)}},{key:"respot",value:function(e){var t=y.respotAllPottedColours(this.container.table,e);if(t.length>0){var n={balls:t.map(function(e){return e.serialise()}),rerack:!0},r=new i.g(n);this.container.sendEvent(r),this.container.recorder.record(r)}}}],w(n.prototype,e),t&&w(n,t),n}();k(T,"tablemodel","models/snooker.min.gltf")},"./src/controller/watchaim.ts":(e,t,n)=>{n.d(t,{Q:()=>a});var r=n("./src/controller/watchshot.ts");function i(e,t){for(var n=0;n{n.d(t,{O:()=>u});var r=n("./src/controller/aim.ts"),i=n("./src/controller/watchaim.ts"),o=n("./src/controller/controllerbase.ts"),s=n("./src/controller/placeball.ts");function a(e,t){for(var n=0;n{n.d(t,{Y:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{f:()=>f});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts"),s=n("./node_modules/three/build/three.module.js");function a(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){for(var n=0;n{n.d(t,{Z:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{l:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{s:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{var r;n.d(t,{t:()=>r}),function(e){e.BEGIN="BEGIN",e.BREAK="BREAK",e.WATCHAIM="WATCHAIM",e.AIM="AIM",e.HIT="HIT",e.STATIONARY="STATIONARY",e.CHAT="CHAT",e.ABORT="ABORT",e.PLACEBALL="PLACEBALL",e.REJOIN="REJOIN",e.RERACK="RERACK",e.STARTAIM="STARTAIM"}(r||(r={}))},"./src/events/gameevent.ts":(e,t,n)=>{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{Z:()=>i});var i=function e(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"type",void 0),r(this,"sequence",void 0)}},"./src/events/hitevent.ts":(e,t,n)=>{n.d(t,{O:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{I:()=>i});var i=function e(t,n){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"t",void 0),r(this,"key",void 0),this.t=t,this.key=n}},"./src/events/keyboard.ts":(e,t,n)=>{n.d(t,{N:()=>l});var r=n("./src/events/input.ts"),i=n("./node_modules/interactjs/dist/interact.min.js"),o=n.n(i);function s(e,t){for(var n=0;nMath.abs(i.movementY)&&(i.movementY=0)}),this.addHandlers(e),/Android|iPhone/i.test(navigator.userAgent)||(e.contentEditable="true")}return e=[{key:"getEvents",value:function(){var e=this,t=Object.keys(this.pressed).filter(function(e){return!/Shift/.test(e)}).filter(function(e){return!/Control/.test(e)}),n=Object.keys(this.pressed).some(function(e){return/Shift/.test(e)}),i=Object.keys(this.pressed).some(function(e){return/Control/.test(e)}),o=[];return t.forEach(function(t){var s=performance.now()-e.pressed[t];o.push(new r.I(i?s/3:s,n?"Shift"+t:t)),"Space"!=t&&(e.pressed[t]=performance.now())}),Object.keys(this.released).forEach(function(t){return o.push(new r.I(e.released[t],t+"Up"))}),this.released={},o}},{key:"addHandlers",value:function(e){var t=this;e.addEventListener("keydown",this.keydown),e.addEventListener("keyup",this.keyup),e.focus(),o()(e).draggable({listeners:{move:function(e){t.mousetouch(e)}}}),o()(e).gesturable({onmove:function(e){e.dx/=3,t.mousetouch(e)}})}}],s(n.prototype,e),t&&s(n,t),n}()},"./src/events/placeballevent.ts":(e,t,n)=>{n.d(t,{I:()=>h});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts");function s(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(e,t){for(var n=0;n{n.d(t,{K:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{H:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:0;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,u),(t="foul")in(e=o(n=c.call(this)))?Object.defineProperty(e,t,{value:0,enumerable:!0,configurable:!0,writable:!0}):e[t]=0,n.type=i.t.STARTAIM,n.foul=r,n}return n=[{key:"applyToController",value:function(e){return e.handleStartAim(this)}}],r=[{key:"fromJson",value:function(e){return new u(e.foul)}}],n&&s(u.prototype,n),r&&s(u,r),u}(r.Z)},"./src/events/stationaryevent.ts":(e,t,n)=>{n.d(t,{I:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{g:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{var r=n("./src/container/container.ts"),i=n("./src/events/keyboard.ts"),o=n("./src/events/eventtype.ts"),s=n("./src/events/aimevent.ts"),a=n("./src/events/watchevent.ts"),l=n("./src/events/hitevent.ts"),c=n("./src/events/abortevent.ts"),u=n("./src/events/breakevent.ts"),h=n("./src/events/beginevent.ts"),f=n("./src/events/chatevent.ts");function p(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,s),v(p(e=i.call(this)),"clientResendFrom",void 0),v(p(e),"serverResendFrom",void 0),e.type=o.t.REJOIN,e.clientResendFrom=t,e.serverResendFrom=n,e}return n=[{key:"applyToController",value:function(e){return e.handleRejoin(this)}}],r=[{key:"fromJson",value:function(e){return new s(e.clientResendFrom,e.serverResendFrom)}}],n&&d(s.prototype,n),r&&d(s,r),s}(n("./src/events/gameevent.ts").Z),g=n("./src/events/placeballevent.ts"),w=n("./src/events/rerackevent.ts"),k=n("./src/events/startaimevent.ts"),T=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"serialise",value:function(e){return JSON.stringify(e)}},{key:"fromJson",value:function(e){switch(e.type){case o.t.BEGIN:return new h.Z;case o.t.AIM:return s.f.fromJson(e);case o.t.BREAK:return u.l.fromJson(e);case o.t.WATCHAIM:return a.g.fromJson(e.json);case o.t.HIT:return l.O.fromJson(e);case o.t.CHAT:return f.s.fromJson(e);case o.t.REJOIN:return b.fromJson(e);case o.t.ABORT:return new c.Y;case o.t.PLACEBALL:return g.I.fromJson(e);case o.t.RERACK:return w.K.fromJson(e);case o.t.STARTAIM:return k.H.fromJson(e);default:throw Error("Unknown GameEvent :"+e)}}},{key:"fromSerialised",value:function(e){var n=JSON.parse(e),r=t.fromJson(n);return"sequence"in n&&(r.sequence=n.sequence),r}}],function(e,t){for(var n=0;n upload high score {n.d(t,{e:()=>m,Z:()=>r});var r,i=n("./src/utils/utils.ts"),o=n("./src/model/physics/physics.ts"),s=n("./node_modules/three/build/three.module.js"),a=n("./src/model/physics/constants.ts");function l(e,t){for(var n=0;nMath.PI/32?.01*a.R:a.R,i=this.lastPos.distanceTo(e);this.addTraceGiven(e,t,i,r,n)}}},{key:"addTraceGiven",value:function(e,t,n,r,i){var o=this.geometry.drawRange.count;0!==o&&n1&&i<1e-4&&o--,this.lastPos.copy(e),this.lastVel.copy(t),this.addPoint(e,o))}},{key:"addPoint",value:function(e,t){var n=3*t;n>this.positions.length||(this.positions[n++]=e.x,this.positions[n++]=e.y,this.positions[n]=e.z,this.geometry.setDrawRange(0,t+1),this.line.geometry.attributes.position.needsUpdate=!0)}}],l(n.prototype,e),t&&l(n,t),n}();function h(e,t){for(var n=0;nMath.abs(this.rvel.z))&&(this.setStationary(),!0)}},{key:"setStationary",value:function(){this.vel.copy(i.bM),this.rvel.copy(i.bM),this.state="Stationary"}},{key:"isRolling",value:function(){return 0!==this.vel.lengthSq()&&0!==this.rvel.lengthSq()&&(0,o.E9)(this.vel,this.rvel).length(){function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{k:()=>o}),function(e){e.Pot="Pot",e.Cushion="Cushion",e.Collision="Collision",e.Hit="Hit"}(i||(i={}));var i,o=function(){var e;function t(e,n,i,o){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),r(this,"type",void 0),r(this,"timestamp",void 0),r(this,"ballA",null),r(this,"ballB",null),r(this,"incidentSpeed",void 0),this.type=e,this.ballA=n,this.ballB=i,this.incidentSpeed=o,this.timestamp=Date.now()}return e=[{key:"pot",value:function(e,n){return new t("Pot",e,e,n)}},{key:"cushion",value:function(e,n){return new t("Cushion",e,e,n)}},{key:"collision",value:function(e,n,r){return new t("Collision",e,n,r)}},{key:"hit",value:function(e,n){return new t("Hit",e,e,n)}},{key:"isCueBallPotted",value:function(e,t){return t.some(function(t){return"Pot"==t.type&&t.ballA===e})}},{key:"isBallPottedNoFoul",value:function(e,n){return n.some(function(e){return"Pot"==e.type&&null!==e.ballA})&&!t.isCueBallPotted(e,n)}},{key:"pots",value:function(e){return e.filter(function(e){return"Pot"==e.type}).map(function(e){return e.ballA})}},{key:"potCount",value:function(e){return this.pots(e).length}},{key:"onlyRedsPotted",value:function(e){return this.pots(e).every(function(e){return e.id>6})}},{key:"firstCollision",value:function(e){var t=e.filter(function(e){return"Collision"===e.type});return t.length>0?t[0]:void 0}},{key:"isClearTable",value:function(e){var t=e.balls.filter(function(e){return e.onTable()});return 1===t.length&&t[0]===e.cueball}},{key:"isThreeCushionPoint",value:function(e,n){n=t.cueBallFirst(e,n).filter(function(t){return t.ballA===e});var r=new Set,i=0,o=!0,s=!1,a=void 0;try{for(var l,c=n[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){var u=l.value;if("Cushion"===u.type&&i++,"Collision"===u.type&&(r.add(u.ballB),2===r.size))return i>=3}}catch(e){s=!0,a=e}finally{try{o||null==c.return||c.return()}finally{if(s)throw a}}return!1}},{key:"cueBallFirst",value:function(e,t){return t.forEach(function(t){"Collision"===t.type&&t.ballB===e&&(t.ballB=t.ballA,t.ballA=e)}),t}}],function(e,t){for(var n=0;n{n.d(t,{Dt:()=>c,Ew:()=>v,G3:()=>w,Hz:()=>i,I:()=>o,Mz:()=>r,R:()=>f,Xm:()=>k,_5:()=>u,dE:()=>y,e:()=>p,f7:()=>g,fN:()=>m,g:()=>s,m:()=>h,mu:()=>a,zq:()=>b,zv:()=>l});var r,i,o,s=9.8,a=.00985,l=.15,c=.8,u=.024,h=.23,f=.03275,p=.86;function d(){r=a*h*s*2/3*u,i=7/(5*Math.sqrt(2))*f*a*h*s,o=.4*h*f*f}function v(e){f=e,d()}function m(e){h=e,d()}function y(e){a=e,d()}function b(e){u=e,d()}function g(e){l=e}function w(e){p=e}function k(e){c=e}d()},"./src/model/physics/knuckle.ts":(e,t,n)=>{n.d(t,{T:()=>a});var r=n("./src/model/physics/constants.ts"),i=n("./src/view/pocketgeometry.ts");function o(e,t){for(var n=0;n{n.d(t,{E9:()=>a,Fn:()=>A,IT:()=>h,NP:()=>g,QC:()=>u,Vp:()=>c,WL:()=>P,ZI:()=>f,al:()=>b,c0:()=>y,h_:()=>x,s0:()=>m,vZ:()=>w});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/utils/utils.ts"),o=n("./src/model/physics/constants.ts"),s=new r.Pa4;function a(e,t){return s.copy(e).addScaledVector((0,i.a1)(t),o.R)}var l={v:new r.Pa4,w:new r.Pa4};function c(e,t){var n=a(e,t).setZ(0);return l.v.copy((0,i.KO)(n).multiplyScalar(-o.zv*o.g)),l.w.copy((0,i.KO)((0,i.a1)(n)).multiplyScalar(2.5*o.zv*o.g/o.R)),l.w.setZ(-2.5*(o.Mz/(o.m*o.R*o.R))*Math.sign(t.z)),l}function u(e){var t=new r.Pa4(e.x,e.y,0).length(),n=5/7*o.Hz/(o.m*o.R)/t,i=5/7*o.Hz/(o.m*o.R*o.R)/t;return l.v.set(-n*e.y,n*e.x,0),l.w.set(-i*e.x,-i*e.y,-2.5*(o.Mz/(o.m*o.R*o.R))*Math.sign(e.z)),l}function h(e,t){var n=t.z;t.copy((0,i.a1)(e).multiplyScalar(1/o.R)),t.setZ(n)}function f(e,t,n,r){var o=r(t.clone().applyAxisAngle(i.up,e),n.clone().applyAxisAngle(i.up,e));return o.v.applyAxisAngle(i.up,-e),o.w.applyAxisAngle(i.up,-e),o}Object.freeze(l);var p=Math.asin(.1*o.R/o.R),d=Math.sin(p),v=Math.cos(p);function m(e,t){return new r.Pa4(e.x*d-e.z*v+o.R*t.y,-e.y-o.R*t.z*v+o.R*t.x*d)}function y(e){return e.x*v}function b(e){var t=3.5/o.m;return e.length()/t}function g(e){var t,n=1/o.m,i=.39+.257*(t=new r.Pa4(e/v,0,0)).x-.044*t.x*t.x;return o.Dt*((1+i)*e)/n}function w(e,t){var n=g(y(e));return b(m(e,t))<=n}function k(e,t){return{c:y(e),s:m(e,t),A:3.5/o.m,B:1/o.m}}function T(e,t){var n=k(e,t),r=n.c,i=n.s,s=n.A,a=n.B,l=(1+o.e)*(r/a);return E(-i.x/s*d-l*v,i.y/s,i.x/s*v-l*d)}function R(e,t){var n=k(e,t),r=n.c,i=n.B,s=(1+o.e)*(r/i),a=.471-.241*Math.atan2(Math.abs(e.y),e.x),l=Math.atan2(e.y,e.x),c=Math.cos(l);return E(-a*s*c*v-s*v,a*s*Math.sin(l),a*s*c*v-s*d)}function A(e,t){return w(e,t)?T(e,t):R(e,t)}function x(e,t){var n=T(e,t),r=R(e,t),i=Math.sign(e.y)===Math.sign(t.z)?Math.cos(Math.atan2(e.y,e.x)):1;return{v:r.v.lerp(n.v,i),w:r.w.lerp(n.w,i)}}function E(e,t,n){return{v:new r.Pa4(e/o.m,t/o.m),w:new r.Pa4(-o.R/o.I*t*d,o.R/o.I*(e*d-n*v),o.R/o.I*t*v)}}function P(e,t){var n=Math.atan2(-e.x,e.y),r=2.5*t.length()*(e.length()*o.R)/(o.R*o.R),s=t.clone().normalize();return(0,i.a1)(s).applyAxisAngle(s,n).multiplyScalar(r)}},"./src/model/physics/pocket.ts":(e,t,n)=>{n.d(t,{f:()=>l});var r=n("./src/model/ball.ts"),i=n("./src/model/physics/constants.ts"),o=n("./src/utils/utils.ts");function s(e,t){for(var n=0;nthis.radius-i.R){var s=this.pos.clone().sub(e.pos).normalize().setZ(0);n>-i.R/2&&e.vel.addScaledVector(s,7*i.R*t*i.g),0>e.vel.dot(s)&&(e.ballmesh.trace.forceTrace(e.pos),e.vel.x=s.x*e.vel.length()/2,e.vel.y=s.y*e.vel.length()/2)}var a=this.restingDepth(e);n{n.d(t,{i:()=>b});var r=n("./src/view/tablegeometry.ts"),i=n("./src/model/physics/physics.ts"),o=n("./src/view/pocketgeometry.ts"),s=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"bounceAny",value:function(e,n){var o=!(arguments.length>2)||void 0===arguments[2]||arguments[2],s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:i.h_,a=e.futurePosition(n);if(t.willBounceLong(a,o)){var l=a.y>r.H.tableY?-Math.PI/2:Math.PI/2;return t.bounceIn(l,e,s)}if(t.willBounceShort(a,o)){var c=a.x>r.H.tableX?0:Math.PI;return t.bounceIn(c,e,s)}}},{key:"willBounceShort",value:function(e,n){return n?t.willBounceShortSegment(o.u.pockets.pocketNW.knuckleSW.pos.y,o.u.pockets.pocketSW.knuckleNW.pos.y,e):t.willBounceShortSegment(r.H.Y,-r.H.Y,e)}},{key:"willBounceLong",value:function(e,n){return n?t.willBounceLongSegment(o.u.pockets.pocketNW.knuckleNE.pos.x,o.u.pockets.pocketN.knuckleNW.pos.x,e)||t.willBounceLongSegment(o.u.pockets.pocketN.knuckleNE.pos.x,o.u.pockets.pocketNE.knuckleNW.pos.x,e):t.willBounceLongSegment(-r.H.X,r.H.X,e)}},{key:"willBounceLongSegment",value:function(e,t,n){return n.x>e&&n.xr.H.tableY}},{key:"willBounceShortSegment",value:function(e,t,n){return n.y>t&&n.yr.H.tableX}},{key:"bounceIn",value:function(e,t,n){t.ballmesh.trace.forceTrace(t.futurePos);var r=(0,i.ZI)(e,t.vel,t.rvel,n);return t.vel.add(r.v),t.rvel.add(r.w),r.v.length()}}],function(e,t){for(var n=0;n100)throw Error("Depth exceeded resolving collisions");this.balls.forEach(function(t){t.update(e)})}},{key:"prepareAdvanceAll",value:function(e){var t=this;return this.pairs.every(function(n){return t.prepareAdvancePair(n.a,n.b,e)})&&this.balls.every(function(n){return t.prepareAdvanceToCushions(n,e)})}},{key:"prepareAdvancePair",value:function(e,t,n){if(c.willCollide(e,t,n)){var r=c.collide(e,t);return this.outcome.push(d.k.collision(e,t,r)),!1}return!0}},{key:"prepareAdvanceToCushions",value:function(e,t){if(!e.onTable())return!0;var n=e.futurePosition(t);if(Math.abs(n.y)1&&void 0!==arguments[1]?arguments[1]:this.cueball;return this.balls.filter(function(e){return e!==t}).some(function(t){return t.pos.distanceTo(e)<2*l.R})}}],t=[{key:"fromSerialised",value:function(e){var t=new n(e.balls.map(function(e){return a.e.fromSerialised(e)}));return t.updateFromSerialised(e),t}}],e&&m(n.prototype,e),t&&m(n,t),n}()},"./src/utils/gltf.ts":(e,t,n)=>{let r,i,o,s;n.d(t,{pC:()=>eP,MR:()=>eS});var a=n("./node_modules/three/build/three.module.js");function l(e,t=1/0,n=null){i||(i=new a._12(2,2,1,1)),o||(o=new a.jyz({uniforms:{blitTexture:new a.xWb(e)},vertexShader:` +"use strict";(self.webpackChunkbilliards=self.webpackChunkbilliards||[]).push([[826],{"./src/container/container.ts":(e,t,n)=>{n.d(t,{W:()=>ec});var r=n("./src/events/stationaryevent.ts"),i=n("./node_modules/three/build/three.module.js"),o=n("./src/utils/utils.ts"),s=n("./src/view/cameratop.ts"),a=n("./src/model/physics/constants.ts");function l(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:.08,n=this.height,r=this.camera.aspect<.8;if(this.camera.fov=r?60:40,n<10*a.R){var i=100*(10*a.R-n);this.camera.fov-=i*(r?3:1)}this.camera.position.lerp(e.pos.clone().addScaledVector((0,o.AA)(e.angle),-(18*a.R)),t),this.camera.position.z=n,this.camera.up=o.up,this.camera.lookAt(e.pos.clone().addScaledVector(o.up,n/2))}},{key:"adjustHeight",value:function(e){e=this.height<10*a.R?e/8:e,this.height=i.M8C.clamp(this.height+e,6*a.R,120*a.R),this.height>110*a.R&&this.suggestMode(this.topView),this.height<105*a.R&&this.suggestMode(this.aimView)}},{key:"suggestMode",value:function(e){this.mainMode===this.aimView&&(this.mode=e)}},{key:"forceMode",value:function(e){this.mode=e,this.mainMode=e}},{key:"forceMove",value:function(e){this.mode===this.aimView&&this.aimView(e,1)}},{key:"toggleMode",value:function(){this.mode===this.topView?this.mode=this.aimView:this.mode=this.topView,this.mainMode=this.mode}}],l(n.prototype,e),t&&l(n,t),n}(),h=n("./src/view/tablegeometry.ts");function f(e,t){for(var n=0;n0&&(null===(t=this.cuePowerElement)||void 0===t?void 0:t.value)&&(this.cuePowerElement.value=e)}}],_(n.prototype,e),t&&_(n,t),n}(),j=n("./src/controller/aim.ts"),N=n("./src/controller/playshot.ts"),B=n("./src/controller/watchshot.ts"),L=n("./src/controller/end.ts");function H(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function F(e,t){for(var n=0;nthis.sentTime+this.period||e.type!==z.t.AIM){this.flush(),this.apply(e),this.sentTime=performance.now();return}this.pending=e}}]),e&&K(t,e),t}(),W=n("./src/view/sliders.ts"),Y=n("./src/model/outcome.ts"),Z=n("./node_modules/jsoncrush/JSONCrush.js"),J=n("./src/events/rerackevent.ts");function q(e,t){for(var n=0;n0&&"RERACK"===this.shots[e].type&&e--,e}},{key:"lastShot",value:function(){var e=this.last();return this.state(this.states[e],[this.shots[e]])}},{key:"currentBreak",value:function(){if(void 0!==this.breakStart)return this.state(this.states[this.breakStart],this.shots.slice(this.breakStart),this.breakStartTime,this.container.rules.previousBreak)}},{key:"state",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];return{init:e,shots:t,start:n,now:Date.now(),score:r,wholeGame:i}}},{key:"updateBreak",value:function(e){var t=this.container.rules.isPartOfBreak(e),n=this.container.rules.isEndOfGame(e),r=Y.k.potCount(e);if(t||this.breakLink(n),this.lastShotLink(t||n,r,Y.k.pots(e)),n&&this.breakLink(n),!t){this.breakStart=void 0;return}void 0===this.breakStart&&(this.breakStart=this.last(),this.breakStartTime=Date.now())}},{key:"lastShotLink",value:function(e,t,n){var r="#000000";n.length>0&&n.forEach(function(e){r="#"+e.ballmesh.color.getHexString()});var i="⚈".repeat(t>1?t-1:0)+(e?"⚈":"⚆"),o=JSON.stringify(this.lastShot());this.generateLink(i,o,r)}},{key:"breakLink",value:function(e){var t=this.currentBreak();if(t&&(e||t.shots.pop(),1!==t.shots.length)){var n=this.container.rules.previousBreak>0?this.container.rules.previousBreak:t.shots.length,r=JSON.stringify(t),i=Z.Z.crush(r);this.generateLink("break(".concat(n,")"),i,"black")}}},{key:"wholeGameLink",value:function(){var e=this.wholeGame(),t="frame(".concat(e.shots.length," shots)"),n=JSON.stringify(e),r=Z.Z.crush(n);this.generateLink(t,r,"black")}},{key:"generateLink",value:function(e,t,n){var r="".concat(this.replayUrl).concat(encodeURIComponent(t)),i='').concat(e,"");this.container.eventQueue.push(new G.s(null,"".concat(i)))}}],q(n.prototype,e),t&&q(n,t),n}(),ee=n("./src/controller/rules/rulefactory.ts"),et=n("./src/events/breakevent.ts");function en(e,t){for(var n=0;n').concat(e,"")));r.push(new G.s(null,s))})},this.redo.onclick=function(e){var r=new et.l(t.init,t.shots);r.retry=!0,n.interuptEventQueue(r)},this.replay.onclick=function(e){n.interuptEventQueue(t)}}}},{key:"interuptEventQueue",value:function(e){this.container.table.halt();var t=this.container.eventQueue;t.length=0,t.push(new r.I),t.push(e)}},{key:"getElement",value:function(e){return document.getElementById(e)}}],en(n.prototype,e),t&&en(n,t),n}();function eo(e,t){for(var n=0;n0?this.element.innerHTML="Break
"+e:this.element.innerHTML="")}},{key:"getElement",value:function(e){return document.getElementById(e)}}]),e&&eo(t,e),t}();function ea(e,t){for(var n=0;n0;){this.lastEventTime=this.last;var t=this.inputQueue.shift();t&&this.updateController(this.controller.handleInput(t))}if(this.table.allStationary()){var n=this.eventQueue.shift();n&&(this.lastEventTime=performance.now(),this.updateController(n.applyToController(this.controller)))}}},{key:"animate",value:function(e){var t=this;this.advance((e-this.last)/1e3),this.last=e,this.processEvents(),(e{n.d(t,{h:()=>u});var r=n("./src/controller/controller.ts"),i=n("./src/controller/controllerbase.ts"),o=n("./src/controller/playshot.ts"),s=n("./src/controller/replay.ts");function a(e,t){for(var n=0;n{n.d(t,{II:()=>i.I,OF:()=>r.O,Qr:()=>s}),n("./src/events/beginevent.ts"),n("./src/events/aimevent.ts");var r=n("./src/events/hitevent.ts"),i=n("./src/events/input.ts");function o(e,t){for(var n=0;n{n.d(t,{r:()=>f});var r=n("./src/controller/controller.ts"),i=n("./src/controller/end.ts"),o=n("./src/utils/gltf.ts"),s=n("./src/model/outcome.ts"),a=n("./node_modules/three/build/three.module.js");function l(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function c(e,t){for(var n=0;n{function r(e,t){for(var n=0;ns});var s=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}(a,e);var t,n,s=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n,r=i(a);if(t){var o=i(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(e=n)&&("object"==(e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)||"function"==typeof e)?e:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this)});function a(){return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),s.apply(this,arguments)}return r(a.prototype,[{key:"handleChat",value:function(e){var t=e.sender?"".concat(e.sender,":"):"",n="".concat(t," ").concat(e.message);return this.container.chat.showMessage(n),this}}]),n&&r(a,n),a}(n("./src/controller/controller.ts").Qr)},"./src/controller/placeball.ts":(e,t,n)=>{n.d(t,{a:()=>v});var r=n("./src/controller/controllerbase.ts"),i=n("./src/controller/controller.ts"),o=n("./src/controller/aim.ts"),s=n("./src/events/breakevent.ts"),a=n("./src/model/physics/constants.ts"),l=n("./node_modules/three/build/three.module.js"),c=n("./src/view/cuemesh.ts"),u=n("./src/utils/utils.ts");function h(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(e,t){for(var n=0;n{function r(e,t){for(var n=0;ns});var s=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}(l,e);var t,n,s,a=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n,r=i(l);if(t){var o=i(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(e=n)&&("object"==(e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)||"function"==typeof e)?e:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this)});function l(e){var t;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,l),(t=a.call(this,e)).hit(),t}return n=[{key:"handleStationary",value:function(e){var t=this.container.table,n=t.outcome,r=this.container.rules.update(n);return this.container.recorder.updateBreak(n),t.cue.aimAtNext(t.cueball,this.container.rules.nextCandidateBall()),r}},{key:"handleInput",value:function(e){return this.commonKeyHandler(e),this}}],r(l.prototype,n),s&&r(l,s),l}(n("./src/controller/controllerbase.ts").r)},"./src/controller/replay.ts":(e,t,n)=>{n.d(t,{U:()=>y});var r=n("./src/events/hitevent.ts"),i=n("./src/controller/controllerbase.ts"),o=n("./src/events/aimevent.ts"),s=n("./src/events/breakevent.ts"),a=n("./src/controller/aim.ts"),l=n("./src/events/eventtype.ts"),c=n("./src/events/rerackevent.ts");function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1500;if(!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,u),p(h(r=i.call(this,e)),"delay",void 0),p(h(r),"shots",void 0),p(h(r),"firstShot",void 0),p(h(r),"timer",void 0),p(h(r),"init",void 0),r.init=t,r.shots=m(n),r.firstShot=r.shots[0],r.delay=a,r.container.table.showTraces(!0),r.container.table.updateFromShortSerialised(r.init),o){var l=new s.l(t,n);l.retry=!0,r.container.eventQueue.push(l)}else r.container.view.camera.forceMode(r.container.view.camera.topView),r.playNextShot(1.5*r.delay);return r}return f(u.prototype,[{key:"playNextShot",value:function(e){var t=this,n=this.shots.shift();if((null==n?void 0:n.type)===l.t.RERACK){c.K.fromJson(n.ballinfo).applyToController(this),this.shots.length>0&&this.playNextShot(e);return}var i=o.f.fromJson(n);this.container.table.cueball=this.container.table.balls[i.i],this.container.table.cueball.pos.copy(i.pos),this.container.table.cue.aim=i,this.container.table.cue.updateAimInput(),this.container.table.cue.t=1,clearTimeout(this.timer),this.timer=setTimeout(function(){t.container.eventQueue.push(new r.O(t.container.table.cue.aim)),t.timer=void 0},e)}},{key:"handleHit",value:function(e){return this.hit(),this}},{key:"handleStationary",value:function(e){return this.shots.length>0&&void 0===this.timer&&this.playNextShot(this.delay),this}},{key:"handleInput",value:function(e){return this.commonKeyHandler(e),this}},{key:"handleBreak",value:function(e){return(this.container.table.updateFromShortSerialised(e.init),this.shots=m(e.shots),this.container.table.showSpin(!0),e.retry)?this.retry():(this.playNextShot(this.delay),this)}},{key:"retry",value:function(){clearTimeout(this.timer),this.timer=void 0,this.container.table.updateFromShortSerialised(this.init);var e=o.f.fromJson(this.firstShot);return this.container.table.cueball=this.container.table.balls[e.i],this.container.rules.cueball=this.container.table.cueball,this.container.table.cueball.pos.copy(e.pos),this.container.table.cue.aim=e,this.container.view.camera.forceMode(this.container.view.camera.aimView),new a.h(this.container)}}]),n&&f(u,n),u}(i.r)},"./src/controller/rules/rulefactory.ts":(e,t,n)=>{n.d(t,{N:()=>I});var r=n("./src/events/watchevent.ts"),i=n("./src/utils/rack.ts"),o=n("./node_modules/three/build/three.module.js"),s=n("./src/controller/aim.ts"),a=n("./src/controller/placeball.ts"),l=n("./src/controller/watchaim.ts"),c=n("./src/events/chatevent.ts"),u=n("./src/events/placeballevent.ts"),h=n("./src/model/outcome.ts"),f=n("./src/model/table.ts"),p=n("./src/utils/utils.ts"),d=n("./src/controller/end.ts"),v=n("./src/model/physics/constants.ts"),m=n("./src/utils/respot.ts"),y=n("./src/view/tablegeometry.ts"),b=n("./src/events/startaimevent.ts");function g(e,t){for(var n=0;n{n.d(t,{x:()=>T});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/events/watchevent.ts"),o=n("./src/model/outcome.ts"),s=n("./src/utils/rack.ts"),a=n("./src/utils/respot.ts"),l=n("./src/controller/aim.ts"),c=n("./src/controller/watchaim.ts"),u=n("./src/events/chatevent.ts"),h=n("./src/controller/end.ts"),f=n("./src/model/table.ts"),p=n("./src/view/tablegeometry.ts"),d=n("./src/controller/placeball.ts"),v=n("./src/events/placeballevent.ts"),m=n("./src/utils/utils.ts"),y=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"shotInfo",value:function(e,n,r){var i=o.k.firstCollision(n);return{pots:o.k.potCount(n),firstCollision:i,legalFirstCollision:t.isLegalFirstCollision(e,r,i),whitePotted:o.k.isCueBallPotted(e.cueball,n)}}},{key:"isLegalFirstCollision",value:function(e,n,r){if(!r)return!1;var i=r.ballB.id,o=t.coloursOnTable(e).filter(function(e){return e.id0;return n?i>=7:!o}},{key:"respotAllPottedColours",value:function(e,t){return o.k.pots(t).filter(function(e){return e.id<7}).filter(function(e){return 0!==e.id}).map(function(t){return a.s.respot(t,e)})}},{key:"redsOnTable",value:function(e){return e.balls.slice(7).filter(function(e){return e.onTable()})}},{key:"coloursOnTable",value:function(e){return e.balls.slice(1,7).filter(function(e){return e.onTable()})}}],function(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=Array(t);n0,this.switchPlayer()}return this.targetIsRed?this.targetRedRule(e,t):this.targetColourRule(e,t)}},{key:"targetRedRule",value:function(e,t){return(console.log("applying target red rule"),t.legalFirstCollision&&o.k.onlyRedsPotted(e))?(this.currentBreak+=t.pots,this.targetIsRed=!1,this.previousPotRed=!0,this.container.hud.updateBreak(this.currentBreak),this.continueBreak()):(this.foulPoints=this.foulCalculation(e,t),this.respot(e),t.whitePotted)?this.whiteInHand():this.switchPlayer()}},{key:"targetColourRule",value:function(e,t){if(console.log("applying target colour rule"),t.whitePotted)return this.respot(e),this.whiteInHand();if(t.pots>1)return this.foulPoints=this.foulCalculation(e,t),this.respot(e),this.switchPlayer();if(o.k.pots(e)[0].id>6)return this.foulPoints=this.foulCalculation(e,t),this.switchPlayer();this.targetIsRed=y.redsOnTable(this.container.table).length>0;var n=o.k.pots(e)[0].id;if(!this.previousPotRed){var r=y.coloursOnTable(this.container.table).filter(function(e){return e.id0;if(!t.legalFirstCollision||r)return this.foulPoints=this.foulCalculation(e,t),this.respot(e),this.switchPlayer()}return this.previousPotRed&&this.respot(e),this.currentBreak+=n+1,this.previousPotRed=!1,this.container.hud.updateBreak(this.currentBreak),this.continueBreak()}},{key:"foulCalculation",value:function(e,t){var n,r,i,s,a=o.k.pots(e).map(function(e){return e.id}).filter(function(e){return e<7}),l=null!==(s=null===(i=t.firstCollision)||void 0===i?void 0:null===(r=i.ballB)||void 0===r?void 0:r.id)&&void 0!==s?s:0;return l>6&&(l=0),(n=Math).max.apply(n,[3,l].concat(function(e){if(Array.isArray(e))return g(e)}(a)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(a)||function(e,t){if(e){if("string"==typeof e)return g(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return g(e,t)}}(a)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()))+1}},{key:"tableGeometry",value:function(){p.H.hasPockets=!0}},{key:"table",value:function(){var e=new f.i(this.rack());return this.cueball=e.cueball,e}},{key:"otherPlayersCueBall",value:function(){return this.cueball}},{key:"secondToPlay",value:function(){}},{key:"isPartOfBreak",value:function(e){return this.currentBreak>0}},{key:"isEndOfGame",value:function(e){return o.k.isClearTable(this.container.table)&&this.currentBreak>0}},{key:"allowsPlaceBall",value:function(){return!0}},{key:"asset",value:function(){return n.tablemodel}},{key:"startTurn",value:function(){this.previousPotRed=!1,this.targetIsRed=y.redsOnTable(this.container.table).length>0,this.previousBreak=this.currentBreak,this.currentBreak=0,this.container.hud.updateBreak(this.currentBreak)}},{key:"rack",value:function(){return s.F.snooker()}},{key:"nextCandidateBall",value:function(){var e=this.container.table,t=y.redsOnTable(e),n=y.coloursOnTable(e);return this.previousPotRed?a.s.closest(e.cueball,n):t.length>0?a.s.closest(e.cueball,t):n.length>0?n[0]:void 0}},{key:"placeBall",value:function(e){if(e){var t=new r.Pa4(s.F.baulk,s.F.sixth),n=new r.Pa4(s.F.baulk-s.F.sixth,-s.F.sixth);return e.clamp(n,t)}return new r.Pa4(s.F.baulk,-s.F.sixth/3,0)}},{key:"switchPlayer",value:function(){this.foulPoints>0&&console.log("foul, ".concat(this.foulPoints," to opponent")),console.log("end of break, switch player");var e=this.container.table;return(console.log(e.cue.aim),this.container.sendEvent(new b.H(this.foulPoints)),this.container.isSinglePlayer)?(this.container.sendEvent(new i.g(e.serialise())),this.startTurn(),new l.h(this.container)):new c.Q(this.container)}},{key:"continueBreak",value:function(){var e=this.container.table;return(this.container.sound.playSuccess(e.inPockets()),o.k.isClearTable(e))?(this.container.eventQueue.push(new u.s(null,"game over")),this.container.recorder.wholeGameLink(),new h.C(this.container)):(this.container.sendEvent(new i.g(e.serialise())),new l.h(this.container))}},{key:"whiteInHand",value:function(){return(this.foulPoints>0&&console.log("foul, ".concat(this.foulPoints," to opponent")),this.startTurn(),this.container.isSinglePlayer)?new d.a(this.container):(this.container.sendEvent(new v.I(m.bM,!0)),new c.Q(this.container))}},{key:"update",value:function(e){return this.snookerrule(e)}},{key:"respot",value:function(e){var t=y.respotAllPottedColours(this.container.table,e);if(t.length>0){var n={balls:t.map(function(e){return e.serialise()}),rerack:!0},r=new i.g(n);this.container.sendEvent(r),this.container.recorder.record(r)}}}],w(n.prototype,e),t&&w(n,t),n}();k(T,"tablemodel","models/snooker.min.gltf")},"./src/controller/watchaim.ts":(e,t,n)=>{n.d(t,{Q:()=>a});var r=n("./src/controller/watchshot.ts");function i(e,t){for(var n=0;n{n.d(t,{O:()=>u});var r=n("./src/controller/aim.ts"),i=n("./src/controller/watchaim.ts"),o=n("./src/controller/controllerbase.ts"),s=n("./src/controller/placeball.ts");function a(e,t){for(var n=0;n{n.d(t,{Y:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{f:()=>f});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts"),s=n("./node_modules/three/build/three.module.js");function a(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){for(var n=0;n{n.d(t,{Z:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{l:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{s:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{var r;n.d(t,{t:()=>r}),function(e){e.BEGIN="BEGIN",e.BREAK="BREAK",e.WATCHAIM="WATCHAIM",e.AIM="AIM",e.HIT="HIT",e.STATIONARY="STATIONARY",e.CHAT="CHAT",e.ABORT="ABORT",e.PLACEBALL="PLACEBALL",e.REJOIN="REJOIN",e.RERACK="RERACK",e.STARTAIM="STARTAIM"}(r||(r={}))},"./src/events/gameevent.ts":(e,t,n)=>{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{Z:()=>i});var i=function e(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"type",void 0),r(this,"sequence",void 0)}},"./src/events/hitevent.ts":(e,t,n)=>{n.d(t,{O:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{I:()=>i});var i=function e(t,n){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"t",void 0),r(this,"key",void 0),this.t=t,this.key=n}},"./src/events/keyboard.ts":(e,t,n)=>{n.d(t,{N:()=>l});var r=n("./src/events/input.ts"),i=n("./node_modules/interactjs/dist/interact.min.js"),o=n.n(i);function s(e,t){for(var n=0;nMath.abs(i.movementY)&&(i.movementY=0)}),this.addHandlers(e),/Android|iPhone/i.test(navigator.userAgent)||(e.contentEditable="true")}return e=[{key:"getEvents",value:function(){var e=this,t=Object.keys(this.pressed).filter(function(e){return!/Shift/.test(e)}).filter(function(e){return!/Control/.test(e)}),n=Object.keys(this.pressed).some(function(e){return/Shift/.test(e)}),i=Object.keys(this.pressed).some(function(e){return/Control/.test(e)}),o=[];return t.forEach(function(t){var s=performance.now()-e.pressed[t];o.push(new r.I(i?s/3:s,n?"Shift"+t:t)),"Space"!=t&&(e.pressed[t]=performance.now())}),Object.keys(this.released).forEach(function(t){return o.push(new r.I(e.released[t],t+"Up"))}),this.released={},o}},{key:"addHandlers",value:function(e){var t=this;e.addEventListener("keydown",this.keydown),e.addEventListener("keyup",this.keyup),e.focus(),o()(e).draggable({listeners:{move:function(e){t.mousetouch(e)}}}),o()(e).gesturable({onmove:function(e){e.dx/=3,t.mousetouch(e)}})}}],s(n.prototype,e),t&&s(n,t),n}()},"./src/events/placeballevent.ts":(e,t,n)=>{n.d(t,{I:()=>h});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts");function s(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(e,t){for(var n=0;n{n.d(t,{K:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{H:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:0;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,u),(t="foul")in(e=o(n=c.call(this)))?Object.defineProperty(e,t,{value:0,enumerable:!0,configurable:!0,writable:!0}):e[t]=0,n.type=i.t.STARTAIM,n.foul=r,n}return n=[{key:"applyToController",value:function(e){return e.handleStartAim(this)}}],r=[{key:"fromJson",value:function(e){return new u(e.foul)}}],n&&s(u.prototype,n),r&&s(u,r),u}(r.Z)},"./src/events/stationaryevent.ts":(e,t,n)=>{n.d(t,{I:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{g:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{var r=n("./src/container/container.ts"),i=n("./src/events/keyboard.ts"),o=n("./src/events/eventtype.ts"),s=n("./src/events/aimevent.ts"),a=n("./src/events/watchevent.ts"),l=n("./src/events/hitevent.ts"),c=n("./src/events/abortevent.ts"),u=n("./src/events/breakevent.ts"),h=n("./src/events/beginevent.ts"),f=n("./src/events/chatevent.ts");function p(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,s),v(p(e=i.call(this)),"clientResendFrom",void 0),v(p(e),"serverResendFrom",void 0),e.type=o.t.REJOIN,e.clientResendFrom=t,e.serverResendFrom=n,e}return n=[{key:"applyToController",value:function(e){return e.handleRejoin(this)}}],r=[{key:"fromJson",value:function(e){return new s(e.clientResendFrom,e.serverResendFrom)}}],n&&d(s.prototype,n),r&&d(s,r),s}(n("./src/events/gameevent.ts").Z),g=n("./src/events/placeballevent.ts"),w=n("./src/events/rerackevent.ts"),k=n("./src/events/startaimevent.ts"),T=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"serialise",value:function(e){return JSON.stringify(e)}},{key:"fromJson",value:function(e){switch(e.type){case o.t.BEGIN:return new h.Z;case o.t.AIM:return s.f.fromJson(e);case o.t.BREAK:return u.l.fromJson(e);case o.t.WATCHAIM:return a.g.fromJson(e.json);case o.t.HIT:return l.O.fromJson(e);case o.t.CHAT:return f.s.fromJson(e);case o.t.REJOIN:return b.fromJson(e);case o.t.ABORT:return new c.Y;case o.t.PLACEBALL:return g.I.fromJson(e);case o.t.RERACK:return w.K.fromJson(e);case o.t.STARTAIM:return k.H.fromJson(e);default:throw Error("Unknown GameEvent :"+e)}}},{key:"fromSerialised",value:function(e){var n=JSON.parse(e),r=t.fromJson(n);return"sequence"in n&&(r.sequence=n.sequence),r}}],function(e,t){for(var n=0;n upload high score {n.d(t,{e:()=>m,Z:()=>r});var r,i=n("./src/utils/utils.ts"),o=n("./src/model/physics/physics.ts"),s=n("./node_modules/three/build/three.module.js"),a=n("./src/model/physics/constants.ts");function l(e,t){for(var n=0;nMath.PI/32?.01*a.R:a.R,i=this.lastPos.distanceTo(e);this.addTraceGiven(e,t,i,r,n)}}},{key:"addTraceGiven",value:function(e,t,n,r,i){var o=this.geometry.drawRange.count;0!==o&&n1&&i<1e-4&&o--,this.lastPos.copy(e),this.lastVel.copy(t),this.addPoint(e,o))}},{key:"addPoint",value:function(e,t){var n=3*t;n>this.positions.length||(this.positions[n++]=e.x,this.positions[n++]=e.y,this.positions[n]=e.z,this.geometry.setDrawRange(0,t+1),this.line.geometry.attributes.position.needsUpdate=!0)}}],l(n.prototype,e),t&&l(n,t),n}();function h(e,t){for(var n=0;nMath.abs(this.rvel.z))&&(this.setStationary(),!0)}},{key:"setStationary",value:function(){this.vel.copy(i.bM),this.rvel.copy(i.bM),this.state="Stationary"}},{key:"isRolling",value:function(){return 0!==this.vel.lengthSq()&&0!==this.rvel.lengthSq()&&(0,o.E9)(this.vel,this.rvel).length(){function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{k:()=>o}),function(e){e.Pot="Pot",e.Cushion="Cushion",e.Collision="Collision",e.Hit="Hit"}(i||(i={}));var i,o=function(){var e;function t(e,n,i,o){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),r(this,"type",void 0),r(this,"timestamp",void 0),r(this,"ballA",null),r(this,"ballB",null),r(this,"incidentSpeed",void 0),this.type=e,this.ballA=n,this.ballB=i,this.incidentSpeed=o,this.timestamp=Date.now()}return e=[{key:"pot",value:function(e,n){return new t("Pot",e,e,n)}},{key:"cushion",value:function(e,n){return new t("Cushion",e,e,n)}},{key:"collision",value:function(e,n,r){return new t("Collision",e,n,r)}},{key:"hit",value:function(e,n){return new t("Hit",e,e,n)}},{key:"isCueBallPotted",value:function(e,t){return t.some(function(t){return"Pot"==t.type&&t.ballA===e})}},{key:"isBallPottedNoFoul",value:function(e,n){return n.some(function(e){return"Pot"==e.type&&null!==e.ballA})&&!t.isCueBallPotted(e,n)}},{key:"pots",value:function(e){return e.filter(function(e){return"Pot"==e.type}).map(function(e){return e.ballA})}},{key:"potCount",value:function(e){return this.pots(e).length}},{key:"onlyRedsPotted",value:function(e){return this.pots(e).every(function(e){return e.id>6})}},{key:"firstCollision",value:function(e){var t=e.filter(function(e){return"Collision"===e.type});return t.length>0?t[0]:void 0}},{key:"isClearTable",value:function(e){var t=e.balls.filter(function(e){return e.onTable()});return 1===t.length&&t[0]===e.cueball}},{key:"isThreeCushionPoint",value:function(e,n){n=t.cueBallFirst(e,n).filter(function(t){return t.ballA===e});var r=new Set,i=0,o=!0,s=!1,a=void 0;try{for(var l,c=n[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){var u=l.value;if("Cushion"===u.type&&i++,"Collision"===u.type&&(r.add(u.ballB),2===r.size))return i>=3}}catch(e){s=!0,a=e}finally{try{o||null==c.return||c.return()}finally{if(s)throw a}}return!1}},{key:"cueBallFirst",value:function(e,t){return t.forEach(function(t){"Collision"===t.type&&t.ballB===e&&(t.ballB=t.ballA,t.ballA=e)}),t}}],function(e,t){for(var n=0;n{n.d(t,{Dt:()=>c,Ew:()=>v,G3:()=>w,Hz:()=>i,I:()=>o,Mz:()=>r,R:()=>f,Xm:()=>k,_5:()=>u,dE:()=>y,e:()=>p,f7:()=>g,fN:()=>m,g:()=>s,m:()=>h,mu:()=>a,zq:()=>b,zv:()=>l});var r,i,o,s=9.8,a=.00985,l=.15,c=.8,u=.024,h=.23,f=.03275,p=.86;function d(){r=a*h*s*2/3*u,i=7/(5*Math.sqrt(2))*f*a*h*s,o=.4*h*f*f}function v(e){f=e,d()}function m(e){h=e,d()}function y(e){a=e,d()}function b(e){u=e,d()}function g(e){l=e}function w(e){p=e}function k(e){c=e}d()},"./src/model/physics/knuckle.ts":(e,t,n)=>{n.d(t,{T:()=>a});var r=n("./src/model/physics/constants.ts"),i=n("./src/view/pocketgeometry.ts");function o(e,t){for(var n=0;n{n.d(t,{E9:()=>a,Fn:()=>A,IT:()=>h,NP:()=>g,QC:()=>u,Vp:()=>c,WL:()=>P,ZI:()=>f,al:()=>b,c0:()=>y,h_:()=>x,s0:()=>m,vZ:()=>w});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/utils/utils.ts"),o=n("./src/model/physics/constants.ts"),s=new r.Pa4;function a(e,t){return s.copy(e).addScaledVector((0,i.a1)(t),o.R)}var l={v:new r.Pa4,w:new r.Pa4};function c(e,t){var n=a(e,t).setZ(0);return l.v.copy((0,i.KO)(n).multiplyScalar(-o.zv*o.g)),l.w.copy((0,i.KO)((0,i.a1)(n)).multiplyScalar(2.5*o.zv*o.g/o.R)),l.w.setZ(-2.5*(o.Mz/(o.m*o.R*o.R))*Math.sign(t.z)),l}function u(e){var t=new r.Pa4(e.x,e.y,0).length(),n=5/7*o.Hz/(o.m*o.R)/t,i=5/7*o.Hz/(o.m*o.R*o.R)/t;return l.v.set(-n*e.y,n*e.x,0),l.w.set(-i*e.x,-i*e.y,-2.5*(o.Mz/(o.m*o.R*o.R))*Math.sign(e.z)),l}function h(e,t){var n=t.z;t.copy((0,i.a1)(e).multiplyScalar(1/o.R)),t.setZ(n)}function f(e,t,n,r){var o=r(t.clone().applyAxisAngle(i.up,e),n.clone().applyAxisAngle(i.up,e));return o.v.applyAxisAngle(i.up,-e),o.w.applyAxisAngle(i.up,-e),o}Object.freeze(l);var p=Math.asin(.1*o.R/o.R),d=Math.sin(p),v=Math.cos(p);function m(e,t){return new r.Pa4(e.x*d-e.z*v+o.R*t.y,-e.y-o.R*t.z*v+o.R*t.x*d)}function y(e){return e.x*v}function b(e){var t=3.5/o.m;return e.length()/t}function g(e){var t,n=1/o.m,i=.39+.257*(t=new r.Pa4(e/v,0,0)).x-.044*t.x*t.x;return o.Dt*((1+i)*e)/n}function w(e,t){var n=g(y(e));return b(m(e,t))<=n}function k(e,t){return{c:y(e),s:m(e,t),A:3.5/o.m,B:1/o.m}}function T(e,t){var n=k(e,t),r=n.c,i=n.s,s=n.A,a=n.B,l=(1+o.e)*(r/a);return E(-i.x/s*d-l*v,i.y/s,i.x/s*v-l*d)}function R(e,t){var n=k(e,t),r=n.c,i=n.B,s=(1+o.e)*(r/i),a=.471-.241*Math.atan2(Math.abs(e.y),e.x),l=Math.atan2(e.y,e.x),c=Math.cos(l);return E(-a*s*c*v-s*v,a*s*Math.sin(l),a*s*c*v-s*d)}function A(e,t){return w(e,t)?T(e,t):R(e,t)}function x(e,t){var n=T(e,t),r=R(e,t),i=Math.sign(e.y)===Math.sign(t.z)?Math.cos(Math.atan2(e.y,e.x)):1;return{v:r.v.lerp(n.v,i),w:r.w.lerp(n.w,i)}}function E(e,t,n){return{v:new r.Pa4(e/o.m,t/o.m),w:new r.Pa4(-o.R/o.I*t*d,o.R/o.I*(e*d-n*v),o.R/o.I*t*v)}}function P(e,t){var n=Math.atan2(-e.x,e.y),r=2.5*t.length()*(e.length()*o.R)/(o.R*o.R),s=t.clone().normalize();return(0,i.a1)(s).applyAxisAngle(s,n).multiplyScalar(r)}},"./src/model/physics/pocket.ts":(e,t,n)=>{n.d(t,{f:()=>l});var r=n("./src/model/ball.ts"),i=n("./src/model/physics/constants.ts"),o=n("./src/utils/utils.ts");function s(e,t){for(var n=0;nthis.radius-i.R){var s=this.pos.clone().sub(e.pos).normalize().setZ(0);n>-i.R/2&&e.vel.addScaledVector(s,7*i.R*t*i.g),0>e.vel.dot(s)&&(e.ballmesh.trace.forceTrace(e.pos),e.vel.x=s.x*e.vel.length()/2,e.vel.y=s.y*e.vel.length()/2)}var a=this.restingDepth(e);n{n.d(t,{i:()=>b});var r=n("./src/view/tablegeometry.ts"),i=n("./src/model/physics/physics.ts"),o=n("./src/view/pocketgeometry.ts"),s=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"bounceAny",value:function(e,n){var o=!(arguments.length>2)||void 0===arguments[2]||arguments[2],s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:i.h_,a=e.futurePosition(n);if(t.willBounceLong(a,o)){var l=a.y>r.H.tableY?-Math.PI/2:Math.PI/2;return t.bounceIn(l,e,s)}if(t.willBounceShort(a,o)){var c=a.x>r.H.tableX?0:Math.PI;return t.bounceIn(c,e,s)}}},{key:"willBounceShort",value:function(e,n){return n?t.willBounceShortSegment(o.u.pockets.pocketNW.knuckleSW.pos.y,o.u.pockets.pocketSW.knuckleNW.pos.y,e):t.willBounceShortSegment(r.H.Y,-r.H.Y,e)}},{key:"willBounceLong",value:function(e,n){return n?t.willBounceLongSegment(o.u.pockets.pocketNW.knuckleNE.pos.x,o.u.pockets.pocketN.knuckleNW.pos.x,e)||t.willBounceLongSegment(o.u.pockets.pocketN.knuckleNE.pos.x,o.u.pockets.pocketNE.knuckleNW.pos.x,e):t.willBounceLongSegment(-r.H.X,r.H.X,e)}},{key:"willBounceLongSegment",value:function(e,t,n){return n.x>e&&n.xr.H.tableY}},{key:"willBounceShortSegment",value:function(e,t,n){return n.y>t&&n.yr.H.tableX}},{key:"bounceIn",value:function(e,t,n){t.ballmesh.trace.forceTrace(t.futurePos);var r=(0,i.ZI)(e,t.vel,t.rvel,n);return t.vel.add(r.v),t.rvel.add(r.w),r.v.length()}}],function(e,t){for(var n=0;n100)throw Error("Depth exceeded resolving collisions");this.balls.forEach(function(t){t.update(e)})}},{key:"prepareAdvanceAll",value:function(e){var t=this;return this.pairs.every(function(n){return t.prepareAdvancePair(n.a,n.b,e)})&&this.balls.every(function(n){return t.prepareAdvanceToCushions(n,e)})}},{key:"prepareAdvancePair",value:function(e,t,n){if(c.willCollide(e,t,n)){var r=c.collide(e,t);return this.outcome.push(d.k.collision(e,t,r)),!1}return!0}},{key:"prepareAdvanceToCushions",value:function(e,t){if(!e.onTable())return!0;var n=e.futurePosition(t);if(Math.abs(n.y)1&&void 0!==arguments[1]?arguments[1]:this.cueball;return this.balls.filter(function(e){return e!==t}).some(function(t){return t.pos.distanceTo(e)<2*l.R})}}],t=[{key:"fromSerialised",value:function(e){var t=new n(e.balls.map(function(e){return a.e.fromSerialised(e)}));return t.updateFromSerialised(e),t}}],e&&m(n.prototype,e),t&&m(n,t),n}()},"./src/utils/gltf.ts":(e,t,n)=>{let r,i,o,s;n.d(t,{pC:()=>eP,MR:()=>eS});var a=n("./node_modules/three/build/three.module.js");function l(e,t=1/0,n=null){i||(i=new a._12(2,2,1,1)),o||(o=new a.jyz({uniforms:{blitTexture:new a.xWb(e)},vertexShader:` varying vec2 vUv; void main(){ vUv = uv; diff --git a/package.json b/package.json index c0e6da9..32353ef 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@testing-library/dom": "^9.3.3", "@types/chai": "^4.3.10", "@types/jest": "^29.5.8", - "@types/node": "^20.9.0", + "@types/node": "^20.9.1", "@types/three": "^0.158.2", "chai": "^4.3.10", "ini": "^4.1.1", diff --git a/src/container/browsercontainer.ts b/src/container/browsercontainer.ts index d070a14..d80bcd9 100644 --- a/src/container/browsercontainer.ts +++ b/src/container/browsercontainer.ts @@ -110,7 +110,7 @@ export class BrowserContainer { startReplay(replay) { this.breakState = this.parse(decodeURIComponent(replay)) console.log(this.breakState) - if (Date.now() - this.breakState.now < 5000) { + if (Date.now() - this.breakState.now < 500000) { console.log("upload") this.offerUpload() } diff --git a/src/controller/rules/nineball.ts b/src/controller/rules/nineball.ts index 18bddfc..3048bdb 100644 --- a/src/controller/rules/nineball.ts +++ b/src/controller/rules/nineball.ts @@ -31,7 +31,8 @@ export class NineBall implements Rules { } startTurn() { - // not used + this.previousBreak = this.currentBreak + this.currentBreak = 0 } nextCandidateBall() { @@ -80,6 +81,7 @@ export class NineBall implements Rules { return new WatchAim(this.container) } if (Outcome.isBallPottedNoFoul(table.cueball, outcome)) { + this.currentBreak += Outcome.potCount(outcome) this.container.sound.playSuccess(table.inPockets()) if (this.isEndOfGame(outcome)) { this.container.eventQueue.push(new ChatEvent(null, `game over`)) diff --git a/src/events/recorder.ts b/src/events/recorder.ts index 0fe1e3b..93142f0 100644 --- a/src/events/recorder.ts +++ b/src/events/recorder.ts @@ -11,6 +11,7 @@ export class Recorder { container: Container shots: GameEvent[] = [] states: number[][] = [] + start = Date.now() breakStart: number | undefined breakStartTime replayUrl @@ -34,7 +35,7 @@ export class Recorder { } wholeGame() { - return this.state(this.states[0], this.shots) + return this.state(this.states[0], this.shots, this.start, 0, true) } last() { @@ -62,13 +63,14 @@ export class Recorder { return undefined } - private state(init, events, start = 0, score = 0) { + private state(init, events, start = 0, score = 0, wholeGame = false) { return { init: init, shots: events, start: start, now: Date.now(), score: score, + wholeGame: wholeGame, } } @@ -103,10 +105,6 @@ export class Recorder { lastShotLink(isPartOfBreak, potCount, balls) { const pots = potCount > 1 ? potCount - 1 : 0 - const breakPoints = - this.container.rules.currentBreak > 0 - ? " " + this.container.rules.currentBreak - : "" let colourString = "#000000" if (balls.length > 0) { @@ -115,8 +113,7 @@ export class Recorder { }) } - const shotIcon = - "⚈".repeat(pots) + (isPartOfBreak ? "⚈" : "⚆") + breakPoints + const shotIcon = "⚈".repeat(pots) + (isPartOfBreak ? "⚈" : "⚆") const serialisedShot = JSON.stringify(this.lastShot()) this.generateLink(shotIcon, serialisedShot, colourString) } diff --git a/test/events/recorder.spec.ts b/test/events/recorder.spec.ts index 0f02514..b0a5a43 100644 --- a/test/events/recorder.spec.ts +++ b/test/events/recorder.spec.ts @@ -22,10 +22,6 @@ describe("Recorder", () => { const event: HitEvent = new HitEvent(container.table.serialise()) recorder.record(event) expect(recorder.wholeGame()).to.be.not.null - const replay = recorder.wholeGame() - const last = recorder.lastShot() - last.now = replay.now - expect(JSON.stringify(last)).to.equals(JSON.stringify(replay)) done() }) diff --git a/yarn.lock b/yarn.lock index cf7e421..76c4e38 100644 --- a/yarn.lock +++ b/yarn.lock @@ -936,10 +936,10 @@ dependencies: "@types/node" "*" -"@types/node@*", "@types/node@^20.9.0": - version "20.9.0" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.0.tgz#bfcdc230583aeb891cf51e73cfdaacdd8deae298" - integrity sha512-nekiGu2NDb1BcVofVcEKMIwzlx4NjHlcjhoxxKBNLtz15Y1z7MYf549DFvkHSId02Ax6kGwWntIBPC3l/JZcmw== +"@types/node@*", "@types/node@^20.9.1": + version "20.9.1" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.1.tgz#9d578c610ce1e984adda087f685ace940954fe19" + integrity sha512-HhmzZh5LSJNS5O8jQKpJ/3ZcrrlG6L70hpGqMIAoM9YVD0YBRNWYsfwcXq8VnSjlNpCpgLzMXdiPo+dxcvSmiA== dependencies: undici-types "~5.26.4" @@ -1578,9 +1578,9 @@ camelcase@^6.0.0, camelcase@^6.2.0: integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== caniuse-lite@^1.0.30001541: - version "1.0.30001562" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001562.tgz#9d16c5fd7e9c592c4cd5e304bc0f75b0008b2759" - integrity sha512-kfte3Hym//51EdX4239i+Rmp20EsLIYGdPkERegTgU19hQWCRhsRFGKHTliUlsry53tv17K7n077Kqa0WJU4ng== + version "1.0.30001563" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001563.tgz#aa68a64188903e98f36eb9c56e48fba0c1fe2a32" + integrity sha512-na2WUmOxnwIZtwnFI2CZ/3er0wdNzU7hN+cPYz/z2ajHThnkWjNBOpEPP4n+4r2WPM847JaMotaJE3bnfzjyKw== chai@^4.3.10: version "4.3.10" @@ -2029,9 +2029,9 @@ ee-first@1.1.1: integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow== electron-to-chromium@^1.4.535: - version "1.4.586" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.586.tgz#68683163ed52a111213e2482ff847e76a5c6e891" - integrity sha512-qMa+E6yf1fNQbg3G66pHLXeJUP5CCCzNat1VPczOZOqgI2w4u+8y9sQnswMdGs5m4C1rOePq37EVBr/nsPQY7w== + version "1.4.588" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.588.tgz#d553f3c008e73488fb181fdf2601fdb0b1ffbb78" + integrity sha512-soytjxwbgcCu7nh5Pf4S2/4wa6UIu+A3p03U2yVr53qGxi1/VTR3ENI+p50v+UxqqZAfl48j3z55ud7VHIOr9w== emittery@^0.13.1: version "0.13.1"