diff --git a/dist/index.js b/dist/index.js index 066b2f4..19e00a9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,4 +1,4 @@ -"use strict";(self.webpackChunkbilliards=self.webpackChunkbilliards||[]).push([[57],{"./src/container/container.ts":(e,t,n)=>{n.d(t,{m:()=>J});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,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=function(){var e;function t(e){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),l(this,"camera",void 0),l(this,"mode",this.topView),l(this,"mainMode",this.aimView),l(this,"height",8*a.R),l(this,"elapsed",void 0),this.camera=new i.ubm(45,e,a.R,1e3*a.R)}return e=[{key:"update",value:function(e,t){this.elapsed=e,this.mode(t)}},{key:"topView",value:function(e){this.camera.fov=s.v.fov,this.camera.position.lerp(s.v.viewPoint(this.camera.aspect,this.camera.fov),.9),this.camera.up=o.up,this.camera.lookAt(o.v_)}},{key:"aimView",value:function(e){var t=arguments.length>1&&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.Dz)(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.cj9.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}}],function(e,t){for(var n=0;n0&&(null===(t=this.cuePowerElement)||void 0===t?void 0:t.value)&&(this.cuePowerElement.value=e)}}],function(e,t){for(var n=0;nthis.sentTime+this.period||e.type!==N.B.AIM){this.flush(),this.apply(e),this.sentTime=performance.now();return}this.pending=e}}],function(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=U.P.potCount(e);if(t||this.breakLink(n),this.lastShotLink(t||n,r,U.P.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=0===this.container.rules.currentBreak?this.container.rules.previousBreak:this.container.rules.currentBreak;t.score=n;var r=JSON.stringify(t),i=D.A.crush(r);this.generateLink("break(".concat(n,")"),i,"black"),n>=4&&this.generateHiScoreLink(i)}}},{key:"wholeGameLink",value:function(){var e=this.wholeGame(),t="frame(".concat(this.shotCount(e.shots)," shots)"),n=JSON.stringify(e),r=D.A.crush(n);this.generateLink(t,r,"black")}},{key:"shotCount",value:function(e){return e.filter(function(e){return"RERACK"!==e.type}).length}},{key:"generateLink",value:function(e,t,n){var r="".concat(this.replayUrl).concat(this.fullyEncodeURI(t)),i='').concat(e,"");this.container.eventQueue.push(new B.b(null,"".concat(i)))}},{key:"generateHiScoreLink",value:function(e){var t="".concat(this.hiScoreUrl,"?ruletype=").concat(this.container.rules.rulename,"&state=").concat(this.fullyEncodeURI(e)),n='').concat("hi score 🏆","");this.container.eventQueue.push(new B.b(null,"".concat(n)))}},{key:"fullyEncodeURI",value:function(e){return encodeURIComponent(e).replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\!/g,"%21").replace(/\*/g,"%2A")}}],function(e,t){for(var n=0;n').concat(e,"")));r.push(new B.b(null,s))})},this.redo.onclick=function(e){var r=new V.W(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.T),t.push(e)}},{key:"getElement",value:function(e){return document.getElementById(e)}}],function(e,t){for(var n=0;n0?this.element.innerHTML="Break
"+e:this.element.innerHTML="")}},{key:"getElement",value:function(e){return document.getElementById(e)}}],function(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,{m:()=>c});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){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var c=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&&l(e,t)}(c,e);var t,n,i=(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=a(c);return e=t?Reflect.construct(n,arguments,a(this).constructor):n.apply(this,arguments),e&&("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 c(e){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,c);var t,n=(t=i.call(this,e)).container.table;return n.cue.aimMode(),n.cue.showHelper(!0),n.cueball=t.container.rules.cueball,n.cue.moveTo(n.cueball.pos),t.container.view.camera.suggestMode(t.container.view.camera.aimView),n.cue.aimInputs.showOverlap(),t}return n=[{key:"handleInput",value:function(e){switch(e.key){case"Space":this.container.table.cue.adjustPower(e.t*this.scale*.7);break;case"SpaceUp":return this.playShot();default:if(!this.commonKeyHandler(e))return this}return this.container.sendEvent(this.container.table.cue.aim),this}},{key:"handleBreak",value:function(e){return new s.e(this.container,e.init,e.shots,e.retry)}},{key:"playShot",value:function(){var e=new r.Qe(this.container.table.serialise());return this.container.sendEvent(e),this.container.recorder.record(e),new o.H(this.container)}}],function(e,t){for(var n=0;n{n.d(t,{Qe:()=>r.Q,pd:()=>i.p,xI:()=>o}),n("./src/events/beginevent.ts"),n("./src/events/aimevent.ts");var r=n("./src/events/hitevent.ts"),i=n("./src/events/input.ts");n("./src/events/abortevent.ts"),n("./src/events/stationaryevent.ts");var o=function(){var e;function t(e){var n,r;!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),r=void 0,(n="container")in this?Object.defineProperty(this,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):this[n]=r,this.container=e}return e=[{key:"handleInput",value:function(e){return this}},{key:"handleBegin",value:function(e){return this}},{key:"handleBreak",value:function(e){return this}},{key:"handleStartAim",value:function(e){return this}},{key:"handleAim",value:function(e){return this}},{key:"handleHit",value:function(e){return this}},{key:"handleAbort",value:function(e){return this}},{key:"handleWatch",value:function(e){return this}},{key:"handlePlaceBall",value:function(e){return this}},{key:"handleStationary",value:function(e){return this}},{key:"handleChat",value:function(e){return this}},{key:"handleRejoin",value:function(e){return this}},{key:"onFirst",value:function(){}}],function(e,t){for(var n=0;n{n.d(t,{y:()=>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){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}var f=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&&u(e,t)}(f,e);var t,n,r=(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=c(f);return e=t?Reflect.construct(n,arguments,c(this).constructor):n.apply(this,arguments),e&&("object"===h(e)||"function"==typeof e)?e:l(this)});function f(){var e,t,n;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,f),e=r.apply(this,arguments),(n="scale")in(t=l(e))?Object.defineProperty(t,n,{value:.001,enumerable:!0,configurable:!0,writable:!0}):t[n]=.001,e}return n=[{key:"handleAbort",value:function(e){return new i.o(this.container)}},{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}},{key:"hit",value:function(){this.container.table.outcome=[s.P.hit(this.container.table.cueball,this.container.table.cue.aim.power)],this.container.table.hit(),this.container.view.camera.suggestMode(this.container.view.camera.aimView),this.container.table.cue.showHelper(!1)}},{key:"commonKeyHandler",value:function(e){var t=this.container.table.cue,n=e.t*this.scale;switch(e.key){case"ArrowLeft":return t.rotateAim(-n,this.container.table),!0;case"ArrowRight":return t.rotateAim(n,this.container.table),!0;case"ArrowDown":return t.adjustSpin(new a.Pq0(0,-n),this.container.table),!0;case"ArrowUp":return t.adjustSpin(new a.Pq0(0,n),this.container.table),!0;case"ShiftArrowLeft":return t.adjustSpin(new a.Pq0(n,0),this.container.table),!0;case"ShiftArrowRight":return t.adjustSpin(new a.Pq0(-n,0),this.container.table),!0;case"KeyPUp":return(0,o.KP)(this.container.view.scene),!0;case"KeyHUp":return t.toggleHelper(),!0;case"movementXUp":return t.rotateAim(2*n,this.container.table),!0;case"movementYUp":case"NumpadSubtract":return this.container.view.camera.adjustHeight(8*n),!0;case"NumpadAdd":return this.container.view.camera.adjustHeight(-(8*n)),!0;case"KeyOUp":return this.container.view.camera.toggleMode(),!0;case"KeyDUp":return this.togglePanel(),!0;case"KeyFUp":return this.toggleFullscreen(),!0;default:return!1}}},{key:"togglePanel",value:function(){this.container.sliders.toggleVisibility(),this.container.table.showSpin(!0),this.container.table.showTraces(!0),("undefined"==typeof process?"undefined":h(process))!=="object"&&console.log(this.container.table.serialise())}},{key:"toggleFullscreen",value:function(){document.fullscreenElement?document.exitFullscreen&&document.exitFullscreen():document.documentElement.requestFullscreen()}}],function(e,t){for(var n=0;n{function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}n.d(t,{o:()=>o});var o=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&&i(e,t)}(s,e);var t,n,o=(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(s);return e=t?Reflect.construct(n,arguments,r(this).constructor):n.apply(this,arguments),e&&("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 s(){return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,s),o.apply(this,arguments)}return n=[{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}}],function(e,t){for(var n=0;n{n.d(t,{x:()=>p});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");function u(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e,t){return(f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var p=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&&f(e,t)}(p,e);var t,n,r=(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=h(p);return e=t?Reflect.construct(n,arguments,h(this).constructor):n.apply(this,arguments),e&&("object"==(e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)||"function"==typeof e)?e:u(this)});function p(e){var t,n,i,o;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,p),n=u(t=r.call(this,e)),i="placescale",o=.02*a.R,i in n?Object.defineProperty(n,i,{value:o,enumerable:!0,configurable:!0,writable:!0}):n[i]=o,t.container.table.cue.moveTo(t.container.table.cueball.pos),t.container.table.cue.aim.power=0,t.container.view.camera.forceMode(t.container.view.camera.aimView),t}return n=[{key:"onFirst",value:function(){var e=this.container.table.cueball;this.container.rules.allowsPlaceBall()&&e.pos.copy(this.container.rules.placeBall()),e.setStationary(),e.updateMesh(0),this.container.table.cue.placeBallMode(),this.container.table.cue.showHelper(!1),this.container.table.cue.moveTo(this.container.table.cueball.pos),this.container.table.cue.aimInputs.setButtonText("Place\nBall"),this.container.rules.allowsPlaceBall()||this.container.inputQueue.push(new i.pd(1,"SpaceUp"))}},{key:"handleInput",value:function(e){var t=this.container.table.cueball.pos;switch(e.key){case"ArrowLeft":case"KeyI":this.moveTo(0,e.t*this.placescale);break;case"ArrowRight":case"KeyK":this.moveTo(0,-e.t*this.placescale);break;case"movementXUp":this.moveTo(0,-e.t*this.placescale*2);break;case"movementYUp":this.moveTo(-e.t*this.placescale*2,0);break;case"KeyJ":this.moveTo(-e.t*this.placescale,0);break;case"KeyL":this.moveTo(e.t*this.placescale,0);break;case"SpaceUp":return this.placed();default:this.commonKeyHandler(e)}return this.container.table.cue.moveTo(t),this.container.view.camera.forceMove(this.container.table.cue.aim),this.container.sendEvent(this.container.table.cue.aim),this}},{key:"moveTo",value:function(e,t){var n=new l.Pq0(e,t),r=this.container.table.cueball.pos.add(n);r.copy(this.container.rules.placeBall(r)),c.l.indicateValid(!this.container.table.overlapsAny(r))}},{key:"placed",value:function(){return this.container.table.overlapsAny(this.container.table.cueball.pos)?this:(this.container.table.cue.aimInputs.setButtonText("Hit"),this.container.sound.playNotify(),this.container.sendEvent(new s.W(this.container.table.shortSerialise())),new o.m(this.container))}}],function(e,t){for(var n=0;n{function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}n.d(t,{H:()=>o});var o=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&&i(e,t)}(s,e);var t,n,o=(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(s);return e=t?Reflect.construct(n,arguments,r(this).constructor):n.apply(this,arguments),e&&("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 s(e){var t;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,s),(t=o.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}}],function(e,t){for(var n=0;n{n.d(t,{e:()=>v});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),f(h(r=i.call(this,e)),"delay",void 0),f(h(r),"shots",void 0),f(h(r),"firstShot",void 0),f(h(r),"timer",void 0),f(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.W(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 n=[{key:"playNextShot",value:function(e){var t=this,n=this.shots.shift();if((null==n?void 0:n.type)===l.B.RERACK){c.x.fromJson(n.ballinfo).applyToController(this),this.shots.length>0&&this.playNextShot(e);return}var i=o.w.fromJson(n);this.container.table.cueball=this.container.table.balls[i.i],console.log(this.container.table.cueball.pos.distanceTo(i.pos)),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.Q(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.w.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.m(this.container)}}],function(e,t){for(var n=0;n{n.d(t,{V:()=>O});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"),m=n("./src/model/physics/constants.ts"),v=n("./src/utils/respot.ts"),y=n("./src/view/tablegeometry.ts"),b=n("./src/events/startaimevent.ts");function g(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var w=function(){var e;function t(e){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),g(this,"container",void 0),g(this,"cueball",void 0),g(this,"currentBreak",0),g(this,"previousBreak",0),g(this,"score",0),g(this,"rulename","nineball"),this.container=e}return e=[{key:"startTurn",value:function(){this.previousBreak=this.currentBreak,this.currentBreak=0}},{key:"nextCandidateBall",value:function(){return v.k.closest(this.container.table.cueball,this.container.table.balls)}},{key:"placeBall",value:function(e){if(e){var t=new o.Pq0(-y.P.X/2,y.P.tableY),n=new o.Pq0(-y.P.tableX,-y.P.tableY);return e.clamp(n,t)}return new o.Pq0(-(11*m.R)/.5,0,0)}},{key:"asset",value:function(){return"models/p8.min.gltf"}},{key:"tableGeometry",value:function(){y.P.hasPockets=!0}},{key:"table",value:function(){var e=new f.X(this.rack());return this.cueball=e.cueball,e}},{key:"rack",value:function(){return i.m.diamond()}},{key:"update",value:function(e){var t=this.container.table;if(h.P.isCueBallPotted(t.cueball,e))return(this.startTurn(),this.container.isSinglePlayer)?new a.x(this.container):(this.container.sendEvent(new u.z(p.v_,!0)),new l.r(this.container));if(h.P.isBallPottedNoFoul(t.cueball,e)){var n=h.P.potCount(e);return(this.currentBreak+=n,this.score+=n,this.container.sound.playSuccess(t.inPockets()),this.isEndOfGame(e))?(this.container.eventQueue.push(new c.b(null,"game over")),this.container.recorder.wholeGameLink(),new d.o(this.container)):(this.container.sendEvent(new r.Q(t.serialise())),new s.m(this.container))}return(this.container.sendEvent(new b.M),this.container.isSinglePlayer)?(this.container.sendEvent(new r.Q(t.serialise())),this.startTurn(),new s.m(this.container)):new l.r(this.container)}},{key:"isPartOfBreak",value:function(e){return h.P.isBallPottedNoFoul(this.container.table.cueball,e)}},{key:"isEndOfGame",value:function(e){var t=this.container.table.balls.filter(function(e){return e.onTable()});return 1===t.length&&t[0]===this.cueball}},{key:"otherPlayersCueBall",value:function(){return this.cueball}},{key:"secondToPlay",value:function(){}},{key:"allowsPlaceBall",value:function(){return!0}}],function(e,t){for(var n=0;n{n.d(t,{c:()=>k});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"),m=n("./src/events/placeballevent.ts"),v=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.P.firstCollision(n);return{pots:o.P.potCount(n),firstCollision:i,legalFirstCollision:t.isLegalFirstCollision(e,r,i),whitePotted:o.P.isCueBallPotted(e.cueball,n)}}},{key:"isLegalFirstCollision",value:function(e,n,r){if(!r)return!1;var i=r.ballB.id;return n?i>=7:!(t.coloursOnTable(e).filter(function(e){return e.id0)}},{key:"respotAllPottedColours",value:function(e,t){return o.P.pots(t).filter(function(e){return e.id<7}).filter(function(e){return 0!==e.id}).map(function(t){return a.k.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.P.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.P.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.P.pots(e)[0].id;return n!==t.firstCollision.ballB.id?this.foul(e,t):this.previousPotRed?(this.respot(e),this.currentBreak+=n+1,this.previousPotRed=!1,this.continueBreak()):y.coloursOnTable(this.container.table).filter(function(e){return e.id0?this.foul(e,t):(this.currentBreak+=n+1,this.previousPotRed=!1,this.continueBreak())}},{key:"foul",value:function(e,t){return this.foulPoints=this.foulCalculation(e,t),this.respot(e),this.switchPlayer()}},{key:"foulCalculation",value:function(e,t){var n,r,i,s,a=o.P.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,void 0);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,void 0)}}(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.P.hasPockets=!0}},{key:"table",value:function(){var e=new f.X(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.P.isClearTable(this.container.table)&&this.currentBreak>0}},{key:"allowsPlaceBall",value:function(){return!0}},{key:"asset",value:function(){return t.tablemodel}},{key:"startTurn",value:function(){this.previousPotRed=!1,this.targetIsRed=y.redsOnTable(this.container.table).length>0,this.previousBreak=this.currentBreak,this.score+=this.currentBreak,this.currentBreak=0,this.container.hud.updateBreak(this.currentBreak)}},{key:"rack",value:function(){return s.m.snooker()}},{key:"nextCandidateBall",value:function(){var e=this.container.table,t=y.redsOnTable(e),n=y.coloursOnTable(e);return this.previousPotRed?a.k.closest(e.cueball,n):t.length>0?a.k.closest(e.cueball,t):n.length>0?n[0]:void 0}},{key:"placeBall",value:function(e){if(e){var t=new r.Pq0(s.m.baulk,0,0),n=s.m.sixth,i=e.distanceTo(t);if(e.x>=s.m.baulk&&(e.x=s.m.baulk),!(i>n))return e;var o=e.clone().sub(t).normalize();return t.add(o.multiplyScalar(n))}return new r.Pq0(s.m.baulk,-s.m.sixth/2.6,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.M(this.foulPoints)),this.container.isSinglePlayer)?(this.container.sendEvent(new i.Q(e.serialise())),this.startTurn(),new l.m(this.container)):new c.r(this.container)}},{key:"continueBreak",value:function(){this.container.hud.updateBreak(this.currentBreak);var e=this.container.table;return(this.container.sound.playSuccess(e.inPockets()),o.P.isClearTable(e))?(this.container.eventQueue.push(new u.b(null,"game over")),this.container.recorder.wholeGameLink(),new h.o(this.container)):(this.container.sendEvent(new i.Q(e.serialise())),new l.m(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.x(this.container):(this.container.sendEvent(new m.z(v.v_,!0)),new c.r(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.Q(n);this.container.sendEvent(r),this.container.recorder.record(r)}}}],function(e,t){for(var n=0;n{n.d(t,{r:()=>s});var r=n("./src/controller/watchshot.ts");function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}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=i(a);return e=t?Reflect.construct(n,arguments,i(this).constructor):n.apply(this,arguments),e&&("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(e){var t;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),(t=s.call(this,e)).container.table.cueball=t.container.rules.otherPlayersCueBall(),t.container.table.cue.moveTo(t.container.table.cueball.pos),t.container.view.camera.suggestMode(t.container.view.camera.topView),t}return n=[{key:"handleAim",value:function(e){return this.container.table.cue.aim=e,this.container.table.cueball.pos.copy(e.pos),this}},{key:"handleHit",value:function(e){return this.container.table.updateFromSerialised(e.tablejson),new r.O(this.container)}}],function(e,t){for(var n=0;n{n.d(t,{O:()=>c});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){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var c=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&&l(e,t)}(c,e);var t,n,o=(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=a(c);return e=t?Reflect.construct(n,arguments,a(this).constructor):n.apply(this,arguments),e&&("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 c(e){var t;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,c),(t=o.call(this,e)).container.table.outcome=[],t.container.table.hit(),t}return n=[{key:"handleStartAim",value:function(e){return new r.m(this.container)}},{key:"handlePlaceBall",value:function(e){return new s.x(this.container)}},{key:"handleWatch",value:function(e){return"rerack"in e.json?(console.log("Respot"),this.container.table.updateFromSerialised(e.json),this):new i.r(this.container)}}],function(e,t){for(var n=0;n{n.d(t,{h:()=>a});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var a=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&&s(e,t)}(a,e);var t,n,r=(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=o(a);return e=t?Reflect.construct(n,arguments,o(this).constructor):n.apply(this,arguments),e&&("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(){var e;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),(e=r.call(this)).type=i.B.ABORT,e}return n=[{key:"applyToController",value:function(e){return e.handleAbort(this)}}],function(e,t){for(var n=0;n{n.d(t,{w:()=>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,{u:()=>a});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var a=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&&s(e,t)}(a,e);var t,n,r=(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=o(a);return e=t?Reflect.construct(n,arguments,o(this).constructor):n.apply(this,arguments),e&&("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(){var e;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),(e=r.call(this)).type=i.B.BEGIN,e}return n=[{key:"applyToController",value:function(e){return e.handleBegin(this)}}],function(e,t){for(var n=0;n{n.d(t,{W:()=>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,{b:()=>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,{B:()=>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,{F:()=>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,{Q:()=>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,{p:()=>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,{s:()=>a});var r=n("./src/events/input.ts"),i=n("./node_modules/interactjs/dist/interact.min.js"),o=n.n(i);function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a=function(){var e;function t(e){var n=this;!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),s(this,"pressed",{}),s(this,"released",{}),s(this,"keydown",function(e){null==n.pressed[e.code]&&(n.pressed[e.code]=performance.now()),e.stopImmediatePropagation(),"F12"!==e.key&&e.preventDefault()}),s(this,"keyup",function(e){n.released[e.code]=performance.now()-n.pressed[e.code],delete n.pressed[e.code],e.stopImmediatePropagation(),"F12"!==e.key&&e.preventDefault()}),s(this,"mousetouch",function(e){var t,r,i=n.released,o=e.client.yMath.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.p(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.p(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)}})}}],function(e,t){for(var n=0;n{n.d(t,{z:()=>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,{x:()=>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,{M:()=>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.B.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.F)},"./src/events/stationaryevent.ts":(e,t,n)=>{n.d(t,{T:()=>a});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var a=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&&s(e,t)}(a,e);var t,n,r=(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=o(a);return e=t?Reflect.construct(n,arguments,o(this).constructor):n.apply(this,arguments),e&&("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(){var e;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),(e=r.call(this)).type=i.B.STATIONARY,e}return n=[{key:"applyToController",value:function(e){return e.handleStationary(this)}}],function(e,t){for(var n=0;n{n.d(t,{Q:()=>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),m(p(e=i.call(this)),"clientResendFrom",void 0),m(p(e),"serverResendFrom",void 0),e.type=o.B.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").F),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.B.BEGIN:return new h.u;case o.B.AIM:return s.w.fromJson(e);case o.B.BREAK:return u.W.fromJson(e);case o.B.WATCHAIM:return a.Q.fromJson(e.json);case o.B.HIT:return l.Q.fromJson(e);case o.B.CHAT:return f.b.fromJson(e);case o.B.REJOIN:return b.fromJson(e);case o.B.ABORT:return new c.h;case o.B.PLACEBALL:return g.z.fromJson(e);case o.B.RERACK:return w.x.fromJson(e);case o.B.STARTAIM:return k.M.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 \uD83C\uDFC6{n.d(t,{c:()=>d,U:()=>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,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=function(){var e;function t(e,n){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),l(this,"line",void 0),l(this,"geometry",void 0),l(this,"positions",void 0),l(this,"lastPos",new s.Pq0),l(this,"lastVel",new s.Pq0),this.geometry=new s.LoY,this.positions=new Float32Array(3*e),this.geometry.setAttribute("position",new s.THS(this.positions,3)),this.reset();var r=new s.mrM({color:n,opacity:.25,linewidth:3,transparent:!0});this.line=new s.N1A(this.geometry,r),this.line.visible=!1}return e=[{key:"reset",value:function(){this.geometry.setDrawRange(0,0),this.lastVel.setZ(1)}},{key:"forceTrace",value:function(e){this.lastVel.z=1,this.addTraceGiven(e,this.lastVel,1,.1,1)}},{key:"addTrace",value:function(e,t){if(0!==t.length()){var n=this.lastVel.angleTo(t),r=n>Math.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)}}],function(e,t){for(var n=0;nMath.abs(this.rvel.z))&&(this.setStationary(),!0)}},{key:"setStationary",value:function(){this.vel.copy(i.v_),this.rvel.copy(i.v_),this.state="Stationary"}},{key:"isRolling",value:function(){return 0!==this.vel.lengthSq()&&0!==this.rvel.lengthSq()&&(0,o.Mq)(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,{P:()=>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,{I:()=>o,Mz:()=>r,Qg:()=>v,R:()=>f,Wv:()=>b,Ys:()=>g,cM:()=>w,e:()=>p,g:()=>s,gT:()=>c,gf:()=>l,jG:()=>m,kL:()=>u,kM:()=>k,m:()=>h,mu:()=>a,x3:()=>i,xO:()=>y});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 m(e){f=e,d()}function v(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,{O:()=>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,{$8:()=>x,Gp:()=>g,JD:()=>u,Mq:()=>a,QK:()=>f,QV:()=>P,Un:()=>b,c0:()=>y,lx:()=>h,p2:()=>c,s0:()=>v,t6:()=>S,yO:()=>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.Pq0;function a(e,t){return s.copy(e).addScaledVector((0,i.KM)(t),o.R)}var l={v:new r.Pq0,w:new r.Pq0};function c(e,t){var n=a(e,t).setZ(0);return l.v.copy((0,i.xb)(n).multiplyScalar(-o.gf*o.g)),l.w.copy((0,i.xb)((0,i.KM)(n)).multiplyScalar(2.5*o.gf*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.Pq0(e.x,e.y,0).length(),n=5/7*o.x3/(o.m*o.R)/t,i=5/7*o.x3/(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.KM)(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),m=Math.cos(p);function v(e,t){return new r.Pq0(e.x*d-e.z*m+o.R*t.y,-e.y-o.R*t.z*m+o.R*t.x*d)}function y(e){return e.x*m}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.Pq0(e/m,0,0)).x-.044*t.x*t.x;return o.gT*((1+i)*e)/n}function w(e,t){var n=g(y(e));return b(v(e,t))<=n}function k(e,t){return{c:y(e),s:v(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 A(-i.x/s*d-l*m,i.y/s,i.x/s*m-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 A(-a*s*c*m-s*m,a*s*Math.sin(l),a*s*c*m-s*d)}function P(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 A(e,t,n){return{v:new r.Pq0(e/o.m,t/o.m),w:new r.Pq0(-o.R/o.I*t*d,o.R/o.I*(e*d-n*m),o.R/o.I*t*m)}}function S(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.KM)(s).applyAxisAngle(s,n).multiplyScalar(r)}},"./src/model/physics/pocket.ts":(e,t,n)=>{n.d(t,{Z:()=>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,{X:()=>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.$8,a=e.futurePosition(n);if(t.willBounceLong(a,o)){var l=a.y>r.P.tableY?-Math.PI/2:Math.PI/2;return t.bounceIn(l,e,s)}if(t.willBounceShort(a,o)){var c=a.x>r.P.tableX?0:Math.PI;return t.bounceIn(c,e,s)}}},{key:"willBounceShort",value:function(e,n){return n?t.willBounceShortSegment(o.f.pockets.pocketNW.knuckleSW.pos.y,o.f.pockets.pocketSW.knuckleNW.pos.y,e):t.willBounceShortSegment(r.P.Y,-r.P.Y,e)}},{key:"willBounceLong",value:function(e,n){return n?t.willBounceLongSegment(o.f.pockets.pocketNW.knuckleNE.pos.x,o.f.pockets.pocketN.knuckleNW.pos.x,e)||t.willBounceLongSegment(o.f.pockets.pocketN.knuckleNE.pos.x,o.f.pockets.pocketNE.knuckleNW.pos.x,e):t.willBounceLongSegment(-r.P.X,r.P.X,e)}},{key:"willBounceLongSegment",value:function(e,t,n){return n.x>e&&n.xr.P.tableY}},{key:"willBounceShortSegment",value:function(e,t,n){return n.y>t&&n.yr.P.tableX}},{key:"bounceIn",value:function(e,t,n){t.ballmesh.trace.forceTrace(t.futurePos);var r=(0,i.QK)(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.P.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.c.fromSerialised(e)}));return t.updateFromSerialised(e),t}}],e&&v(n.prototype,e),t&&v(n,t),n}()},"./src/utils/gltf.ts":(e,t,n)=>{let r,i,o,s;n.d(t,{KP:()=>e_,Ro:()=>eI});var a=n("./node_modules/three/build/three.module.js");function l(e,t=1/0,n=null){i||(i=new a.bdM(2,2,1,1)),o||(o=new a.BKk({uniforms:{blitTexture:new a.nc$(e)},vertexShader:` +"use strict";(self.webpackChunkbilliards=self.webpackChunkbilliards||[]).push([[57],{"./src/container/container.ts":(e,t,n)=>{n.d(t,{m:()=>J});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,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=function(){var e;function t(e){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),l(this,"camera",void 0),l(this,"mode",this.topView),l(this,"mainMode",this.aimView),l(this,"height",8*a.R),l(this,"elapsed",void 0),this.camera=new i.ubm(45,e,a.R,1e3*a.R)}return e=[{key:"update",value:function(e,t){this.elapsed=e,this.mode(t)}},{key:"topView",value:function(e){this.camera.fov=s.v.fov,this.camera.position.lerp(s.v.viewPoint(this.camera.aspect,this.camera.fov),.9),this.camera.up=o.up,this.camera.lookAt(o.v_)}},{key:"aimView",value:function(e){var t=arguments.length>1&&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.Dz)(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.cj9.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}}],function(e,t){for(var n=0;n0&&(null===(t=this.cuePowerElement)||void 0===t?void 0:t.value)&&(this.cuePowerElement.value=e)}}],function(e,t){for(var n=0;nthis.sentTime+this.period||e.type!==N.B.AIM){this.flush(),this.apply(e),this.sentTime=performance.now();return}this.pending=e}}],function(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=U.P.potCount(e);if(t||this.breakLink(n),this.lastShotLink(t||n,r,U.P.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=0===this.container.rules.currentBreak?this.container.rules.previousBreak:this.container.rules.currentBreak;t.score=n;var r=JSON.stringify(t),i=D.A.crush(r);this.generateLink("break(".concat(n,")"),i,"black"),n>=4&&this.generateHiScoreLink(i)}}},{key:"wholeGameLink",value:function(){var e=this.wholeGame(),t="frame(".concat(this.shotCount(e.shots)," shots)"),n=JSON.stringify(e),r=D.A.crush(n);this.generateLink(t,r,"black")}},{key:"shotCount",value:function(e){return e.filter(function(e){return"RERACK"!==e.type}).length}},{key:"generateLink",value:function(e,t,n){var r="".concat(this.replayUrl).concat(this.fullyEncodeURI(t)),i='').concat(e,"");this.container.eventQueue.push(new B.b(null,"".concat(i)))}},{key:"generateHiScoreLink",value:function(e){var t="".concat(this.hiScoreUrl,"?ruletype=").concat(this.container.rules.rulename,"&state=").concat(this.fullyEncodeURI(e)),n='').concat("hi score 🏆","");this.container.eventQueue.push(new B.b(null,"".concat(n)))}},{key:"fullyEncodeURI",value:function(e){return encodeURIComponent(e).replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\!/g,"%21").replace(/\*/g,"%2A")}}],function(e,t){for(var n=0;n').concat(e,"")));r.push(new B.b(null,s))})},this.redo.onclick=function(e){var r=new V.W(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.T),t.push(e)}},{key:"getElement",value:function(e){return document.getElementById(e)}}],function(e,t){for(var n=0;n0?this.element.innerHTML="Break
"+e:this.element.innerHTML="")}},{key:"getElement",value:function(e){return document.getElementById(e)}}],function(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,{m:()=>c});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){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var c=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&&l(e,t)}(c,e);var t,n,i=(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=a(c);return e=t?Reflect.construct(n,arguments,a(this).constructor):n.apply(this,arguments),e&&("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 c(e){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,c);var t,n=(t=i.call(this,e)).container.table;return n.cue.aimMode(),n.cue.showHelper(!0),n.cueball=t.container.rules.cueball,n.cue.moveTo(n.cueball.pos),t.container.view.camera.suggestMode(t.container.view.camera.aimView),n.cue.aimInputs.showOverlap(),t}return n=[{key:"handleInput",value:function(e){switch(e.key){case"Space":this.container.table.cue.adjustPower(e.t*this.scale*.7);break;case"SpaceUp":return this.playShot();default:if(!this.commonKeyHandler(e))return this}return this.container.sendEvent(this.container.table.cue.aim),this}},{key:"handleBreak",value:function(e){return new s.e(this.container,e.init,e.shots,e.retry)}},{key:"playShot",value:function(){var e=new r.Qe(this.container.table.serialise());return this.container.sendEvent(e),this.container.recorder.record(e),new o.H(this.container)}}],function(e,t){for(var n=0;n{n.d(t,{Qe:()=>r.Q,pd:()=>i.p,xI:()=>o}),n("./src/events/beginevent.ts"),n("./src/events/aimevent.ts");var r=n("./src/events/hitevent.ts"),i=n("./src/events/input.ts");n("./src/events/abortevent.ts"),n("./src/events/stationaryevent.ts");var o=function(){var e;function t(e){var n,r;!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),r=void 0,(n="container")in this?Object.defineProperty(this,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):this[n]=r,this.container=e}return e=[{key:"handleInput",value:function(e){return this}},{key:"handleBegin",value:function(e){return this}},{key:"handleBreak",value:function(e){return this}},{key:"handleStartAim",value:function(e){return this}},{key:"handleAim",value:function(e){return this}},{key:"handleHit",value:function(e){return this}},{key:"handleAbort",value:function(e){return this}},{key:"handleWatch",value:function(e){return this}},{key:"handlePlaceBall",value:function(e){return this}},{key:"handleStationary",value:function(e){return this}},{key:"handleChat",value:function(e){return this}},{key:"handleRejoin",value:function(e){return this}},{key:"onFirst",value:function(){}}],function(e,t){for(var n=0;n{n.d(t,{y:()=>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){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}var f=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&&u(e,t)}(f,e);var t,n,r=(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=c(f);return e=t?Reflect.construct(n,arguments,c(this).constructor):n.apply(this,arguments),e&&("object"===h(e)||"function"==typeof e)?e:l(this)});function f(){var e,t,n;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,f),e=r.apply(this,arguments),(n="scale")in(t=l(e))?Object.defineProperty(t,n,{value:.001,enumerable:!0,configurable:!0,writable:!0}):t[n]=.001,e}return n=[{key:"handleAbort",value:function(e){return new i.o(this.container)}},{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}},{key:"hit",value:function(){this.container.table.outcome=[s.P.hit(this.container.table.cueball,this.container.table.cue.aim.power)],this.container.table.hit(),this.container.view.camera.suggestMode(this.container.view.camera.aimView),this.container.table.cue.showHelper(!1)}},{key:"commonKeyHandler",value:function(e){var t=this.container.table.cue,n=e.t*this.scale;switch(e.key){case"ArrowLeft":return t.rotateAim(-n,this.container.table),!0;case"ArrowRight":return t.rotateAim(n,this.container.table),!0;case"ArrowDown":return t.adjustSpin(new a.Pq0(0,-n),this.container.table),!0;case"ArrowUp":return t.adjustSpin(new a.Pq0(0,n),this.container.table),!0;case"ShiftArrowLeft":return t.adjustSpin(new a.Pq0(n,0),this.container.table),!0;case"ShiftArrowRight":return t.adjustSpin(new a.Pq0(-n,0),this.container.table),!0;case"KeyPUp":return(0,o.KP)(this.container.view.scene),!0;case"KeyHUp":return t.toggleHelper(),!0;case"movementXUp":return t.rotateAim(2*n,this.container.table),!0;case"movementYUp":case"NumpadSubtract":return this.container.view.camera.adjustHeight(8*n),!0;case"NumpadAdd":return this.container.view.camera.adjustHeight(-(8*n)),!0;case"KeyOUp":return this.container.view.camera.toggleMode(),!0;case"KeyDUp":return this.togglePanel(),!0;case"KeyFUp":return this.toggleFullscreen(),!0;default:return!1}}},{key:"togglePanel",value:function(){this.container.sliders.toggleVisibility(),this.container.table.showSpin(!0),this.container.table.showTraces(!0),("undefined"==typeof process?"undefined":h(process))!=="object"&&console.log(this.container.table.serialise())}},{key:"toggleFullscreen",value:function(){document.fullscreenElement?document.exitFullscreen&&document.exitFullscreen():document.documentElement.requestFullscreen()}}],function(e,t){for(var n=0;n{function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}n.d(t,{o:()=>o});var o=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&&i(e,t)}(s,e);var t,n,o=(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(s);return e=t?Reflect.construct(n,arguments,r(this).constructor):n.apply(this,arguments),e&&("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 s(){return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,s),o.apply(this,arguments)}return n=[{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}}],function(e,t){for(var n=0;n{n.d(t,{x:()=>p});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");function u(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e,t){return(f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var p=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&&f(e,t)}(p,e);var t,n,r=(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=h(p);return e=t?Reflect.construct(n,arguments,h(this).constructor):n.apply(this,arguments),e&&("object"==(e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)||"function"==typeof e)?e:u(this)});function p(e){var t,n,i,o;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,p),n=u(t=r.call(this,e)),i="placescale",o=.02*a.R,i in n?Object.defineProperty(n,i,{value:o,enumerable:!0,configurable:!0,writable:!0}):n[i]=o,t.container.table.cue.moveTo(t.container.table.cueball.pos),t.container.table.cue.aim.power=0,t.container.view.camera.forceMode(t.container.view.camera.aimView),t}return n=[{key:"onFirst",value:function(){var e=this.container.table.cueball;this.container.rules.allowsPlaceBall()&&e.pos.copy(this.container.rules.placeBall()),e.setStationary(),e.updateMesh(0),this.container.table.cue.placeBallMode(),this.container.table.cue.showHelper(!1),this.container.table.cue.moveTo(this.container.table.cueball.pos),this.container.table.cue.aimInputs.setButtonText("Place\nBall"),this.container.rules.allowsPlaceBall()||this.container.inputQueue.push(new i.pd(1,"SpaceUp"))}},{key:"handleInput",value:function(e){var t=this.container.table.cueball.pos;switch(e.key){case"ArrowLeft":case"KeyI":this.moveTo(0,e.t*this.placescale);break;case"ArrowRight":case"KeyK":this.moveTo(0,-e.t*this.placescale);break;case"movementXUp":this.moveTo(0,-e.t*this.placescale*2);break;case"movementYUp":this.moveTo(-e.t*this.placescale*2,0);break;case"KeyJ":this.moveTo(-e.t*this.placescale,0);break;case"KeyL":this.moveTo(e.t*this.placescale,0);break;case"SpaceUp":return this.placed();default:this.commonKeyHandler(e)}return this.container.table.cue.moveTo(t),this.container.view.camera.forceMove(this.container.table.cue.aim),this.container.sendEvent(this.container.table.cue.aim),this}},{key:"moveTo",value:function(e,t){var n=new l.Pq0(e,t),r=this.container.table.cueball.pos.add(n);r.copy(this.container.rules.placeBall(r)),c.l.indicateValid(!this.container.table.overlapsAny(r))}},{key:"placed",value:function(){return this.container.table.overlapsAny(this.container.table.cueball.pos)?this:(this.container.table.cue.aimInputs.setButtonText("Hit"),this.container.sound.playNotify(),this.container.sendEvent(new s.W(this.container.table.shortSerialise())),new o.m(this.container))}}],function(e,t){for(var n=0;n{function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}n.d(t,{H:()=>o});var o=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&&i(e,t)}(s,e);var t,n,o=(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(s);return e=t?Reflect.construct(n,arguments,r(this).constructor):n.apply(this,arguments),e&&("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 s(e){var t;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,s),(t=o.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}}],function(e,t){for(var n=0;n{n.d(t,{e:()=>v});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),f(h(r=i.call(this,e)),"delay",void 0),f(h(r),"shots",void 0),f(h(r),"firstShot",void 0),f(h(r),"timer",void 0),f(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.W(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 n=[{key:"playNextShot",value:function(e){var t=this,n=this.shots.shift();if((null==n?void 0:n.type)===l.B.RERACK){c.x.fromJson(n.ballinfo).applyToController(this),this.shots.length>0&&this.playNextShot(e);return}var i=o.w.fromJson(n);this.container.table.cueball=this.container.table.balls[i.i],console.log(this.container.table.cueball.pos.distanceTo(i.pos)),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.Q(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.w.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.m(this.container)}}],function(e,t){for(var n=0;n{n.d(t,{V:()=>O});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"),m=n("./src/model/physics/constants.ts"),v=n("./src/utils/respot.ts"),y=n("./src/view/tablegeometry.ts"),b=n("./src/events/startaimevent.ts");function g(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var w=function(){var e;function t(e){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),g(this,"container",void 0),g(this,"cueball",void 0),g(this,"currentBreak",0),g(this,"previousBreak",0),g(this,"score",0),g(this,"rulename","nineball"),this.container=e}return e=[{key:"startTurn",value:function(){this.previousBreak=this.currentBreak,this.currentBreak=0}},{key:"nextCandidateBall",value:function(){return v.k.closest(this.container.table.cueball,this.container.table.balls)}},{key:"placeBall",value:function(e){if(e){var t=new o.Pq0(-y.P.X/2,y.P.tableY),n=new o.Pq0(-y.P.tableX,-y.P.tableY);return e.clamp(n,t)}return new o.Pq0(-(11*m.R)/.5,0,0)}},{key:"asset",value:function(){return"models/p8.min.gltf"}},{key:"tableGeometry",value:function(){y.P.hasPockets=!0}},{key:"table",value:function(){var e=new f.X(this.rack());return this.cueball=e.cueball,e}},{key:"rack",value:function(){return i.m.diamond()}},{key:"update",value:function(e){var t=this.container.table;if(h.P.isCueBallPotted(t.cueball,e))return(this.startTurn(),this.container.isSinglePlayer)?new a.x(this.container):(this.container.sendEvent(new u.z(p.v_,!0)),new l.r(this.container));if(h.P.isBallPottedNoFoul(t.cueball,e)){var n=h.P.potCount(e);return(this.currentBreak+=n,this.score+=n,this.container.sound.playSuccess(t.inPockets()),this.isEndOfGame(e))?(this.container.eventQueue.push(new c.b(null,"game over")),this.container.recorder.wholeGameLink(),new d.o(this.container)):(this.container.sendEvent(new r.Q(t.serialise())),new s.m(this.container))}return(this.container.sendEvent(new b.M),this.container.isSinglePlayer)?(this.container.sendEvent(new r.Q(t.serialise())),this.startTurn(),new s.m(this.container)):new l.r(this.container)}},{key:"isPartOfBreak",value:function(e){return h.P.isBallPottedNoFoul(this.container.table.cueball,e)}},{key:"isEndOfGame",value:function(e){var t=this.container.table.balls.filter(function(e){return e.onTable()});return 1===t.length&&t[0]===this.cueball}},{key:"otherPlayersCueBall",value:function(){return this.cueball}},{key:"secondToPlay",value:function(){}},{key:"allowsPlaceBall",value:function(){return!0}}],function(e,t){for(var n=0;n{n.d(t,{c:()=>k});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"),m=n("./src/events/placeballevent.ts"),v=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.P.firstCollision(n);return{pots:o.P.potCount(n),firstCollision:i,legalFirstCollision:t.isLegalFirstCollision(e,r,i),whitePotted:o.P.isCueBallPotted(e.cueball,n)}}},{key:"isLegalFirstCollision",value:function(e,n,r){if(!r)return!1;var i=r.ballB.id;return n?i>=7:!(t.coloursOnTable(e).filter(function(e){return e.id0)}},{key:"respotAllPottedColours",value:function(e,t){return o.P.pots(t).filter(function(e){return e.id<7}).filter(function(e){return 0!==e.id}).map(function(t){return a.k.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.P.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.P.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.P.pots(e)[0].id;return n!==t.firstCollision.ballB.id?this.foul(e,t):this.previousPotRed?(this.respot(e),this.currentBreak+=n+1,this.previousPotRed=!1,this.continueBreak()):y.coloursOnTable(this.container.table).filter(function(e){return e.id0?this.foul(e,t):(this.currentBreak+=n+1,this.previousPotRed=!1,this.continueBreak())}},{key:"foul",value:function(e,t){return this.foulPoints=this.foulCalculation(e,t),this.respot(e),this.switchPlayer()}},{key:"foulCalculation",value:function(e,t){var n,r,i,s,a=o.P.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,void 0);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,void 0)}}(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.P.hasPockets=!0}},{key:"table",value:function(){var e=new f.X(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.P.isClearTable(this.container.table)&&this.currentBreak>0}},{key:"allowsPlaceBall",value:function(){return!0}},{key:"asset",value:function(){return t.tablemodel}},{key:"startTurn",value:function(){this.previousPotRed=!1,this.targetIsRed=y.redsOnTable(this.container.table).length>0,this.previousBreak=this.currentBreak,this.score+=this.currentBreak,this.currentBreak=0,this.container.hud.updateBreak(this.currentBreak)}},{key:"rack",value:function(){return s.m.snooker()}},{key:"nextCandidateBall",value:function(){var e=this.container.table,t=y.redsOnTable(e),n=y.coloursOnTable(e);return this.previousPotRed?a.k.closest(e.cueball,n):t.length>0?a.k.closest(e.cueball,t):n.length>0?n[0]:void 0}},{key:"placeBall",value:function(e){if(e){var t=new r.Pq0(s.m.baulk,0,0),n=s.m.sixth,i=e.distanceTo(t);if(e.x>=s.m.baulk&&(e.x=s.m.baulk),!(i>n))return e;var o=e.clone().sub(t).normalize();return t.add(o.multiplyScalar(n))}return new r.Pq0(s.m.baulk,-s.m.sixth/2.6,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.M(this.foulPoints)),this.container.isSinglePlayer)?(this.container.sendEvent(new i.Q(e.serialise())),this.startTurn(),new l.m(this.container)):new c.r(this.container)}},{key:"continueBreak",value:function(){this.container.hud.updateBreak(this.currentBreak);var e=this.container.table;return(this.container.sound.playSuccess(e.inPockets()),o.P.isClearTable(e))?(this.container.eventQueue.push(new u.b(null,"game over")),this.container.recorder.wholeGameLink(),new h.o(this.container)):(this.container.sendEvent(new i.Q(e.serialise())),new l.m(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.x(this.container):(this.container.sendEvent(new m.z(v.v_,!0)),new c.r(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.Q(n);this.container.sendEvent(r),this.container.recorder.record(r)}}}],function(e,t){for(var n=0;n{n.d(t,{r:()=>s});var r=n("./src/controller/watchshot.ts");function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}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=i(a);return e=t?Reflect.construct(n,arguments,i(this).constructor):n.apply(this,arguments),e&&("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(e){var t;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),(t=s.call(this,e)).container.table.cueball=t.container.rules.otherPlayersCueBall(),t.container.table.cue.moveTo(t.container.table.cueball.pos),t.container.view.camera.suggestMode(t.container.view.camera.topView),t}return n=[{key:"handleAim",value:function(e){return this.container.table.cue.aim=e,this.container.table.cueball.pos.copy(e.pos),this}},{key:"handleHit",value:function(e){return this.container.table.updateFromSerialised(e.tablejson),new r.O(this.container)}}],function(e,t){for(var n=0;n{n.d(t,{O:()=>c});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){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var c=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&&l(e,t)}(c,e);var t,n,o=(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=a(c);return e=t?Reflect.construct(n,arguments,a(this).constructor):n.apply(this,arguments),e&&("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 c(e){var t;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,c),(t=o.call(this,e)).container.table.outcome=[],t.container.table.hit(),t}return n=[{key:"handleStartAim",value:function(e){return new r.m(this.container)}},{key:"handlePlaceBall",value:function(e){return new s.x(this.container)}},{key:"handleWatch",value:function(e){return"rerack"in e.json?(console.log("Respot"),this.container.table.updateFromSerialised(e.json),this):new i.r(this.container)}}],function(e,t){for(var n=0;n{n.d(t,{h:()=>a});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var a=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&&s(e,t)}(a,e);var t,n,r=(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=o(a);return e=t?Reflect.construct(n,arguments,o(this).constructor):n.apply(this,arguments),e&&("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(){var e;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),(e=r.call(this)).type=i.B.ABORT,e}return n=[{key:"applyToController",value:function(e){return e.handleAbort(this)}}],function(e,t){for(var n=0;n{n.d(t,{w:()=>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,{u:()=>a});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var a=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&&s(e,t)}(a,e);var t,n,r=(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=o(a);return e=t?Reflect.construct(n,arguments,o(this).constructor):n.apply(this,arguments),e&&("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(){var e;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),(e=r.call(this)).type=i.B.BEGIN,e}return n=[{key:"applyToController",value:function(e){return e.handleBegin(this)}}],function(e,t){for(var n=0;n{n.d(t,{W:()=>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,{b:()=>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,{B:()=>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,{F:()=>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,{Q:()=>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,{p:()=>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,{s:()=>a});var r=n("./src/events/input.ts"),i=n("./node_modules/interactjs/dist/interact.min.js"),o=n.n(i);function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a=function(){var e;function t(e){var n=this;!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),s(this,"pressed",{}),s(this,"released",{}),s(this,"keydown",function(e){null==n.pressed[e.code]&&(n.pressed[e.code]=performance.now()),e.stopImmediatePropagation(),"F12"!==e.key&&e.preventDefault()}),s(this,"keyup",function(e){n.released[e.code]=performance.now()-n.pressed[e.code],delete n.pressed[e.code],e.stopImmediatePropagation(),"F12"!==e.key&&e.preventDefault()}),s(this,"mousetouch",function(e){var t,r,i=n.released,o=e.client.yMath.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.p(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.p(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)}})}}],function(e,t){for(var n=0;n{n.d(t,{z:()=>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,{x:()=>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,{M:()=>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.B.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.F)},"./src/events/stationaryevent.ts":(e,t,n)=>{n.d(t,{T:()=>a});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var a=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&&s(e,t)}(a,e);var t,n,r=(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=o(a);return e=t?Reflect.construct(n,arguments,o(this).constructor):n.apply(this,arguments),e&&("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(){var e;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),(e=r.call(this)).type=i.B.STATIONARY,e}return n=[{key:"applyToController",value:function(e){return e.handleStationary(this)}}],function(e,t){for(var n=0;n{n.d(t,{Q:()=>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),m(p(e=i.call(this)),"clientResendFrom",void 0),m(p(e),"serverResendFrom",void 0),e.type=o.B.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").F),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.B.BEGIN:return new h.u;case o.B.AIM:return s.w.fromJson(e);case o.B.BREAK:return u.W.fromJson(e);case o.B.WATCHAIM:return a.Q.fromJson(e.json);case o.B.HIT:return l.Q.fromJson(e);case o.B.CHAT:return f.b.fromJson(e);case o.B.REJOIN:return b.fromJson(e);case o.B.ABORT:return new c.h;case o.B.PLACEBALL:return g.z.fromJson(e);case o.B.RERACK:return w.x.fromJson(e);case o.B.STARTAIM:return k.M.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 \uD83C\uDFC6{n.d(t,{c:()=>d,U:()=>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,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=function(){var e;function t(e,n){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),l(this,"line",void 0),l(this,"geometry",void 0),l(this,"positions",void 0),l(this,"lastPos",new s.Pq0),l(this,"lastVel",new s.Pq0),this.geometry=new s.LoY,this.positions=new Float32Array(3*e),this.geometry.setAttribute("position",new s.THS(this.positions,3)),this.reset();var r=new s.mrM({color:n,opacity:.25,linewidth:3,transparent:!0});this.line=new s.N1A(this.geometry,r),this.line.visible=!1}return e=[{key:"reset",value:function(){this.geometry.setDrawRange(0,0),this.lastVel.setZ(1)}},{key:"forceTrace",value:function(e){this.lastVel.z=1,this.addTraceGiven(e,this.lastVel,1,.1,1)}},{key:"addTrace",value:function(e,t){if(0!==t.length()){var n=this.lastVel.angleTo(t),r=n>Math.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)}}],function(e,t){for(var n=0;nMath.abs(this.rvel.z))&&(this.setStationary(),!0)}},{key:"setStationary",value:function(){this.vel.copy(i.v_),this.rvel.copy(i.v_),this.state="Stationary"}},{key:"isRolling",value:function(){return 0!==this.vel.lengthSq()&&0!==this.rvel.lengthSq()&&(0,o.Mq)(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,{P:()=>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,{I:()=>o,Mz:()=>r,Qg:()=>v,R:()=>f,Wv:()=>b,Ys:()=>g,cM:()=>w,e:()=>p,g:()=>s,gT:()=>c,gf:()=>l,jG:()=>m,kL:()=>u,kM:()=>k,m:()=>h,mu:()=>a,x3:()=>i,xO:()=>y});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 m(e){f=e,d()}function v(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,{O:()=>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,{$8:()=>x,Gp:()=>g,JD:()=>u,Mq:()=>a,QK:()=>f,QV:()=>P,Un:()=>b,c0:()=>y,lx:()=>h,p2:()=>c,s0:()=>v,t6:()=>S,yO:()=>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.Pq0;function a(e,t){return s.copy(e).addScaledVector((0,i.KM)(t),o.R)}var l={v:new r.Pq0,w:new r.Pq0};function c(e,t){var n=a(e,t).setZ(0);return l.v.copy((0,i.xb)(n).multiplyScalar(-o.gf*o.g)),l.w.copy((0,i.xb)((0,i.KM)(n)).multiplyScalar(2.5*o.gf*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.Pq0(e.x,e.y,0).length(),n=5/7*o.x3/(o.m*o.R)/t,i=5/7*o.x3/(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.KM)(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),m=Math.cos(p);function v(e,t){return new r.Pq0(e.x*d-e.z*m+o.R*t.y,-e.y-o.R*t.z*m+o.R*t.x*d)}function y(e){return e.x*m}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.Pq0(e/m,0,0)).x-.044*t.x*t.x;return o.gT*((1+i)*e)/n}function w(e,t){var n=g(y(e));return b(v(e,t))<=n}function k(e,t){return{c:y(e),s:v(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 A(-i.x/s*d-l*m,i.y/s,i.x/s*m-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 A(-a*s*c*m-s*m,a*s*Math.sin(l),a*s*c*m-s*d)}function P(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 A(e,t,n){return{v:new r.Pq0(e/o.m,t/o.m),w:new r.Pq0(-o.R/o.I*t*d,o.R/o.I*(e*d-n*m),o.R/o.I*t*m)}}function S(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.KM)(s).applyAxisAngle(s,n).multiplyScalar(r)}},"./src/model/physics/pocket.ts":(e,t,n)=>{n.d(t,{Z:()=>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,{X:()=>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.$8,a=e.futurePosition(n);if(t.willBounceLong(a,o)){var l=a.y>r.P.tableY?-Math.PI/2:Math.PI/2;return t.bounceIn(l,e,s)}if(t.willBounceShort(a,o)){var c=a.x>r.P.tableX?0:Math.PI;return t.bounceIn(c,e,s)}}},{key:"willBounceShort",value:function(e,n){return n?t.willBounceShortSegment(o.f.pockets.pocketNW.knuckleSW.pos.y,o.f.pockets.pocketSW.knuckleNW.pos.y,e):t.willBounceShortSegment(r.P.Y,-r.P.Y,e)}},{key:"willBounceLong",value:function(e,n){return n?t.willBounceLongSegment(o.f.pockets.pocketNW.knuckleNE.pos.x,o.f.pockets.pocketN.knuckleNW.pos.x,e)||t.willBounceLongSegment(o.f.pockets.pocketN.knuckleNE.pos.x,o.f.pockets.pocketNE.knuckleNW.pos.x,e):t.willBounceLongSegment(-r.P.X,r.P.X,e)}},{key:"willBounceLongSegment",value:function(e,t,n){return n.x>e&&n.xr.P.tableY}},{key:"willBounceShortSegment",value:function(e,t,n){return n.y>t&&n.yr.P.tableX}},{key:"bounceIn",value:function(e,t,n){t.ballmesh.trace.forceTrace(t.futurePos);var r=(0,i.QK)(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.P.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.c.fromSerialised(e)}));return t.updateFromSerialised(e),t}}],e&&v(n.prototype,e),t&&v(n,t),n}()},"./src/utils/gltf.ts":(e,t,n)=>{let r,i,o,s;n.d(t,{KP:()=>e_,Ro:()=>eI});var a=n("./node_modules/three/build/three.module.js");function l(e,t=1/0,n=null){i||(i=new a.bdM(2,2,1,1)),o||(o=new a.BKk({uniforms:{blitTexture:new a.nc$(e)},vertexShader:` varying vec2 vUv; void main(){ vUv = uv; diff --git a/src/container/browsercontainer.ts b/src/container/browsercontainer.ts index e0022be..f3070f4 100644 --- a/src/container/browsercontainer.ts +++ b/src/container/browsercontainer.ts @@ -108,6 +108,7 @@ export class BrowserContainer { } startReplay(replay) { + console.log(replay) this.breakState = this.parse(decodeURIComponent(replay)) console.log(this.breakState) if (Date.now() - this.breakState.now < 500000) { diff --git a/test/gen/diamond.spec.ts b/test/gen/diamond.spec.ts index 2317f61..1fc7095 100644 --- a/test/gen/diamond.spec.ts +++ b/test/gen/diamond.spec.ts @@ -43,5 +43,13 @@ describe("jsonCrush", () => { done() }) - + const bad = `https://tailuge.github.io/billiards/dist/?ruletype=snooker&state=%28%27init%21%5B%24Q%2BT8645T24U%2C-j084380814484855Q21937523769470274T8642%2C0Tk01%2C0Q7208%2C0%2Cj23986553562S715Q144446Z80v39k7Q7879QkUQ8457QU38Q846TU37Q9U3Tk02Q9U9T0668Q9U6Q0671TW8881407667921T5315991337382775Q96u9u91388U81QU3721U5220v6186Q9621970994338601TU35k0Z87930511Q87923Z92584601T2S3344811829063%2Cj3935838802U887T36242749Z0S3755%2Cj09499Z92336568T25596k5281194045%2Cj0187062806539k7Qk09672810906v244%2Cj0206846147370106Q474277737u31935%2Cj15318W68939533Q491u632645063407%5D~shots%21%5B%22XU153153153153153OJ05V6DX8577u7710S3594L3.43875F%24OJ%2B_J0111U49815296408OX299794450130U014D2.84u153657914833L4.9ZNk5Fj07S856047456245OX3432242831158396BY%2AX2991537846886426OX0225u951535704283DXSU339979956484Lj32637N3Fj195955385S56528OX18Zv19336571Z4_X%2FJu666666666666666DJ9297272184550487%25X197335v229013978OX3284082021983u9BY%2AX058834840S145521OJ294v420270727607DX813746341U0Z87%25J9778284764097188OJ26295u2913011u_Xk45045045045045045O%3ADj4067672859559628%25j2890738976838352OJuu27205082U496BP%2AJqX0V59D4.86399653U22461L3.193ZN7Fj3113827327S8073OJ29641064449574744_%20D-2.23384757088ZS%23j245136u85652333OJv5147Z31370v3BP%2A%20D-3.614Z0883627753%23J8669924959388464OJU04646515058k14_%3BOJ21v1v1v1v1v1D-j744S395378U475%23J59157k637636978OJ4928572484523u1B%26J9743Z5kkkk5O0Hd%215%29%5D%29%2A3.1026943625995973e-14OJ3D7.830877308756267L3.684375Fj08245765724S865OJ4S3504218395997_J%2FX05V6Dj3044710484236743L4.666875Fj02248746991187uOX389378615114185UBP%2AXqJ2747747747747748DJ759228Z44662196LJ786kkkkkk1FJ5v6809256108742OX21827769k9923584_X21552S8659v5133OJ20868340765233068DX93143181402U374Lj2772N02FjU2062280u96528OJ2364520805702285BP%2AX13338975553749208OJ2687139243091956D-4.027296110856934%3C8294056426943863OX53Uu4059027643_J09486832980505136OJ2846049894151S1DX9Z110Z15314409Lj52287N2FX18489492220983275OJ3U8261502869WBY%2AJqX0V59DX092509S5147v948%3CZ3S910110618822OX48328893258Wv5_J%2FJZu2u2u2u2u3DJ9676914322439181L2.898375FJ8502325297808555OX510u99880596818BP%2AJ0137470Z2588150SOX099684867242u813D-j59U8108762790ULj91587N2FXv3428431986u51OJ5014595268966328_JW7Z84Z3340419OJ267S8v27v282SD2.706836627322867L2.407Z5FX64329S736669448OX024119869Z309053B%26J7205O0Hd%212%29%5D%29%2AXv849336774U853OJ241Z26195791v01D3.3513931559v8824L2.407Z5Fj2606633514298724OX21577S2074318Z3H%210%29%5D~start%21v187257205S~now%21v18726079Z1~score%2170~wholeGame%21false%29%2A%29%2C%22BH%210%29%2C%28%27type%21%27RERACK%27~ballinfo%21%28%27balls%21%5B%28%27poD~z%210%29~angle%21F~po%26H~z%210%29~iJ0.L~power%21N5kkkk0O~y%21P%26jv9O0Hd%216%29%5D%29Q%2CJS54T%2CXU03V85585585585585W135X-JY%260O0Hd%214%29%5D%29Z12_H%210%2Aj1.k00q049S9S9S9S955Ou16v17%20%3AO%3B%22%28%27type%21%27AIM%27~offset%21%28%27x%21%23L2.21062N3F%24-j0649043227374102%25LJ73687N1F%26s%21%28%27x%21%2BS90706793083953%2F0WWWWW14O%3AJ040S0S0S0S0S%3BJ1U6U6U6U6U6%3CLJ93337N1FJ%01%3C%3B%3A%2F%2B%26%25%24%23%22%20vuqkj_ZYXWVUTSQPONLJHFDB%2A_` + + it("decode", (done) => { + const d = decodeURIComponent(bad) + expect(d).to.be.length(2673) + console.log(d) + done() + }) + })