waves/public/assets/g/idleresearch/static/js/1708334879473/3751.974c66ef.js
2025-04-09 17:11:14 -05:00

45 lines
30 KiB
JavaScript

"use strict";(self.webpackChunkcrazygames_gameframe=self.webpackChunkcrazygames_gameframe||[]).push([[3751,6327],{36327:(e,t,a)=>{a.r(t),a.d(t,{IFRAME_LOADER_IFRAME_ID:()=>p,default:()=>f});var s=a(47313),i=a(90831),r=a(23004),n=a(25831),o=a(73411),d=a(86604),l=a(95681),c=a(47178),h=a(6689),u=a(71534),m=a(87308),g=a(46417);const p="game-iframe";class S extends s.Component{constructor(e){super(e),this.config=void 0,this.options=void 0,this.progressTracker=void 0,this.iframe=null,this.onIframeLoad=()=>{this.progressTracker.trackLoadFinished(),this.onLoad(),this.focusOnIframe()},this.onLoad=()=>{"loaded"!==this.state.state&&(this.setState({state:"loaded"}),setTimeout((()=>{this.setState({showLoadingBar:!1})}),600),this.props.onLoadFinished())},this.onFullscreenClose=async()=>{await this.props.requestFullscreen(),this.startLoading()},this.adFinished=()=>{this.focusOnIframe()},this.config=(0,i.NI)(),this.options=this.config.loaderOptions,this.state={state:"checking",showLoadingBar:!1},this.progressTracker=new l.Z}componentDidMount(){const e=(0,m.uo)();"REQUIRED"!==this.config.fullscreen||e||this.props.isFullscreen?this.startLoading():this.setState({state:"fullscreen"}),(0,c.Q)().addAdFinishedListener(this.adFinished)}componentWillUnmount(){(0,c.Q)().removeAdFinishedListener(this.adFinished)}componentDidUpdate(e){e.isFullscreen!==this.props.isFullscreen&&this.focusOnIframe()}renderForState(){const{state:e}=this.state;switch(e){case"checking":return this.renderChecking();case"fullscreen":return this.renderFullscreenOverlay();case"loaded":return this.renderLoaded();default:throw new Error(`[IFrameLoader] unexpected state ${e}`)}}render(){return(0,g.jsxs)(g.Fragment,{children:[this.renderForState(),this.state.showLoadingBar&&this.renderLoading()]})}renderChecking(){return(0,g.jsx)(o.Z,{showProgress:!1})}renderFullscreenOverlay(){return(0,g.jsx)(d.Z,{warning:"force-fullscreen",close:this.onFullscreenClose})}renderLoading(){return(0,g.jsx)(o.Z,{showProgress:!1})}renderLoaded(){return null}loadIframe(){const{scrolling:e}=this.options,{sandbox:t}=this.config,a=this.config.allowWebCam?"camera;":"",s=document.createElement("iframe");if(s.id=p,s.src=this.getIframeUrl(),s.onload=this.onIframeLoad,s.style.border="0",s.style.backgroundColor="#fff",e&&s.setAttribute("scrolling",e),s.style.width="10px",s.style.height="10px",s.style.minWidth="100%",s.style.minHeight="100%",s.setAttribute("allow",`${a} autoplay; payment; fullscreen; microphone; clipboard-read; clipboard-write 'self' ${s.src}`),s.setAttribute("webkitallowfullscreen","true"),s.setAttribute("mozallowfullscreen","true"),s.setAttribute("msallowfullscreen","true"),s.setAttribute("allowfullscreen","true"),t){s.setAttribute("sandbox","");const e=["allow-forms","allow-modals","allow-orientation-lock","allow-pointer-lock","allow-popups","allow-presentation","allow-scripts","allow-same-origin","allow-downloads"];s.sandbox.add(...e)}this.iframe=s;(0,r.$7)().appendChild(s)}async startLoading(){this.setState({showLoadingBar:!0});try{await h.Z.Instance.waitForAPS()}catch(e){}finally{this.loadIframe(),this.progressTracker.trackLoadStarted(),setTimeout((()=>{this.onLoad()}),1e4)}}getIframeUrl(){const e=new URL(this.options.url);return new URLSearchParams(window.location.search).forEach(((t,a)=>{"v"!==a&&e.searchParams.append(a,t)})),e.toString().includes("html5.gamedistribution.com")&&e.searchParams.set("gd_sdk_referrer_url",this.config.gameLink),e.toString()}focusOnIframe(){this.iframe&&this.iframe.contentWindow&&this.iframe.contentWindow.focus()}}const f=(0,n.Z)((0,u.q)(S))},86604:(e,t,a)=>{a.d(t,{Z:()=>l});a(47313);var s=a(9172),i=a(99187),r=a(46604),n=a(69121),o=a(40889),d=a(46417);const l=e=>{let{warning:t,close:a,showCrazyLogo:l=!0}=e;const{countryCode:c}=(0,n.bG)(),h=(0,n.Ax)(c)&&r.Z.isEmbeddedExternally();return(0,d.jsxs)(i.Z,{showCrazyLogo:l,showGDPRNotice:h,children:[(0,d.jsx)(s.Z,{close:a,warning:t}),(0,d.jsx)(o.Z,{hasFooter:!1,disableMove:!0})]})}},95681:(e,t,a)=>{a.d(t,{Z:()=>o});var s=a(22870),i=a(20505);const r=class{constructor(){this.loadStartedSent=void 0,this.firstQuarterSent=void 0,this.secondQuarterSent=void 0,this.thirdQuarterSent=void 0,this.ninetyPercentSent=void 0,this.loadFinishedSent=void 0,this.ga=void 0,this.ga=i.Z.Instance,this.loadStartedSent=!1,this.firstQuarterSent=!1,this.secondQuarterSent=!1,this.thirdQuarterSent=!1,this.ninetyPercentSent=!1,this.loadFinishedSent=!1}trackLoadStarted(){this.loadStartedSent?s.kg.warn("trackLoadStarted called multiple times"):(this.loadStartedSent=!0,this.ga.trackLoadStarted())}trackProgress(e){!this.firstQuarterSent&&e>=.25&&(this.ga.trackFirstQuarterLoaded(),this.firstQuarterSent=!0),!this.secondQuarterSent&&e>=.5&&(this.ga.trackSecondQuarterLoaded(),this.secondQuarterSent=!0),!this.thirdQuarterSent&&e>=.75&&(this.ga.trackThirdQuarterLoaded(),this.thirdQuarterSent=!0),!this.ninetyPercentSent&&e>=.9&&(this.ga.trackNinetyPercentLoaded(),this.ninetyPercentSent=!0)}trackLoadFinished(){this.loadStartedSent?this.loadFinishedSent?s.kg.warn("trackLoadFinished called multiple times"):(this.loadFinishedSent=!0,this.ga.trackLoadFinished()):s.kg.warn("trackLoadFinished called before trackLoadStart was called")}};var n=a(96607);const o=class{constructor(){this.lastReportedProgress=void 0,this.currentProgress=0,this.tracker=void 0,this.tracker=new r}reset(){this.lastReportedProgress=void 0,this.currentProgress=0,this.tracker=new r}trackLoadStarted(){n.Z.trackProgress(0),this.lastReportedProgress=0,this.tracker.trackLoadStarted()}trackProgress(e){if(e<=this.currentProgress)return this.currentProgress;this.currentProgress=e,this.tracker.trackProgress(e);const t=Math.floor(10*e)/10;return 1!==t&&(!this.lastReportedProgress||e>this.lastReportedProgress+.1)&&(n.Z.trackProgress(t),this.lastReportedProgress=e),e}trackLoadFinished(){1!==this.lastReportedProgress&&(this.lastReportedProgress=1,this.tracker.trackLoadFinished(),n.Z.trackProgress(1),n.Z.loadFinished())}}},73411:(e,t,a)=>{a.d(t,{Z:()=>x});var s=a(7136),i=(a(47313),a(90831)),r=a(42379),n=a(30686),o=a(32606);const d=(0,r.ZP)("div")((e=>{let{theme:t}=e;return{fontSize:"14px",color:"#FFFFFF",display:"flex",gap:t.spacing(.5),height:40}})),l=(0,r.ZP)("div")({fontWeight:700}),c=(0,r.ZP)("div")({fontWeight:400}),h=(0,r.ZP)("div")({height:12,borderRadius:6,backgroundColor:"black",position:"relative"}),u=(0,r.ZP)("div",{shouldForwardProp:e=>"percentage"!==e})((e=>{let{percentage:t}=e;return{position:"absolute",backgroundColor:o.D.brand[100],left:0,top:0,bottom:0,borderRadius:6,width:100*t+"%"}})),m=n.F4`
0% { width: 5%; }
100% { width: 100%; }
`,g=(0,r.ZP)("div")({backgroundColor:"#ffffff",position:"absolute",borderRadius:6,top:0,height:"100%",left:0,right:0,opacity:.3,animation:`${m} 1s infinite`}),p=n.F4`
0% {
left:0%;
right:100%;
width:0%;
}
10% {
left:0%;
right:75%;
width:25%;
}
90% {
right:0%;
left:75%;
width:25%;
}
100% {
left:100%;
right:0%;
width:0%;
}
`,S=(0,r.ZP)("div")({position:"absolute",backgroundColor:o.D.brand[100],borderRadius:6,top:0,right:"100%",bottom:0,left:0,width:0,animation:`${p} 2s linear infinite`}),f=n.F4`
0% {
opacity:0;
}
17% {
opacity:1;
}
83% {
opacity:1;
}
100% {
opacity: 0;
}
`,D=n.F4`
0% {
opacity:0;
}
100% {
opacity:1;
}
`,y=(0,r.ZP)("div")({"& div":{position:"absolute",left:"50%",transform:"translate(-50%)",opacity:0,animation:`${f} 3s linear 1`},"& .msg0":{animation:`${f} 3s linear 1`},"& .msg1":{animationDelay:"3s"},"& .msg2":{animationDelay:"6s"},"& .msg3":{animationDelay:"9s"},"& .msg4":{animationDelay:"12s"},"& .msg5":{animationDelay:"15s"},"& .msg6":{animationDelay:"18s"},"& .msg7":{animationDelay:"21s"},"& .msg8":{animationDelay:"24s"},"& .msg9":{animationDelay:"27s"},"& .msg10":{animationDelay:"30s"},"& .msg11":{animationDelay:"33s"},"& .msg12":{animationDelay:"36s"},"& .msg13":{animationDelay:"39s"},"& .msg14":{animationDelay:"42s"},"& .msg15":{animationDelay:"45s"},"& .msg16":{animationDelay:"48s"},"& .msg17":{animationDelay:"51s"},"& .msg18":{animationDelay:"54s"},"& .msg19":{animationDelay:"57s"},"& .msg20":{animationDelay:"60s"},"& .msg21":{animationDelay:"63s"},"& .msg22":{animationDelay:"66s"},"& .msg23":{animation:`${D} 2s linear 1`,animationDelay:"69s",animationFillMode:"forwards"}});var I=a(46417);const w=()=>{const e=[s.ag._("loadingBarScreen.message1"),s.ag._("loadingBarScreen.message2"),s.ag._("loadingBarScreen.message3"),s.ag._("loadingBarScreen.message4"),s.ag._("loadingBarScreen.message5"),s.ag._("loadingBarScreen.message6"),s.ag._("loadingBarScreen.message7"),s.ag._("loadingBarScreen.message8")],t=[...e,...e,...e];return(0,I.jsx)(y,{children:t.map(((e,t)=>(0,I.jsx)("div",{className:`msg${t}`,children:e},t)))})};var v=a(93458);const x=e=>{let{progress:t,showProgress:a}=e;const r=(0,i.NI)(),n=t<=.95,m=a&&!n||!a;return(0,I.jsx)("div",{style:{position:"fixed",inset:0,zIndex:2,background:o.D.black[90]},children:(0,I.jsx)(v.Z,{children:a?(()=>{const e=r.totalSizeBytes?Math.round(1e-6*r.totalSizeBytes):null;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(h,{sx:{width:"80%"},children:(0,I.jsx)(u,{percentage:t,children:(0,I.jsx)(g,{})})}),(0,I.jsxs)(d,{children:[(0,I.jsx)(l,{children:n?`${Math.round(100*t)}%`:m?(0,I.jsx)(w,{}):s.ag._("loadingBarScreen.message1")}),n&&e&&(0,I.jsxs)(c,{children:["(",Math.round(t*e)," / ",e," MB)"]})]})]})})():(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(h,{sx:{width:"80%"},children:(0,I.jsx)(S,{})}),(0,I.jsx)(l,{children:m?(0,I.jsx)(w,{}):s.ag._("loadingBarScreen.message1")})]})})})}},3751:(e,t,a)=>{a.r(t),a.d(t,{default:()=>$});var s=a(47313),i=a(90831),r=a(64819),n=a(91469),o=a(85307),d=a(61627),l=a(23004),c=a(96607),h=a(13751),u=a(6689),m=a(42379),g=a(85541),p=a(46417);const S=s.memo((e=>(0,p.jsx)(g.Z,{...e,width:"24",height:"24",viewBox:"0 0 30 30",children:(0,p.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5 3.75C5.69036 3.75 6.25 4.30964 6.25 5V7.92873C8.31173 5.38058 11.4646 3.75 15 3.75C20.7379 3.75 25.4709 8.04455 26.163 13.5953C26.2485 14.2804 25.7624 14.905 25.0773 14.9904C24.3923 15.0758 23.7677 14.5897 23.6822 13.9047C23.1442 9.58967 19.4611 6.25 15 6.25C12.0279 6.25 9.39998 7.73208 7.81803 10H11.25C11.9404 10 12.5 10.5596 12.5 11.25C12.5 11.9404 11.9404 12.5 11.25 12.5H5C4.30964 12.5 3.75 11.9404 3.75 11.25V5C3.75 4.30964 4.30964 3.75 5 3.75ZM4.92269 15.0096C5.60774 14.9242 6.23234 15.4103 6.31776 16.0953C6.85583 20.4103 10.5389 23.75 15 23.75C17.9721 23.75 20.6 22.2679 22.182 20H18.75C18.0596 20 17.5 19.4404 17.5 18.75C17.5 18.0596 18.0596 17.5 18.75 17.5H25C25.6904 17.5 26.25 18.0596 26.25 18.75V25C26.25 25.6904 25.6904 26.25 25 26.25C24.3096 26.25 23.75 25.6904 23.75 25V22.0713C21.6883 24.6194 18.5354 26.25 15 26.25C9.26209 26.25 4.52915 21.9555 3.83697 16.4047C3.75155 15.7196 4.23764 15.095 4.92269 15.0096Z"})})));var f=a(91423),D=a(32606);const y=(0,m.ZP)("div")({opacity:.9,backgroundColor:"rgba(0, 0, 0, 0.85)",position:"absolute",left:0,top:0,height:"100vh",width:"100vw",zIndex:1}),I=(0,m.ZP)("div")({backgroundColor:D.D.brand[200],display:"flex",alignItems:"center",justifyContent:"center",position:"absolute",left:0,top:0,height:"100vh",width:"100vw",zIndex:2}),w=(0,m.ZP)("div")((e=>{let{theme:{typography:t}}=e;return{alignItems:"center",alignSelf:"center",backgroundColor:D.D.black[70],borderRadius:20,boxShadow:"0 10px 20px 0 rgba(0, 0, 0, 0.3)",display:"flex",flexDirection:"column",fontFamily:t.fontFamily,justifyContent:"center",padding:20,position:"relative",maxWidth:"100%",width:340}})),v=(0,m.ZP)(S)({fill:D.D.brand[60],height:48,width:48}),x=(0,m.ZP)("div")((e=>{let{theme:{spacing:t}}=e;return{color:D.D.white[100],fontSize:20,fontWeight:700,textAlign:"center",margin:`${t(2)} 0 ${t()}`}})),T=(0,m.ZP)("div")((e=>{let{theme:t}=e;return{color:D.D.white[60],fontSize:"16px",fontWeight:400,lineHeight:"22px",textAlign:"center",marginBottom:t.spacing(2)}})),P=(0,m.ZP)("span")({color:D.D.brand[60]}),U=(0,m.ZP)(f.Z)((e=>{let{theme:t}=e;return{backgroundColor:D.D.brand[100],color:D.D.white[60],fontFamily:t.typography.fontFamily,fontSize:"16px",fontWeight:800,justifyContent:"center",padding:8,textAlign:"center",textTransform:"none",width:"100%"}}));var F=a(77626);const L=e=>{let{onReload:t}=e;return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(y,{}),(0,p.jsx)(I,{onClick:t,children:(0,p.jsxs)(w,{onClick:e=>{e.stopPropagation(),e.preventDefault()},children:[(0,p.jsx)(v,{}),(0,p.jsx)(x,{children:(0,p.jsx)(F.Z,{id:"aps.reload.title"})}),(0,p.jsx)(T,{children:(0,p.jsx)(F.Z,{id:"aps.reload.text",values:{highlight:(0,p.jsx)(P,{children:(0,p.jsx)(F.Z,{id:"aps.reload.textHighlight"})})}})}),(0,p.jsx)(U,{onClick:t,children:(0,p.jsx)(F.Z,{id:"aps.reload.title"})})]})})]})};var b=a(22870),k=a(71534),G=a(36327),A=a(11414),Z=a(76306),j=a(74309),C=a(1247);class E extends Error{}class R extends s.PureComponent{constructor(e,t){super(e),this.context=void 0,this.config=void 0,this.apsLoaded=!1,this.apsInterjectorIframe=null,this.apsStorageKey=void 0,this.apiData=null,this.userStatus="pending",this.gameDataHandleTimeoutId=void 0,this.scriptEvents=[],this.logger=(0,b.fq)((0,h.Qg)()).withPrefix("[APS-Iframe]"),this.isFetchingGameDataFromSignedUrl=!1,this.isWaitingForGameDataUrlFromUP=!1,this.processAPSInterjectorMessage=async e=>{try{const{type:t}=e.data;switch(t){case"loadGame":this.onMessageLoadGame();break;case"reloadPopup":this.onMessageReloadPopup();break;case"sessionconflict":this.onMessageAPSSessionConflict();break;case"replaceGameData":await C.n.Instance.replaceGameData(e.data.data);break;case"clearGameData":await C.n.Instance.clearGameData(e.data.data)}}catch(a){var t;console.error("message error: ",a),null===(t=u.Z.Instance.getDeferred())||void 0===t||t.resolve()}},this.handleUserInit=async()=>{if("pending"!==this.userStatus&&"none"!==this.userStatus)return;const e="NOT_STARTED"!==this.props.gameLoadStatus;this.userStatus="none"===this.userStatus&&e?"fetching-late":"fetching",this.logger.debug("has user: "),u.Z.Instance.setType("IFRAME"),window.addEventListener("message",this.processAPSInterjectorMessage);try{const e=await this.getUsersGameData();if("failed"===this.userStatus)return;e?this.handleGameData(e):this.handleEmptyGameData()}catch(t){this.handleGameDataFailure(t)}},this.handleEmptyGameData=()=>{this.apiData=null,this.handleSendMsgToScript("requestGameDataResponse"),this.handleLoadGame(),this.userStatus="normal"},this.getUsersGameData=async()=>{var e;this.isWaitingForGameDataUrlFromUP=!0;const t=await C.n.Instance.getGameData();if(this.isWaitingForGameDataUrlFromUP=!1,t.errors||!t.resultData)throw new C.J(t.errors);if(null===(e=t.resultData.gameData)||void 0===e||!e.dataUrl)return null;this.isFetchingGameDataFromSignedUrl=!0;const a=await(0,h.do)(t.resultData.gameData.dataUrl);this.isFetchingGameDataFromSignedUrl=!1;return{data:a,metadata:t.resultData.gameData.metadata,version:t.resultData.gameData.version}},this.handleNoUserInit=()=>{"pending"===this.userStatus&&this.context.hasUserLoaded&&(this.userStatus="none",this.logger.debug("has no user: "),this.handleSendMsgToScript("requestGameDataNone"),this.handleLoadGame())},this.handleLoadGame=()=>{var e;null===(e=u.Z.Instance.getDeferred())||void 0===e||e.resolve(),window.clearTimeout(this.gameDataHandleTimeoutId)},this.onMessageLoadGame=()=>{this.userStatus="normal",this.handleLoadGame()},this.onMessageAPSSessionConflict=()=>{c.Z.trackAPSSessionConflict((0,i.NI)().loader,this.context.hasUserLoaded,this.apsLoaded)},this.onMessageReloadPopup=()=>{"NOT_STARTED"!==this.props.gameLoadStatus?this.setState({showReloadPopup:!0}):this.apiData&&this.handleSendMsgToScript("handleReloadData",this.apiData)},this.onSelectReload=async()=>{const e=document.getElementById(G.IFRAME_LOADER_IFRAME_ID);e&&e.contentWindow?(this.apiData&&this.handleSendMsgToScript("handleReloadData",this.apiData),e.src=`${e.src}`,this.userStatus="normal",this.setState({showReloadPopup:!1})):window.location.reload()},this.handleGameData=e=>{const t=(0,o.Z)(e.metadata.updatedAt,"yyyy-MM-dd HH:mm:ss",new Date),a=(0,r.Z)((0,n.Z)(t,-t.getTimezoneOffset()),"T");this.apiData={...e,hasDelayedUser:"fetching-late"===this.userStatus,metadata:{...e.metadata,updatedAtTz:a}},this.userStatus="installing-gameData",this.handleSendMsgToScript("requestGameDataResponse",this.apiData)},this.loadAPSInterjector=()=>{const e=document.createElement("iframe");e.src=(0,h.z6)(this.config.gameSlug,this.apsStorageKey,this.props.loader,(0,h.VB)()),e.style.display="none",e.onload=()=>{this.apsLoaded=!0,this.handleUserInitLogic(),this.scriptEvents.length>0&&(this.scriptEvents.forEach(this.sendMsgToScript),this.scriptEvents=[])},e.onerror=e=>{this.handleGameDataFailure(new E("APSInterjector failed to load"))},document.body.appendChild(e),this.apsInterjectorIframe=e},this.onPreloadGame=async()=>{const e=(0,l.PQ)();u.Z.Instance.setDeferred(e),this.loadAPSInterjector(),await e.promise,u.Z.Instance.setIsDeferredFinished(!0)},this.sendMsgToScript=e=>{var t,a;let{type:s,data:i}=e;null===(t=this.apsInterjectorIframe)||void 0===t||null===(a=t.contentWindow)||void 0===a||a.postMessage({type:s,data:i},"*")},this.handleSendMsgToScript=(e,t)=>{this.apsLoaded?this.sendMsgToScript({type:e,data:t}):this.scriptEvents.push({type:e,data:t})},this.handleGameDataTimeoutStart=async()=>{if("NOT_STARTED"===this.props.gameLoadStatus||u.Z.Instance.getIsDeferredFinished()||void 0!==this.gameDataHandleTimeoutId)return;const e=(0,h.i2)(this.context.isUserExpected);this.gameDataHandleTimeoutId=window.setTimeout((()=>{"normal"!==this.userStatus&&"failed"!==this.userStatus&&this.handleGameDataFailure(new Z.W("GameDataTimeout",e))}),e)},this.getTimeoutApsIssueType=()=>this.context.userId&&this.context.hasUserLoaded?this.isWaitingForGameDataUrlFromUP?"up-timeout":this.isFetchingGameDataFromSignedUrl?"fetch-timeout":"timeout":"firebase-timeout",this.handleGameDataFailure=e=>{this.logger.err(new Error("GameDataFailure"),JSON.stringify(e));const t=this.userStatus;if(this.userStatus="failed",this.handleSendMsgToScript("requestGameDataNone"),this.handleLoadGame(),e instanceof E)c.Z.trackAPSIssue("apsInterjectorLoadError",(0,i.NI)().loader,!1,!1);else if(e instanceof Z.W&&"GameDataTimeout"===e.source){const a=this.getTimeoutApsIssueType();c.Z.trackAPSIssue(a,(0,i.NI)().loader,this.context.hasUserLoaded,this.apsLoaded,{timer:e.timer,userStatus:t})}else if(e instanceof Z.W&&"UPGFConnector"===e.source)c.Z.trackAPSIssue("gfconnector-timeout",(0,i.NI)().loader,this.context.hasUserLoaded,this.apsLoaded,{userStatus:t});else{if(e instanceof C.J){return e.errors.find((e=>e&&e.extensions&&"NOT_AUTHENTICATED"===e.extensions.code))?void c.Z.trackAPSIssue("getGameData-notAuthenticated-error",(0,i.NI)().loader,this.context.hasUserLoaded,!1,{userStatus:t}):void c.Z.trackAPSIssue("getGameData-error",(0,i.NI)().loader,this.context.hasUserLoaded,this.apsLoaded,{userStatus:t})}e instanceof j.k?c.Z.trackAPSIssue("fetch-error-signed-url",(0,i.NI)().loader,this.context.hasUserLoaded,!1,{userStatus:t}):c.Z.trackAPSIssue("fetch-error",(0,i.NI)().loader,this.context.hasUserLoaded,this.apsLoaded,{userStatus:t})}},this.config=(0,i.NI)(),this.apsStorageKey=(0,A.Z5)(),this.logger.debug("enabled:"),this.logger.debug(`version ${h.bs}`),this.state={showReloadPopup:!1}}componentDidMount(){(0,h.VO)("Loading iframe loader"),this.onPreloadGame(),this.handleUserInitLogic(),this.handleGameDataTimeoutStart()}componentDidUpdate(e){this.handleUserInitLogic(),this.handleGameDataTimeoutStart()}componentWillUnmount(){window.removeEventListener("message",this.processAPSInterjectorMessage)}handleUserInitLogic(){var e;this.context.hasUserLoaded&&(null!==(e=this.context)&&void 0!==e&&e.userId?this.handleUserInit():this.handleNoUserInit())}render(){return(0,p.jsx)(p.Fragment,{children:this.state.showReloadPopup&&(0,p.jsx)(L,{onReload:this.onSelectReload})})}}R.contextType=d.N;const N=(0,k.q)(R);var M=a(52012);const _=e=>{let{clearUnitySyncTime:t,logger:a}=e;const i=s.useRef(!1),r=s.useRef(!1),n=s.useRef(0);return s.useEffect((()=>{const e=()=>{r.current?i.current=!0:(r.current=!0,i.current=!1,u.Z.Instance.setCurrentSyncType("sdk"),t(),C.n.Instance.syncUnityData(!0),n.current=window.setTimeout((()=>{r.current=!1,i.current&&e()}),(0,h.VB)()))},s=async t=>{try{const{type:s}=t.data;if("syncUnityGameData"===s){if(a.debug("syncUnityGameData requested"),"disabled"===u.Z.Instance.getCurrentSyncType())return void a.warn("syncUnityGameData request rejected");e()}}catch(s){i.current=!1,r.current=!1,a.err(new Error("message err: "),s)}};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s),n.current&&window.clearTimeout(n.current),i.current=!1,r.current=!1}}),[t,a]),null};var O=a(2022);class B extends s.PureComponent{constructor(e,t){super(e),this.context=void 0,this.userStatus="pending",this.gameDataHandleTimeoutId=void 0,this.apiData=null,this.logger=(0,b.fq)((0,h.Qg)()).withPrefix("[APS-Unity]"),this.isFetchingGameDataFromSignedUrl=!1,this.isWaitingForGameDataUrlFromUP=!1,this.syncTimerInterval=void 0,this.handleUserInit=async()=>{if("pending"!==this.userStatus&&"none"!==this.userStatus)return;const e="NOT_STARTED"!==this.props.gameLoadStatus;this.userStatus="none"===this.userStatus&&e?"fetching-late":"fetching",this.logger.debug("has user: "),u.Z.Instance.setType("UNITY");try{const e=await this.getUsersGameData();if("failed"===this.userStatus)return;e?await this.handleGameData(e):this.handleEmptyGameData()}catch(t){this.handleGameDataFailure(t)}},this.getUsersGameData=async()=>{var e;this.isWaitingForGameDataUrlFromUP=!0;const t=await C.n.Instance.getGameData();if(this.isWaitingForGameDataUrlFromUP=!1,t.errors||!t.resultData)throw new C.J(t.errors);if(null===(e=t.resultData.gameData)||void 0===e||!e.dataUrl)return null;this.isFetchingGameDataFromSignedUrl=!0;const a=await(0,h.do)(t.resultData.gameData.dataUrl);this.isFetchingGameDataFromSignedUrl=!1;return{data:a,metadata:t.resultData.gameData.metadata,version:t.resultData.gameData.version}},this.handleEmptyGameData=()=>{C.n.Instance.syncUnityData(!1),this.handleGameDataInitSuccess()},this.handleNoUserInit=()=>{"pending"===this.userStatus&&(this.userStatus="none",this.logger.debug("has no user: "),this.handleLoadGame())},this.handleLoadGame=()=>{var e;null===(e=u.Z.Instance.getDeferred())||void 0===e||e.resolve(),window.clearTimeout(this.gameDataHandleTimeoutId)},this.handleGameData=async e=>{const t=(0,o.Z)(e.metadata.updatedAt,"yyyy-MM-dd HH:mm:ss",new Date),a=parseInt((0,r.Z)((0,n.Z)(t,-t.getTimezoneOffset()),"T"));if("fetching-late"===this.userStatus)return this.logger.debug("reload game popup"),this.apiData={store:e,apiUpdatedAtTz:a},this.setState({showReloadPopup:!0}),void(this.userStatus="reload-popup");let s;this.userStatus="installing-gameData";try{s=await(0,M.getExistingPlayerPrefUpdatedAtTz)()}catch(i){this.logger.debug("Existing data err: ",i)}return s?s===a?(this.logger.debug("same"),(0,M.setSyncTimeOfIndexDb)(s),void this.handleGameDataInitSuccess()):s>a&&s-a<(0,M.getSyncTimerMs)()?(this.logger.debug("choosing LS",s,a),C.n.Instance.syncUnityData(!1),void this.handleGameDataInitSuccess()):(this.logger.debug("choosing API"),await(0,M.setAPIDataToIDB)(e,a),void this.handleGameDataInitSuccess()):(this.logger.debug("no local"),await(0,M.setAPIDataToIDB)(e,a),void this.handleGameDataInitSuccess())},this.onSelectReload=async()=>{this.apiData&&await(0,M.setAPIDataToIDB)(this.apiData.store,this.apiData.apiUpdatedAtTz),window.location.reload()},this.onPreloadGame=async()=>{const e=(0,l.PQ)();u.Z.Instance.setDeferred(e),await e.promise,u.Z.Instance.setIsDeferredFinished(!0)},this.clearUnitySyncTime=()=>{window.clearInterval(this.syncTimerInterval),this.syncTimerInterval=void 0},this.getTimeoutApsIssueType=()=>this.context.userId&&this.context.hasUserLoaded?this.isWaitingForGameDataUrlFromUP?"up-timeout":this.isFetchingGameDataFromSignedUrl?"fetch-timeout":"timeout":"firebase-timeout",this.handleGameDataTimeoutStart=async()=>{if("NOT_STARTED"===this.props.gameLoadStatus||u.Z.Instance.getIsDeferredFinished()||void 0!==this.gameDataHandleTimeoutId)return;this.logger.debug("game data timeout started");const e=(0,h.i2)(this.context.isUserExpected);this.gameDataHandleTimeoutId=window.setTimeout((()=>{"normal"!==this.userStatus&&"failed"!==this.userStatus&&this.handleGameDataFailure(new Z.W("GameDataTimeout",e))}),e)},this.handleGameDataInitSuccess=()=>{this.userStatus="normal",u.Z.Instance.setCurrentSyncType("aps"),this.handleUnitySyncTimeStart(),this.handleLoadGame()},this.handleGameDataFailure=e=>{this.logger.err(new Error("GameDataFailure"),JSON.stringify(e));const t=this.userStatus;if(this.userStatus="failed",this.handleLoadGame(),e instanceof Z.W&&"GameDataTimeout"===e.source){const a=this.getTimeoutApsIssueType();c.Z.trackAPSIssue(a,(0,i.NI)().loader,this.context.hasUserLoaded,!1,{timer:e.timer,userStatus:t})}else if(e instanceof Z.W&&"UPGFConnector"===e.source)c.Z.trackAPSIssue("gfconnector-timeout",(0,i.NI)().loader,this.context.hasUserLoaded,!1,{userStatus:t});else{if(e instanceof C.J){return e.errors.find((e=>e&&e.extensions&&"NOT_AUTHENTICATED"===e.extensions.code))?void c.Z.trackAPSIssue("getGameData-notAuthenticated-error","iframe",this.context.hasUserLoaded,!1,{userStatus:t}):void c.Z.trackAPSIssue("getGameData-error","iframe",this.context.hasUserLoaded,!1,{userStatus:t})}e instanceof j.k?c.Z.trackAPSIssue("fetch-error-signed-url","iframe",this.context.hasUserLoaded,!1,{userStatus:t}):e instanceof O.K?c.Z.trackAPSIssue("getGameData-install-error","iframe",this.context.hasUserLoaded,!1,{userStatus:t}):c.Z.trackAPSIssue("fetch-error",(0,i.NI)().loader,this.context.hasUserLoaded,!1,{userStatus:t})}},this.logger.debug("enabled"),this.state={showReloadPopup:!1}}componentDidMount(){(0,h.VO)("Loading Unity loader"),this.onPreloadGame(),this.handleUserInitLogic(),this.handleGameDataTimeoutStart(),this.handleUnitySyncTimeStart()}componentDidUpdate(){this.handleUserInitLogic(),this.handleGameDataTimeoutStart(),this.handleUnitySyncTimeStart()}componentWillUnmount(){this.clearUnitySyncTime(),window.clearTimeout(this.gameDataHandleTimeoutId)}handleUnitySyncTimeStart(){"NOT_STARTED"===this.props.gameLoadStatus||"aps"!==u.Z.Instance.getCurrentSyncType()||void 0!==this.syncTimerInterval||(this.logger.debug("starting interval sync for user"),this.syncTimerInterval=window.setInterval((async()=>{"aps"===u.Z.Instance.getCurrentSyncType()&&C.n.Instance.syncUnityData(!0)}),(0,M.getSyncTimerMs)()))}handleUserInitLogic(){var e;this.context.hasUserLoaded&&(null!==(e=this.context)&&void 0!==e&&e.userId?this.handleUserInit():this.handleNoUserInit())}render(){return(0,p.jsxs)(p.Fragment,{children:[this.state.showReloadPopup&&(0,p.jsx)(L,{onReload:this.onSelectReload}),(0,p.jsx)(_,{clearUnitySyncTime:this.clearUnitySyncTime,logger:this.logger})]})}}B.contextType=d.N;const W=(0,k.q)(B);var z=a(72071);const $=()=>{const{hasUserLoaded:e}=s.useContext(d.N),{gameLoadStatus:t}=s.useContext(z.r);if("NOT_STARTED"===t&&!e)return null;const a=(0,i.NI)().loader;return"iframe"===a&&(0,h.x3)()?(0,p.jsx)(N,{loader:"iframe"}):"ruffle"===a&&(0,h.o5)()?(0,p.jsx)(N,{loader:"ruffle"}):i.Fw.includes(a)&&(0,h.v9)()?(0,p.jsx)(W,{}):null}},52012:(e,t,a)=>{a.r(t),a.d(t,{getExistingIndexedData:()=>I,getExistingPlayerPrefUpdatedAtTz:()=>y,getLastSyncTimeOfIDBTz:()=>T,getPlayedTimeInLS:()=>v,getSyncTimerMs:()=>g,savePlayedTimeInLS:()=>w,setAPIDataToIDB:()=>U,setSyncTimeOfIndexDb:()=>x});var s=a(41989),i=a.n(s),r=a(94845),n=a(90831),o=a(22870),d=a(74082),l=a(2022);const c="/idbfs",h="FILE_DATA";let u;const m=e=>+new Date(e),g=()=>{const{apsSyncTimerMs:e}=(0,n.NI)();return e||3e4},p=()=>window.indexedDB,S=()=>{const e=(()=>{const e=window.location.origin+window.location.pathname,t=e.substring(0,e.lastIndexOf("/"));return i()(t)})(),t=`/idbfs/${e}/PlayerPrefs`;const a=(0,n.NI)().loaderOptions,s=a.unitySaveFileNames?a.unitySaveFileNames[0]:void 0,r=[`/idbfs/${e}`,t];return s&&r.push(`/idbfs/${e}/${s}`),r},f=e=>{const t=e.target.result,a=e.target.transaction;let s;s=t.objectStoreNames.contains(h)?a.objectStore(h):t.createObjectStore(h),s.indexNames.contains("timestamp")||s.createIndex("timestamp","timestamp",{unique:!1})},D=(e,t)=>new Promise(((a,s)=>{e.transaction(h).objectStore(h).get(t).onsuccess=e=>{try{const s=e.target.result;if(!s)return a(null);if(!s.timestamp)return console.error("[APS-U] IDB data incomplete: "+t+s),a(null);const i=new Date(s.timestamp).setMilliseconds(0);a(i)}catch(s){o.kg.debug("[APS-U] Error:",s)}}})),y=()=>{const e=p().open(c,21);return new Promise(((t,a)=>{e.onupgradeneeded=f,e.onsuccess=async()=>{const a=e.result;a.objectStoreNames.contains(h)||a.createObjectStore(h);const s=S();let i=await D(a,s[1]);i||(i=await D(a,s[0])),t(i)},e.onerror=e=>{o.kg.debug("[APS-U] Error:",e),a()}}))},I=()=>{const e=p().open(c,21);return new Promise(((t,a)=>{e.onupgradeneeded=f,e.onsuccess=()=>{const s=e.result,i=S(),n=s.transaction(h),o=n.objectStore(h),d={};let l;i.forEach((e=>{o.get(e).onsuccess=t=>{const s=t.target.result;if(s){var i;s.timestamp||a("[APS-U] IDB data incomplete: "+e+s);const t=new Date(s.timestamp);t.getTime()>((null===(i=l)||void 0===i?void 0:i.getTime())||0)&&(l=t);const o={...s,timestamp:m(s.timestamp)};s.contents&&(o.contents=(n=s.contents,(0,r.hd)(n))),d[e]=o}var n}})),n.oncomplete=()=>{Object.keys(d).length>0?t({data:d,updatedAtTz:m(l)}):t({data:null})},n.onerror=e=>{a(e)}}}))},w=e=>{const{gameSlug:t}=(0,n.NI)();d.m.Instance.setItem(`_czy_${t}_pt`,`${e}`)},v=()=>{const{gameSlug:e}=(0,n.NI)(),t=d.m.Instance.getItem(`_czy_${e}_pt`)||"0";return JSON.parse(t)},x=e=>{u=e},T=()=>u,P=(e,t)=>{const a=p().open(c,21);return new Promise(((s,i)=>{a.onupgradeneeded=f,a.onsuccess=()=>{const n=a.result.transaction(h,"readwrite");t.forEach((t=>{const a=e[t];if(a){a.timestamp||i("[APS-U] API data incomplete: "+e);const o={...a,timestamp:new Date(a.timestamp)};o.contents&&(o.contents=(s=o.contents,new Uint8Array((0,r.fJ)(s)))),n.objectStore(h).put(o,t)}var s})),n.oncomplete=()=>{s(null)},n.onerror=()=>{i(null)}}}))},U=async(e,t)=>{try{const a=JSON.parse(e.data),s=S();await P(a,s),u=t}catch(a){throw new l.K("setAPIDataToIDB",a)}}},91423:(e,t,a)=>{a.d(t,{Z:()=>r});a(47313);var s=a(31080),i=a(46417);const r=e=>{let{onClick:t,className:a,responsive:r,customStyle:n,children:o,variant:d="contained"}=e;return(0,i.jsx)(s.v,{responsive:!!r,variant:d,className:a,onClick:t,style:n,children:o})}},2022:(e,t,a)=>{a.d(t,{K:()=>s});class s extends Error{constructor(e,t){super(`IdbError:${e}`),this.originalError=void 0,this.source=void 0,this.originalError=t,this.source=e,Object.setPrototypeOf(this,s.prototype)}}}}]);