1 line
54 KiB
JavaScript
1 line
54 KiB
JavaScript
import{d as e,c as t,a as n,w as o,b as i,r as l,o as a,e as s,t as r,F as c,f as d,g as u,h as g,v as p,i as h,j as m,k as y,l as f,m as w,n as v,p as b,q as x,s as C}from"./vendor.b622ee49.js";var k=e({name:"app",computed:{showNav(){return!["game","replay"].includes(String(this.$route.name))}}});const A={id:"app"},z={key:0,class:"nav"},S=s("Index"),P=s("New game");k.render=function(e,s,r,c,d,u){const g=l("router-link"),p=l("router-view");return a(),t("div",A,[e.showNav?(a(),t("ul",z,[n("li",null,[n(g,{class:"btn",to:{name:"index"}},{default:o((()=>[S])),_:1})]),n("li",null,[n(g,{class:"btn",to:{name:"new-game"}},{default:o((()=>[P])),_:1})])])):i("",!0),n(p)])};const I=864e5,T=e=>{const t=Math.floor(e/I);e%=I;const n=Math.floor(e/36e5);e%=36e5;const o=Math.floor(e/6e4);e%=6e4;return`${t}d ${n}h ${o}m ${Math.floor(e/1e3)}s`};var _=1e3,D=()=>{const e=new Date;return Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())},B=(e,t)=>T(t-e),E=T,O=e({name:"game-teaser",props:{game:{type:Object,required:!0}},computed:{style(){return{"background-image":`url("${this.game.imageUrl.replace("uploads/","uploads/r/")+"-375x210.webp"}")`}}},methods:{time(e,t){const n=t?"🏁":"⏳",o=e,i=t||D();return`${n} ${B(o,i)}`}}});const N={class:"game-info-text"},U=n("br",null,null,-1),M=n("br",null,null,-1),G=n("br",null,null,-1),$=s(" ↪️ Watch replay ");O.render=function(e,c,d,u,g,p){const h=l("router-link");return a(),t("div",{class:"game-teaser",style:e.style},[n(h,{class:"game-info",to:{name:"game",params:{id:e.game.id}}},{default:o((()=>[n("span",N,[s(" 🧩 "+r(e.game.tilesFinished)+"/"+r(e.game.tilesTotal),1),U,s(" 👥 "+r(e.game.players),1),M,s(" "+r(e.time(e.game.started,e.game.finished)),1),G])])),_:1},8,["to"]),e.game.hasReplay?(a(),t(h,{key:0,class:"game-replay",to:{name:"replay",params:{id:e.game.id}}},{default:o((()=>[$])),_:1},8,["to"])):i("",!0)],4)};var R=e({components:{GameTeaser:O},data:()=>({gamesRunning:[],gamesFinished:[]}),async created(){const e=await fetch("/api/index-data"),t=await e.json();this.gamesRunning=t.gamesRunning,this.gamesFinished=t.gamesFinished}});const V=n("h1",null,"Running games",-1),j=n("h1",null,"Finished games",-1);R.render=function(e,o,i,s,r,u){const g=l("game-teaser");return a(),t("div",null,[V,(a(!0),t(c,null,d(e.gamesRunning,((e,o)=>(a(),t("div",{class:"game-teaser-wrap",key:o},[n(g,{game:e},null,8,["game"])])))),128)),j,(a(!0),t(c,null,d(e.gamesFinished,((e,o)=>(a(),t("div",{class:"game-teaser-wrap",key:o},[n(g,{game:e},null,8,["game"])])))),128))])};var F=e({name:"image-teaser",props:{image:{type:Object,required:!0}},computed:{style(){return{backgroundImage:`url("${this.image.url.replace("uploads/","uploads/r/")+"-150x100.webp"}")`}}},emits:{click:null,editClick:null},methods:{onClick(){this.$emit("click")},onEditClick(){this.$emit("editClick")}}});F.render=function(e,o,i,l,s,r){return a(),t("div",{class:"imageteaser",style:e.style,onClick:o[2]||(o[2]=(...t)=>e.onClick&&e.onClick(...t))},[n("div",{class:"btn edit",onClick:o[1]||(o[1]=u(((...t)=>e.onEditClick&&e.onEditClick(...t)),["stop"]))},"✏️")],4)};var L=e({name:"image-library",components:{ImageTeaser:F},props:{images:{type:Array,required:!0}},emits:{imageClicked:null,imageEditClicked:null},methods:{imageClicked(e){this.$emit("imageClicked",e)},imageEditClicked(e){this.$emit("imageEditClicked",e)}}});L.render=function(e,n,o,i,s,r){const u=l("image-teaser");return a(),t("div",null,[(a(!0),t(c,null,d(e.images,((n,o)=>(a(),t(u,{image:n,onClick:t=>e.imageClicked(n),onEditClick:t=>e.imageEditClicked(n),key:o},null,8,["image","onClick","onEditClick"])))),128))])};const W={name:"responsive-image",props:{src:String,title:{type:String,default:""},height:{type:String,default:"100%"},width:{type:String,default:"100%"}},computed:{style(){return{display:"inline-block",verticalAlign:"text-bottom",backgroundImage:`url('${this.src}')`,backgroundRepeat:"no-repeat",backgroundSize:"contain",backgroundPosition:"center",width:this.width,height:this.height}}}};W.render=function(e,n,o,i,l,s){return a(),t("div",{style:s.style,title:o.title},null,12,["title"])};var q=e({name:"tags-input",props:{modelValue:{type:Array,required:!0}},emits:{"update:modelValue":null},data:()=>({input:"",values:[]}),created(){this.values=this.modelValue},methods:{onKeyUp(e){if(","===e.key)return this.add(),e.stopPropagation(),!1},add(){const e=this.input.replace(/,/g,"").trim();e&&(this.values.includes(e)||this.values.push(e),this.input="",this.$emit("update:modelValue",this.values))},rm(e){this.values=this.values.filter((t=>t!==e)),this.$emit("update:modelValue",this.values)}}});const H=m()(((e,o,i,l,s,u)=>(a(),t("div",null,[g(n("input",{class:"input",type:"text","onUpdate:modelValue":o[1]||(o[1]=t=>e.input=t),placeholder:"Plants, People",onKeydown:o[2]||(o[2]=h(((...t)=>e.add&&e.add(...t)),["enter"])),onKeyup:o[3]||(o[3]=(...t)=>e.onKeyUp&&e.onKeyUp(...t))},null,544),[[p,e.input]]),(a(!0),t(c,null,d(e.values,((n,o)=>(a(),t("span",{key:o,class:"bit",onClick:t=>e.rm(n)},r(n)+" ✖",9,["onClick"])))),128))]))));q.render=H,q.__scopeId="data-v-771460ae";var Q=e({name:"new-image-dialog",components:{ResponsiveImage:W,TagsInput:q},emits:{bgclick:null,setupGameClick:null,postToGalleryClick:null},data:()=>({previewUrl:"",file:null,title:"",tags:[]}),computed:{canPostToGallery(){return!(!this.previewUrl||!this.file)},canSetupGameClick(){return!(!this.previewUrl||!this.file)}},methods:{preview(e){const t=e.target;if(!t.files)return;const n=t.files[0];if(!n)return;const o=new FileReader;o.readAsDataURL(n),o.onload=e=>{this.previewUrl=e.target.result,this.file=n}},postToGallery(){this.$emit("postToGalleryClick",{file:this.file,title:this.title,tags:this.tags})},setupGameClick(){this.$emit("setupGameClick",{file:this.file,title:this.title,tags:this.tags})}}});const Y={key:0,class:"has-image"},K={key:1},Z={class:"upload"},J=n("span",{class:"btn"},"Upload File",-1),X={class:"area-settings"},ee=n("td",null,[n("label",null,"Title")],-1),te=n("tr",null,[n("td",{colspan:"2"},[n("div",{class:"hint"},"Feel free to leave a credit to the artist/photographer in the title :)")])],-1),ne=n("td",null,[n("label",null,"Tags")],-1),oe={class:"area-buttons"},ie=s("🧩 Post to gallery "),le=n("br",null,null,-1),ae=s(" + set up game");Q.render=function(e,o,i,s,r,c){const d=l("responsive-image"),h=l("tags-input");return a(),t("div",{class:"overlay new-image-dialog",onClick:o[8]||(o[8]=t=>e.$emit("bgclick"))},[n("div",{class:"overlay-content",onClick:o[7]||(o[7]=u((()=>{}),["stop"]))},[n("div",{class:["area-image",{"has-image":!!e.previewUrl,"no-image":!e.previewUrl}]},[e.previewUrl?(a(),t("div",Y,[n("span",{class:"remove btn",onClick:o[1]||(o[1]=t=>e.previewUrl="")},"X"),n(d,{src:e.previewUrl},null,8,["src"])])):(a(),t("div",K,[n("label",Z,[n("input",{type:"file",style:{display:"none"},onChange:o[2]||(o[2]=(...t)=>e.preview&&e.preview(...t)),accept:"image/*"},null,32),J])]))],2),n("div",X,[n("table",null,[n("tr",null,[ee,n("td",null,[g(n("input",{type:"text","onUpdate:modelValue":o[3]||(o[3]=t=>e.title=t),placeholder:"Flower by @artist"},null,512),[[p,e.title]])])]),te,n("tr",null,[ne,n("td",null,[n(h,{modelValue:e.tags,"onUpdate:modelValue":o[4]||(o[4]=t=>e.tags=t)},null,8,["modelValue"])])])])]),n("div",oe,[n("button",{class:"btn",disabled:!e.canPostToGallery,onClick:o[5]||(o[5]=(...t)=>e.postToGallery&&e.postToGallery(...t))},"🖼️ Post to gallery",8,["disabled"]),n("button",{class:"btn",disabled:!e.canSetupGameClick,onClick:o[6]||(o[6]=(...t)=>e.setupGameClick&&e.setupGameClick(...t))},[ie,le,ae],8,["disabled"])])])])};var se=e({name:"edit-image-dialog",components:{ResponsiveImage:W,TagsInput:q},props:{image:{type:Object,required:!0}},emits:{bgclick:null,saveClick:null},data:()=>({title:"",tags:[]}),created(){this.title=this.image.title,this.tags=this.image.tags.map((e=>e.title))},methods:{saveImage(){this.$emit("saveClick",{id:this.image.id,title:this.title,tags:this.tags})}}});const re={class:"area-image"},ce={class:"has-image"},de={class:"area-settings"},ue=n("td",null,[n("label",null,"Title")],-1),ge=n("tr",null,[n("td",{colspan:"2"},[n("div",{class:"hint"},"Feel free to leave a credit to the artist/photographer in the title :)")])],-1),pe=n("td",null,[n("label",null,"Tags")],-1),he={class:"area-buttons"};var me,ye,fe,we;se.render=function(e,o,i,s,r,c){const d=l("responsive-image"),h=l("tags-input");return a(),t("div",{class:"overlay edit-image-dialog",onClick:o[5]||(o[5]=t=>e.$emit("bgclick"))},[n("div",{class:"overlay-content",onClick:o[4]||(o[4]=u((()=>{}),["stop"]))},[n("div",re,[n("div",ce,[n(d,{src:e.image.url,title:e.image.title},null,8,["src","title"])])]),n("div",de,[n("table",null,[n("tr",null,[ue,n("td",null,[g(n("input",{type:"text","onUpdate:modelValue":o[1]||(o[1]=t=>e.title=t),placeholder:"Flower by @artist"},null,512),[[p,e.title]])])]),ge,n("tr",null,[pe,n("td",null,[n(h,{modelValue:e.tags,"onUpdate:modelValue":o[2]||(o[2]=t=>e.tags=t)},null,8,["modelValue"])])])])]),n("div",he,[n("button",{class:"btn",onClick:o[3]||(o[3]=(...t)=>e.saveImage&&e.saveImage(...t))},"🖼️ Save image")])])])},(ye=me||(me={}))[ye.Flat=0]="Flat",ye[ye.Out=1]="Out",ye[ye.In=-1]="In",(we=fe||(fe={}))[we.FINAL=0]="FINAL",we[we.ANY=1]="ANY";var ve=e({name:"new-game-dialog",components:{ResponsiveImage:W},props:{image:{type:Object,required:!0}},emits:{newGame:null,bgclick:null},data:()=>({tiles:1e3,scoreMode:fe.ANY}),methods:{onNewGameClick(){this.$emit("newGame",{tiles:this.tilesInt,image:this.image,scoreMode:this.scoreModeInt})}},computed:{canStartNewGame(){return!!(this.tilesInt&&this.image&&this.image.url&&[0,1].includes(this.scoreModeInt))},scoreModeInt(){return parseInt(`${this.scoreMode}`,10)},tilesInt(){return parseInt(`${this.tiles}`,10)}}});const be={class:"area-image"},xe={class:"has-image"},Ce={class:"area-settings"},ke=n("td",null,[n("label",null,"Pieces")],-1),Ae=n("td",null,[n("label",null,"Scoring: ")],-1),ze=s(" Any (Score when pieces are connected to each other or on final location)"),Se=n("br",null,null,-1),Pe=s(" Final (Score when pieces are put to their final location)"),Ie={class:"area-buttons"};ve.render=function(e,o,i,s,r,c){const d=l("responsive-image");return a(),t("div",{class:"overlay new-game-dialog",onClick:o[6]||(o[6]=t=>e.$emit("bgclick"))},[n("div",{class:"overlay-content",onClick:o[5]||(o[5]=u((()=>{}),["stop"]))},[n("div",be,[n("div",xe,[n(d,{src:e.image.url,title:e.image.title},null,8,["src","title"])])]),n("div",Ce,[n("table",null,[n("tr",null,[ke,n("td",null,[g(n("input",{type:"text","onUpdate:modelValue":o[1]||(o[1]=t=>e.tiles=t)},null,512),[[p,e.tiles]])])]),n("tr",null,[Ae,n("td",null,[n("label",null,[g(n("input",{type:"radio","onUpdate:modelValue":o[2]||(o[2]=t=>e.scoreMode=t),value:"1"},null,512),[[y,e.scoreMode]]),ze]),Se,n("label",null,[g(n("input",{type:"radio","onUpdate:modelValue":o[3]||(o[3]=t=>e.scoreMode=t),value:"0"},null,512),[[y,e.scoreMode]]),Pe])])])])]),n("div",Ie,[n("button",{class:"btn",disabled:!e.canStartNewGame,onClick:o[4]||(o[4]=(...t)=>e.onNewGameClick&&e.onNewGameClick(...t))}," 🧩 Generate Puzzle ",8,["disabled"])])])])};class Te{constructor(e){this.rand_high=e||3735929054,this.rand_low=1231121986^e}random(e,t){this.rand_high=(this.rand_high<<16)+(this.rand_high>>16)+this.rand_low&4294967295,this.rand_low=this.rand_low+this.rand_high&4294967295;return e+(this.rand_high>>>0)/4294967295*(t-e+1)|0}choice(e){return e[this.random(0,e.length-1)]}shuffle(e){const t=e.slice();for(let n=0;n<=t.length-2;n++){const e=this.random(n,t.length-1),o=t[n];t[n]=t[e],t[e]=o}return t}static serialize(e){return{rand_high:e.rand_high,rand_low:e.rand_low}}static unserialize(e){const t=new Te(0);return t.rand_high=e.rand_high,t.rand_low=e.rand_low,t}}const _e=(e,t)=>{const n=`${e}`;return n.length>=t.length?n:t.substr(0,t.length-n.length)+n},De=(...e)=>{const t=t=>(...n)=>{const o=new Date,i=_e(o.getHours(),"00"),l=_e(o.getMinutes(),"00"),a=_e(o.getSeconds(),"00");console[t](`${i}:${l}:${a}`,...e,...n)};return{log:t("log"),error:t("error"),info:t("info")}};var Be={hash:e=>{let t=0;for(let n=0;n<e.length;n++){t=(t<<5)-t+e.charCodeAt(n),t|=0}return t},slug:e=>{let t=e.toLowerCase();return t=t.replace(/[^a-z0-9]+/g,"-"),t=t.replace(/^-|-$/,""),t},uniqId:()=>Date.now().toString(36)+Math.random().toString(36).substring(2),encodeShape:function(e){return e.top+1<<0|e.right+1<<2|e.bottom+1<<4|e.left+1<<6},decodeShape:function(e){return{top:(e>>0&3)-1,right:(e>>2&3)-1,bottom:(e>>4&3)-1,left:(e>>6&3)-1}},encodePiece:function(e){return[e.idx,e.pos.x,e.pos.y,e.z,e.owner,e.group]},decodePiece:function(e){return{idx:e[0],pos:{x:e[1],y:e[2]},z:e[3],owner:e[4],group:e[5]}},encodePlayer:function(e){return[e.id,e.x,e.y,e.d,e.name,e.color,e.bgcolor,e.points,e.ts]},decodePlayer:function(e){return{id:e[0],x:e[1],y:e[2],d:e[3],name:e[4],color:e[5],bgcolor:e[6],points:e[7],ts:e[8]}},encodeGame:function(e){return[e.id,e.rng.type||"",Te.serialize(e.rng.obj),e.puzzle,e.players,e.evtInfos,e.scoreMode||fe.FINAL]},decodeGame:function(e){return{id:e[0],rng:{type:e[1],obj:Te.unserialize(e[2])},puzzle:e[3],players:e[4],evtInfos:e[5],scoreMode:e[6]}},coordByPieceIdx:function(e,t){const n=e.width/e.tileSize;return{x:t%n,y:Math.floor(t/n)}},asQueryArgs:function(e){const t=[];for(const n in e){const o=[n,e[n]].map(encodeURIComponent);t.push(o.join("="))}return 0===t.length?"":`?${t.join("&")}`}},Ee=e({components:{ImageLibrary:L,NewImageDialog:Q,EditImageDialog:se,NewGameDialog:ve},data:()=>({filters:{sort:"date_desc",tags:[]},images:[],tags:[],image:{id:0,filename:"",file:"",url:"",title:"",tags:[],created:0},dialog:""}),async created(){await this.loadImages()},methods:{toggleTag(e){this.filters.tags.includes(e.slug)?this.filters.tags=this.filters.tags.filter((t=>t!==e.slug)):this.filters.tags.push(e.slug),this.filtersChanged()},async loadImages(){const e=await fetch(`/api/newgame-data${Be.asQueryArgs(this.filters)}`),t=await e.json();this.images=t.images,this.tags=t.tags},async filtersChanged(){await this.loadImages()},onImageClicked(e){this.image=e,this.dialog="new-game"},onImageEditClicked(e){this.image=e,this.dialog="edit-image"},async uploadImage(e){const t=new FormData;t.append("file",e.file,e.file.name),t.append("title",e.title),t.append("tags",e.tags);const n=await fetch("/api/upload",{method:"post",body:t});return await n.json()},async saveImage(e){const t=await fetch("/api/save-image",{method:"post",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({id:e.id,title:e.title,tags:e.tags})});return await t.json()},async onSaveImageClick(e){await this.saveImage(e),this.dialog="",await this.loadImages()},async postToGalleryClick(e){await this.uploadImage(e),this.dialog="",await this.loadImages()},async setupGameClick(e){const t=await this.uploadImage(e);this.loadImages(),this.image=t,this.dialog="new-game"},async onNewGame(e){const t=await fetch("/api/newgame",{method:"post",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e)});if(200===t.status){const e=await t.json();this.$router.push({name:"game",params:{id:e.id}})}}}});const Oe={class:"upload-image-teaser"},Ne=n("div",{class:"hint"},"(The image you upload will be added to the public gallery.)",-1),Ue={key:0},Me=s(" Tags: "),Ge=s(" Sort by: "),$e=n("option",{value:"date_desc"},"Newest first",-1),Re=n("option",{value:"date_asc"},"Oldest first",-1),Ve=n("option",{value:"alpha_asc"},"A-Z",-1),je=n("option",{value:"alpha_desc"},"Z-A",-1);Ee.render=function(e,o,s,u,p,h){const m=l("image-library"),y=l("new-image-dialog"),w=l("edit-image-dialog"),v=l("new-game-dialog");return a(),t("div",null,[n("div",Oe,[n("div",{class:"btn btn-big",onClick:o[1]||(o[1]=t=>e.dialog="new-image")},"Upload your image"),Ne]),n("div",null,[e.tags.length>0?(a(),t("label",Ue,[Me,(a(!0),t(c,null,d(e.tags,((n,o)=>(a(),t("span",{class:["bit",{on:e.filters.tags.includes(n.slug)}],key:o,onClick:t=>e.toggleTag(n)},r(n.title),11,["onClick"])))),128))])):i("",!0),n("label",null,[Ge,g(n("select",{"onUpdate:modelValue":o[2]||(o[2]=t=>e.filters.sort=t),onChange:o[3]||(o[3]=(...t)=>e.filtersChanged&&e.filtersChanged(...t))},[$e,Re,Ve,je],544),[[f,e.filters.sort]])])]),n(m,{images:e.images,onImageClicked:e.onImageClicked,onImageEditClicked:e.onImageEditClicked},null,8,["images","onImageClicked","onImageEditClicked"]),"new-image"===e.dialog?(a(),t(y,{key:0,onBgclick:o[4]||(o[4]=t=>e.dialog=""),onPostToGalleryClick:e.postToGalleryClick,onSetupGameClick:e.setupGameClick},null,8,["onPostToGalleryClick","onSetupGameClick"])):i("",!0),"edit-image"===e.dialog?(a(),t(w,{key:1,onBgclick:o[5]||(o[5]=t=>e.dialog=""),onSaveClick:e.onSaveImageClick,image:e.image},null,8,["onSaveClick","image"])):i("",!0),e.image&&"new-game"===e.dialog?(a(),t(v,{key:2,onBgclick:o[6]||(o[6]=t=>e.dialog=""),onNewGame:e.onNewGame,image:e.image},null,8,["onNewGame","image"])):i("",!0)])};var Fe=e({name:"scores",props:{activePlayers:{type:Array,required:!0},idlePlayers:{type:Array,required:!0}},computed:{actives(){return this.activePlayers.sort(((e,t)=>t.points-e.points)),this.activePlayers},idles(){return this.idlePlayers.sort(((e,t)=>t.points-e.points)),this.idlePlayers}}});const Le={class:"scores"},We=n("div",null,"Scores",-1),qe=n("td",null,"⚡",-1),He=n("td",null,"💤",-1);Fe.render=function(e,o,i,l,s,u){return a(),t("div",Le,[We,n("table",null,[(a(!0),t(c,null,d(e.actives,((e,o)=>(a(),t("tr",{key:o,style:{color:e.color}},[qe,n("td",null,r(e.name),1),n("td",null,r(e.points),1)],4)))),128)),(a(!0),t(c,null,d(e.idles,((e,o)=>(a(),t("tr",{key:o,style:{color:e.color}},[He,n("td",null,r(e.name),1),n("td",null,r(e.points),1)],4)))),128))])])};var Qe=e({name:"puzzle-status",props:{finished:{type:Boolean,required:!0},duration:{type:Number,required:!0},piecesDone:{type:Number,required:!0},piecesTotal:{type:Number,required:!0}},computed:{icon(){return this.finished?"🏁":"⏳"},durationStr(){return E(this.duration)}}});const Ye={class:"timer"};Qe.render=function(e,o,i,l,s,c){return a(),t("div",Ye,[n("div",null," 🧩 "+r(e.piecesDone)+"/"+r(e.piecesTotal),1),n("div",null,r(e.icon)+" "+r(e.durationStr),1),w(e.$slots,"default")])};var Ke=e({name:"settings-overlay",emits:{bgclick:null,"update:modelValue":null},props:{modelValue:Object},created(){this.$watch("modelValue",(e=>{this.$emit("update:modelValue",e)}),{deep:!0})}});const Ze=n("td",null,[n("label",null,"Background: ")],-1),Je=n("td",null,[n("label",null,"Color: ")],-1),Xe=n("td",null,[n("label",null,"Name: ")],-1);Ke.render=function(e,o,i,l,s,r){return a(),t("div",{class:"overlay transparent",onClick:o[5]||(o[5]=t=>e.$emit("bgclick"))},[n("table",{class:"overlay-content settings",onClick:o[4]||(o[4]=u((()=>{}),["stop"]))},[n("tr",null,[Ze,n("td",null,[g(n("input",{type:"color","onUpdate:modelValue":o[1]||(o[1]=t=>e.modelValue.background=t)},null,512),[[p,e.modelValue.background]])])]),n("tr",null,[Je,n("td",null,[g(n("input",{type:"color","onUpdate:modelValue":o[2]||(o[2]=t=>e.modelValue.color=t)},null,512),[[p,e.modelValue.color]])])]),n("tr",null,[Xe,n("td",null,[g(n("input",{type:"text",maxLength:"16","onUpdate:modelValue":o[3]||(o[3]=t=>e.modelValue.name=t)},null,512),[[p,e.modelValue.name]])])])])])};var et=e({name:"preview-overlay",props:{img:String},emits:{bgclick:null},computed:{previewStyle(){return{backgroundImage:`url('${this.img}')`}}}});const tt={class:"preview"};et.render=function(e,o,i,l,s,r){return a(),t("div",{class:"overlay",onClick:o[1]||(o[1]=t=>e.$emit("bgclick"))},[n("div",tt,[n("div",{class:"img",style:e.previewStyle},null,4)])])};var nt=1,ot=4,it=2,lt=3,at=2,st=4,rt=3,ct=9,dt=1,ut=2,gt=3,pt=4,ht=5,mt=6,yt=7,ft=8,wt=10,vt=1,bt=2,xt=3;const Ct=De("Communication.js");let kt,At=[],zt=e=>{At.push(e)},St=[],Pt=e=>{St.push(e)};let It=0;const Tt=e=>{It!==e&&(It=e,Pt(e))};function _t(e){if(2===It)try{kt.send(JSON.stringify(e))}catch(t){Ct.info("unable to send message.. maybe because ws is invalid?")}}let Dt,Bt;var Et={connect:function(e,t,n){return Dt=0,Bt={},Tt(3),new Promise((o=>{kt=new WebSocket(e,n+"|"+t),kt.onopen=()=>{Tt(2),_t([lt])},kt.onmessage=e=>{const t=JSON.parse(e.data),i=t[0];if(i===ot){const e=t[1];o(e)}else{if(i!==nt)throw`[ 2021-05-09 invalid connect msgType ${i} ]`;{const e=t[1],o=t[2];if(e===n&&Bt[o])return void delete Bt[o];zt(t)}}},kt.onerror=()=>{throw Tt(1),"[ 2021-05-15 onerror ]"},kt.onclose=e=>{4e3===e.code||1001===e.code?Tt(4):Tt(1)}}))},requestReplayData:async function(e,t,n){const o={gameId:e,offset:t,size:n},i=await fetch(`/api/replay-data${Be.asQueryArgs(o)}`);return await i.json()},disconnect:function(){kt&&kt.close(4e3),Dt=0,Bt={}},sendClientEvent:function(e){Dt++,Bt[Dt]=e,_t([it,Dt,Bt[Dt]])},onServerChange:function(e){zt=e;for(const t of At)zt(t);At=[]},onConnectionStateChange:function(e){Pt=e;for(const t of St)Pt(t);St=[]},CODE_CUSTOM_DISCONNECT:4e3,CONN_STATE_NOT_CONNECTED:0,CONN_STATE_DISCONNECTED:1,CONN_STATE_CLOSED:4,CONN_STATE_CONNECTED:2,CONN_STATE_CONNECTING:3},Ot=e({name:"connection-overlay",emits:{reconnect:null},props:{connectionState:Number},computed:{lostConnection(){return this.connectionState===Et.CONN_STATE_DISCONNECTED},connecting(){return this.connectionState===Et.CONN_STATE_CONNECTING},show(){return!(!this.lostConnection&&!this.connecting)}}});const Nt={key:0,class:"overlay connection-lost"},Ut={key:0,class:"overlay-content"},Mt=n("div",null,"⁉️ LOST CONNECTION ⁉️",-1),Gt={key:1,class:"overlay-content"},$t=n("div",null,"Connecting...",-1);Ot.render=function(e,o,l,s,r,c){return e.show?(a(),t("div",Nt,[e.lostConnection?(a(),t("div",Ut,[Mt,n("span",{class:"btn",onClick:o[1]||(o[1]=t=>e.$emit("reconnect"))},"Reconnect")])):i("",!0),e.connecting?(a(),t("div",Gt,[$t])):i("",!0)])):i("",!0)};var Rt=e({name:"help-overlay",emits:{bgclick:null}});const Vt=n("tr",null,[n("td",null,"⬆️ Move up:"),n("td",null,[n("div",null,[n("kbd",null,"W"),s("/"),n("kbd",null,"↑"),s("/🖱️")])])],-1),jt=n("tr",null,[n("td",null,"⬇️ Move down:"),n("td",null,[n("div",null,[n("kbd",null,"S"),s("/"),n("kbd",null,"↓"),s("/🖱️")])])],-1),Ft=n("tr",null,[n("td",null,"⬅️ Move left:"),n("td",null,[n("div",null,[n("kbd",null,"A"),s("/"),n("kbd",null,"←"),s("/🖱️")])])],-1),Lt=n("tr",null,[n("td",null,"➡️ Move right:"),n("td",null,[n("div",null,[n("kbd",null,"D"),s("/"),n("kbd",null,"→"),s("/🖱️")])])],-1),Wt=n("tr",null,[n("td"),n("td",null,[n("div",null,[s("Move faster by holding "),n("kbd",null,"Shift")])])],-1),qt=n("tr",null,[n("td",null,"🔍+ Zoom in:"),n("td",null,[n("div",null,[n("kbd",null,"E"),s("/🖱️-Wheel")])])],-1),Ht=n("tr",null,[n("td",null,"🔍- Zoom out:"),n("td",null,[n("div",null,[n("kbd",null,"Q"),s("/🖱️-Wheel")])])],-1),Qt=n("tr",null,[n("td",null,"🖼️ Toggle preview:"),n("td",null,[n("div",null,[n("kbd",null,"Space")])])],-1),Yt=n("tr",null,[n("td",null,"🧩✔️ Toggle fixed pieces:"),n("td",null,[n("div",null,[n("kbd",null,"F")])])],-1),Kt=n("tr",null,[n("td",null,"🧩❓ Toggle loose pieces:"),n("td",null,[n("div",null,[n("kbd",null,"G")])])],-1);Rt.render=function(e,o,i,l,s,r){return a(),t("div",{class:"overlay transparent",onClick:o[2]||(o[2]=t=>e.$emit("bgclick"))},[n("table",{class:"overlay-content help",onClick:o[1]||(o[1]=u((()=>{}),["stop"]))},[Vt,jt,Ft,Lt,Wt,qt,Ht,Qt,Yt,Kt])])};var Zt=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAW0lEQVQ4je1RywrAIAxLxP//5exixRWlVgZelpOKeTQFfnDypgy3eLIkSLLL8mxGPoHsU2hPAgDHBLvRX6hZZw/fwT0BtlLSONqCbWAmEIqMZOCDDlaDR3N03gOyDCn+y4DWmAAAAABJRU5ErkJggg=="}),Jt=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAARElEQVQ4jWNgGAU0Af+hmBCbgYGBgYERhwHEAEYGBgYGJtIdiApYyLAZBVDsAqoagC1ACQJyY4ERg0GCISh6KA4DigEAou8LC+LnIJoAAAAASUVORK5CYII="}),Xt=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAcUlEQVQ4ja1TQQ7AIAgD///n7jCozA2Hbk00jbG1KIrcARszTugoBs49qioZj7r2kKACptkyAOCJsJuA+GzglwHjvMSSWFVaENWVASxh5eRLiq5fN/ASjI89VcP2K3hHpq1cEXNaMfnrL3TDZP2tDuoOA6MzCCXWr38AAAAASUVORK5CYII="}),en=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAU0lEQVQ4jWNgoAH4D8X42HDARKlt5BoAd82AuQAOGLGIYQQUPv0wF5CiCQUge4EsQ5C9QI4BjMguwBYeBAElscCIy1ZivMKIwSDBEBQ9FCckigEAU3QOD7TGvY4AAAAASUVORK5CYII="});function tn(){let e=0,t=0,n=1;const o=(o,i)=>{e+=o/n,t+=i/n},i=e=>{const t=n+.05*n*("in"===e?1:-1);return Math.min(Math.max(t,.1),6)},l=o=>({x:o.x/n-e,y:o.y/n-t}),a=o=>({x:(o.x+e)*n,y:(o.y+t)*n}),s=e=>({w:e.w*n,h:e.h*n});return{move:o,canZoom:e=>n!=i(e),zoom:(e,t)=>((e,t)=>{if(n==e)return!1;const i=1-n/e;return o(-t.x*i,-t.y*i),n=e,!0})(i(e),t),worldToViewport:e=>{const{x:t,y:n}=a(e);return{x:Math.round(t),y:Math.round(n)}},worldToViewportRaw:a,worldDimToViewport:e=>{const{w:t,h:n}=s(e);return{w:Math.round(t),h:Math.round(n)}},worldDimToViewportRaw:s,viewportToWorld:e=>{const{x:t,y:n}=l(e);return{x:Math.round(t),y:Math.round(n)}},viewportToWorldRaw:l}}function nn(e=0,t=0){const n=document.createElement("canvas");return n.width=e,n.height=t,n}var on={createCanvas:nn,loadImageToBitmap:async function(e){return new Promise((t=>{const n=new Image;n.onload=()=>{createImageBitmap(n).then(t)},n.src=e}))},resizeBitmap:async function(e,t,n){const o=nn(t,n);return o.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t,n),await createImageBitmap(o)},colorizedCanvas:function(e,t,n){const o=nn(e.width,e.height),i=o.getContext("2d");return i.save(),i.drawImage(t,0,0),i.fillStyle=n,i.globalCompositeOperation="source-in",i.fillRect(0,0,t.width,t.height),i.restore(),i.save(),i.globalCompositeOperation="destination-over",i.drawImage(e,0,0),i.restore(),o}};const ln=De("Debug.js");let an=0,sn=0;var rn=e=>{an=performance.now(),sn=e},cn=e=>{const t=performance.now(),n=t-an;n>sn&&ln.log(e+": "+n),an=t};function dn(e,t){const n=e.x-t.x,o=e.y-t.y;return Math.sqrt(n*n+o*o)}function un(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}var gn={pointSub:function(e,t){return{x:e.x-t.x,y:e.y-t.y}},pointAdd:function(e,t){return{x:e.x+t.x,y:e.y+t.y}},pointDistance:dn,pointInBounds:function(e,t){return e.x>=t.x&&e.x<=t.x+t.w&&e.y>=t.y&&e.y<=t.y+t.h},rectCenter:un,rectMoved:function(e,t,n){return{x:e.x+t,y:e.y+n,w:e.w,h:e.h}},rectCenterDistance:function(e,t){return dn(un(e),un(t))},rectsOverlap:function(e,t){return!(t.x>e.x+e.w||e.x>t.x+t.w||t.y>e.y+e.h||e.y>t.y+t.h)}};const pn=De("PuzzleGraphics.js");function hn(e,t){const n=Be.coordByPieceIdx(e,t);return{x:n.x*e.tileSize,y:n.y*e.tileSize,w:e.tileSize,h:e.tileSize}}var mn={loadPuzzleBitmaps:async function(e){const t=await on.loadImageToBitmap(e.info.imageUrl),n=await on.resizeBitmap(t,e.info.width,e.info.height);return await async function(e,t,n){pn.log("start createPuzzleTileBitmaps");const o=n.tileSize,i=n.tileMarginWidth,l=n.tileDrawSize,a=o/100,s=[0,0,40,15,37,5,37,5,40,0,38,-5,38,-5,20,-20,50,-20,50,-20,80,-20,62,-5,62,-5,60,0,63,5,63,5,65,15,100,0],r=new Array(t.length),c={};function d(e){const t=`${e.top}${e.right}${e.left}${e.bottom}`;if(c[t])return c[t];const n=new Path2D,l={x:i,y:i},r=gn.pointAdd(l,{x:o,y:0}),d=gn.pointAdd(r,{x:0,y:o}),u=gn.pointSub(d,{x:o,y:0});if(n.moveTo(l.x,l.y),0!==e.top)for(let o=0;o<s.length/6;o++){const t=gn.pointAdd(l,{x:s[6*o+0]*a,y:e.top*s[6*o+1]*a}),i=gn.pointAdd(l,{x:s[6*o+2]*a,y:e.top*s[6*o+3]*a}),r=gn.pointAdd(l,{x:s[6*o+4]*a,y:e.top*s[6*o+5]*a});n.bezierCurveTo(t.x,t.y,i.x,i.y,r.x,r.y)}else n.lineTo(r.x,r.y);if(0!==e.right)for(let o=0;o<s.length/6;o++){const t=gn.pointAdd(r,{x:-e.right*s[6*o+1]*a,y:s[6*o+0]*a}),i=gn.pointAdd(r,{x:-e.right*s[6*o+3]*a,y:s[6*o+2]*a}),l=gn.pointAdd(r,{x:-e.right*s[6*o+5]*a,y:s[6*o+4]*a});n.bezierCurveTo(t.x,t.y,i.x,i.y,l.x,l.y)}else n.lineTo(d.x,d.y);if(0!==e.bottom)for(let o=0;o<s.length/6;o++){const t=gn.pointSub(d,{x:s[6*o+0]*a,y:e.bottom*s[6*o+1]*a}),i=gn.pointSub(d,{x:s[6*o+2]*a,y:e.bottom*s[6*o+3]*a}),l=gn.pointSub(d,{x:s[6*o+4]*a,y:e.bottom*s[6*o+5]*a});n.bezierCurveTo(t.x,t.y,i.x,i.y,l.x,l.y)}else n.lineTo(u.x,u.y);if(0!==e.left)for(let o=0;o<s.length/6;o++){const t=gn.pointSub(u,{x:-e.left*s[6*o+1]*a,y:s[6*o+0]*a}),i=gn.pointSub(u,{x:-e.left*s[6*o+3]*a,y:s[6*o+2]*a}),l=gn.pointSub(u,{x:-e.left*s[6*o+5]*a,y:s[6*o+4]*a});n.bezierCurveTo(t.x,t.y,i.x,i.y,l.x,l.y)}else n.lineTo(l.x,l.y);return c[t]=n,n}const u=on.createCanvas(l,l),g=u.getContext("2d"),p=on.createCanvas(l,l),h=p.getContext("2d");for(const m of t){const t=Be.decodePiece(m),o=hn(n,t.idx),a=d(Be.decodeShape(n.shapes[t.idx]));g.clearRect(0,0,l,l),g.save(),g.lineWidth=2,g.stroke(a),g.globalCompositeOperation="source-in",g.drawImage(e,o.x-i,o.y-i,l,l,0,0,l,l),g.restore(),g.save(),g.globalCompositeOperation="source-in",g.globalAlpha=.2,g.fillStyle="black",g.fillRect(0,0,u.width,u.height),g.restore(),g.save(),g.clip(a),g.drawImage(e,o.x-i,o.y-i,l,l,0,0,l,l),g.restore(),g.save(),g.clip(a),g.strokeStyle="rgba(0,0,0,.4)",g.lineWidth=0,g.shadowColor="black",g.shadowBlur=2,g.shadowOffsetX=-1,g.shadowOffsetY=-1,g.stroke(a),g.restore(),g.save(),g.clip(a),g.strokeStyle="rgba(255,255,255,.4)",g.lineWidth=0,g.shadowColor="white",g.shadowBlur=2,g.shadowOffsetX=1,g.shadowOffsetY=1,g.stroke(a),g.restore(),h.clearRect(0,0,l,l),h.save(),h.lineWidth=1,h.stroke(a),h.globalCompositeOperation="source-in",h.drawImage(e,o.x-i,o.y-i,l,l,0,0,l,l),h.restore(),g.drawImage(p,0,0),r[t.idx]=await createImageBitmap(u)}return pn.log("end createPuzzleTileBitmaps"),r}(n,e.tiles,e.info)}};const yn={};function fn(e,t){let n=0;for(const o of yn[e].players){if(Be.decodePlayer(o).id===t)return n;n++}return-1}function wn(e,t){const n=fn(e,t);return-1===n?null:Be.decodePlayer(yn[e].players[n])}function vn(e,t,n){const o=fn(e,t);-1===o?yn[e].players.push(Be.encodePlayer(n)):yn[e].players[o]=Be.encodePlayer(n)}function bn(e,t){return-1!==fn(e,t)}function xn(e){return yn[e]?yn[e].players.map(Be.decodePlayer):[]}function Cn(e){return yn[e].puzzle.tiles.length}function kn(e){return yn[e].scoreMode||fe.FINAL}function An(e){return zn(e)===Cn(e)}function zn(e){let t=0;for(const n of yn[e].puzzle.tiles)-1===Be.decodePiece(n).owner&&t++;return t}function Sn(e,t,n){const o=wn(e,t);if(null!==o){for(const e of Object.keys(n))o[e]=n[e];vn(e,t,o)}}function Pn(e,t){for(const n of Object.keys(t))yn[e].puzzle.data[n]=t[n]}function In(e,t,n){for(const o of Object.keys(n)){const i=Be.decodePiece(yn[e].puzzle.tiles[t]);i[o]=n[o],yn[e].puzzle.tiles[t]=Be.encodePiece(i)}}const Tn=(e,t)=>Be.decodePiece(yn[e].puzzle.tiles[t]),_n=(e,t)=>Tn(e,t).group,Dn=(e,t)=>{const n=yn[e].puzzle.info,o={x:(n.table.width-n.width)/2,y:(n.table.height-n.height)/2},i=function(e,t){const n=yn[e].puzzle.info,o=Be.coordByPieceIdx(n,t),i=o.x*n.tileSize,l=o.y*n.tileSize;return{x:i,y:l}}(e,t);return gn.pointAdd(o,i)},Bn=(e,t)=>Tn(e,t).pos,En=e=>{const t=Qn(e),n=Yn(e),o=Math.round(t/4),i=Math.round(n/4);return{x:0-o,y:0-i,w:t+2*o,h:n+2*i}},On=(e,t)=>{const n=Gn(e),o=Tn(e,t);return{x:o.pos.x,y:o.pos.y,w:n,h:n}},Nn=(e,t)=>Tn(e,t).z,Un=(e,t)=>{for(const n of yn[e].puzzle.tiles){const e=Be.decodePiece(n);if(e.owner===t)return e.idx}return-1},Mn=e=>yn[e].puzzle.info.tileDrawSize,Gn=e=>yn[e].puzzle.info.tileSize,$n=e=>yn[e].puzzle.data.maxGroup,Rn=e=>yn[e].puzzle.data.maxZ;function Vn(e,t){const n=yn[e].puzzle.info,o=Be.coordByPieceIdx(n,t);return[o.y>0?t-n.tilesX:-1,o.x<n.tilesX-1?t+1:-1,o.y<n.tilesY-1?t+n.tilesX:-1,o.x>0?t-1:-1]}const jn=(e,t,n)=>{for(const o of t)In(e,o,{z:n})},Fn=(e,t,n)=>{const o=Bn(e,t);In(e,t,{pos:gn.pointAdd(o,n)})},Ln=(e,t,n)=>{const o=Mn(e),i=En(e),l=n;for(const a of t){const t=Tn(e,a);t.pos.x+n.x<i.x?l.x=Math.max(i.x-t.pos.x,l.x):t.pos.x+o+n.x>i.x+i.w&&(l.x=Math.min(i.x+i.w-t.pos.x+o,l.x)),t.pos.y+n.y<i.y?l.y=Math.max(i.y-t.pos.y,l.y):t.pos.y+o+n.y>i.y+i.h&&(l.y=Math.min(i.y+i.h-t.pos.y+o,l.y))}for(const a of t)Fn(e,a,l)},Wn=(e,t,n)=>{for(const o of t)In(e,o,{owner:n})};function qn(e,t){const n=yn[e].puzzle.tiles,o=Be.decodePiece(n[t]),i=[];if(o.group)for(const l of n){const e=Be.decodePiece(l);e.group===o.group&&i.push(e.idx)}else i.push(o.idx);return i}const Hn=(e,t)=>{const n=wn(e,t);return n?n.points:0},Qn=e=>yn[e].puzzle.info.table.width,Yn=e=>yn[e].puzzle.info.table.height;var Kn={setGame:function(e,t){yn[e]=t},exists:function(e){return!!yn[e]||!1},playerExists:bn,getActivePlayers:function(e,t){const n=t-30*_;return xn(e).filter((e=>e.ts>=n))},getIdlePlayers:function(e,t){const n=t-30*_;return xn(e).filter((e=>e.ts<n&&e.points>0))},addPlayer:function(e,t,n){bn(e,t)?Sn(e,t,{ts:n}):vn(e,t,function(e,t){return{id:e,x:0,y:0,d:0,name:null,color:null,bgcolor:null,points:0,ts:t}}(t,n))},getFinishedPiecesCount:zn,getPieceCount:Cn,getImageUrl:function(e){return yn[e].puzzle.info.imageUrl},setImageUrl:function(e,t){yn[e].puzzle.info.imageUrl=t},get:function(e){return yn[e]||null},getAllGames:function(){return Object.values(yn).sort(((e,t)=>An(e.id)===An(t.id)?t.puzzle.data.started-e.puzzle.data.started:An(e.id)?1:-1))},getPlayerBgColor:(e,t)=>{const n=wn(e,t);return n?n.bgcolor:null},getPlayerColor:(e,t)=>{const n=wn(e,t);return n?n.color:null},getPlayerName:(e,t)=>{const n=wn(e,t);return n?n.name:null},getPlayerIndexById:fn,getPlayerIdByIndex:function(e,t){return yn[e].players.length>t?Be.decodePlayer(yn[e].players[t]).id:null},changePlayer:Sn,setPlayer:vn,setPiece:function(e,t,n){yn[e].puzzle.tiles[t]=Be.encodePiece(n)},setPuzzleData:function(e,t){yn[e].puzzle.data=t},getTableWidth:Qn,getTableHeight:Yn,getPuzzle:e=>yn[e].puzzle,getRng:e=>yn[e].rng.obj,getPuzzleWidth:e=>yn[e].puzzle.info.width,getPuzzleHeight:e=>yn[e].puzzle.info.height,getPiecesSortedByZIndex:function(e){return yn[e].puzzle.tiles.map(Be.decodePiece).sort(((e,t)=>e.z-t.z))},getFirstOwnedPiece:(e,t)=>{const n=Un(e,t);return n<0?null:yn[e].puzzle.tiles[n]},getPieceDrawOffset:e=>yn[e].puzzle.info.tileDrawOffset,getPieceDrawSize:Mn,getFinalPiecePos:Dn,getStartTs:e=>yn[e].puzzle.data.started,getFinishTs:e=>yn[e].puzzle.data.finished,handleInput:function(e,t,n,o){const i=yn[e].puzzle,l=function(e,t){return t in yn[e].evtInfos?yn[e].evtInfos[t]:{_last_mouse:null,_last_mouse_down:null}}(e,t),a=[],s=()=>{a.push([vt,i.data])},r=t=>{a.push([bt,Be.encodePiece(Tn(e,t))])},c=e=>{for(const t of e)r(t)},d=()=>{const n=wn(e,t);n&&a.push([xt,Be.encodePlayer(n)])},u=n[0];if(u===mt){const i=n[1];Sn(e,t,{bgcolor:i,ts:o}),d()}else if(u===yt){const i=n[1];Sn(e,t,{color:i,ts:o}),d()}else if(u===ft){const i=`${n[1]}`.substr(0,16);Sn(e,t,{name:i,ts:o}),d()}else if(u===dt){const i={x:n[1],y:n[2]};Sn(e,t,{d:1,ts:o}),d(),l._last_mouse_down=i;const a=((e,t)=>{const n=yn[e].puzzle.info,o=yn[e].puzzle.tiles;let i=-1,l=-1;for(let a=0;a<o.length;a++){const e=Be.decodePiece(o[a]);if(0!==e.owner)continue;const s={x:e.pos.x,y:e.pos.y,w:n.tileSize,h:n.tileSize};gn.pointInBounds(t,s)&&(-1===i||e.z>i)&&(i=e.z,l=a)}return l})(e,i);if(a>=0){const n=Rn(e)+1;Pn(e,{maxZ:n}),s();const o=qn(e,a);jn(e,o,Rn(e)),Wn(e,o,t),c(o)}l._last_mouse=i}else if(u===gt){const i=n[1],a=n[2],s={x:i,y:a};if(null===l._last_mouse_down)Sn(e,t,{x:i,y:a,ts:o}),d();else{const n=Un(e,t);if(n>=0){Sn(e,t,{x:i,y:a,ts:o}),d();const r=qn(e,n);let u=gn.pointInBounds(s,En(e))&&gn.pointInBounds(l._last_mouse_down,En(e));for(const t of r){const n=On(e,t);if(gn.pointInBounds(s,n)){u=!0;break}}if(u){const t=i-l._last_mouse_down.x,n=a-l._last_mouse_down.y;Ln(e,r,{x:t,y:n}),c(r)}}else Sn(e,t,{ts:o}),d();l._last_mouse_down=s}l._last_mouse=s}else if(u===ut){const a={x:n[1],y:n[2]},u=0;l._last_mouse_down=null;const g=Un(e,t);if(g>=0){const n=qn(e,g);Wn(e,n,0),c(n);const l=Bn(e,g),a=Dn(e,g);if(gn.pointDistance(a,l)<i.info.snapDistance){const i=gn.pointSub(a,l);Ln(e,n,i),((e,t)=>{for(const n of t)In(e,n,{owner:-1,z:1})})(e,n),c(n);let r=Hn(e,t);kn(e)===fe.FINAL?r+=n.length:kn(e)===fe.ANY&&(r+=1),Sn(e,t,{d:u,ts:o,points:r}),d(),zn(e)===Cn(e)&&(Pn(e,{finished:o}),s())}else{const n=(e,t,n,o)=>{const i=yn[e].puzzle.info;if(n<0)return!1;if(((e,t,n)=>{const o=_n(e,t),i=_n(e,n);return!(!o||o!==i)})(e,t,n))return!1;const l=Bn(e,t),a=gn.pointAdd(Bn(e,n),{x:o[0]*i.tileSize,y:o[1]*i.tileSize});if(gn.pointDistance(l,a)<i.snapDistance){const o=gn.pointSub(a,l);let i=qn(e,t);Ln(e,i,o),((e,t,n)=>{const o=yn[e].puzzle.tiles,i=_n(e,t),l=_n(e,n);let a;const c=[];i&&c.push(i),l&&c.push(l),i?a=i:l?a=l:(Pn(e,{maxGroup:$n(e)+1}),s(),a=$n(e));if(In(e,t,{group:a}),r(t),In(e,n,{group:a}),r(n),c.length>0)for(const s of o){const t=Be.decodePiece(s);c.includes(t.group)&&(In(e,t.idx,{group:a}),r(t.idx))}})(e,t,n),i=qn(e,t);const d=((e,t)=>{let n=0;for(const o of t){const t=Nn(e,o);t>n&&(n=t)}return n})(e,i);return jn(e,i,d),c(i),!0}return!1};let i=!1;for(const t of qn(e,g)){const o=Vn(e,t);if(n(e,t,o[0],[0,1])||n(e,t,o[1],[-1,0])||n(e,t,o[2],[0,-1])||n(e,t,o[3],[1,0])){i=!0;break}}if(i&&kn(e)===fe.ANY){const n=Hn(e,t)+1;Sn(e,t,{d:u,ts:o,points:n}),d()}else Sn(e,t,{d:u,ts:o}),d()}}else Sn(e,t,{d:u,ts:o}),d();l._last_mouse=a}else if(u===pt){const i=n[1],a=n[2];Sn(e,t,{x:i,y:a,ts:o}),d(),l._last_mouse={x:i,y:a}}else if(u===ht){const i=n[1],a=n[2];Sn(e,t,{x:i,y:a,ts:o}),d(),l._last_mouse={x:i,y:a}}else Sn(e,t,{ts:o}),d();return function(e,t,n){yn[e].evtInfos[t]=n}(e,t,l),a}};let Zn=-10,Jn=20,Xn=2,eo=15;class to{constructor(e){this.radius=10,this.previousRadius=10,this.explodingDuration=100,this.hasExploded=!1,this.alive=!0,this.color=function(e){return"rgba("+e.random(0,255)+","+e.random(0,255)+","+e.random(0,255)+", 0.8)"}(e),this.px=window.innerWidth/4+Math.random()*window.innerWidth/2,this.py=window.innerHeight,this.vx=Zn+Math.random()*Jn,this.vy=-1*(Xn+Math.random()*eo),this.duration=0}update(e){if(this.hasExploded){const e=200-this.radius;this.previousRadius=this.radius,this.radius+=e/10,this.explodingDuration--,0==this.explodingDuration&&(this.alive=!1)}else this.vx+=0,this.vy+=1,this.vy>=0&&e&&this.explode(e),this.px+=this.vx,this.py+=this.vy}draw(e){e.beginPath(),e.arc(this.px,this.py,this.previousRadius,0,2*Math.PI,!1),this.hasExploded||(e.fillStyle=this.color,e.lineWidth=1,e.fill())}explode(e){this.hasExploded=!0;const t=3+Math.floor(3*Math.random());for(let n=0;n<t;n++){const t=10+Math.floor(21*Math.random()),n=5+5*Math.random(),o=2*Math.PI/t,i=Math.random()*o;for(let l=0;l<t;l++)e.push(new no(this,l*o+i,n))}}}class no{constructor(e,t,n){this.px=e.px,this.py=e.py,this.vx=Math.cos(t)*n,this.vy=Math.sin(t)*n,this.color=e.color,this.duration=40+Math.floor(20*Math.random()),this.alive=!0,this.radius=0}update(){this.vx+=0,this.vy+=.1,this.px+=this.vx,this.py+=this.vy,this.radius=3,this.duration--,this.duration<=0&&(this.alive=!1)}draw(e){e.beginPath(),e.arc(this.px,this.py,this.radius,0,2*Math.PI,!1),e.fillStyle=this.color,e.lineWidth=1,e.fill()}}class oo{constructor(e,t){this.canvas=e,this.rng=t,this.ctx=this.canvas.getContext("2d"),this.resize(),this.readyBombs=[],this.explodedBombs=[],this.particles=[],window.addEventListener("resize",(()=>{this.resize()}))}setSpeedParams(){let e=0,t=0;for(;e<this.canvas.height&&t>=0;)t+=1,e+=t;Xn=t/2,eo=t-Xn;const n=1/4*this.canvas.width/(t/2);Zn=-n,Jn=2*n}resize(){this.setSpeedParams()}init(){this.readyBombs=[],this.explodedBombs=[],this.particles=[];for(let e=0;e<1;e++)this.readyBombs.push(new to(this.rng))}update(){100*Math.random()<5&&this.readyBombs.push(new to(this.rng));const e=[];for(;this.explodedBombs.length>0;){const t=this.explodedBombs.shift();if(!t)break;t.update(),t.alive&&e.push(t)}this.explodedBombs=e;const t=[];for(;this.readyBombs.length>0;){const e=this.readyBombs.shift();if(!e)break;e.update(this.particles),e.hasExploded?this.explodedBombs.push(e):t.push(e)}this.readyBombs=t;const n=[];for(;this.particles.length>0;){const e=this.particles.shift();if(!e)break;e.update(),e.alive&&n.push(e)}this.particles=n}render(){this.ctx.beginPath(),this.ctx.fillStyle="rgba(0, 0, 0, 0.1)",this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height);for(let e=0;e<this.readyBombs.length;e++)this.readyBombs[e].draw(this.ctx);for(let e=0;e<this.explodedBombs.length;e++)this.explodedBombs[e].draw(this.ctx);for(let e=0;e<this.particles.length;e++)this.particles[e].draw(this.ctx)}}const io={"./grab.png":Zt,"./grab_mask.png":Jt,"./hand.png":Xt,"./hand_mask.png":en};let lo=!0,ao=!0;let so=!0;async function ro(e,t,n,o,i,l){void 0===window.DEBUG&&(window.DEBUG=!1);const a=await on.loadImageToBitmap(io["./grab.png"].default),s=await on.loadImageToBitmap(io["./hand.png"].default),r=await on.loadImageToBitmap(io["./grab_mask.png"].default),c=await on.loadImageToBitmap(io["./hand_mask.png"].default),d=a.width,u=Math.round(d/2),g=a.height,p=Math.round(g/2),h={},m=async e=>{const t=e.color+" "+e.d;if(!h[t]){const n=e.d?a:s;if(e.color){const o=e.d?r:c;h[t]=await createImageBitmap(on.colorizedCanvas(n,o,e.color))}else h[t]=n}return h[t]},y=function(e,t){return t.width=window.innerWidth,t.height=window.innerHeight,e.appendChild(t),window.addEventListener("resize",(()=>{t.width=window.innerWidth,t.height=window.innerHeight,so=!0})),t}(i,on.createCanvas()),f={final:!1,requesting:!0,log:[],logPointer:0,speeds:[.5,1,2,5,10,20,50,100,250,500],speedIdx:1,paused:!1,lastRealTs:0,lastGameTs:0,gameStartTs:0,dataOffset:0,dataSize:1e4};Et.onConnectionStateChange((e=>{l.setConnectionState(e)}));const w=async e=>{f.requesting=!0;const t=await Et.requestReplayData(e,f.dataOffset,f.dataSize);return f.dataOffset+=f.dataSize,f.requesting=!1,t};let v=()=>0;const b=async()=>{if("play"===o){const o=await Et.connect(n,e,t),i=Be.decodeGame(o);Kn.setGame(i.id,i),v=()=>D()}else{if("replay"!==o)throw"[ 2020-12-22 MODE invalid, must be play|replay ]";{const t=await w(e);if(!t.game)throw"[ 2021-05-29 no game received ]";const n=Be.decodeGame(t.game);Kn.setGame(n.id,n),f.requesting=!1,f.log=t.log,f.lastRealTs=D(),f.gameStartTs=parseInt(f.log[0][4],10),f.lastGameTs=f.gameStartTs,v=()=>f.lastGameTs}}so=!0};await b();const x=Kn.getPieceDrawOffset(e),C=Kn.getPieceDrawSize(e),k=Kn.getPuzzleWidth(e),A=Kn.getPuzzleHeight(e),z=Kn.getTableWidth(e),S=Kn.getTableHeight(e),P={x:(z-k)/2,y:(S-A)/2},I={w:k,h:A},T={w:C,h:C},_=await mn.loadPuzzleBitmaps(Kn.getPuzzle(e)),B=new oo(y,Kn.getRng(e));B.init();const E=y.getContext("2d");y.classList.add("loaded");const O=tn();O.move(-(z-y.width)/2,-(S-y.height)/2);const N=function(e,t,n){let o=[],i=!0,l=!1,a=!1,s=!1,r=!1,c=!1,d=!1,u=!1;const g=(e,t)=>{const o=n.viewportToWorld({x:e,y:t});return[o.x,o.y]},p=e=>g(e.offsetX,e.offsetY),h=()=>g(e.width/2,e.height/2),m=(e,t)=>{i&&("Shift"===t.key?u=e:"ArrowUp"===t.key||"w"===t.key||"W"===t.key?s=e:"ArrowDown"===t.key||"s"===t.key||"S"===t.key?r=e:"ArrowLeft"===t.key||"a"===t.key||"A"===t.key?l=e:"ArrowRight"===t.key||"d"===t.key||"D"===t.key?a=e:"q"===t.key?d=e:"e"===t.key&&(c=e))};e.addEventListener("mousedown",(e=>{0===e.button&&y([dt,...p(e)])})),e.addEventListener("mouseup",(e=>{0===e.button&&y([ut,...p(e)])})),e.addEventListener("mousemove",(e=>{y([gt,...p(e)])})),e.addEventListener("wheel",(e=>{if(n.canZoom(e.deltaY<0?"in":"out")){const t=e.deltaY<0?pt:ht;y([t,...p(e)])}})),t.addEventListener("keydown",(e=>m(!0,e))),t.addEventListener("keyup",(e=>m(!1,e))),t.addEventListener("keypress",(e=>{i&&(" "===e.key&&y([wt]),"F"!==e.key&&"f"!==e.key||(lo=!lo,so=!0),"G"!==e.key&&"g"!==e.key||(ao=!ao,so=!0))}));const y=e=>{o.push(e)};return{addEvent:y,consumeAll:()=>{if(0===o.length)return[];const e=o.slice();return o=[],e},createKeyEvents:()=>{const e=u?20:10,t=(l?e:0)-(a?e:0),o=(s?e:0)-(r?e:0);0===t&&0===o||y([ct,t,o]),c&&d||(c?n.canZoom("in")&&y([pt,...h()]):d&&n.canZoom("out")&&y([ht,...h()]))},setHotkeys:e=>{i=e}}}(y,window,O),U=Kn.getImageUrl(e),M=()=>{const t=Kn.getStartTs(e),n=Kn.getFinishTs(e),o=v();l.setFinished(!!n),l.setDuration((n||o)-t)};M(),l.setPiecesDone(Kn.getFinishedPiecesCount(e)),l.setPiecesTotal(Kn.getPieceCount(e));const G=v();l.setActivePlayers(Kn.getActivePlayers(e,G)),l.setIdlePlayers(Kn.getIdlePlayers(e,G));const $=!!Kn.getFinishTs(e);let R=$;const V=()=>R&&!$,j=()=>Kn.getPlayerBgColor(e,t)||localStorage.getItem("bg_color")||"#222222",F=()=>Kn.getPlayerColor(e,t)||localStorage.getItem("player_color")||"#ffffff";let L="",W="",q=!1;const H=e=>{q=e;const[t,n]=e?[L,"grab"]:[W,"default"];y.style.cursor=`url('${t}') ${u} ${p}, ${n}`},Q=e=>{L=on.colorizedCanvas(a,r,e).toDataURL(),W=on.colorizedCanvas(s,c,e).toDataURL(),H(q)};Q(F());const Y=()=>{l.setReplaySpeed&&l.setReplaySpeed(f.speeds[f.speedIdx]),l.setReplayPaused&&l.setReplayPaused(f.paused)};if("play"===o?setInterval(M,1e3):"replay"===o&&Y(),"play"===o)Et.onServerChange((n=>{n[0],n[1],n[2];const o=n[3];for(const[i,l]of o)switch(i){case xt:{const n=Be.decodePlayer(l);n.id!==t&&(Kn.setPlayer(e,n.id,n),so=!0)}break;case bt:{const t=Be.decodePiece(l);Kn.setPiece(e,t.idx,t),so=!0}break;case vt:Kn.setPuzzleData(e,l),so=!0}R=!!Kn.getFinishTs(e)}));else if("replay"===o){const t=setInterval((()=>{const n=D();if(f.requesting)return void(f.lastRealTs=n);if(f.logPointer+1>=f.log.length)return f.lastRealTs=n,void(async e=>{const t=await w(e);f.log=f.log.slice(f.logPointer),f.logPointer=0,f.log.push(...t.log),t.log.length<f.dataSize&&(f.final=!0)})(e);if(f.paused)return void(f.lastRealTs=n);const o=(n-f.lastRealTs)*f.speeds[f.speedIdx],i=f.lastGameTs+o;for(;;){if(f.paused)break;const n=f.logPointer+1;if(n>=f.log.length){f.final&&clearInterval(t);break}const o=f.log[n],l=f.gameStartTs+o[o.length-1];if(l>i)break;const a=o.slice();if(a[0]===at){const t=a[1];Kn.addPlayer(e,t,l),so=!0}else if(a[0]===st){const t=Kn.getPlayerIdByIndex(e,a[1]);if(!t)throw"[ 2021-05-17 player not found (update player) ]";Kn.addPlayer(e,t,l),so=!0}else if(a[0]===rt){const t=Kn.getPlayerIdByIndex(e,a[1]);if(!t)throw"[ 2021-05-17 player not found (handle input) ]";const n=a[2];Kn.handleInput(e,t,n,l),so=!0}f.logPointer=n}f.lastRealTs=n,f.lastGameTs=i,M()}),50)}let K=null;return(e=>{const t=e.fps||60,n=e.slow||1,o=e.update,i=e.render,l=window.requestAnimationFrame,a=1/t,s=n*a;let r,c=0,d=window.performance.now();const u=()=>{for(r=window.performance.now(),c+=Math.min(1,(r-d)/1e3);c>s;)c-=s,o(a);i(c/n),d=r,l(u)};l(u)})({update:()=>{N.createKeyEvents();for(const n of N.consumeAll())if("play"===o){const o=n[0];if(o===ct){const e=n[1],t=n[2];so=!0,O.move(e,t)}else if(o===gt){if(K&&!Kn.getFirstOwnedPiece(e,t)){const e={x:n[1],y:n[2]},t=O.worldToViewport(e),o=Math.round(t.x-K.x),i=Math.round(t.y-K.y);so=!0,O.move(o,i),K=t}}else if(o===yt)Q(n[1]);else if(o===dt){const e={x:n[1],y:n[2]};K=O.worldToViewport(e),H(!0)}else if(o===ut)K=null,H(!1);else if(o===pt){const e={x:n[1],y:n[2]};so=!0,O.zoom("in",O.worldToViewport(e))}else if(o===ht){const e={x:n[1],y:n[2]};so=!0,O.zoom("out",O.worldToViewport(e))}else o===wt&&l.togglePreview();const i=v();Kn.handleInput(e,t,n,i).length>0&&(so=!0),Et.sendClientEvent(n)}else if("replay"===o){const e=n[0];if(e===ct){const e=n[1],t=n[2];so=!0,O.move(e,t)}else if(e===gt){if(K){const e={x:n[1],y:n[2]},t=O.worldToViewport(e),o=Math.round(t.x-K.x),i=Math.round(t.y-K.y);so=!0,O.move(o,i),K=t}}else if(e===dt){const e={x:n[1],y:n[2]};K=O.worldToViewport(e)}else if(e===ut)K=null;else if(e===pt){const e={x:n[1],y:n[2]};so=!0,O.zoom("in",O.worldToViewport(e))}else if(e===ht){const e={x:n[1],y:n[2]};so=!0,O.zoom("out",O.worldToViewport(e))}else e===wt&&l.togglePreview()}R=!!Kn.getFinishTs(e),V()&&(B.update(),so=!0)},render:async()=>{if(!so)return;const n=v();let i,a,s;window.DEBUG&&rn(0),E.fillStyle=j(),E.fillRect(0,0,y.width,y.height),window.DEBUG&&cn("clear done"),i=O.worldToViewportRaw(P),a=O.worldDimToViewportRaw(I),E.fillStyle="rgba(255, 255, 255, .3)",E.fillRect(i.x,i.y,a.w,a.h),window.DEBUG&&cn("board done");const r=Kn.getPiecesSortedByZIndex(e);window.DEBUG&&cn("get tiles done"),a=O.worldDimToViewportRaw(T);for(const e of r)(-1===e.owner?lo:ao)&&(s=_[e.idx],i=O.worldToViewportRaw({x:x+e.pos.x,y:x+e.pos.y}),E.drawImage(s,0,0,s.width,s.height,i.x,i.y,a.w,a.h));window.DEBUG&&cn("tiles done");const c=[];for(const l of Kn.getActivePlayers(e,n))d=l,("replay"===o||d.id!==t)&&(s=await m(l),i=O.worldToViewport(l),E.drawImage(s,i.x-u,i.y-p),c.push([`${l.name} (${l.points})`,i.x,i.y+g]));var d;E.fillStyle="white",E.textAlign="center";for(const[e,t,o]of c)E.fillText(e,t,o);window.DEBUG&&cn("players done"),l.setActivePlayers(Kn.getActivePlayers(e,n)),l.setIdlePlayers(Kn.getIdlePlayers(e,n)),l.setPiecesDone(Kn.getFinishedPiecesCount(e)),window.DEBUG&&cn("HUD done"),V()&&B.render(),so=!1}}),{setHotkeys:e=>{N.setHotkeys(e)},onBgChange:e=>{localStorage.setItem("bg_color",e),N.addEvent([mt,e])},onColorChange:e=>{localStorage.setItem("player_color",e),N.addEvent([yt,e])},onNameChange:e=>{localStorage.setItem("player_name",e),N.addEvent([ft,e])},replayOnSpeedUp:()=>{f.speedIdx+1<f.speeds.length&&(f.speedIdx++,Y())},replayOnSpeedDown:()=>{f.speedIdx>=1&&(f.speedIdx--,Y())},replayOnPauseToggle:()=>{f.paused=!f.paused,Y()},previewImageUrl:U,player:{background:j(),color:F(),name:Kn.getPlayerName(e,t)||localStorage.getItem("player_name")||"anon"},disconnect:Et.disconnect,connect:b}}var co=e({name:"game",components:{PuzzleStatus:Qe,Scores:Fe,SettingsOverlay:Ke,PreviewOverlay:et,ConnectionOverlay:Ot,HelpOverlay:Rt},data:()=>({activePlayers:[],idlePlayers:[],finished:!1,duration:0,piecesDone:0,piecesTotal:0,overlay:"",connectionState:0,g:{player:{background:"",color:"",name:""},previewImageUrl:"",setHotkeys:e=>{},onBgChange:e=>{},onColorChange:e=>{},onNameChange:e=>{},disconnect:()=>{},connect:()=>{}}}),async mounted(){this.$route.params.id&&(this.$watch((()=>this.g.player.background),(e=>{this.g.onBgChange(e)})),this.$watch((()=>this.g.player.color),(e=>{this.g.onColorChange(e)})),this.$watch((()=>this.g.player.name),(e=>{this.g.onNameChange(e)})),this.g=await ro(`${this.$route.params.id}`,this.$clientId,this.$config.WS_ADDRESS,"play",this.$el,{setActivePlayers:e=>{this.activePlayers=e},setIdlePlayers:e=>{this.idlePlayers=e},setFinished:e=>{this.finished=e},setDuration:e=>{this.duration=e},setPiecesDone:e=>{this.piecesDone=e},setPiecesTotal:e=>{this.piecesTotal=e},setConnectionState:e=>{this.connectionState=e},togglePreview:()=>{this.toggle("preview",!1)}}))},unmounted(){this.g.disconnect()},methods:{reconnect(){this.g.connect()},toggle(e,t){""===this.overlay?(this.overlay=e,t&&this.g.setHotkeys(!1)):(this.overlay="",t&&this.g.setHotkeys(!0))}}});const uo={id:"game"},go={class:"menu"},po={class:"tabs"},ho=s("🧩 Puzzles");co.render=function(e,i,s,r,c,d){const u=l("settings-overlay"),p=l("preview-overlay"),h=l("help-overlay"),m=l("connection-overlay"),y=l("puzzle-status"),f=l("router-link"),w=l("scores");return a(),t("div",uo,[g(n(u,{onBgclick:i[1]||(i[1]=t=>e.toggle("settings",!0)),modelValue:e.g.player,"onUpdate:modelValue":i[2]||(i[2]=t=>e.g.player=t)},null,8,["modelValue"]),[[v,"settings"===e.overlay]]),g(n(p,{onBgclick:i[3]||(i[3]=t=>e.toggle("preview",!1)),img:e.g.previewImageUrl},null,8,["img"]),[[v,"preview"===e.overlay]]),g(n(h,{onBgclick:i[4]||(i[4]=t=>e.toggle("help",!0))},null,512),[[v,"help"===e.overlay]]),n(m,{connectionState:e.connectionState,onReconnect:e.reconnect},null,8,["connectionState","onReconnect"]),n(y,{finished:e.finished,duration:e.duration,piecesDone:e.piecesDone,piecesTotal:e.piecesTotal},null,8,["finished","duration","piecesDone","piecesTotal"]),n("div",go,[n("div",po,[n(f,{class:"opener",to:{name:"index"},target:"_blank"},{default:o((()=>[ho])),_:1}),n("div",{class:"opener",onClick:i[5]||(i[5]=t=>e.toggle("preview",!1))},"🖼️ Preview"),n("div",{class:"opener",onClick:i[6]||(i[6]=t=>e.toggle("settings",!0))},"🛠️ Settings"),n("div",{class:"opener",onClick:i[7]||(i[7]=t=>e.toggle("help",!0))},"ℹ️ Help")])]),n(w,{activePlayers:e.activePlayers,idlePlayers:e.idlePlayers},null,8,["activePlayers","idlePlayers"])])};var mo=e({name:"replay",components:{PuzzleStatus:Qe,Scores:Fe,SettingsOverlay:Ke,PreviewOverlay:et,HelpOverlay:Rt},data:()=>({activePlayers:[],idlePlayers:[],finished:!1,duration:0,piecesDone:0,piecesTotal:0,overlay:"",connectionState:0,g:{player:{background:"",color:"",name:""},previewImageUrl:"",setHotkeys:e=>{},onBgChange:e=>{},onColorChange:e=>{},onNameChange:e=>{},replayOnSpeedUp:()=>{},replayOnSpeedDown:()=>{},replayOnPauseToggle:()=>{},disconnect:()=>{}},replay:{speed:1,paused:!1}}),async mounted(){this.$route.params.id&&(this.$watch((()=>this.g.player.background),(e=>{this.g.onBgChange(e)})),this.$watch((()=>this.g.player.color),(e=>{this.g.onColorChange(e)})),this.$watch((()=>this.g.player.name),(e=>{this.g.onNameChange(e)})),this.g=await ro(`${this.$route.params.id}`,this.$clientId,this.$config.WS_ADDRESS,"replay",this.$el,{setActivePlayers:e=>{this.activePlayers=e},setIdlePlayers:e=>{this.idlePlayers=e},setFinished:e=>{this.finished=e},setDuration:e=>{this.duration=e},setPiecesDone:e=>{this.piecesDone=e},setPiecesTotal:e=>{this.piecesTotal=e},togglePreview:()=>{this.toggle("preview",!1)},setConnectionState:e=>{this.connectionState=e},setReplaySpeed:e=>{this.replay.speed=e},setReplayPaused:e=>{this.replay.paused=e}}))},unmounted(){this.g.disconnect()},methods:{toggle(e,t){""===this.overlay?(this.overlay=e,t&&this.g.setHotkeys(!1)):(this.overlay="",t&&this.g.setHotkeys(!0))}},computed:{replayText(){return"Replay-Speed: "+this.replay.speed+"x"+(this.replay.paused?" Paused":"")}}});const yo={id:"replay"},fo={class:"menu"},wo={class:"tabs"},vo=s("🧩 Puzzles");mo.render=function(e,i,s,c,d,u){const p=l("settings-overlay"),h=l("preview-overlay"),m=l("help-overlay"),y=l("puzzle-status"),f=l("router-link"),w=l("scores");return a(),t("div",yo,[g(n(p,{onBgclick:i[1]||(i[1]=t=>e.toggle("settings",!0)),modelValue:e.g.player,"onUpdate:modelValue":i[2]||(i[2]=t=>e.g.player=t)},null,8,["modelValue"]),[[v,"settings"===e.overlay]]),g(n(h,{onBgclick:i[3]||(i[3]=t=>e.toggle("preview",!1)),img:e.g.previewImageUrl},null,8,["img"]),[[v,"preview"===e.overlay]]),g(n(m,{onBgclick:i[4]||(i[4]=t=>e.toggle("help",!0))},null,512),[[v,"help"===e.overlay]]),n(y,{finished:e.finished,duration:e.duration,piecesDone:e.piecesDone,piecesTotal:e.piecesTotal},{default:o((()=>[n("div",null,[n("div",null,r(e.replayText),1),n("button",{class:"btn",onClick:i[5]||(i[5]=t=>e.g.replayOnSpeedUp())},"⏫"),n("button",{class:"btn",onClick:i[6]||(i[6]=t=>e.g.replayOnSpeedDown())},"⏬"),n("button",{class:"btn",onClick:i[7]||(i[7]=t=>e.g.replayOnPauseToggle())},"⏸️")])])),_:1},8,["finished","duration","piecesDone","piecesTotal"]),n("div",fo,[n("div",wo,[n(f,{class:"opener",to:{name:"index"},target:"_blank"},{default:o((()=>[vo])),_:1}),n("div",{class:"opener",onClick:i[8]||(i[8]=t=>e.toggle("preview",!1))},"🖼️ Preview"),n("div",{class:"opener",onClick:i[9]||(i[9]=t=>e.toggle("settings",!0))},"🛠️ Settings"),n("div",{class:"opener",onClick:i[10]||(i[10]=t=>e.toggle("help",!0))},"ℹ️ Help")])]),n(w,{activePlayers:e.activePlayers,idlePlayers:e.idlePlayers},null,8,["activePlayers","idlePlayers"])])},(async()=>{const e=await fetch("/api/conf"),t=await e.json();const n=b({history:x(),routes:[{name:"index",path:"/",component:R},{name:"new-game",path:"/new-game",component:Ee},{name:"game",path:"/g/:id",component:co},{name:"replay",path:"/replay/:id",component:mo}]});n.beforeEach(((e,t)=>{t.name&&document.documentElement.classList.remove(`view-${String(t.name)}`),document.documentElement.classList.add(`view-${String(e.name)}`)}));const o=C(k);o.config.globalProperties.$config=t,o.config.globalProperties.$clientId=function(){let e=localStorage.getItem("ID");return e||(e=Be.uniqId(),localStorage.setItem("ID",e)),e}(),o.use(n),o.mount("#app")})();
|