From b410f400faf88afa08d16c8de44ae17aee2b88ee Mon Sep 17 00:00:00 2001 From: Zutatensuppe Date: Sun, 20 Jun 2021 13:40:28 +0200 Subject: [PATCH] show upload status when uploading images --- build/public/assets/index.1a1747a7.js | 1 - build/public/assets/index.e0726e0c.js | 1 + build/public/index.html | 2 +- src/frontend/components/NewImageDialog.vue | 32 +++++++++++-- src/frontend/views/NewGame.vue | 24 ++++++++-- src/frontend/xhr.ts | 56 ++++++++++++++++++++++ 6 files changed, 106 insertions(+), 10 deletions(-) delete mode 100644 build/public/assets/index.1a1747a7.js create mode 100644 build/public/assets/index.e0726e0c.js create mode 100644 src/frontend/xhr.ts diff --git a/build/public/assets/index.1a1747a7.js b/build/public/assets/index.1a1747a7.js deleted file mode 100644 index e5421b5..0000000 --- a/build/public/assets/index.1a1747a7.js +++ /dev/null @@ -1 +0,0 @@ -import{d as e,c as t,a as n,w as o,b as l,r as a,o as s,e as i,t as r,F as d,f as c,g as u,h as p,v as g,i as h,j as m,p as y,k as f,l as v,m as w,n as b,q as x,s as C,u as k,x as A,y as S}from"./vendor.684f7bc8.js";var T=e({name:"app",computed:{showNav(){return!["game","replay"].includes(String(this.$route.name))}}});const I={id:"app"},P={key:0,class:"nav"},z=i("Index"),D=i("New game");T.render=function(e,i,r,d,c,u){const p=a("router-link"),g=a("router-view");return s(),t("div",I,[e.showNav?(s(),t("ul",P,[n("li",null,[n(p,{class:"btn",to:{name:"index"}},{default:o((()=>[z])),_:1})]),n("li",null,[n(p,{class:"btn",to:{name:"new-game"}},{default:o((()=>[D])),_:1})])])):l("",!0),n(g)])};const _=864e5,E=e=>{const t=Math.floor(e/_);e%=_;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 M=1,V=1e3,N=()=>{const e=new Date;return Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())},O=(e,t)=>E(t-e),B=E,U=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,l=t||N();return`${n} ${O(o,l)}`}}});const R={class:"game-info-text"},$=n("br",null,null,-1),G=n("br",null,null,-1),F=n("br",null,null,-1),L=i(" β†ͺ️ Watch replay ");U.render=function(e,d,c,u,p,g){const h=a("router-link");return s(),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",R,[i(" 🧩 "+r(e.game.tilesFinished)+"/"+r(e.game.tilesTotal),1),$,i(" πŸ‘₯ "+r(e.game.players),1),G,i(" "+r(e.time(e.game.started,e.game.finished)),1),F])])),_:1},8,["to"]),e.game.hasReplay?(s(),t(h,{key:0,class:"game-replay",to:{name:"replay",params:{id:e.game.id}}},{default:o((()=>[L])),_:1},8,["to"])):l("",!0)],4)};var j=e({components:{GameTeaser:U},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 W=n("h1",null,"Running games",-1),K=n("h1",null,"Finished games",-1);j.render=function(e,o,l,i,r,u){const p=a("game-teaser");return s(),t("div",null,[W,(s(!0),t(d,null,c(e.gamesRunning,((e,o)=>(s(),t("div",{class:"game-teaser-wrap",key:o},[n(p,{game:e},null,8,["game"])])))),128)),K,(s(!0),t(d,null,c(e.gamesFinished,((e,o)=>(s(),t("div",{class:"game-teaser-wrap",key:o},[n(p,{game:e},null,8,["game"])])))),128))])};var H=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")}}});H.render=function(e,o,l,a,i,r){return s(),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 Y,Q,q,Z,X,J,ee,te,ne=e({name:"image-library",components:{ImageTeaser:H},props:{images:{type:Array,required:!0}},emits:{imageClicked:null,imageEditClicked:null},methods:{imageClicked(e){this.$emit("imageClicked",e)},imageEditClicked(e){this.$emit("imageEditClicked",e)}}});ne.render=function(e,n,o,l,i,r){const u=a("image-teaser");return s(),t("div",null,[(s(!0),t(d,null,c(e.images,((n,o)=>(s(),t(u,{image:n,onClick:t=>e.imageClicked(n),onEditClick:t=>e.imageEditClicked(n),key:o},null,8,["image","onClick","onEditClick"])))),128))])},(Q=Y||(Y={}))[Q.Flat=0]="Flat",Q[Q.Out=1]="Out",Q[Q.In=-1]="In",(Z=q||(q={}))[Z.FINAL=0]="FINAL",Z[Z.ANY=1]="ANY",(J=X||(X={}))[J.NORMAL=0]="NORMAL",J[J.ANY=1]="ANY",J[J.FLAT=2]="FLAT",(te=ee||(ee={}))[te.NORMAL=0]="NORMAL",te[te.REAL=1]="REAL";class oe{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 oe(0);return t.rand_high=e.rand_high,t.rand_low=e.rand_low,t}}const le=(e,t)=>{const n=`${e}`;return n.length>=t.length?n:t.substr(0,t.length-n.length)+n},ae=(...e)=>{const t=t=>(...n)=>{const o=new Date,l=le(o.getHours(),"00"),a=le(o.getMinutes(),"00"),s=le(o.getSeconds(),"00");console[t](`${l}:${a}:${s}`,...e,...n)};return{log:t("log"),error:t("error"),info:t("info")}};var se={hash:e=>{let t=0;for(let n=0;n{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||"",oe.serialize(e.rng.obj),e.puzzle,e.players,e.evtInfos,e.scoreMode||q.FINAL,e.shapeMode||X.ANY,e.snapMode||ee.NORMAL]},decodeGame:function(e){return{id:e[0],rng:{type:e[1],obj:oe.unserialize(e[2])},puzzle:e[3],players:e[4],evtInfos:e[5],scoreMode:e[6],shapeMode:e[7],snapMode:e[8]}},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("&")}`}};const ie={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}}}};ie.render=function(e,n,o,l,a,i){return s(),t("div",{style:i.style,title:o.title},null,12,["title"])};var re=e({name:"tags-input",props:{modelValue:{type:Array,required:!0},autocompleteTags:{type:Function}},emits:{"update:modelValue":null},data:()=>({input:"",values:[],autocomplete:{idx:-1,values:[]}}),created(){this.values=this.modelValue},methods:{onKeyUp(e){return"ArrowDown"===e.code&&this.autocomplete.values.length>0?(this.autocomplete.idx0?(this.autocomplete.idx>0&&this.autocomplete.idx--,e.stopPropagation(),!1):","===e.key?(this.add(),e.stopPropagation(),!1):void(this.input&&this.autocompleteTags?(this.autocomplete.values=this.autocompleteTags(this.input,this.values),this.autocomplete.idx=-1):(this.autocomplete.values=[],this.autocomplete.idx=-1))},addVal(e){const t=e.replace(/,/g,"").trim();t&&(this.values.includes(t)||this.values.push(t),this.input="",this.autocomplete.values=[],this.autocomplete.idx=-1,this.$emit("update:modelValue",this.values),this.$refs.input.focus())},add(){const e=this.autocomplete.idx>=0?this.autocomplete.values[this.autocomplete.idx]:this.input;this.addVal(e)},rm(e){this.values=this.values.filter((t=>t!==e)),this.$emit("update:modelValue",this.values)}}});const de=m();y("data-v-a4fa5e7e");const ce={key:0,class:"autocomplete"};f();const ue=de(((e,o,a,i,u,m)=>(s(),t("div",null,[p(n("input",{ref:"input",class:"input",type:"text","onUpdate:modelValue":o[1]||(o[1]=t=>e.input=t),placeholder:"Plants, People",onChange:o[2]||(o[2]=(...t)=>e.onChange&&e.onChange(...t)),onKeydown:o[3]||(o[3]=h(((...t)=>e.add&&e.add(...t)),["enter"])),onKeyup:o[4]||(o[4]=(...t)=>e.onKeyUp&&e.onKeyUp(...t))},null,544),[[g,e.input]]),e.autocomplete.values?(s(),t("div",ce,[n("ul",null,[(s(!0),t(d,null,c(e.autocomplete.values,((n,o)=>(s(),t("li",{key:o,class:{active:o===e.autocomplete.idx},onClick:t=>e.addVal(n)},r(n),11,["onClick"])))),128))])])):l("",!0),(s(!0),t(d,null,c(e.values,((n,o)=>(s(),t("span",{key:o,class:"bit",onClick:t=>e.rm(n)},r(n)+" βœ–",9,["onClick"])))),128))]))));re.render=ue,re.__scopeId="data-v-a4fa5e7e";const pe=ae("NewImageDialog.vue");var ge=e({name:"new-image-dialog",components:{ResponsiveImage:ie,TagsInput:re},props:{autocompleteTags:{type:Function}},emits:{bgclick:null,setupGameClick:null,postToGalleryClick:null},data:()=>({previewUrl:"",file:null,title:"",tags:[],droppable:!1}),computed:{canPostToGallery(){return!(!this.previewUrl||!this.file)},canSetupGameClick(){return!(!this.previewUrl||!this.file)}},methods:{imageFromDragEvt(e){var t;const n=null==(t=e.dataTransfer)?void 0:t.items;if(!n||0===n.length)return null;const o=n[0];return o.type.startsWith("image/")?o:null},onFileSelect(e){const t=e.target;if(!t.files)return;const n=t.files[0];n&&this.preview(n)},preview(e){const t=new FileReader;t.readAsDataURL(e),t.onload=t=>{this.previewUrl=t.target.result,this.file=e}},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})},onDrop(e){this.droppable=!1;const t=this.imageFromDragEvt(e);if(!t)return!1;const n=t.getAsFile();return!!n&&(this.file=n,this.preview(n),e.preventDefault(),!1)},onDragover(e){return!!this.imageFromDragEvt(e)&&(this.droppable=!0,e.preventDefault(),!1)},onDragleave(){pe.info("onDragleave"),this.droppable=!1}}});const he=n("div",{class:"drop-target"},null,-1),me={key:0,class:"has-image"},ye={key:1},fe={class:"upload"},ve=n("span",{class:"btn"},"Upload File",-1),we={class:"area-settings"},be=n("td",null,[n("label",null,"Title")],-1),xe=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),Ce=n("td",null,[n("label",null,"Tags")],-1),ke={class:"area-buttons"},Ae=i("🧩 Post to gallery "),Se=n("br",null,null,-1),Te=i(" + set up game");ge.render=function(e,o,l,i,r,d){const c=a("responsive-image"),h=a("tags-input");return s(),t("div",{class:"overlay new-image-dialog",onClick:o[11]||(o[11]=t=>e.$emit("bgclick"))},[n("div",{class:"overlay-content",onClick:o[10]||(o[10]=u((()=>{}),["stop"]))},[n("div",{class:["area-image",{"has-image":!!e.previewUrl,"no-image":!e.previewUrl,droppable:e.droppable}],onDrop:o[3]||(o[3]=(...t)=>e.onDrop&&e.onDrop(...t)),onDragover:o[4]||(o[4]=(...t)=>e.onDragover&&e.onDragover(...t)),onDragleave:o[5]||(o[5]=(...t)=>e.onDragleave&&e.onDragleave(...t))},[he,e.previewUrl?(s(),t("div",me,[n("span",{class:"remove btn",onClick:o[1]||(o[1]=t=>e.previewUrl="")},"X"),n(c,{src:e.previewUrl},null,8,["src"])])):(s(),t("div",ye,[n("label",fe,[n("input",{type:"file",style:{display:"none"},onChange:o[2]||(o[2]=(...t)=>e.onFileSelect&&e.onFileSelect(...t)),accept:"image/*"},null,32),ve])]))],34),n("div",we,[n("table",null,[n("tr",null,[be,n("td",null,[p(n("input",{type:"text","onUpdate:modelValue":o[6]||(o[6]=t=>e.title=t),placeholder:"Flower by @artist"},null,512),[[g,e.title]])])]),xe,n("tr",null,[Ce,n("td",null,[n(h,{modelValue:e.tags,"onUpdate:modelValue":o[7]||(o[7]=t=>e.tags=t),autocompleteTags:e.autocompleteTags},null,8,["modelValue","autocompleteTags"])])])])]),n("div",ke,[n("button",{class:"btn",disabled:!e.canPostToGallery,onClick:o[8]||(o[8]=(...t)=>e.postToGallery&&e.postToGallery(...t))},"πŸ–ΌοΈ Post to gallery",8,["disabled"]),n("button",{class:"btn",disabled:!e.canSetupGameClick,onClick:o[9]||(o[9]=(...t)=>e.setupGameClick&&e.setupGameClick(...t))},[Ae,Se,Te],8,["disabled"])])])])};var Ie=e({name:"edit-image-dialog",components:{ResponsiveImage:ie,TagsInput:re},props:{image:{type:Object,required:!0},autocompleteTags:{type:Function}},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 Pe={class:"area-image"},ze={class:"has-image"},De={class:"area-settings"},_e=n("td",null,[n("label",null,"Title")],-1),Ee=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),Me=n("td",null,[n("label",null,"Tags")],-1),Ve={class:"area-buttons"};Ie.render=function(e,o,l,i,r,d){const c=a("responsive-image"),h=a("tags-input");return s(),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",Pe,[n("div",ze,[n(c,{src:e.image.url,title:e.image.title},null,8,["src","title"])])]),n("div",De,[n("table",null,[n("tr",null,[_e,n("td",null,[p(n("input",{type:"text","onUpdate:modelValue":o[1]||(o[1]=t=>e.title=t),placeholder:"Flower by @artist"},null,512),[[g,e.title]])])]),Ee,n("tr",null,[Me,n("td",null,[n(h,{modelValue:e.tags,"onUpdate:modelValue":o[2]||(o[2]=t=>e.tags=t),autocompleteTags:e.autocompleteTags},null,8,["modelValue","autocompleteTags"])])])])]),n("div",Ve,[n("button",{class:"btn",onClick:o[3]||(o[3]=(...t)=>e.saveImage&&e.saveImage(...t))},"πŸ–ΌοΈ Save image")])])])};var Ne=e({name:"new-game-dialog",components:{ResponsiveImage:ie},props:{image:{type:Object,required:!0}},emits:{newGame:null,bgclick:null},data:()=>({tiles:1e3,scoreMode:q.ANY,shapeMode:X.NORMAL,snapMode:ee.NORMAL}),methods:{onNewGameClick(){this.$emit("newGame",{tiles:this.tilesInt,image:this.image,scoreMode:this.scoreModeInt,shapeMode:this.shapeModeInt,snapMode:this.snapModeInt})}},computed:{canStartNewGame(){return!!(this.tilesInt&&this.image&&this.image.url&&[0,1].includes(this.scoreModeInt))},scoreModeInt(){return parseInt(`${this.scoreMode}`,10)},shapeModeInt(){return parseInt(`${this.shapeMode}`,10)},snapModeInt(){return parseInt(`${this.snapMode}`,10)},tilesInt(){return parseInt(`${this.tiles}`,10)}}});const Oe={class:"area-image"},Be={class:"has-image"},Ue={key:0,class:"image-title"},Re={class:"area-settings"},$e=n("td",null,[n("label",null,"Pieces")],-1),Ge=n("td",null,[n("label",null,"Scoring: ")],-1),Fe=i(" Any (Score when pieces are connected to each other or on final location)"),Le=n("br",null,null,-1),je=i(" Final (Score when pieces are put to their final location)"),We=n("td",null,[n("label",null,"Shapes: ")],-1),Ke=i(" Normal"),He=n("br",null,null,-1),Ye=i(" Any (flat pieces can occur anywhere)"),Qe=n("br",null,null,-1),qe=i(" Flat (all pieces flat on all sides)"),Ze=n("td",null,[n("label",null,"Snapping: ")],-1),Xe=i(" Normal (pieces snap to final destination and to each other)"),Je=n("br",null,null,-1),et=i(" Real (pieces snap only to corners, already snapped pieces and to each other)"),tt={class:"area-buttons"};Ne.render=function(e,o,i,d,c,h){const m=a("responsive-image");return s(),t("div",{class:"overlay new-game-dialog",onClick:o[11]||(o[11]=t=>e.$emit("bgclick"))},[n("div",{class:"overlay-content",onClick:o[10]||(o[10]=u((()=>{}),["stop"]))},[n("div",Oe,[n("div",Be,[n(m,{src:e.image.url,title:e.image.title},null,8,["src","title"])]),e.image.title?(s(),t("div",Ue,'"'+r(e.image.title)+'"',1)):l("",!0)]),n("div",Re,[n("table",null,[n("tr",null,[$e,n("td",null,[p(n("input",{type:"text","onUpdate:modelValue":o[1]||(o[1]=t=>e.tiles=t)},null,512),[[g,e.tiles]])])]),n("tr",null,[Ge,n("td",null,[n("label",null,[p(n("input",{type:"radio","onUpdate:modelValue":o[2]||(o[2]=t=>e.scoreMode=t),value:"1"},null,512),[[v,e.scoreMode]]),Fe]),Le,n("label",null,[p(n("input",{type:"radio","onUpdate:modelValue":o[3]||(o[3]=t=>e.scoreMode=t),value:"0"},null,512),[[v,e.scoreMode]]),je])])]),n("tr",null,[We,n("td",null,[n("label",null,[p(n("input",{type:"radio","onUpdate:modelValue":o[4]||(o[4]=t=>e.shapeMode=t),value:"0"},null,512),[[v,e.shapeMode]]),Ke]),He,n("label",null,[p(n("input",{type:"radio","onUpdate:modelValue":o[5]||(o[5]=t=>e.shapeMode=t),value:"1"},null,512),[[v,e.shapeMode]]),Ye]),Qe,n("label",null,[p(n("input",{type:"radio","onUpdate:modelValue":o[6]||(o[6]=t=>e.shapeMode=t),value:"2"},null,512),[[v,e.shapeMode]]),qe])])]),n("tr",null,[Ze,n("td",null,[n("label",null,[p(n("input",{type:"radio","onUpdate:modelValue":o[7]||(o[7]=t=>e.snapMode=t),value:"0"},null,512),[[v,e.snapMode]]),Xe]),Je,n("label",null,[p(n("input",{type:"radio","onUpdate:modelValue":o[8]||(o[8]=t=>e.snapMode=t),value:"1"},null,512),[[v,e.snapMode]]),et])])])])]),n("div",tt,[n("button",{class:"btn",disabled:!e.canStartNewGame,onClick:o[9]||(o[9]=(...t)=>e.onNewGameClick&&e.onNewGameClick(...t))}," 🧩 Generate Puzzle ",8,["disabled"])])])])};var nt=e({components:{ImageLibrary:ne,NewImageDialog:ge,EditImageDialog:Ie,NewGameDialog:Ne},data:()=>({filters:{sort:"date_desc",tags:[]},images:[],tags:[],image:{id:0,filename:"",file:"",url:"",title:"",tags:[],created:0},dialog:""}),async created(){await this.loadImages()},computed:{relevantTags(){return this.tags.filter((e=>e.total>0))}},methods:{autocompleteTags(e,t){return this.tags.filter((n=>!t.includes(n.title)&&n.title.toLowerCase().startsWith(e.toLowerCase()))).slice(0,10).map((e=>e.title))},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${se.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 ot={class:"upload-image-teaser"},lt=n("div",{class:"hint"},"(The image you upload will be added to the public gallery.)",-1),at={key:0},st=i(" Tags: "),it=i(" Sort by: "),rt=n("option",{value:"date_desc"},"Newest first",-1),dt=n("option",{value:"date_asc"},"Oldest first",-1),ct=n("option",{value:"alpha_asc"},"A-Z",-1),ut=n("option",{value:"alpha_desc"},"Z-A",-1);nt.render=function(e,o,i,u,g,h){const m=a("image-library"),y=a("new-image-dialog"),f=a("edit-image-dialog"),v=a("new-game-dialog");return s(),t("div",null,[n("div",ot,[n("div",{class:"btn btn-big",onClick:o[1]||(o[1]=t=>e.dialog="new-image")},"Upload your image"),lt]),n("div",null,[e.tags.length>0?(s(),t("label",at,[st,(s(!0),t(d,null,c(e.relevantTags,((n,o)=>(s(),t("span",{class:["bit",{on:e.filters.tags.includes(n.slug)}],key:o,onClick:t=>e.toggleTag(n)},r(n.title)+" ("+r(n.total)+")",11,["onClick"])))),128))])):l("",!0),n("label",null,[it,p(n("select",{"onUpdate:modelValue":o[2]||(o[2]=t=>e.filters.sort=t),onChange:o[3]||(o[3]=(...t)=>e.filtersChanged&&e.filtersChanged(...t))},[rt,dt,ct,ut],544),[[w,e.filters.sort]])])]),n(m,{images:e.images,onImageClicked:e.onImageClicked,onImageEditClicked:e.onImageEditClicked},null,8,["images","onImageClicked","onImageEditClicked"]),"new-image"===e.dialog?(s(),t(y,{key:0,autocompleteTags:e.autocompleteTags,onBgclick:o[4]||(o[4]=t=>e.dialog=""),onPostToGalleryClick:e.postToGalleryClick,onSetupGameClick:e.setupGameClick},null,8,["autocompleteTags","onPostToGalleryClick","onSetupGameClick"])):l("",!0),"edit-image"===e.dialog?(s(),t(f,{key:1,autocompleteTags:e.autocompleteTags,onBgclick:o[5]||(o[5]=t=>e.dialog=""),onSaveClick:e.onSaveImageClick,image:e.image},null,8,["autocompleteTags","onSaveClick","image"])):l("",!0),e.image&&"new-game"===e.dialog?(s(),t(v,{key:2,onBgclick:o[6]||(o[6]=t=>e.dialog=""),onNewGame:e.onNewGame,image:e.image},null,8,["onNewGame","image"])):l("",!0)])};var pt=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 gt={class:"scores"},ht=n("div",null,"Scores",-1),mt=n("td",null,"⚑",-1),yt=n("td",null,"πŸ’€",-1);pt.render=function(e,o,l,a,i,u){return s(),t("div",gt,[ht,n("table",null,[(s(!0),t(d,null,c(e.actives,((e,o)=>(s(),t("tr",{key:o,style:{color:e.color}},[mt,n("td",null,r(e.name),1),n("td",null,r(e.points),1)],4)))),128)),(s(!0),t(d,null,c(e.idles,((e,o)=>(s(),t("tr",{key:o,style:{color:e.color}},[yt,n("td",null,r(e.name),1),n("td",null,r(e.points),1)],4)))),128))])])};var ft=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 B(this.duration)}}});const vt={class:"timer"};ft.render=function(e,o,l,a,i,d){return s(),t("div",vt,[n("div",null," 🧩 "+r(e.piecesDone)+"/"+r(e.piecesTotal),1),n("div",null,r(e.icon)+" "+r(e.durationStr),1),b(e.$slots,"default")])};var wt=e({name:"settings-overlay",emits:{bgclick:null,"update:modelValue":null},props:{modelValue:{type:Object,required:!0}},methods:{updateVolume(e){this.modelValue.soundsVolume=e.target.value},decreaseVolume(){const e=parseInt(this.modelValue.soundsVolume,10)-5;this.modelValue.soundsVolume=Math.max(0,e)},increaseVolume(){const e=parseInt(this.modelValue.soundsVolume,10)+5;this.modelValue.soundsVolume=Math.min(100,e)}},created(){this.$watch("modelValue",(e=>{this.$emit("update:modelValue",e)}),{deep:!0})}});const bt=m();y("data-v-a1d1c822");const xt=n("td",null,[n("label",null,"Background: ")],-1),Ct=n("td",null,[n("label",null,"Color: ")],-1),kt=n("td",null,[n("label",null,"Name: ")],-1),At=n("td",null,[n("label",null,"Sounds: ")],-1),St=n("td",null,[n("label",null,"Sounds Volume: ")],-1),Tt={class:"sound-volume"};f();const It=bt(((e,o,l,a,i,r)=>(s(),t("div",{class:"overlay transparent",onClick:o[9]||(o[9]=t=>e.$emit("bgclick"))},[n("table",{class:"overlay-content settings",onClick:o[8]||(o[8]=u((()=>{}),["stop"]))},[n("tr",null,[xt,n("td",null,[p(n("input",{type:"color","onUpdate:modelValue":o[1]||(o[1]=t=>e.modelValue.background=t)},null,512),[[g,e.modelValue.background]])])]),n("tr",null,[Ct,n("td",null,[p(n("input",{type:"color","onUpdate:modelValue":o[2]||(o[2]=t=>e.modelValue.color=t)},null,512),[[g,e.modelValue.color]])])]),n("tr",null,[kt,n("td",null,[p(n("input",{type:"text",maxLength:"16","onUpdate:modelValue":o[3]||(o[3]=t=>e.modelValue.name=t)},null,512),[[g,e.modelValue.name]])])]),n("tr",null,[At,n("td",null,[p(n("input",{type:"checkbox","onUpdate:modelValue":o[4]||(o[4]=t=>e.modelValue.soundsEnabled=t)},null,512),[[x,e.modelValue.soundsEnabled]])])]),n("tr",null,[St,n("td",Tt,[n("span",{onClick:o[5]||(o[5]=(...t)=>e.decreaseVolume&&e.decreaseVolume(...t))},"πŸ”‰"),n("input",{type:"range",min:"0",max:"100",value:e.modelValue.soundsVolume,onChange:o[6]||(o[6]=(...t)=>e.updateVolume&&e.updateVolume(...t))},null,40,["value"]),n("span",{onClick:o[7]||(o[7]=(...t)=>e.increaseVolume&&e.increaseVolume(...t))},"πŸ”Š")])])])]))));wt.render=It,wt.__scopeId="data-v-a1d1c822";var Pt=e({name:"preview-overlay",props:{img:String},emits:{bgclick:null},computed:{previewStyle(){return{backgroundImage:`url('${this.img}')`}}}});const zt={class:"preview"};Pt.render=function(e,o,l,a,i,r){return s(),t("div",{class:"overlay",onClick:o[1]||(o[1]=t=>e.$emit("bgclick"))},[n("div",zt,[n("div",{class:"img",style:e.previewStyle},null,4)])])};var Dt=1,_t=4,Et=2,Mt=3,Vt=2,Nt=4,Ot=3,Bt=9,Ut=1,Rt=2,$t=3,Gt=4,Ft=5,Lt=6,jt=7,Wt=8,Kt=10,Ht=11,Yt=12,Qt=13,qt=14,Zt=1,Xt=2,Jt=3;const en=ae("Communication.js");let tn,nn=[],on=e=>{nn.push(e)},ln=[],an=e=>{ln.push(e)};let sn=0;const rn=e=>{sn!==e&&(sn=e,an(e))};function dn(e){if(2===sn)try{tn.send(JSON.stringify(e))}catch(t){en.info("unable to send message.. maybe because ws is invalid?")}}let cn,un;var pn={connect:function(e,t,n){return cn=0,un={},rn(3),new Promise((o=>{tn=new WebSocket(e,n+"|"+t),tn.onopen=()=>{rn(2),dn([Mt])},tn.onmessage=e=>{const t=JSON.parse(e.data),l=t[0];if(l===_t){const e=t[1];o(e)}else{if(l!==Dt)throw`[ 2021-05-09 invalid connect msgType ${l} ]`;{const e=t[1],o=t[2];if(e===n&&un[o])return void delete un[o];on(t)}}},tn.onerror=()=>{throw rn(1),"[ 2021-05-15 onerror ]"},tn.onclose=e=>{4e3===e.code||1001===e.code?rn(4):rn(1)}}))},requestReplayData:async function(e,t){const n={gameId:e,offset:t},o=await fetch(`/api/replay-data${se.asQueryArgs(n)}`);return await o.json()},disconnect:function(){tn&&tn.close(4e3),cn=0,un={}},sendClientEvent:function(e){cn++,un[cn]=e,dn([Et,cn,un[cn]])},onServerChange:function(e){on=e;for(const t of nn)on(t);nn=[]},onConnectionStateChange:function(e){an=e;for(const t of ln)an(t);ln=[]},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},gn=e({name:"connection-overlay",emits:{reconnect:null},props:{connectionState:Number},computed:{lostConnection(){return this.connectionState===pn.CONN_STATE_DISCONNECTED},connecting(){return this.connectionState===pn.CONN_STATE_CONNECTING},show(){return!(!this.lostConnection&&!this.connecting)}}});const hn={key:0,class:"overlay connection-lost"},mn={key:0,class:"overlay-content"},yn=n("div",null,"⁉️ LOST CONNECTION ⁉️",-1),fn={key:1,class:"overlay-content"},vn=n("div",null,"Connecting...",-1);gn.render=function(e,o,a,i,r,d){return e.show?(s(),t("div",hn,[e.lostConnection?(s(),t("div",mn,[yn,n("span",{class:"btn",onClick:o[1]||(o[1]=t=>e.$emit("reconnect"))},"Reconnect")])):l("",!0),e.connecting?(s(),t("div",fn,[vn])):l("",!0)])):l("",!0)};var wn=e({name:"help-overlay",emits:{bgclick:null}});const bn=n("tr",null,[n("td",null,"⬆️ Move up:"),n("td",null,[n("div",null,[n("kbd",null,"W"),i("/"),n("kbd",null,"↑"),i("/πŸ–±οΈ")])])],-1),xn=n("tr",null,[n("td",null,"⬇️ Move down:"),n("td",null,[n("div",null,[n("kbd",null,"S"),i("/"),n("kbd",null,"↓"),i("/πŸ–±οΈ")])])],-1),Cn=n("tr",null,[n("td",null,"⬅️ Move left:"),n("td",null,[n("div",null,[n("kbd",null,"A"),i("/"),n("kbd",null,"←"),i("/πŸ–±οΈ")])])],-1),kn=n("tr",null,[n("td",null,"➑️ Move right:"),n("td",null,[n("div",null,[n("kbd",null,"D"),i("/"),n("kbd",null,"β†’"),i("/πŸ–±οΈ")])])],-1),An=n("tr",null,[n("td"),n("td",null,[n("div",null,[i("Move faster by holding "),n("kbd",null,"Shift")])])],-1),Sn=n("tr",null,[n("td",null,"πŸ”+ Zoom in:"),n("td",null,[n("div",null,[n("kbd",null,"E"),i("/πŸ–±οΈ-Wheel")])])],-1),Tn=n("tr",null,[n("td",null,"πŸ”- Zoom out:"),n("td",null,[n("div",null,[n("kbd",null,"Q"),i("/πŸ–±οΈ-Wheel")])])],-1),In=n("tr",null,[n("td",null,"πŸ–ΌοΈ Toggle preview:"),n("td",null,[n("div",null,[n("kbd",null,"Space")])])],-1),Pn=n("tr",null,[n("td",null,"πŸ§©βœ”οΈ Toggle fixed pieces:"),n("td",null,[n("div",null,[n("kbd",null,"F")])])],-1),zn=n("tr",null,[n("td",null,"πŸ§©β“ Toggle loose pieces:"),n("td",null,[n("div",null,[n("kbd",null,"G")])])],-1),Dn=n("tr",null,[n("td",null,"πŸ”‰ Toggle sounds:"),n("td",null,[n("div",null,[n("kbd",null,"M")])])],-1),_n=n("tr",null,[n("td",null,"⏫ Speed up (replay):"),n("td",null,[n("div",null,[n("kbd",null,"I")])])],-1),En=n("tr",null,[n("td",null,"⏬ Speed down (replay):"),n("td",null,[n("div",null,[n("kbd",null,"O")])])],-1),Mn=n("tr",null,[n("td",null,"⏸️ Pause (replay):"),n("td",null,[n("div",null,[n("kbd",null,"P")])])],-1);wn.render=function(e,o,l,a,i,r){return s(),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"]))},[bn,xn,Cn,kn,An,Sn,Tn,In,Pn,zn,Dn,_n,En,Mn])])};var Vn=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"/assets/click.bb97cb07.mp3"}),Nn=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAW0lEQVQ4je1RywrAIAxLxP//5exixRWlVgZelpOKeTQFfnDypgy3eLIkSLLL8mxGPoHsU2hPAgDHBLvRX6hZZw/fwT0BtlLSONqCbWAmEIqMZOCDDlaDR3N03gOyDCn+y4DWmAAAAABJRU5ErkJggg=="}),On=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAARElEQVQ4jWNgGAU0Af+hmBCbgYGBgYERhwHEAEYGBgYGJtIdiApYyLAZBVDsAqoagC1ACQJyY4ERg0GCISh6KA4DigEAou8LC+LnIJoAAAAASUVORK5CYII="}),Bn=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAcUlEQVQ4ja1TQQ7AIAgD///n7jCozA2Hbk00jbG1KIrcARszTugoBs49qioZj7r2kKACptkyAOCJsJuA+GzglwHjvMSSWFVaENWVASxh5eRLiq5fN/ASjI89VcP2K3hHpq1cEXNaMfnrL3TDZP2tDuoOA6MzCCXWr38AAAAASUVORK5CYII="}),Un=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAU0lEQVQ4jWNgoAH4D8X42HDARKlt5BoAd82AuQAOGLGIYQQUPv0wF5CiCQUge4EsQ5C9QI4BjMguwBYeBAElscCIy1ZivMKIwSDBEBQ9FCckigEAU3QOD7TGvY4AAAAASUVORK5CYII="});function Rn(){let e=0,t=0,n=1;const o=(o,l)=>{e+=o/n,t+=l/n},l=e=>{const t=n+.05*n*("in"===e?1:-1);return Math.min(Math.max(t,.1),6)},a=o=>({x:o.x/n-e,y:o.y/n-t}),s=o=>({x:(o.x+e)*n,y:(o.y+t)*n}),i=e=>({w:e.w*n,h:e.h*n}),r=e=>({w:e.w/n,h:e.h/n});return{getCurrentZoom:()=>n,move:o,canZoom:e=>n!=l(e),zoom:(e,t)=>((e,t)=>{if(n==e)return!1;const l=1-n/e;return o(-t.x*l,-t.y*l),n=e,!0})(l(e),t),worldToViewport:e=>{const{x:t,y:n}=s(e);return{x:Math.round(t),y:Math.round(n)}},worldToViewportRaw:s,worldDimToViewport:e=>{const{w:t,h:n}=i(e);return{w:Math.round(t),h:Math.round(n)}},worldDimToViewportRaw:i,viewportToWorld:e=>{const{x:t,y:n}=a(e);return{x:Math.round(t),y:Math.round(n)}},viewportToWorldRaw:a,viewportDimToWorld:e=>{const{w:t,h:n}=r(e);return{w:Math.round(t),h:Math.round(n)}},viewportDimToWorldRaw:r}}function $n(e=0,t=0){const n=document.createElement("canvas");return n.width=e,n.height=t,n}var Gn={createCanvas:$n,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=$n(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=$n(e.width,e.height),l=o.getContext("2d");return l.save(),l.drawImage(t,0,0),l.fillStyle=n,l.globalCompositeOperation="source-in",l.fillRect(0,0,t.width,t.height),l.restore(),l.save(),l.globalCompositeOperation="destination-over",l.drawImage(e,0,0),l.restore(),o}};const Fn=ae("Debug.js");let Ln=0,jn=0;var Wn=e=>{Ln=performance.now(),jn=e},Kn=e=>{const t=performance.now(),n=t-Ln;n>jn&&Fn.log(e+": "+n),Ln=t};function Hn(e,t){const n=e.x-t.x,o=e.y-t.y;return Math.sqrt(n*n+o*o)}function Yn(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}var Qn={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:Hn,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:Yn,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 Hn(Yn(e),Yn(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 qn=ae("PuzzleGraphics.js");function Zn(e,t){const n=se.coordByPieceIdx(e,t);return{x:n.x*e.tileSize,y:n.y*e.tileSize,w:e.tileSize,h:e.tileSize}}var Xn={loadPuzzleBitmaps:async function(e){const t=await Gn.loadImageToBitmap(e.info.imageUrl),n=await Gn.resizeBitmap(t,e.info.width,e.info.height);return await async function(e,t,n){qn.log("start createPuzzleTileBitmaps");const o=n.tileSize,l=n.tileMarginWidth,a=n.tileDrawSize,s=o/100,i=[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),d={};function c(e){const t=`${e.top}${e.right}${e.left}${e.bottom}`;if(d[t])return d[t];const n=new Path2D,a={x:l,y:l},r=Qn.pointAdd(a,{x:o,y:0}),c=Qn.pointAdd(r,{x:0,y:o}),u=Qn.pointSub(c,{x:o,y:0});if(n.moveTo(a.x,a.y),0!==e.top)for(let o=0;ose.decodePiece(Jn[e].puzzle.tiles[t]),mo=(e,t)=>ho(e,t).group,yo=(e,t)=>{const n=Jn[e].puzzle.info;return 0===t||t===n.tilesX-1||t===n.tiles-n.tilesX||t===n.tiles-1},fo=(e,t)=>{const n=Jn[e].puzzle.info,o={x:(n.table.width-n.width)/2,y:(n.table.height-n.height)/2},l=function(e,t){const n=Jn[e].puzzle.info,o=se.coordByPieceIdx(n,t),l=o.x*n.tileSize,a=o.y*n.tileSize;return{x:l,y:a}}(e,t);return Qn.pointAdd(o,l)},vo=(e,t)=>ho(e,t).pos,wo=e=>{const t=Oo(e),n=Bo(e),o=Math.round(t/4),l=Math.round(n/4);return{x:0-o,y:0-l,w:t+2*o,h:n+2*l}},bo=(e,t)=>{const n=Ao(e),o=ho(e,t);return{x:o.pos.x,y:o.pos.y,w:n,h:n}},xo=(e,t)=>ho(e,t).z,Co=(e,t)=>{for(const n of Jn[e].puzzle.tiles){const e=se.decodePiece(n);if(e.owner===t)return e.idx}return-1},ko=e=>Jn[e].puzzle.info.tileDrawSize,Ao=e=>Jn[e].puzzle.info.tileSize,So=e=>Jn[e].puzzle.data.maxGroup,To=e=>Jn[e].puzzle.data.maxZ;function Io(e,t){const n=Jn[e].puzzle.info,o=se.coordByPieceIdx(n,t);return[o.y>0?t-n.tilesX:-1,o.x0?t-1:-1]}const Po=(e,t,n)=>{for(const o of t)go(e,o,{z:n})},zo=(e,t,n)=>{const o=vo(e,t);go(e,t,{pos:Qn.pointAdd(o,n)})},Do=(e,t,n)=>{const o=ko(e),l=wo(e),a=n;for(const s of t){const t=ho(e,s);t.pos.x+n.xl.x+l.w&&(a.x=Math.min(l.x+l.w-t.pos.x+o,a.x)),t.pos.y+n.yl.y+l.h&&(a.y=Math.min(l.y+l.h-t.pos.y+o,a.y))}for(const s of t)zo(e,s,a)},_o=(e,t)=>ho(e,t).owner,Eo=(e,t)=>{for(const n of t)go(e,n,{owner:-1,z:1})},Mo=(e,t,n)=>{for(const o of t)go(e,o,{owner:n})};function Vo(e,t){const n=Jn[e].puzzle.tiles,o=se.decodePiece(n[t]),l=[];if(o.group)for(const a of n){const e=se.decodePiece(a);e.group===o.group&&l.push(e.idx)}else l.push(o.idx);return l}const No=(e,t)=>{const n=to(e,t);return n?n.points:0},Oo=e=>Jn[e].puzzle.info.table.width,Bo=e=>Jn[e].puzzle.info.table.height;var Uo={setGame:function(e,t){Jn[e]=t},exists:function(e){return!!Jn[e]||!1},playerExists:oo,getActivePlayers:function(e,t){const n=t-30*V;return lo(e).filter((e=>e.ts>=n))},getIdlePlayers:function(e,t){const n=t-30*V;return lo(e).filter((e=>e.ts0))},addPlayer:function(e,t,n){oo(e,t)?uo(e,t,{ts:n}):no(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:co,getPieceCount:ao,getImageUrl:function(e){return Jn[e].puzzle.info.imageUrl},setImageUrl:function(e,t){Jn[e].puzzle.info.imageUrl=t},get:function(e){return Jn[e]||null},getAllGames:function(){return Object.values(Jn).sort(((e,t)=>ro(e.id)===ro(t.id)?t.puzzle.data.started-e.puzzle.data.started:ro(e.id)?1:-1))},getPlayerBgColor:(e,t)=>{const n=to(e,t);return n?n.bgcolor:null},getPlayerColor:(e,t)=>{const n=to(e,t);return n?n.color:null},getPlayerName:(e,t)=>{const n=to(e,t);return n?n.name:null},getPlayerIndexById:eo,getPlayerIdByIndex:function(e,t){return Jn[e].players.length>t?se.decodePlayer(Jn[e].players[t]).id:null},changePlayer:uo,setPlayer:no,setPiece:function(e,t,n){Jn[e].puzzle.tiles[t]=se.encodePiece(n)},setPuzzleData:function(e,t){Jn[e].puzzle.data=t},getTableWidth:Oo,getTableHeight:Bo,getPuzzle:e=>Jn[e].puzzle,getRng:e=>Jn[e].rng.obj,getPuzzleWidth:e=>Jn[e].puzzle.info.width,getPuzzleHeight:e=>Jn[e].puzzle.info.height,getPiecesSortedByZIndex:function(e){return Jn[e].puzzle.tiles.map(se.decodePiece).sort(((e,t)=>e.z-t.z))},getFirstOwnedPiece:(e,t)=>{const n=Co(e,t);return n<0?null:Jn[e].puzzle.tiles[n]},getPieceDrawOffset:e=>Jn[e].puzzle.info.tileDrawOffset,getPieceDrawSize:ko,getFinalPiecePos:fo,getStartTs:e=>Jn[e].puzzle.data.started,getFinishTs:e=>Jn[e].puzzle.data.finished,handleInput:function(e,t,n,o,l){const a=Jn[e].puzzle,s=function(e,t){return t in Jn[e].evtInfos?Jn[e].evtInfos[t]:{_last_mouse:null,_last_mouse_down:null}}(e,t),i=[],r=()=>{i.push([Zt,a.data])},d=t=>{i.push([Xt,se.encodePiece(ho(e,t))])},c=e=>{for(const t of e)d(t)},u=()=>{const n=to(e,t);n&&i.push([Jt,se.encodePlayer(n)])},p=n[0];if(p===Lt){const l=n[1];uo(e,t,{bgcolor:l,ts:o}),u()}else if(p===jt){const l=n[1];uo(e,t,{color:l,ts:o}),u()}else if(p===Wt){const l=`${n[1]}`.substr(0,16);uo(e,t,{name:l,ts:o}),u()}else if(p===Bt){const l=n[1],a=n[2],s=to(e,t);if(s){const n=s.x-l,i=s.y-a;uo(e,t,{ts:o,x:n,y:i}),u()}}else if(p===Ut){const l={x:n[1],y:n[2]};uo(e,t,{d:1,ts:o}),u(),s._last_mouse_down=l;const a=((e,t)=>{const n=Jn[e].puzzle.info,o=Jn[e].puzzle.tiles;let l=-1,a=-1;for(let s=0;sl)&&(l=e.z,a=s)}return a})(e,l);if(a>=0){const n=To(e)+1;po(e,{maxZ:n}),r();const o=Vo(e,a);Po(e,o,To(e)),Mo(e,o,t),c(o)}s._last_mouse=l}else if(p===$t){const l=n[1],a=n[2],i={x:l,y:a};if(null===s._last_mouse_down)uo(e,t,{x:l,y:a,ts:o}),u();else{const n=Co(e,t);if(n>=0){uo(e,t,{x:l,y:a,ts:o}),u();const r=Vo(e,n);let d=Qn.pointInBounds(i,wo(e))&&Qn.pointInBounds(s._last_mouse_down,wo(e));for(const t of r){const n=bo(e,t);if(Qn.pointInBounds(i,n)){d=!0;break}}if(d){const t=l-s._last_mouse_down.x,n=a-s._last_mouse_down.y;Do(e,r,{x:t,y:n}),c(r)}}else uo(e,t,{ts:o}),u();s._last_mouse_down=i}s._last_mouse=i}else if(p===Rt){const i={x:n[1],y:n[2]},p=0;s._last_mouse_down=null;const g=Co(e,t);if(g>=0){const n=Vo(e,g);Mo(e,n,0),c(n);const s=vo(e,g),i=fo(e,g);let h=!1;if(io(e)===ee.REAL){for(const t of n)if(yo(e,t)){h=!0;break}}else h=!0;if(h&&Qn.pointDistance(i,s){const l=Jn[e].puzzle.info;if(n<0)return!1;if(((e,t,n)=>{const o=mo(e,t),l=mo(e,n);return!(!o||o!==l)})(e,t,n))return!1;const a=vo(e,t),s=Qn.pointAdd(vo(e,n),{x:o[0]*l.tileSize,y:o[1]*l.tileSize});if(Qn.pointDistance(a,s){const o=Jn[e].puzzle.tiles,l=mo(e,t),a=mo(e,n);let s;const i=[];l&&i.push(l),a&&i.push(a),l?s=l:a?s=a:(po(e,{maxGroup:So(e)+1}),r(),s=So(e));if(go(e,t,{group:s}),d(t),go(e,n,{group:s}),d(n),i.length>0)for(const r of o){const t=se.decodePiece(r);i.includes(t.group)&&(go(e,t.idx,{group:s}),d(t.idx))}})(e,t,n),l=Vo(e,t),((e,t)=>-1===_o(e,t))(e,n))Eo(e,l);else{const t=((e,t)=>{let n=0;for(const o of t){const t=xo(e,o);t>n&&(n=t)}return n})(e,l);Po(e,l,t)}return c(l),!0}return!1};let a=!1;for(const t of Vo(e,g)){const o=Io(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])){a=!0;break}}if(a&&so(e)===q.ANY){const n=No(e,t)+1;uo(e,t,{d:p,ts:o,points:n}),u()}else uo(e,t,{d:p,ts:o}),u();a&&io(e)===ee.REAL&&co(e)===ao(e)&&(po(e,{finished:o}),r()),a&&l&&l(t)}}else uo(e,t,{d:p,ts:o}),u();s._last_mouse=i}else if(p===Gt){const l=n[1],a=n[2];uo(e,t,{x:l,y:a,ts:o}),u(),s._last_mouse={x:l,y:a}}else if(p===Ft){const l=n[1],a=n[2];uo(e,t,{x:l,y:a,ts:o}),u(),s._last_mouse={x:l,y:a}}else uo(e,t,{ts:o}),u();return function(e,t,n){Jn[e].evtInfos[t]=n}(e,t,s),i}};let Ro=-10,$o=20,Go=2,Fo=15;class Lo{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=Ro+Math.random()*$o,this.vy=-1*(Go+Math.random()*Fo),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{this.resize()}))}setSpeedParams(){let e=0,t=0;for(;e=0;)t+=1,e+=t;Go=t/2,Fo=t-Go;const n=1/4*this.canvas.width/(t/2);Ro=-n,$o=2*n}resize(){this.setSpeedParams()}init(){this.readyBombs=[],this.explodedBombs=[],this.particles=[];for(let e=0;e<1;e++)this.readyBombs.push(new Lo(this.rng))}update(){100*Math.random()<5&&this.readyBombs.push(new Lo(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{const t=e.color+" "+e.d;if(!y[t]){const n=e.d?r:d;if(e.color){const o=e.d?c:u;y[t]=await createImageBitmap(Gn.colorizedCanvas(n,o,e.color))}else y[t]=n}return y[t]},v=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,Zo=!0})),t}(l,Gn.createCanvas()),w={final:!1,log:[],logPointer:0,speeds:[.5,1,2,5,10,20,50,100,250,500],speedIdx:1,paused:!1,lastRealTs:0,lastGameTs:0,gameStartTs:0,skipNonActionPhases:!0,dataOffset:0};pn.onConnectionStateChange((e=>{a.setConnectionState(e)}));const b=async e=>{const t=w.dataOffset;w.dataOffset+=1e4;const n=await pn.requestReplayData(e,t);return w.log=w.log.slice(w.logPointer),w.logPointer=0,w.log.push(...n.log),0===n.log.length&&(w.final=!0),n};let x=()=>0;const C=async()=>{if("play"===o){const o=await pn.connect(n,e,t),l=se.decodeGame(o);Uo.setGame(l.id,l),x=()=>N()}else{if("replay"!==o)throw"[ 2020-12-22 MODE invalid, must be play|replay ]";{const t=await b(e);if(!t.game)throw"[ 2021-05-29 no game received ]";const n=se.decodeGame(t.game);Uo.setGame(n.id,n),w.lastRealTs=N(),w.gameStartTs=parseInt(t.log[0][4],10),w.lastGameTs=w.gameStartTs,x=()=>w.lastGameTs}}Zo=!0};await C();const k=Uo.getPieceDrawOffset(e),A=Uo.getPieceDrawSize(e),S=Uo.getPuzzleWidth(e),T=Uo.getPuzzleHeight(e),I=Uo.getTableWidth(e),P=Uo.getTableHeight(e),z={x:(I-S)/2,y:(P-T)/2},D={w:S,h:T},_={w:A,h:A},E=await Xn.loadPuzzleBitmaps(Uo.getPuzzle(e)),V=new Wo(v,Uo.getRng(e));V.init();const O=v.getContext("2d");v.classList.add("loaded");const B=Rn();B.move(-(I-v.width)/2,-(P-v.height)/2);const U=function(e,t,n,o){let l=[],a=!0,s=!1,i=!1,r=!1,d=!1,c=!1,u=!1,p=!1;const g=(e,t)=>{const o=n.viewportToWorld({x:e,y:t});return[o.x,o.y]},h=e=>g(e.offsetX,e.offsetY),m=()=>g(e.width/2,e.height/2),y=(e,t)=>{a&&("ShiftLeft"===t.code||"ShiftRight"===t.code?p=e:"ArrowUp"===t.code||"KeyW"===t.code?r=e:"ArrowDown"===t.code||"KeyS"===t.code?d=e:"ArrowLeft"===t.code||"KeyA"===t.code?s=e:"ArrowRight"===t.code||"KeyD"===t.code?i=e:"KeyQ"===t.code?u=e:"KeyE"===t.code&&(c=e))};let f=null;e.addEventListener("mousedown",(e=>{f=h(e),0===e.button&&v([Ut,...f])})),e.addEventListener("mouseup",(e=>{f=h(e),0===e.button&&v([Rt,...f])})),e.addEventListener("mousemove",(e=>{f=h(e),v([$t,...f])})),e.addEventListener("wheel",(e=>{if(f=h(e),n.canZoom(e.deltaY<0?"in":"out")){const t=e.deltaY<0?Gt:Ft;v([t,...f])}})),t.addEventListener("keydown",(e=>y(!0,e))),t.addEventListener("keyup",(e=>y(!1,e))),t.addEventListener("keypress",(e=>{a&&("Space"===e.code&&v([Kt]),"replay"===o&&("KeyI"===e.code&&v([Qt]),"KeyO"===e.code&&v([qt]),"KeyP"===e.code&&v([Yt])),"KeyF"===e.code&&(Qo=!Qo,Zo=!0),"KeyG"===e.code&&(qo=!qo,Zo=!0),"KeyM"===e.code&&v([Ht]))}));const v=e=>{l.push(e)};return{addEvent:v,consumeAll:()=>{if(0===l.length)return[];const e=l.slice();return l=[],e},createKeyEvents:()=>{const e=(s?1:0)-(i?1:0),t=(r?1:0)-(d?1:0);if(0!==e||0!==t){const o=(p?24:12)*Math.sqrt(n.getCurrentZoom()),l=n.viewportDimToWorld({w:e*o,h:t*o});v([Bt,l.w,l.h]),f&&(f[0]-=l.w,f[1]-=l.h)}if(c&&u);else if(c){if(n.canZoom("in")){const e=f||m();v([Gt,...e])}}else if(u&&n.canZoom("out")){const e=f||m();v([Ft,...e])}},setHotkeys:e=>{a=e}}}(v,window,B,o),R=Uo.getImageUrl(e),$=()=>{const t=Uo.getStartTs(e),n=Uo.getFinishTs(e),o=x();a.setFinished(!!n),a.setDuration((n||o)-t)};$(),a.setPiecesDone(Uo.getFinishedPiecesCount(e)),a.setPiecesTotal(Uo.getPieceCount(e));const G=x();a.setActivePlayers(Uo.getActivePlayers(e,G)),a.setIdlePlayers(Uo.getIdlePlayers(e,G));const F=!!Uo.getFinishTs(e);let L=F;const j=()=>L&&!F,W=()=>{const e=localStorage.getItem("sound_volume");if(null===e)return 100;const t=parseInt(e,10);return isNaN(t)?100:t},K=()=>{const e=localStorage.getItem("sound_enabled");return null!==e&&"1"===e},H=()=>{const e=W();i.volume=e/100,i.play()},Y=()=>"replay"===o?localStorage.getItem("bg_color")||"#222222":Uo.getPlayerBgColor(e,t)||localStorage.getItem("bg_color")||"#222222",Q=()=>"replay"===o?localStorage.getItem("player_color")||"#ffffff":Uo.getPlayerColor(e,t)||localStorage.getItem("player_color")||"#ffffff";let q="",Z="",X=!1;const J=e=>{X=e;const[t,n]=e?[q,"grab"]:[Z,"default"];v.style.cursor=`url('${t}') ${g} ${m}, ${n}`},ee=e=>{q=Gn.colorizedCanvas(r,c,e).toDataURL(),Z=Gn.colorizedCanvas(d,u,e).toDataURL(),J(X)};ee(Q());const te=()=>{a.setReplaySpeed&&a.setReplaySpeed(w.speeds[w.speedIdx]),a.setReplayPaused&&a.setReplayPaused(w.paused)},ne=()=>{w.speedIdx+1{w.speedIdx>=1&&(w.speedIdx--,te())},le=()=>{w.paused=!w.paused,te()},ae=[];let ie;let re;if("play"===o?ae.push(setInterval((()=>{$()}),1e3)):"replay"===o&&te(),"play"===o)pn.onServerChange((n=>{n[0],n[1],n[2];const o=n[3];for(const[l,a]of o)switch(l){case Jt:{const n=se.decodePlayer(a);n.id!==t&&(Uo.setPlayer(e,n.id,n),Zo=!0)}break;case Xt:{const t=se.decodePiece(a);Uo.setPiece(e,t.idx,t),Zo=!0}break;case Zt:Uo.setPuzzleData(e,a),Zo=!0}L=!!Uo.getFinishTs(e)}));else if("replay"===o){const t=(t,n)=>{const o=t;if(o[0]===Vt){const t=o[1];return Uo.addPlayer(e,t,n),!0}if(o[0]===Nt){const t=Uo.getPlayerIdByIndex(e,o[1]);if(!t)throw"[ 2021-05-17 player not found (update player) ]";return Uo.addPlayer(e,t,n),!0}if(o[0]===Ot){const t=Uo.getPlayerIdByIndex(e,o[1]);if(!t)throw"[ 2021-05-17 player not found (handle input) ]";const l=o[2];return Uo.handleInput(e,t,l,n),!0}return!1};let n=w.lastGameTs;const o=async()=>{w.logPointer+1>=w.log.length&&await b(e);const l=N();if(w.paused)return w.lastRealTs=l,void(ie=setTimeout(o,50));const a=(l-w.lastRealTs)*w.speeds[w.speedIdx];let s=w.lastGameTs+a;for(;;){if(w.paused)break;const e=w.logPointer+1;if(e>=w.log.length)break;const o=w.log[w.logPointer],l=n+o[o.length-1],a=w.log[e],i=a[a.length-1],r=l+i;if(r>s){w.skipNonActionPhases&&s+500*M{let t=!1;const n=e.fps||60,o=e.slow||1,l=e.update,a=e.render,s=window.requestAnimationFrame,i=1/n,r=o*i;let d,c=0,u=window.performance.now();const p=()=>{for(d=window.performance.now(),c+=Math.min(1,(d-u)/1e3);c>r;)c-=r,l(i);a(c/o),u=d,t||s(p)};return s(p),{stop:()=>{t=!0}}})({update:()=>{U.createKeyEvents();for(const n of U.consumeAll())if("play"===o){const o=n[0];if(o===Bt){const e=n[1],t=n[2],o=B.worldDimToViewport({w:e,h:t});Zo=!0,B.move(o.w,o.h)}else if(o===$t){if(de&&!Uo.getFirstOwnedPiece(e,t)){const e={x:n[1],y:n[2]},t=B.worldToViewport(e),o=Math.round(t.x-de.x),l=Math.round(t.y-de.y);Zo=!0,B.move(o,l),de=t}}else if(o===jt)ee(n[1]);else if(o===Ut){const e={x:n[1],y:n[2]};de=B.worldToViewport(e),J(!0)}else if(o===Rt)de=null,J(!1);else if(o===Gt){const e={x:n[1],y:n[2]};Zo=!0,B.zoom("in",B.worldToViewport(e))}else if(o===Ft){const e={x:n[1],y:n[2]};Zo=!0,B.zoom("out",B.worldToViewport(e))}else o===Kt?a.togglePreview():o===Ht&&a.toggleSoundsEnabled();const l=x();Uo.handleInput(e,t,n,l,(e=>{K()&&H()})).length>0&&(Zo=!0),pn.sendClientEvent(n)}else if("replay"===o){const e=n[0];if(e===Yt)le();else if(e===qt)oe();else if(e===Qt)ne();else if(e===Bt){const e=n[1],t=n[2];Zo=!0,B.move(e,t)}else if(e===$t){if(de){const e={x:n[1],y:n[2]},t=B.worldToViewport(e),o=Math.round(t.x-de.x),l=Math.round(t.y-de.y);Zo=!0,B.move(o,l),de=t}}else if(e===jt)ee(n[1]);else if(e===Ut){const e={x:n[1],y:n[2]};de=B.worldToViewport(e),J(!0)}else if(e===Rt)de=null,J(!1);else if(e===Gt){const e={x:n[1],y:n[2]};Zo=!0,B.zoom("in",B.worldToViewport(e))}else if(e===Ft){const e={x:n[1],y:n[2]};Zo=!0,B.zoom("out",B.worldToViewport(e))}else e===Kt&&a.togglePreview()}L=!!Uo.getFinishTs(e),j()&&(V.update(),Zo=!0)},render:async()=>{if(!Zo)return;const n=x();let l,s,i;window.DEBUG&&Wn(0),O.fillStyle=Y(),O.fillRect(0,0,v.width,v.height),window.DEBUG&&Kn("clear done"),l=B.worldToViewportRaw(z),s=B.worldDimToViewportRaw(D),O.fillStyle="rgba(255, 255, 255, .3)",O.fillRect(l.x,l.y,s.w,s.h),window.DEBUG&&Kn("board done");const r=Uo.getPiecesSortedByZIndex(e);window.DEBUG&&Kn("get tiles done"),s=B.worldDimToViewportRaw(_);for(const e of r)(-1===e.owner?Qo:qo)&&(i=E[e.idx],l=B.worldToViewportRaw({x:k+e.pos.x,y:k+e.pos.y}),O.drawImage(i,0,0,i.width,i.height,l.x,l.y,s.w,s.h));window.DEBUG&&Kn("tiles done");const d=[];for(const a of Uo.getActivePlayers(e,n))c=a,("replay"===o||c.id!==t)&&(i=await f(a),l=B.worldToViewport(a),O.drawImage(i,l.x-g,l.y-m),d.push([`${a.name} (${a.points})`,l.x,l.y+h]));var c;O.fillStyle="white",O.textAlign="center";for(const[e,t,o]of d)O.fillText(e,t,o);window.DEBUG&&Kn("players done"),a.setActivePlayers(Uo.getActivePlayers(e,n)),a.setIdlePlayers(Uo.getIdlePlayers(e,n)),a.setPiecesDone(Uo.getFinishedPiecesCount(e)),window.DEBUG&&Kn("HUD done"),j()&&V.render(),Zo=!1}}),{setHotkeys:e=>{U.setHotkeys(e)},onBgChange:e=>{localStorage.setItem("bg_color",e),U.addEvent([Lt,e])},onColorChange:e=>{localStorage.setItem("player_color",e),U.addEvent([jt,e])},onNameChange:e=>{localStorage.setItem("player_name",e),U.addEvent([Wt,e])},onSoundsEnabledChange:e=>{localStorage.setItem("sound_enabled",e?"1":"0")},onSoundsVolumeChange:e=>{Ko.info("vol changed",e),localStorage.setItem("sound_volume",`${e}`),H()},replayOnSpeedUp:ne,replayOnSpeedDown:oe,replayOnPauseToggle:le,replayOnSkipToggle:()=>{w.skipNonActionPhases=!w.skipNonActionPhases},previewImageUrl:R,player:{background:Y(),color:Q(),name:"replay"===o?localStorage.getItem("player_name")||"#ffffff":Uo.getPlayerName(e,t)||localStorage.getItem("player_name")||"anon",soundsEnabled:K(),soundsVolume:W()},disconnect:pn.disconnect,connect:C,unload:()=>{ae.forEach((e=>{clearInterval(e)})),ie&&clearTimeout(ie),re&&re.stop()}}}var Jo=e({name:"game",components:{PuzzleStatus:ft,Scores:pt,SettingsOverlay:wt,PreviewOverlay:Pt,ConnectionOverlay:gn,HelpOverlay:wn},data:()=>({activePlayers:[],idlePlayers:[],finished:!1,duration:0,piecesDone:0,piecesTotal:0,overlay:"",connectionState:0,g:{player:{background:"",color:"",name:"",soundsEnabled:!1,soundsVolume:100},previewImageUrl:"",setHotkeys:e=>{},onBgChange:e=>{},onColorChange:e=>{},onNameChange:e=>{},onSoundsEnabledChange:e=>{},onSoundsVolumeChange:e=>{},connect:()=>{},disconnect:()=>{},unload:()=>{}}}),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.$watch((()=>this.g.player.soundsEnabled),(e=>{this.g.onSoundsEnabledChange(e)})),this.$watch((()=>this.g.player.soundsVolume),(e=>{this.g.onSoundsVolumeChange(e)})),this.g=await Xo(`${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},togglePreview:()=>{this.toggle("preview",!1)},setConnectionState:e=>{this.connectionState=e},toggleSoundsEnabled:()=>{this.g.player.soundsEnabled=!this.g.player.soundsEnabled}}))},unmounted(){this.g.unload(),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 el={id:"game"},tl={class:"menu"},nl={class:"tabs"},ol=i("🧩 Puzzles");Jo.render=function(e,l,i,r,d,c){const u=a("settings-overlay"),g=a("preview-overlay"),h=a("help-overlay"),m=a("connection-overlay"),y=a("puzzle-status"),f=a("router-link"),v=a("scores");return s(),t("div",el,[p(n(u,{onBgclick:l[1]||(l[1]=t=>e.toggle("settings",!0)),modelValue:e.g.player,"onUpdate:modelValue":l[2]||(l[2]=t=>e.g.player=t)},null,8,["modelValue"]),[[C,"settings"===e.overlay]]),p(n(g,{onBgclick:l[3]||(l[3]=t=>e.toggle("preview",!1)),img:e.g.previewImageUrl},null,8,["img"]),[[C,"preview"===e.overlay]]),p(n(h,{onBgclick:l[4]||(l[4]=t=>e.toggle("help",!0))},null,512),[[C,"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",tl,[n("div",nl,[n(f,{class:"opener",to:{name:"index"},target:"_blank"},{default:o((()=>[ol])),_:1}),n("div",{class:"opener",onClick:l[5]||(l[5]=t=>e.toggle("preview",!1))},"πŸ–ΌοΈ Preview"),n("div",{class:"opener",onClick:l[6]||(l[6]=t=>e.toggle("settings",!0))},"πŸ› οΈ Settings"),n("div",{class:"opener",onClick:l[7]||(l[7]=t=>e.toggle("help",!0))},"ℹ️ Help")])]),n(v,{activePlayers:e.activePlayers,idlePlayers:e.idlePlayers},null,8,["activePlayers","idlePlayers"])])};var ll=e({name:"replay",components:{PuzzleStatus:ft,Scores:pt,SettingsOverlay:wt,PreviewOverlay:Pt,HelpOverlay:wn},data:()=>({activePlayers:[],idlePlayers:[],finished:!1,duration:0,piecesDone:0,piecesTotal:0,skipNoAction:!0,overlay:"",connectionState:0,g:{player:{background:"",color:"",name:"",soundsEnabled:!1,soundsVolume:100},previewImageUrl:"",setHotkeys:e=>{},onBgChange:e=>{},onColorChange:e=>{},onNameChange:e=>{},onSoundsEnabledChange:e=>{},onSoundsVolumeChange:e=>{},replayOnSpeedUp:()=>{},replayOnSpeedDown:()=>{},replayOnPauseToggle:()=>{},replayOnSkipToggle:()=>{},connect:()=>{},disconnect:()=>{},unload:()=>{}},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.$watch((()=>this.g.player.soundsEnabled),(e=>{this.g.onSoundsEnabledChange(e)})),this.$watch((()=>this.g.player.soundsVolume),(e=>{this.g.onSoundsVolumeChange(e)})),this.g=await Xo(`${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},toggleSoundsEnabled:()=>{this.g.player.soundsEnabled=!this.g.player.soundsEnabled}}))},unmounted(){this.g.unload(),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 al={id:"replay"},sl=i("Skip no action phases: "),il={class:"menu"},rl={class:"tabs"},dl=i("🧩 Puzzles");ll.render=function(e,l,i,d,c,u){const g=a("settings-overlay"),h=a("preview-overlay"),m=a("help-overlay"),y=a("puzzle-status"),f=a("router-link"),v=a("scores");return s(),t("div",al,[p(n(g,{onBgclick:l[1]||(l[1]=t=>e.toggle("settings",!0)),modelValue:e.g.player,"onUpdate:modelValue":l[2]||(l[2]=t=>e.g.player=t)},null,8,["modelValue"]),[[C,"settings"===e.overlay]]),p(n(h,{onBgclick:l[3]||(l[3]=t=>e.toggle("preview",!1)),img:e.g.previewImageUrl},null,8,["img"]),[[C,"preview"===e.overlay]]),p(n(m,{onBgclick:l[4]||(l[4]=t=>e.toggle("help",!0))},null,512),[[C,"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("div",null,[n("label",null,[sl,p(n("input",{type:"checkbox","onUpdate:modelValue":l[5]||(l[5]=t=>e.skipNoAction=t),onChange:l[6]||(l[6]=t=>e.g.replayOnSkipToggle())},null,544),[[x,e.skipNoAction]])])]),n("button",{class:"btn",onClick:l[7]||(l[7]=t=>e.g.replayOnSpeedUp())},"⏫"),n("button",{class:"btn",onClick:l[8]||(l[8]=t=>e.g.replayOnSpeedDown())},"⏬"),n("button",{class:"btn",onClick:l[9]||(l[9]=t=>e.g.replayOnPauseToggle())},"⏸️")])])),_:1},8,["finished","duration","piecesDone","piecesTotal"]),n("div",il,[n("div",rl,[n(f,{class:"opener",to:{name:"index"},target:"_blank"},{default:o((()=>[dl])),_:1}),n("div",{class:"opener",onClick:l[10]||(l[10]=t=>e.toggle("preview",!1))},"πŸ–ΌοΈ Preview"),n("div",{class:"opener",onClick:l[11]||(l[11]=t=>e.toggle("settings",!0))},"πŸ› οΈ Settings"),n("div",{class:"opener",onClick:l[12]||(l[12]=t=>e.toggle("help",!0))},"ℹ️ Help")])]),n(v,{activePlayers:e.activePlayers,idlePlayers:e.idlePlayers},null,8,["activePlayers","idlePlayers"])])},(async()=>{const e=await fetch("/api/conf"),t=await e.json();const n=k({history:A(),routes:[{name:"index",path:"/",component:j},{name:"new-game",path:"/new-game",component:nt},{name:"game",path:"/g/:id",component:Jo},{name:"replay",path:"/replay/:id",component:ll}]});n.beforeEach(((e,t)=>{t.name&&document.documentElement.classList.remove(`view-${String(t.name)}`),document.documentElement.classList.add(`view-${String(e.name)}`)}));const o=S(T);o.config.globalProperties.$config=t,o.config.globalProperties.$clientId=function(){let e=localStorage.getItem("ID");return e||(e=se.uniqId(),localStorage.setItem("ID",e)),e}(),o.use(n),o.mount("#app")})(); diff --git a/build/public/assets/index.e0726e0c.js b/build/public/assets/index.e0726e0c.js new file mode 100644 index 0000000..a54c646 --- /dev/null +++ b/build/public/assets/index.e0726e0c.js @@ -0,0 +1 @@ +import{d as e,c as t,a as o,w as n,b as l,r as a,o as s,e as i,t as r,F as d,f as c,g as u,h as p,v as g,i as h,j as m,p as y,k as f,l as v,m as w,n as b,q as x,s as C,u as k,x as A,y as S}from"./vendor.684f7bc8.js";var P=e({name:"app",computed:{showNav(){return!["game","replay"].includes(String(this.$route.name))}}});const T={id:"app"},I={key:0,class:"nav"},z=i("Index"),D=i("New game");P.render=function(e,i,r,d,c,u){const p=a("router-link"),g=a("router-view");return s(),t("div",T,[e.showNav?(s(),t("ul",I,[o("li",null,[o(p,{class:"btn",to:{name:"index"}},{default:n((()=>[z])),_:1})]),o("li",null,[o(p,{class:"btn",to:{name:"new-game"}},{default:n((()=>[D])),_:1})])])):l("",!0),o(g)])};const E=864e5,_=e=>{const t=Math.floor(e/E);e%=E;const o=Math.floor(e/36e5);e%=36e5;const n=Math.floor(e/6e4);e%=6e4;return`${t}d ${o}h ${n}m ${Math.floor(e/1e3)}s`};var M=1,V=1e3,N=()=>{const e=new Date;return Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())},O=(e,t)=>_(t-e),U=_,B=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 o=t?"🏁":"⏳",n=e,l=t||N();return`${o} ${O(n,l)}`}}});const R={class:"game-info-text"},G=o("br",null,null,-1),$=o("br",null,null,-1),L=o("br",null,null,-1),F=i(" β†ͺ️ Watch replay ");B.render=function(e,d,c,u,p,g){const h=a("router-link");return s(),t("div",{class:"game-teaser",style:e.style},[o(h,{class:"game-info",to:{name:"game",params:{id:e.game.id}}},{default:n((()=>[o("span",R,[i(" 🧩 "+r(e.game.tilesFinished)+"/"+r(e.game.tilesTotal),1),G,i(" πŸ‘₯ "+r(e.game.players),1),$,i(" "+r(e.time(e.game.started,e.game.finished)),1),L])])),_:1},8,["to"]),e.game.hasReplay?(s(),t(h,{key:0,class:"game-replay",to:{name:"replay",params:{id:e.game.id}}},{default:n((()=>[F])),_:1},8,["to"])):l("",!0)],4)};var j=e({components:{GameTeaser:B},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 W=o("h1",null,"Running games",-1),H=o("h1",null,"Finished games",-1);j.render=function(e,n,l,i,r,u){const p=a("game-teaser");return s(),t("div",null,[W,(s(!0),t(d,null,c(e.gamesRunning,((e,n)=>(s(),t("div",{class:"game-teaser-wrap",key:n},[o(p,{game:e},null,8,["game"])])))),128)),H,(s(!0),t(d,null,c(e.gamesFinished,((e,n)=>(s(),t("div",{class:"game-teaser-wrap",key:n},[o(p,{game:e},null,8,["game"])])))),128))])};var K=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")}}});K.render=function(e,n,l,a,i,r){return s(),t("div",{class:"imageteaser",style:e.style,onClick:n[2]||(n[2]=(...t)=>e.onClick&&e.onClick(...t))},[o("div",{class:"btn edit",onClick:n[1]||(n[1]=u(((...t)=>e.onEditClick&&e.onEditClick(...t)),["stop"]))},"✏️")],4)};var Y,q,Q,Z,X,J,ee,te,oe=e({name:"image-library",components:{ImageTeaser:K},props:{images:{type:Array,required:!0}},emits:{imageClicked:null,imageEditClicked:null},methods:{imageClicked(e){this.$emit("imageClicked",e)},imageEditClicked(e){this.$emit("imageEditClicked",e)}}});oe.render=function(e,o,n,l,i,r){const u=a("image-teaser");return s(),t("div",null,[(s(!0),t(d,null,c(e.images,((o,n)=>(s(),t(u,{image:o,onClick:t=>e.imageClicked(o),onEditClick:t=>e.imageEditClicked(o),key:n},null,8,["image","onClick","onEditClick"])))),128))])},(q=Y||(Y={}))[q.Flat=0]="Flat",q[q.Out=1]="Out",q[q.In=-1]="In",(Z=Q||(Q={}))[Z.FINAL=0]="FINAL",Z[Z.ANY=1]="ANY",(J=X||(X={}))[J.NORMAL=0]="NORMAL",J[J.ANY=1]="ANY",J[J.FLAT=2]="FLAT",(te=ee||(ee={}))[te.NORMAL=0]="NORMAL",te[te.REAL=1]="REAL";class ne{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 o=0;o<=t.length-2;o++){const e=this.random(o,t.length-1),n=t[o];t[o]=t[e],t[e]=n}return t}static serialize(e){return{rand_high:e.rand_high,rand_low:e.rand_low}}static unserialize(e){const t=new ne(0);return t.rand_high=e.rand_high,t.rand_low=e.rand_low,t}}const le=(e,t)=>{const o=`${e}`;return o.length>=t.length?o:t.substr(0,t.length-o.length)+o},ae=(...e)=>{const t=t=>(...o)=>{const n=new Date,l=le(n.getHours(),"00"),a=le(n.getMinutes(),"00"),s=le(n.getSeconds(),"00");console[t](`${l}:${a}:${s}`,...e,...o)};return{log:t("log"),error:t("error"),info:t("info")}};var se={hash:e=>{let t=0;for(let o=0;o{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||"",ne.serialize(e.rng.obj),e.puzzle,e.players,e.evtInfos,e.scoreMode||Q.FINAL,e.shapeMode||X.ANY,e.snapMode||ee.NORMAL]},decodeGame:function(e){return{id:e[0],rng:{type:e[1],obj:ne.unserialize(e[2])},puzzle:e[3],players:e[4],evtInfos:e[5],scoreMode:e[6],shapeMode:e[7],snapMode:e[8]}},coordByPieceIdx:function(e,t){const o=e.width/e.tileSize;return{x:t%o,y:Math.floor(t/o)}},asQueryArgs:function(e){const t=[];for(const o in e){const n=[o,e[o]].map(encodeURIComponent);t.push(n.join("="))}return 0===t.length?"":`?${t.join("&")}`}};const ie={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}}}};ie.render=function(e,o,n,l,a,i){return s(),t("div",{style:i.style,title:n.title},null,12,["title"])};var re=e({name:"tags-input",props:{modelValue:{type:Array,required:!0},autocompleteTags:{type:Function}},emits:{"update:modelValue":null},data:()=>({input:"",values:[],autocomplete:{idx:-1,values:[]}}),created(){this.values=this.modelValue},methods:{onKeyUp(e){return"ArrowDown"===e.code&&this.autocomplete.values.length>0?(this.autocomplete.idx0?(this.autocomplete.idx>0&&this.autocomplete.idx--,e.stopPropagation(),!1):","===e.key?(this.add(),e.stopPropagation(),!1):void(this.input&&this.autocompleteTags?(this.autocomplete.values=this.autocompleteTags(this.input,this.values),this.autocomplete.idx=-1):(this.autocomplete.values=[],this.autocomplete.idx=-1))},addVal(e){const t=e.replace(/,/g,"").trim();t&&(this.values.includes(t)||this.values.push(t),this.input="",this.autocomplete.values=[],this.autocomplete.idx=-1,this.$emit("update:modelValue",this.values),this.$refs.input.focus())},add(){const e=this.autocomplete.idx>=0?this.autocomplete.values[this.autocomplete.idx]:this.input;this.addVal(e)},rm(e){this.values=this.values.filter((t=>t!==e)),this.$emit("update:modelValue",this.values)}}});const de=m();y("data-v-a4fa5e7e");const ce={key:0,class:"autocomplete"};f();const ue=de(((e,n,a,i,u,m)=>(s(),t("div",null,[p(o("input",{ref:"input",class:"input",type:"text","onUpdate:modelValue":n[1]||(n[1]=t=>e.input=t),placeholder:"Plants, People",onChange:n[2]||(n[2]=(...t)=>e.onChange&&e.onChange(...t)),onKeydown:n[3]||(n[3]=h(((...t)=>e.add&&e.add(...t)),["enter"])),onKeyup:n[4]||(n[4]=(...t)=>e.onKeyUp&&e.onKeyUp(...t))},null,544),[[g,e.input]]),e.autocomplete.values?(s(),t("div",ce,[o("ul",null,[(s(!0),t(d,null,c(e.autocomplete.values,((o,n)=>(s(),t("li",{key:n,class:{active:n===e.autocomplete.idx},onClick:t=>e.addVal(o)},r(o),11,["onClick"])))),128))])])):l("",!0),(s(!0),t(d,null,c(e.values,((o,n)=>(s(),t("span",{key:n,class:"bit",onClick:t=>e.rm(o)},r(o)+" βœ–",9,["onClick"])))),128))]))));re.render=ue,re.__scopeId="data-v-a4fa5e7e";const pe=ae("NewImageDialog.vue");var ge=e({name:"new-image-dialog",components:{ResponsiveImage:ie,TagsInput:re},props:{autocompleteTags:{type:Function},uploadProgress:{type:Number},uploading:{type:String}},emits:{bgclick:null,setupGameClick:null,postToGalleryClick:null},data:()=>({previewUrl:"",file:null,title:"",tags:[],droppable:!1}),computed:{uploadProgressPercent(){return this.uploadProgress?Math.round(100*this.uploadProgress):0},canPostToGallery(){return!this.uploading&&!(!this.previewUrl||!this.file)},canSetupGameClick(){return!this.uploading&&!(!this.previewUrl||!this.file)}},methods:{imageFromDragEvt(e){var t;const o=null==(t=e.dataTransfer)?void 0:t.items;if(!o||0===o.length)return null;const n=o[0];return n.type.startsWith("image/")?n:null},onFileSelect(e){const t=e.target;if(!t.files)return;const o=t.files[0];o&&this.preview(o)},preview(e){const t=new FileReader;t.readAsDataURL(e),t.onload=t=>{this.previewUrl=t.target.result,this.file=e}},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})},onDrop(e){this.droppable=!1;const t=this.imageFromDragEvt(e);if(!t)return!1;const o=t.getAsFile();return!!o&&(this.file=o,this.preview(o),e.preventDefault(),!1)},onDragover(e){return!!this.imageFromDragEvt(e)&&(this.droppable=!0,e.preventDefault(),!1)},onDragleave(){pe.info("onDragleave"),this.droppable=!1}}});const he=o("div",{class:"drop-target"},null,-1),me={key:0,class:"has-image"},ye={key:1},fe={class:"upload"},ve=o("span",{class:"btn"},"Upload File",-1),we={class:"area-settings"},be=o("td",null,[o("label",null,"Title")],-1),xe=o("tr",null,[o("td",{colspan:"2"},[o("div",{class:"hint"},"Feel free to leave a credit to the artist/photographer in the title :)")])],-1),Ce=o("td",null,[o("label",null,"Tags")],-1),ke={class:"area-buttons"},Ae=i("πŸ–ΌοΈ Post to gallery"),Se=i("🧩 Post to gallery "),Pe=o("br",null,null,-1),Te=i(" + set up game");ge.render=function(e,n,l,c,h,m){const y=a("responsive-image"),f=a("tags-input");return s(),t("div",{class:"overlay new-image-dialog",onClick:n[11]||(n[11]=t=>e.$emit("bgclick"))},[o("div",{class:"overlay-content",onClick:n[10]||(n[10]=u((()=>{}),["stop"]))},[o("div",{class:["area-image",{"has-image":!!e.previewUrl,"no-image":!e.previewUrl,droppable:e.droppable}],onDrop:n[3]||(n[3]=(...t)=>e.onDrop&&e.onDrop(...t)),onDragover:n[4]||(n[4]=(...t)=>e.onDragover&&e.onDragover(...t)),onDragleave:n[5]||(n[5]=(...t)=>e.onDragleave&&e.onDragleave(...t))},[he,e.previewUrl?(s(),t("div",me,[o("span",{class:"remove btn",onClick:n[1]||(n[1]=t=>e.previewUrl="")},"X"),o(y,{src:e.previewUrl},null,8,["src"])])):(s(),t("div",ye,[o("label",fe,[o("input",{type:"file",style:{display:"none"},onChange:n[2]||(n[2]=(...t)=>e.onFileSelect&&e.onFileSelect(...t)),accept:"image/*"},null,32),ve])]))],34),o("div",we,[o("table",null,[o("tr",null,[be,o("td",null,[p(o("input",{type:"text","onUpdate:modelValue":n[6]||(n[6]=t=>e.title=t),placeholder:"Flower by @artist"},null,512),[[g,e.title]])])]),xe,o("tr",null,[Ce,o("td",null,[o(f,{modelValue:e.tags,"onUpdate:modelValue":n[7]||(n[7]=t=>e.tags=t),autocompleteTags:e.autocompleteTags},null,8,["modelValue","autocompleteTags"])])])])]),o("div",ke,[o("button",{class:"btn",disabled:!e.canPostToGallery,onClick:n[8]||(n[8]=(...t)=>e.postToGallery&&e.postToGallery(...t))},["postToGallery"===e.uploading?(s(),t(d,{key:0},[i("Uploading ("+r(e.uploadProgressPercent)+"%)",1)],64)):(s(),t(d,{key:1},[Ae],64))],8,["disabled"]),o("button",{class:"btn",disabled:!e.canSetupGameClick,onClick:n[9]||(n[9]=(...t)=>e.setupGameClick&&e.setupGameClick(...t))},["setupGame"===e.uploading?(s(),t(d,{key:0},[i("Uploading ("+r(e.uploadProgressPercent)+"%)",1)],64)):(s(),t(d,{key:1},[Se,Pe,Te],64))],8,["disabled"])])])])};var Ie=e({name:"edit-image-dialog",components:{ResponsiveImage:ie,TagsInput:re},props:{image:{type:Object,required:!0},autocompleteTags:{type:Function}},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 ze={class:"area-image"},De={class:"has-image"},Ee={class:"area-settings"},_e=o("td",null,[o("label",null,"Title")],-1),Me=o("tr",null,[o("td",{colspan:"2"},[o("div",{class:"hint"},"Feel free to leave a credit to the artist/photographer in the title :)")])],-1),Ve=o("td",null,[o("label",null,"Tags")],-1),Ne={class:"area-buttons"};Ie.render=function(e,n,l,i,r,d){const c=a("responsive-image"),h=a("tags-input");return s(),t("div",{class:"overlay edit-image-dialog",onClick:n[5]||(n[5]=t=>e.$emit("bgclick"))},[o("div",{class:"overlay-content",onClick:n[4]||(n[4]=u((()=>{}),["stop"]))},[o("div",ze,[o("div",De,[o(c,{src:e.image.url,title:e.image.title},null,8,["src","title"])])]),o("div",Ee,[o("table",null,[o("tr",null,[_e,o("td",null,[p(o("input",{type:"text","onUpdate:modelValue":n[1]||(n[1]=t=>e.title=t),placeholder:"Flower by @artist"},null,512),[[g,e.title]])])]),Me,o("tr",null,[Ve,o("td",null,[o(h,{modelValue:e.tags,"onUpdate:modelValue":n[2]||(n[2]=t=>e.tags=t),autocompleteTags:e.autocompleteTags},null,8,["modelValue","autocompleteTags"])])])])]),o("div",Ne,[o("button",{class:"btn",onClick:n[3]||(n[3]=(...t)=>e.saveImage&&e.saveImage(...t))},"πŸ–ΌοΈ Save image")])])])};var Oe=e({name:"new-game-dialog",components:{ResponsiveImage:ie},props:{image:{type:Object,required:!0}},emits:{newGame:null,bgclick:null},data:()=>({tiles:1e3,scoreMode:Q.ANY,shapeMode:X.NORMAL,snapMode:ee.NORMAL}),methods:{onNewGameClick(){this.$emit("newGame",{tiles:this.tilesInt,image:this.image,scoreMode:this.scoreModeInt,shapeMode:this.shapeModeInt,snapMode:this.snapModeInt})}},computed:{canStartNewGame(){return!!(this.tilesInt&&this.image&&this.image.url&&[0,1].includes(this.scoreModeInt))},scoreModeInt(){return parseInt(`${this.scoreMode}`,10)},shapeModeInt(){return parseInt(`${this.shapeMode}`,10)},snapModeInt(){return parseInt(`${this.snapMode}`,10)},tilesInt(){return parseInt(`${this.tiles}`,10)}}});const Ue={class:"area-image"},Be={class:"has-image"},Re={key:0,class:"image-title"},Ge={class:"area-settings"},$e=o("td",null,[o("label",null,"Pieces")],-1),Le=o("td",null,[o("label",null,"Scoring: ")],-1),Fe=i(" Any (Score when pieces are connected to each other or on final location)"),je=o("br",null,null,-1),We=i(" Final (Score when pieces are put to their final location)"),He=o("td",null,[o("label",null,"Shapes: ")],-1),Ke=i(" Normal"),Ye=o("br",null,null,-1),qe=i(" Any (flat pieces can occur anywhere)"),Qe=o("br",null,null,-1),Ze=i(" Flat (all pieces flat on all sides)"),Xe=o("td",null,[o("label",null,"Snapping: ")],-1),Je=i(" Normal (pieces snap to final destination and to each other)"),et=o("br",null,null,-1),tt=i(" Real (pieces snap only to corners, already snapped pieces and to each other)"),ot={class:"area-buttons"};Oe.render=function(e,n,i,d,c,h){const m=a("responsive-image");return s(),t("div",{class:"overlay new-game-dialog",onClick:n[11]||(n[11]=t=>e.$emit("bgclick"))},[o("div",{class:"overlay-content",onClick:n[10]||(n[10]=u((()=>{}),["stop"]))},[o("div",Ue,[o("div",Be,[o(m,{src:e.image.url,title:e.image.title},null,8,["src","title"])]),e.image.title?(s(),t("div",Re,'"'+r(e.image.title)+'"',1)):l("",!0)]),o("div",Ge,[o("table",null,[o("tr",null,[$e,o("td",null,[p(o("input",{type:"text","onUpdate:modelValue":n[1]||(n[1]=t=>e.tiles=t)},null,512),[[g,e.tiles]])])]),o("tr",null,[Le,o("td",null,[o("label",null,[p(o("input",{type:"radio","onUpdate:modelValue":n[2]||(n[2]=t=>e.scoreMode=t),value:"1"},null,512),[[v,e.scoreMode]]),Fe]),je,o("label",null,[p(o("input",{type:"radio","onUpdate:modelValue":n[3]||(n[3]=t=>e.scoreMode=t),value:"0"},null,512),[[v,e.scoreMode]]),We])])]),o("tr",null,[He,o("td",null,[o("label",null,[p(o("input",{type:"radio","onUpdate:modelValue":n[4]||(n[4]=t=>e.shapeMode=t),value:"0"},null,512),[[v,e.shapeMode]]),Ke]),Ye,o("label",null,[p(o("input",{type:"radio","onUpdate:modelValue":n[5]||(n[5]=t=>e.shapeMode=t),value:"1"},null,512),[[v,e.shapeMode]]),qe]),Qe,o("label",null,[p(o("input",{type:"radio","onUpdate:modelValue":n[6]||(n[6]=t=>e.shapeMode=t),value:"2"},null,512),[[v,e.shapeMode]]),Ze])])]),o("tr",null,[Xe,o("td",null,[o("label",null,[p(o("input",{type:"radio","onUpdate:modelValue":n[7]||(n[7]=t=>e.snapMode=t),value:"0"},null,512),[[v,e.snapMode]]),Je]),et,o("label",null,[p(o("input",{type:"radio","onUpdate:modelValue":n[8]||(n[8]=t=>e.snapMode=t),value:"1"},null,512),[[v,e.snapMode]]),tt])])])])]),o("div",ot,[o("button",{class:"btn",disabled:!e.canStartNewGame,onClick:n[9]||(n[9]=(...t)=>e.onNewGameClick&&e.onNewGameClick(...t))}," 🧩 Generate Puzzle ",8,["disabled"])])])])};const nt=async(e,t,o)=>new Promise(((n,l)=>{const a=new window.XMLHttpRequest;a.open(e,t,!0),a.withCredentials=!0;for(const e in o.headers||{})a.setRequestHeader(e,o.headers[e]);a.addEventListener("load",(function(e){n({status:this.status,text:this.responseText,json:async()=>JSON.parse(this.responseText)})})),a.addEventListener("error",(function(e){l(new Error("xhr error"))})),a.upload&&o.onUploadProgress&&a.upload.addEventListener("progress",(function(e){o.onUploadProgress&&o.onUploadProgress(e)})),a.send(o.body)}));var lt=(e,t)=>nt("post",e,t),at=e({components:{ImageLibrary:oe,NewImageDialog:ge,EditImageDialog:Ie,NewGameDialog:Oe},data:()=>({filters:{sort:"date_desc",tags:[]},images:[],tags:[],image:{id:0,filename:"",file:"",url:"",title:"",tags:[],created:0},dialog:"",uploading:"",uploadProgress:0}),async created(){await this.loadImages()},computed:{relevantTags(){return this.tags.filter((e=>e.total>0))}},methods:{autocompleteTags(e,t){return this.tags.filter((o=>!t.includes(o.title)&&o.title.toLowerCase().startsWith(e.toLowerCase()))).slice(0,10).map((e=>e.title))},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${se.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){this.uploadProgress=0;const t=new FormData;t.append("file",e.file,e.file.name),t.append("title",e.title),t.append("tags",e.tags);const o=await lt("/api/upload",{body:t,onUploadProgress:e=>{this.uploadProgress=e.loaded/e.total}});return this.uploadProgress=1,await o.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){this.uploading="postToGallery",await this.uploadImage(e),this.uploading="",this.dialog="",await this.loadImages()},async setupGameClick(e){this.uploading="setupGame";const t=await this.uploadImage(e);this.uploading="",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 st={class:"upload-image-teaser"},it=o("div",{class:"hint"},"(The image you upload will be added to the public gallery.)",-1),rt={key:0},dt=i(" Tags: "),ct=i(" Sort by: "),ut=o("option",{value:"date_desc"},"Newest first",-1),pt=o("option",{value:"date_asc"},"Oldest first",-1),gt=o("option",{value:"alpha_asc"},"A-Z",-1),ht=o("option",{value:"alpha_desc"},"Z-A",-1);at.render=function(e,n,i,u,g,h){const m=a("image-library"),y=a("new-image-dialog"),f=a("edit-image-dialog"),v=a("new-game-dialog");return s(),t("div",null,[o("div",st,[o("div",{class:"btn btn-big",onClick:n[1]||(n[1]=t=>e.dialog="new-image")},"Upload your image"),it]),o("div",null,[e.tags.length>0?(s(),t("label",rt,[dt,(s(!0),t(d,null,c(e.relevantTags,((o,n)=>(s(),t("span",{class:["bit",{on:e.filters.tags.includes(o.slug)}],key:n,onClick:t=>e.toggleTag(o)},r(o.title)+" ("+r(o.total)+")",11,["onClick"])))),128))])):l("",!0),o("label",null,[ct,p(o("select",{"onUpdate:modelValue":n[2]||(n[2]=t=>e.filters.sort=t),onChange:n[3]||(n[3]=(...t)=>e.filtersChanged&&e.filtersChanged(...t))},[ut,pt,gt,ht],544),[[w,e.filters.sort]])])]),o(m,{images:e.images,onImageClicked:e.onImageClicked,onImageEditClicked:e.onImageEditClicked},null,8,["images","onImageClicked","onImageEditClicked"]),"new-image"===e.dialog?(s(),t(y,{key:0,autocompleteTags:e.autocompleteTags,onBgclick:n[4]||(n[4]=t=>e.dialog=""),uploadProgress:e.uploadProgress,uploading:e.uploading,onPostToGalleryClick:e.postToGalleryClick,onSetupGameClick:e.setupGameClick},null,8,["autocompleteTags","uploadProgress","uploading","onPostToGalleryClick","onSetupGameClick"])):l("",!0),"edit-image"===e.dialog?(s(),t(f,{key:1,autocompleteTags:e.autocompleteTags,onBgclick:n[5]||(n[5]=t=>e.dialog=""),onSaveClick:e.onSaveImageClick,image:e.image},null,8,["autocompleteTags","onSaveClick","image"])):l("",!0),e.image&&"new-game"===e.dialog?(s(),t(v,{key:2,onBgclick:n[6]||(n[6]=t=>e.dialog=""),onNewGame:e.onNewGame,image:e.image},null,8,["onNewGame","image"])):l("",!0)])};var mt=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 yt={class:"scores"},ft=o("div",null,"Scores",-1),vt=o("td",null,"⚑",-1),wt=o("td",null,"πŸ’€",-1);mt.render=function(e,n,l,a,i,u){return s(),t("div",yt,[ft,o("table",null,[(s(!0),t(d,null,c(e.actives,((e,n)=>(s(),t("tr",{key:n,style:{color:e.color}},[vt,o("td",null,r(e.name),1),o("td",null,r(e.points),1)],4)))),128)),(s(!0),t(d,null,c(e.idles,((e,n)=>(s(),t("tr",{key:n,style:{color:e.color}},[wt,o("td",null,r(e.name),1),o("td",null,r(e.points),1)],4)))),128))])])};var bt=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 U(this.duration)}}});const xt={class:"timer"};bt.render=function(e,n,l,a,i,d){return s(),t("div",xt,[o("div",null," 🧩 "+r(e.piecesDone)+"/"+r(e.piecesTotal),1),o("div",null,r(e.icon)+" "+r(e.durationStr),1),b(e.$slots,"default")])};var Ct=e({name:"settings-overlay",emits:{bgclick:null,"update:modelValue":null},props:{modelValue:{type:Object,required:!0}},methods:{updateVolume(e){this.modelValue.soundsVolume=e.target.value},decreaseVolume(){const e=parseInt(this.modelValue.soundsVolume,10)-5;this.modelValue.soundsVolume=Math.max(0,e)},increaseVolume(){const e=parseInt(this.modelValue.soundsVolume,10)+5;this.modelValue.soundsVolume=Math.min(100,e)}},created(){this.$watch("modelValue",(e=>{this.$emit("update:modelValue",e)}),{deep:!0})}});const kt=m();y("data-v-a1d1c822");const At=o("td",null,[o("label",null,"Background: ")],-1),St=o("td",null,[o("label",null,"Color: ")],-1),Pt=o("td",null,[o("label",null,"Name: ")],-1),Tt=o("td",null,[o("label",null,"Sounds: ")],-1),It=o("td",null,[o("label",null,"Sounds Volume: ")],-1),zt={class:"sound-volume"};f();const Dt=kt(((e,n,l,a,i,r)=>(s(),t("div",{class:"overlay transparent",onClick:n[9]||(n[9]=t=>e.$emit("bgclick"))},[o("table",{class:"overlay-content settings",onClick:n[8]||(n[8]=u((()=>{}),["stop"]))},[o("tr",null,[At,o("td",null,[p(o("input",{type:"color","onUpdate:modelValue":n[1]||(n[1]=t=>e.modelValue.background=t)},null,512),[[g,e.modelValue.background]])])]),o("tr",null,[St,o("td",null,[p(o("input",{type:"color","onUpdate:modelValue":n[2]||(n[2]=t=>e.modelValue.color=t)},null,512),[[g,e.modelValue.color]])])]),o("tr",null,[Pt,o("td",null,[p(o("input",{type:"text",maxLength:"16","onUpdate:modelValue":n[3]||(n[3]=t=>e.modelValue.name=t)},null,512),[[g,e.modelValue.name]])])]),o("tr",null,[Tt,o("td",null,[p(o("input",{type:"checkbox","onUpdate:modelValue":n[4]||(n[4]=t=>e.modelValue.soundsEnabled=t)},null,512),[[x,e.modelValue.soundsEnabled]])])]),o("tr",null,[It,o("td",zt,[o("span",{onClick:n[5]||(n[5]=(...t)=>e.decreaseVolume&&e.decreaseVolume(...t))},"πŸ”‰"),o("input",{type:"range",min:"0",max:"100",value:e.modelValue.soundsVolume,onChange:n[6]||(n[6]=(...t)=>e.updateVolume&&e.updateVolume(...t))},null,40,["value"]),o("span",{onClick:n[7]||(n[7]=(...t)=>e.increaseVolume&&e.increaseVolume(...t))},"πŸ”Š")])])])]))));Ct.render=Dt,Ct.__scopeId="data-v-a1d1c822";var Et=e({name:"preview-overlay",props:{img:String},emits:{bgclick:null},computed:{previewStyle(){return{backgroundImage:`url('${this.img}')`}}}});const _t={class:"preview"};Et.render=function(e,n,l,a,i,r){return s(),t("div",{class:"overlay",onClick:n[1]||(n[1]=t=>e.$emit("bgclick"))},[o("div",_t,[o("div",{class:"img",style:e.previewStyle},null,4)])])};var Mt=1,Vt=4,Nt=2,Ot=3,Ut=2,Bt=4,Rt=3,Gt=9,$t=1,Lt=2,Ft=3,jt=4,Wt=5,Ht=6,Kt=7,Yt=8,qt=10,Qt=11,Zt=12,Xt=13,Jt=14,eo=1,to=2,oo=3;const no=ae("Communication.js");let lo,ao=[],so=e=>{ao.push(e)},io=[],ro=e=>{io.push(e)};let co=0;const uo=e=>{co!==e&&(co=e,ro(e))};function po(e){if(2===co)try{lo.send(JSON.stringify(e))}catch(t){no.info("unable to send message.. maybe because ws is invalid?")}}let go,ho;var mo={connect:function(e,t,o){return go=0,ho={},uo(3),new Promise((n=>{lo=new WebSocket(e,o+"|"+t),lo.onopen=()=>{uo(2),po([Ot])},lo.onmessage=e=>{const t=JSON.parse(e.data),l=t[0];if(l===Vt){const e=t[1];n(e)}else{if(l!==Mt)throw`[ 2021-05-09 invalid connect msgType ${l} ]`;{const e=t[1],n=t[2];if(e===o&&ho[n])return void delete ho[n];so(t)}}},lo.onerror=()=>{throw uo(1),"[ 2021-05-15 onerror ]"},lo.onclose=e=>{4e3===e.code||1001===e.code?uo(4):uo(1)}}))},requestReplayData:async function(e,t){const o={gameId:e,offset:t},n=await fetch(`/api/replay-data${se.asQueryArgs(o)}`);return await n.json()},disconnect:function(){lo&&lo.close(4e3),go=0,ho={}},sendClientEvent:function(e){go++,ho[go]=e,po([Nt,go,ho[go]])},onServerChange:function(e){so=e;for(const t of ao)so(t);ao=[]},onConnectionStateChange:function(e){ro=e;for(const t of io)ro(t);io=[]},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},yo=e({name:"connection-overlay",emits:{reconnect:null},props:{connectionState:Number},computed:{lostConnection(){return this.connectionState===mo.CONN_STATE_DISCONNECTED},connecting(){return this.connectionState===mo.CONN_STATE_CONNECTING},show(){return!(!this.lostConnection&&!this.connecting)}}});const fo={key:0,class:"overlay connection-lost"},vo={key:0,class:"overlay-content"},wo=o("div",null,"⁉️ LOST CONNECTION ⁉️",-1),bo={key:1,class:"overlay-content"},xo=o("div",null,"Connecting...",-1);yo.render=function(e,n,a,i,r,d){return e.show?(s(),t("div",fo,[e.lostConnection?(s(),t("div",vo,[wo,o("span",{class:"btn",onClick:n[1]||(n[1]=t=>e.$emit("reconnect"))},"Reconnect")])):l("",!0),e.connecting?(s(),t("div",bo,[xo])):l("",!0)])):l("",!0)};var Co=e({name:"help-overlay",emits:{bgclick:null}});const ko=o("tr",null,[o("td",null,"⬆️ Move up:"),o("td",null,[o("div",null,[o("kbd",null,"W"),i("/"),o("kbd",null,"↑"),i("/πŸ–±οΈ")])])],-1),Ao=o("tr",null,[o("td",null,"⬇️ Move down:"),o("td",null,[o("div",null,[o("kbd",null,"S"),i("/"),o("kbd",null,"↓"),i("/πŸ–±οΈ")])])],-1),So=o("tr",null,[o("td",null,"⬅️ Move left:"),o("td",null,[o("div",null,[o("kbd",null,"A"),i("/"),o("kbd",null,"←"),i("/πŸ–±οΈ")])])],-1),Po=o("tr",null,[o("td",null,"➑️ Move right:"),o("td",null,[o("div",null,[o("kbd",null,"D"),i("/"),o("kbd",null,"β†’"),i("/πŸ–±οΈ")])])],-1),To=o("tr",null,[o("td"),o("td",null,[o("div",null,[i("Move faster by holding "),o("kbd",null,"Shift")])])],-1),Io=o("tr",null,[o("td",null,"πŸ”+ Zoom in:"),o("td",null,[o("div",null,[o("kbd",null,"E"),i("/πŸ–±οΈ-Wheel")])])],-1),zo=o("tr",null,[o("td",null,"πŸ”- Zoom out:"),o("td",null,[o("div",null,[o("kbd",null,"Q"),i("/πŸ–±οΈ-Wheel")])])],-1),Do=o("tr",null,[o("td",null,"πŸ–ΌοΈ Toggle preview:"),o("td",null,[o("div",null,[o("kbd",null,"Space")])])],-1),Eo=o("tr",null,[o("td",null,"πŸ§©βœ”οΈ Toggle fixed pieces:"),o("td",null,[o("div",null,[o("kbd",null,"F")])])],-1),_o=o("tr",null,[o("td",null,"πŸ§©β“ Toggle loose pieces:"),o("td",null,[o("div",null,[o("kbd",null,"G")])])],-1),Mo=o("tr",null,[o("td",null,"πŸ”‰ Toggle sounds:"),o("td",null,[o("div",null,[o("kbd",null,"M")])])],-1),Vo=o("tr",null,[o("td",null,"⏫ Speed up (replay):"),o("td",null,[o("div",null,[o("kbd",null,"I")])])],-1),No=o("tr",null,[o("td",null,"⏬ Speed down (replay):"),o("td",null,[o("div",null,[o("kbd",null,"O")])])],-1),Oo=o("tr",null,[o("td",null,"⏸️ Pause (replay):"),o("td",null,[o("div",null,[o("kbd",null,"P")])])],-1);Co.render=function(e,n,l,a,i,r){return s(),t("div",{class:"overlay transparent",onClick:n[2]||(n[2]=t=>e.$emit("bgclick"))},[o("table",{class:"overlay-content help",onClick:n[1]||(n[1]=u((()=>{}),["stop"]))},[ko,Ao,So,Po,To,Io,zo,Do,Eo,_o,Mo,Vo,No,Oo])])};var Uo=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"/assets/click.bb97cb07.mp3"}),Bo=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAW0lEQVQ4je1RywrAIAxLxP//5exixRWlVgZelpOKeTQFfnDypgy3eLIkSLLL8mxGPoHsU2hPAgDHBLvRX6hZZw/fwT0BtlLSONqCbWAmEIqMZOCDDlaDR3N03gOyDCn+y4DWmAAAAABJRU5ErkJggg=="}),Ro=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAARElEQVQ4jWNgGAU0Af+hmBCbgYGBgYERhwHEAEYGBgYGJtIdiApYyLAZBVDsAqoagC1ACQJyY4ERg0GCISh6KA4DigEAou8LC+LnIJoAAAAASUVORK5CYII="}),Go=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAcUlEQVQ4ja1TQQ7AIAgD///n7jCozA2Hbk00jbG1KIrcARszTugoBs49qioZj7r2kKACptkyAOCJsJuA+GzglwHjvMSSWFVaENWVASxh5eRLiq5fN/ASjI89VcP2K3hHpq1cEXNaMfnrL3TDZP2tDuoOA6MzCCXWr38AAAAASUVORK5CYII="}),$o=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAU0lEQVQ4jWNgoAH4D8X42HDARKlt5BoAd82AuQAOGLGIYQQUPv0wF5CiCQUge4EsQ5C9QI4BjMguwBYeBAElscCIy1ZivMKIwSDBEBQ9FCckigEAU3QOD7TGvY4AAAAASUVORK5CYII="});function Lo(){let e=0,t=0,o=1;const n=(n,l)=>{e+=n/o,t+=l/o},l=e=>{const t=o+.05*o*("in"===e?1:-1);return Math.min(Math.max(t,.1),6)},a=n=>({x:n.x/o-e,y:n.y/o-t}),s=n=>({x:(n.x+e)*o,y:(n.y+t)*o}),i=e=>({w:e.w*o,h:e.h*o}),r=e=>({w:e.w/o,h:e.h/o});return{getCurrentZoom:()=>o,move:n,canZoom:e=>o!=l(e),zoom:(e,t)=>((e,t)=>{if(o==e)return!1;const l=1-o/e;return n(-t.x*l,-t.y*l),o=e,!0})(l(e),t),worldToViewport:e=>{const{x:t,y:o}=s(e);return{x:Math.round(t),y:Math.round(o)}},worldToViewportRaw:s,worldDimToViewport:e=>{const{w:t,h:o}=i(e);return{w:Math.round(t),h:Math.round(o)}},worldDimToViewportRaw:i,viewportToWorld:e=>{const{x:t,y:o}=a(e);return{x:Math.round(t),y:Math.round(o)}},viewportToWorldRaw:a,viewportDimToWorld:e=>{const{w:t,h:o}=r(e);return{w:Math.round(t),h:Math.round(o)}},viewportDimToWorldRaw:r}}function Fo(e=0,t=0){const o=document.createElement("canvas");return o.width=e,o.height=t,o}var jo={createCanvas:Fo,loadImageToBitmap:async function(e){return new Promise((t=>{const o=new Image;o.onload=()=>{createImageBitmap(o).then(t)},o.src=e}))},resizeBitmap:async function(e,t,o){const n=Fo(t,o);return n.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t,o),await createImageBitmap(n)},colorizedCanvas:function(e,t,o){const n=Fo(e.width,e.height),l=n.getContext("2d");return l.save(),l.drawImage(t,0,0),l.fillStyle=o,l.globalCompositeOperation="source-in",l.fillRect(0,0,t.width,t.height),l.restore(),l.save(),l.globalCompositeOperation="destination-over",l.drawImage(e,0,0),l.restore(),n}};const Wo=ae("Debug.js");let Ho=0,Ko=0;var Yo=e=>{Ho=performance.now(),Ko=e},qo=e=>{const t=performance.now(),o=t-Ho;o>Ko&&Wo.log(e+": "+o),Ho=t};function Qo(e,t){const o=e.x-t.x,n=e.y-t.y;return Math.sqrt(o*o+n*n)}function Zo(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}var Xo={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:Qo,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:Zo,rectMoved:function(e,t,o){return{x:e.x+t,y:e.y+o,w:e.w,h:e.h}},rectCenterDistance:function(e,t){return Qo(Zo(e),Zo(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 Jo=ae("PuzzleGraphics.js");function en(e,t){const o=se.coordByPieceIdx(e,t);return{x:o.x*e.tileSize,y:o.y*e.tileSize,w:e.tileSize,h:e.tileSize}}var tn={loadPuzzleBitmaps:async function(e){const t=await jo.loadImageToBitmap(e.info.imageUrl),o=await jo.resizeBitmap(t,e.info.width,e.info.height);return await async function(e,t,o){Jo.log("start createPuzzleTileBitmaps");const n=o.tileSize,l=o.tileMarginWidth,a=o.tileDrawSize,s=n/100,i=[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),d={};function c(e){const t=`${e.top}${e.right}${e.left}${e.bottom}`;if(d[t])return d[t];const o=new Path2D,a={x:l,y:l},r=Xo.pointAdd(a,{x:n,y:0}),c=Xo.pointAdd(r,{x:0,y:n}),u=Xo.pointSub(c,{x:n,y:0});if(o.moveTo(a.x,a.y),0!==e.top)for(let n=0;nse.decodePiece(on[e].puzzle.tiles[t]),vn=(e,t)=>fn(e,t).group,wn=(e,t)=>{const o=on[e].puzzle.info;return 0===t||t===o.tilesX-1||t===o.tiles-o.tilesX||t===o.tiles-1},bn=(e,t)=>{const o=on[e].puzzle.info,n={x:(o.table.width-o.width)/2,y:(o.table.height-o.height)/2},l=function(e,t){const o=on[e].puzzle.info,n=se.coordByPieceIdx(o,t),l=n.x*o.tileSize,a=n.y*o.tileSize;return{x:l,y:a}}(e,t);return Xo.pointAdd(n,l)},xn=(e,t)=>fn(e,t).pos,Cn=e=>{const t=Rn(e),o=Gn(e),n=Math.round(t/4),l=Math.round(o/4);return{x:0-n,y:0-l,w:t+2*n,h:o+2*l}},kn=(e,t)=>{const o=Tn(e),n=fn(e,t);return{x:n.pos.x,y:n.pos.y,w:o,h:o}},An=(e,t)=>fn(e,t).z,Sn=(e,t)=>{for(const o of on[e].puzzle.tiles){const e=se.decodePiece(o);if(e.owner===t)return e.idx}return-1},Pn=e=>on[e].puzzle.info.tileDrawSize,Tn=e=>on[e].puzzle.info.tileSize,In=e=>on[e].puzzle.data.maxGroup,zn=e=>on[e].puzzle.data.maxZ;function Dn(e,t){const o=on[e].puzzle.info,n=se.coordByPieceIdx(o,t);return[n.y>0?t-o.tilesX:-1,n.x0?t-1:-1]}const En=(e,t,o)=>{for(const n of t)yn(e,n,{z:o})},_n=(e,t,o)=>{const n=xn(e,t);yn(e,t,{pos:Xo.pointAdd(n,o)})},Mn=(e,t,o)=>{const n=Pn(e),l=Cn(e),a=o;for(const s of t){const t=fn(e,s);t.pos.x+o.xl.x+l.w&&(a.x=Math.min(l.x+l.w-t.pos.x+n,a.x)),t.pos.y+o.yl.y+l.h&&(a.y=Math.min(l.y+l.h-t.pos.y+n,a.y))}for(const s of t)_n(e,s,a)},Vn=(e,t)=>fn(e,t).owner,Nn=(e,t)=>{for(const o of t)yn(e,o,{owner:-1,z:1})},On=(e,t,o)=>{for(const n of t)yn(e,n,{owner:o})};function Un(e,t){const o=on[e].puzzle.tiles,n=se.decodePiece(o[t]),l=[];if(n.group)for(const a of o){const e=se.decodePiece(a);e.group===n.group&&l.push(e.idx)}else l.push(n.idx);return l}const Bn=(e,t)=>{const o=ln(e,t);return o?o.points:0},Rn=e=>on[e].puzzle.info.table.width,Gn=e=>on[e].puzzle.info.table.height;var $n={setGame:function(e,t){on[e]=t},exists:function(e){return!!on[e]||!1},playerExists:sn,getActivePlayers:function(e,t){const o=t-30*V;return rn(e).filter((e=>e.ts>=o))},getIdlePlayers:function(e,t){const o=t-30*V;return rn(e).filter((e=>e.ts0))},addPlayer:function(e,t,o){sn(e,t)?hn(e,t,{ts:o}):an(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,o))},getFinishedPiecesCount:gn,getPieceCount:dn,getImageUrl:function(e){return on[e].puzzle.info.imageUrl},setImageUrl:function(e,t){on[e].puzzle.info.imageUrl=t},get:function(e){return on[e]||null},getAllGames:function(){return Object.values(on).sort(((e,t)=>pn(e.id)===pn(t.id)?t.puzzle.data.started-e.puzzle.data.started:pn(e.id)?1:-1))},getPlayerBgColor:(e,t)=>{const o=ln(e,t);return o?o.bgcolor:null},getPlayerColor:(e,t)=>{const o=ln(e,t);return o?o.color:null},getPlayerName:(e,t)=>{const o=ln(e,t);return o?o.name:null},getPlayerIndexById:nn,getPlayerIdByIndex:function(e,t){return on[e].players.length>t?se.decodePlayer(on[e].players[t]).id:null},changePlayer:hn,setPlayer:an,setPiece:function(e,t,o){on[e].puzzle.tiles[t]=se.encodePiece(o)},setPuzzleData:function(e,t){on[e].puzzle.data=t},getTableWidth:Rn,getTableHeight:Gn,getPuzzle:e=>on[e].puzzle,getRng:e=>on[e].rng.obj,getPuzzleWidth:e=>on[e].puzzle.info.width,getPuzzleHeight:e=>on[e].puzzle.info.height,getPiecesSortedByZIndex:function(e){return on[e].puzzle.tiles.map(se.decodePiece).sort(((e,t)=>e.z-t.z))},getFirstOwnedPiece:(e,t)=>{const o=Sn(e,t);return o<0?null:on[e].puzzle.tiles[o]},getPieceDrawOffset:e=>on[e].puzzle.info.tileDrawOffset,getPieceDrawSize:Pn,getFinalPiecePos:bn,getStartTs:e=>on[e].puzzle.data.started,getFinishTs:e=>on[e].puzzle.data.finished,handleInput:function(e,t,o,n,l){const a=on[e].puzzle,s=function(e,t){return t in on[e].evtInfos?on[e].evtInfos[t]:{_last_mouse:null,_last_mouse_down:null}}(e,t),i=[],r=()=>{i.push([eo,a.data])},d=t=>{i.push([to,se.encodePiece(fn(e,t))])},c=e=>{for(const t of e)d(t)},u=()=>{const o=ln(e,t);o&&i.push([oo,se.encodePlayer(o)])},p=o[0];if(p===Ht){const l=o[1];hn(e,t,{bgcolor:l,ts:n}),u()}else if(p===Kt){const l=o[1];hn(e,t,{color:l,ts:n}),u()}else if(p===Yt){const l=`${o[1]}`.substr(0,16);hn(e,t,{name:l,ts:n}),u()}else if(p===Gt){const l=o[1],a=o[2],s=ln(e,t);if(s){const o=s.x-l,i=s.y-a;hn(e,t,{ts:n,x:o,y:i}),u()}}else if(p===$t){const l={x:o[1],y:o[2]};hn(e,t,{d:1,ts:n}),u(),s._last_mouse_down=l;const a=((e,t)=>{const o=on[e].puzzle.info,n=on[e].puzzle.tiles;let l=-1,a=-1;for(let s=0;sl)&&(l=e.z,a=s)}return a})(e,l);if(a>=0){const o=zn(e)+1;mn(e,{maxZ:o}),r();const n=Un(e,a);En(e,n,zn(e)),On(e,n,t),c(n)}s._last_mouse=l}else if(p===Ft){const l=o[1],a=o[2],i={x:l,y:a};if(null===s._last_mouse_down)hn(e,t,{x:l,y:a,ts:n}),u();else{const o=Sn(e,t);if(o>=0){hn(e,t,{x:l,y:a,ts:n}),u();const r=Un(e,o);let d=Xo.pointInBounds(i,Cn(e))&&Xo.pointInBounds(s._last_mouse_down,Cn(e));for(const t of r){const o=kn(e,t);if(Xo.pointInBounds(i,o)){d=!0;break}}if(d){const t=l-s._last_mouse_down.x,o=a-s._last_mouse_down.y;Mn(e,r,{x:t,y:o}),c(r)}}else hn(e,t,{ts:n}),u();s._last_mouse_down=i}s._last_mouse=i}else if(p===Lt){const i={x:o[1],y:o[2]},p=0;s._last_mouse_down=null;const g=Sn(e,t);if(g>=0){const o=Un(e,g);On(e,o,0),c(o);const s=xn(e,g),i=bn(e,g);let h=!1;if(un(e)===ee.REAL){for(const t of o)if(wn(e,t)){h=!0;break}}else h=!0;if(h&&Xo.pointDistance(i,s){const l=on[e].puzzle.info;if(o<0)return!1;if(((e,t,o)=>{const n=vn(e,t),l=vn(e,o);return!(!n||n!==l)})(e,t,o))return!1;const a=xn(e,t),s=Xo.pointAdd(xn(e,o),{x:n[0]*l.tileSize,y:n[1]*l.tileSize});if(Xo.pointDistance(a,s){const n=on[e].puzzle.tiles,l=vn(e,t),a=vn(e,o);let s;const i=[];l&&i.push(l),a&&i.push(a),l?s=l:a?s=a:(mn(e,{maxGroup:In(e)+1}),r(),s=In(e));if(yn(e,t,{group:s}),d(t),yn(e,o,{group:s}),d(o),i.length>0)for(const r of n){const t=se.decodePiece(r);i.includes(t.group)&&(yn(e,t.idx,{group:s}),d(t.idx))}})(e,t,o),l=Un(e,t),((e,t)=>-1===Vn(e,t))(e,o))Nn(e,l);else{const t=((e,t)=>{let o=0;for(const n of t){const t=An(e,n);t>o&&(o=t)}return o})(e,l);En(e,l,t)}return c(l),!0}return!1};let a=!1;for(const t of Un(e,g)){const n=Dn(e,t);if(o(e,t,n[0],[0,1])||o(e,t,n[1],[-1,0])||o(e,t,n[2],[0,-1])||o(e,t,n[3],[1,0])){a=!0;break}}if(a&&cn(e)===Q.ANY){const o=Bn(e,t)+1;hn(e,t,{d:p,ts:n,points:o}),u()}else hn(e,t,{d:p,ts:n}),u();a&&un(e)===ee.REAL&&gn(e)===dn(e)&&(mn(e,{finished:n}),r()),a&&l&&l(t)}}else hn(e,t,{d:p,ts:n}),u();s._last_mouse=i}else if(p===jt){const l=o[1],a=o[2];hn(e,t,{x:l,y:a,ts:n}),u(),s._last_mouse={x:l,y:a}}else if(p===Wt){const l=o[1],a=o[2];hn(e,t,{x:l,y:a,ts:n}),u(),s._last_mouse={x:l,y:a}}else hn(e,t,{ts:n}),u();return function(e,t,o){on[e].evtInfos[t]=o}(e,t,s),i}};let Ln=-10,Fn=20,jn=2,Wn=15;class Hn{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=Ln+Math.random()*Fn,this.vy=-1*(jn+Math.random()*Wn),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 o=0;o{this.resize()}))}setSpeedParams(){let e=0,t=0;for(;e=0;)t+=1,e+=t;jn=t/2,Wn=t-jn;const o=1/4*this.canvas.width/(t/2);Ln=-o,Fn=2*o}resize(){this.setSpeedParams()}init(){this.readyBombs=[],this.explodedBombs=[],this.particles=[];for(let e=0;e<1;e++)this.readyBombs.push(new Hn(this.rng))}update(){100*Math.random()<5&&this.readyBombs.push(new Hn(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 o=[];for(;this.particles.length>0;){const e=this.particles.shift();if(!e)break;e.update(),e.alive&&o.push(e)}this.particles=o}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{const t=e.color+" "+e.d;if(!y[t]){const o=e.d?r:d;if(e.color){const n=e.d?c:u;y[t]=await createImageBitmap(jo.colorizedCanvas(o,n,e.color))}else y[t]=o}return y[t]},v=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,el=!0})),t}(l,jo.createCanvas()),w={final:!1,log:[],logPointer:0,speeds:[.5,1,2,5,10,20,50,100,250,500],speedIdx:1,paused:!1,lastRealTs:0,lastGameTs:0,gameStartTs:0,skipNonActionPhases:!0,dataOffset:0};mo.onConnectionStateChange((e=>{a.setConnectionState(e)}));const b=async e=>{const t=w.dataOffset;w.dataOffset+=1e4;const o=await mo.requestReplayData(e,t);return w.log=w.log.slice(w.logPointer),w.logPointer=0,w.log.push(...o.log),0===o.log.length&&(w.final=!0),o};let x=()=>0;const C=async()=>{if("play"===n){const n=await mo.connect(o,e,t),l=se.decodeGame(n);$n.setGame(l.id,l),x=()=>N()}else{if("replay"!==n)throw"[ 2020-12-22 MODE invalid, must be play|replay ]";{const t=await b(e);if(!t.game)throw"[ 2021-05-29 no game received ]";const o=se.decodeGame(t.game);$n.setGame(o.id,o),w.lastRealTs=N(),w.gameStartTs=parseInt(t.log[0][4],10),w.lastGameTs=w.gameStartTs,x=()=>w.lastGameTs}}el=!0};await C();const k=$n.getPieceDrawOffset(e),A=$n.getPieceDrawSize(e),S=$n.getPuzzleWidth(e),P=$n.getPuzzleHeight(e),T=$n.getTableWidth(e),I=$n.getTableHeight(e),z={x:(T-S)/2,y:(I-P)/2},D={w:S,h:P},E={w:A,h:A},_=await tn.loadPuzzleBitmaps($n.getPuzzle(e)),V=new Yn(v,$n.getRng(e));V.init();const O=v.getContext("2d");v.classList.add("loaded");const U=Lo();U.move(-(T-v.width)/2,-(I-v.height)/2);const B=function(e,t,o,n){let l=[],a=!0,s=!1,i=!1,r=!1,d=!1,c=!1,u=!1,p=!1;const g=(e,t)=>{const n=o.viewportToWorld({x:e,y:t});return[n.x,n.y]},h=e=>g(e.offsetX,e.offsetY),m=()=>g(e.width/2,e.height/2),y=(e,t)=>{a&&("ShiftLeft"===t.code||"ShiftRight"===t.code?p=e:"ArrowUp"===t.code||"KeyW"===t.code?r=e:"ArrowDown"===t.code||"KeyS"===t.code?d=e:"ArrowLeft"===t.code||"KeyA"===t.code?s=e:"ArrowRight"===t.code||"KeyD"===t.code?i=e:"KeyQ"===t.code?u=e:"KeyE"===t.code&&(c=e))};let f=null;e.addEventListener("mousedown",(e=>{f=h(e),0===e.button&&v([$t,...f])})),e.addEventListener("mouseup",(e=>{f=h(e),0===e.button&&v([Lt,...f])})),e.addEventListener("mousemove",(e=>{f=h(e),v([Ft,...f])})),e.addEventListener("wheel",(e=>{if(f=h(e),o.canZoom(e.deltaY<0?"in":"out")){const t=e.deltaY<0?jt:Wt;v([t,...f])}})),t.addEventListener("keydown",(e=>y(!0,e))),t.addEventListener("keyup",(e=>y(!1,e))),t.addEventListener("keypress",(e=>{a&&("Space"===e.code&&v([qt]),"replay"===n&&("KeyI"===e.code&&v([Xt]),"KeyO"===e.code&&v([Jt]),"KeyP"===e.code&&v([Zt])),"KeyF"===e.code&&(Xn=!Xn,el=!0),"KeyG"===e.code&&(Jn=!Jn,el=!0),"KeyM"===e.code&&v([Qt]))}));const v=e=>{l.push(e)};return{addEvent:v,consumeAll:()=>{if(0===l.length)return[];const e=l.slice();return l=[],e},createKeyEvents:()=>{const e=(s?1:0)-(i?1:0),t=(r?1:0)-(d?1:0);if(0!==e||0!==t){const n=(p?24:12)*Math.sqrt(o.getCurrentZoom()),l=o.viewportDimToWorld({w:e*n,h:t*n});v([Gt,l.w,l.h]),f&&(f[0]-=l.w,f[1]-=l.h)}if(c&&u);else if(c){if(o.canZoom("in")){const e=f||m();v([jt,...e])}}else if(u&&o.canZoom("out")){const e=f||m();v([Wt,...e])}},setHotkeys:e=>{a=e}}}(v,window,U,n),R=$n.getImageUrl(e),G=()=>{const t=$n.getStartTs(e),o=$n.getFinishTs(e),n=x();a.setFinished(!!o),a.setDuration((o||n)-t)};G(),a.setPiecesDone($n.getFinishedPiecesCount(e)),a.setPiecesTotal($n.getPieceCount(e));const $=x();a.setActivePlayers($n.getActivePlayers(e,$)),a.setIdlePlayers($n.getIdlePlayers(e,$));const L=!!$n.getFinishTs(e);let F=L;const j=()=>F&&!L,W=()=>{const e=localStorage.getItem("sound_volume");if(null===e)return 100;const t=parseInt(e,10);return isNaN(t)?100:t},H=()=>{const e=localStorage.getItem("sound_enabled");return null!==e&&"1"===e},K=()=>{const e=W();i.volume=e/100,i.play()},Y=()=>"replay"===n?localStorage.getItem("bg_color")||"#222222":$n.getPlayerBgColor(e,t)||localStorage.getItem("bg_color")||"#222222",q=()=>"replay"===n?localStorage.getItem("player_color")||"#ffffff":$n.getPlayerColor(e,t)||localStorage.getItem("player_color")||"#ffffff";let Q="",Z="",X=!1;const J=e=>{X=e;const[t,o]=e?[Q,"grab"]:[Z,"default"];v.style.cursor=`url('${t}') ${g} ${m}, ${o}`},ee=e=>{Q=jo.colorizedCanvas(r,c,e).toDataURL(),Z=jo.colorizedCanvas(d,u,e).toDataURL(),J(X)};ee(q());const te=()=>{a.setReplaySpeed&&a.setReplaySpeed(w.speeds[w.speedIdx]),a.setReplayPaused&&a.setReplayPaused(w.paused)},oe=()=>{w.speedIdx+1{w.speedIdx>=1&&(w.speedIdx--,te())},le=()=>{w.paused=!w.paused,te()},ae=[];let ie;let re;if("play"===n?ae.push(setInterval((()=>{G()}),1e3)):"replay"===n&&te(),"play"===n)mo.onServerChange((o=>{o[0],o[1],o[2];const n=o[3];for(const[l,a]of n)switch(l){case oo:{const o=se.decodePlayer(a);o.id!==t&&($n.setPlayer(e,o.id,o),el=!0)}break;case to:{const t=se.decodePiece(a);$n.setPiece(e,t.idx,t),el=!0}break;case eo:$n.setPuzzleData(e,a),el=!0}F=!!$n.getFinishTs(e)}));else if("replay"===n){const t=(t,o)=>{const n=t;if(n[0]===Ut){const t=n[1];return $n.addPlayer(e,t,o),!0}if(n[0]===Bt){const t=$n.getPlayerIdByIndex(e,n[1]);if(!t)throw"[ 2021-05-17 player not found (update player) ]";return $n.addPlayer(e,t,o),!0}if(n[0]===Rt){const t=$n.getPlayerIdByIndex(e,n[1]);if(!t)throw"[ 2021-05-17 player not found (handle input) ]";const l=n[2];return $n.handleInput(e,t,l,o),!0}return!1};let o=w.lastGameTs;const n=async()=>{w.logPointer+1>=w.log.length&&await b(e);const l=N();if(w.paused)return w.lastRealTs=l,void(ie=setTimeout(n,50));const a=(l-w.lastRealTs)*w.speeds[w.speedIdx];let s=w.lastGameTs+a;for(;;){if(w.paused)break;const e=w.logPointer+1;if(e>=w.log.length)break;const n=w.log[w.logPointer],l=o+n[n.length-1],a=w.log[e],i=a[a.length-1],r=l+i;if(r>s){w.skipNonActionPhases&&s+500*M{let t=!1;const o=e.fps||60,n=e.slow||1,l=e.update,a=e.render,s=window.requestAnimationFrame,i=1/o,r=n*i;let d,c=0,u=window.performance.now();const p=()=>{for(d=window.performance.now(),c+=Math.min(1,(d-u)/1e3);c>r;)c-=r,l(i);a(c/n),u=d,t||s(p)};return s(p),{stop:()=>{t=!0}}})({update:()=>{B.createKeyEvents();for(const o of B.consumeAll())if("play"===n){const n=o[0];if(n===Gt){const e=o[1],t=o[2],n=U.worldDimToViewport({w:e,h:t});el=!0,U.move(n.w,n.h)}else if(n===Ft){if(de&&!$n.getFirstOwnedPiece(e,t)){const e={x:o[1],y:o[2]},t=U.worldToViewport(e),n=Math.round(t.x-de.x),l=Math.round(t.y-de.y);el=!0,U.move(n,l),de=t}}else if(n===Kt)ee(o[1]);else if(n===$t){const e={x:o[1],y:o[2]};de=U.worldToViewport(e),J(!0)}else if(n===Lt)de=null,J(!1);else if(n===jt){const e={x:o[1],y:o[2]};el=!0,U.zoom("in",U.worldToViewport(e))}else if(n===Wt){const e={x:o[1],y:o[2]};el=!0,U.zoom("out",U.worldToViewport(e))}else n===qt?a.togglePreview():n===Qt&&a.toggleSoundsEnabled();const l=x();$n.handleInput(e,t,o,l,(e=>{H()&&K()})).length>0&&(el=!0),mo.sendClientEvent(o)}else if("replay"===n){const e=o[0];if(e===Zt)le();else if(e===Jt)ne();else if(e===Xt)oe();else if(e===Gt){const e=o[1],t=o[2];el=!0,U.move(e,t)}else if(e===Ft){if(de){const e={x:o[1],y:o[2]},t=U.worldToViewport(e),n=Math.round(t.x-de.x),l=Math.round(t.y-de.y);el=!0,U.move(n,l),de=t}}else if(e===Kt)ee(o[1]);else if(e===$t){const e={x:o[1],y:o[2]};de=U.worldToViewport(e),J(!0)}else if(e===Lt)de=null,J(!1);else if(e===jt){const e={x:o[1],y:o[2]};el=!0,U.zoom("in",U.worldToViewport(e))}else if(e===Wt){const e={x:o[1],y:o[2]};el=!0,U.zoom("out",U.worldToViewport(e))}else e===qt&&a.togglePreview()}F=!!$n.getFinishTs(e),j()&&(V.update(),el=!0)},render:async()=>{if(!el)return;const o=x();let l,s,i;window.DEBUG&&Yo(0),O.fillStyle=Y(),O.fillRect(0,0,v.width,v.height),window.DEBUG&&qo("clear done"),l=U.worldToViewportRaw(z),s=U.worldDimToViewportRaw(D),O.fillStyle="rgba(255, 255, 255, .3)",O.fillRect(l.x,l.y,s.w,s.h),window.DEBUG&&qo("board done");const r=$n.getPiecesSortedByZIndex(e);window.DEBUG&&qo("get tiles done"),s=U.worldDimToViewportRaw(E);for(const e of r)(-1===e.owner?Xn:Jn)&&(i=_[e.idx],l=U.worldToViewportRaw({x:k+e.pos.x,y:k+e.pos.y}),O.drawImage(i,0,0,i.width,i.height,l.x,l.y,s.w,s.h));window.DEBUG&&qo("tiles done");const d=[];for(const a of $n.getActivePlayers(e,o))c=a,("replay"===n||c.id!==t)&&(i=await f(a),l=U.worldToViewport(a),O.drawImage(i,l.x-g,l.y-m),d.push([`${a.name} (${a.points})`,l.x,l.y+h]));var c;O.fillStyle="white",O.textAlign="center";for(const[e,t,n]of d)O.fillText(e,t,n);window.DEBUG&&qo("players done"),a.setActivePlayers($n.getActivePlayers(e,o)),a.setIdlePlayers($n.getIdlePlayers(e,o)),a.setPiecesDone($n.getFinishedPiecesCount(e)),window.DEBUG&&qo("HUD done"),j()&&V.render(),el=!1}}),{setHotkeys:e=>{B.setHotkeys(e)},onBgChange:e=>{localStorage.setItem("bg_color",e),B.addEvent([Ht,e])},onColorChange:e=>{localStorage.setItem("player_color",e),B.addEvent([Kt,e])},onNameChange:e=>{localStorage.setItem("player_name",e),B.addEvent([Yt,e])},onSoundsEnabledChange:e=>{localStorage.setItem("sound_enabled",e?"1":"0")},onSoundsVolumeChange:e=>{qn.info("vol changed",e),localStorage.setItem("sound_volume",`${e}`),K()},replayOnSpeedUp:oe,replayOnSpeedDown:ne,replayOnPauseToggle:le,replayOnSkipToggle:()=>{w.skipNonActionPhases=!w.skipNonActionPhases},previewImageUrl:R,player:{background:Y(),color:q(),name:"replay"===n?localStorage.getItem("player_name")||"#ffffff":$n.getPlayerName(e,t)||localStorage.getItem("player_name")||"anon",soundsEnabled:H(),soundsVolume:W()},disconnect:mo.disconnect,connect:C,unload:()=>{ae.forEach((e=>{clearInterval(e)})),ie&&clearTimeout(ie),re&&re.stop()}}}var ol=e({name:"game",components:{PuzzleStatus:bt,Scores:mt,SettingsOverlay:Ct,PreviewOverlay:Et,ConnectionOverlay:yo,HelpOverlay:Co},data:()=>({activePlayers:[],idlePlayers:[],finished:!1,duration:0,piecesDone:0,piecesTotal:0,overlay:"",connectionState:0,g:{player:{background:"",color:"",name:"",soundsEnabled:!1,soundsVolume:100},previewImageUrl:"",setHotkeys:e=>{},onBgChange:e=>{},onColorChange:e=>{},onNameChange:e=>{},onSoundsEnabledChange:e=>{},onSoundsVolumeChange:e=>{},connect:()=>{},disconnect:()=>{},unload:()=>{}}}),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.$watch((()=>this.g.player.soundsEnabled),(e=>{this.g.onSoundsEnabledChange(e)})),this.$watch((()=>this.g.player.soundsVolume),(e=>{this.g.onSoundsVolumeChange(e)})),this.g=await tl(`${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},togglePreview:()=>{this.toggle("preview",!1)},setConnectionState:e=>{this.connectionState=e},toggleSoundsEnabled:()=>{this.g.player.soundsEnabled=!this.g.player.soundsEnabled}}))},unmounted(){this.g.unload(),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 nl={id:"game"},ll={class:"menu"},al={class:"tabs"},sl=i("🧩 Puzzles");ol.render=function(e,l,i,r,d,c){const u=a("settings-overlay"),g=a("preview-overlay"),h=a("help-overlay"),m=a("connection-overlay"),y=a("puzzle-status"),f=a("router-link"),v=a("scores");return s(),t("div",nl,[p(o(u,{onBgclick:l[1]||(l[1]=t=>e.toggle("settings",!0)),modelValue:e.g.player,"onUpdate:modelValue":l[2]||(l[2]=t=>e.g.player=t)},null,8,["modelValue"]),[[C,"settings"===e.overlay]]),p(o(g,{onBgclick:l[3]||(l[3]=t=>e.toggle("preview",!1)),img:e.g.previewImageUrl},null,8,["img"]),[[C,"preview"===e.overlay]]),p(o(h,{onBgclick:l[4]||(l[4]=t=>e.toggle("help",!0))},null,512),[[C,"help"===e.overlay]]),o(m,{connectionState:e.connectionState,onReconnect:e.reconnect},null,8,["connectionState","onReconnect"]),o(y,{finished:e.finished,duration:e.duration,piecesDone:e.piecesDone,piecesTotal:e.piecesTotal},null,8,["finished","duration","piecesDone","piecesTotal"]),o("div",ll,[o("div",al,[o(f,{class:"opener",to:{name:"index"},target:"_blank"},{default:n((()=>[sl])),_:1}),o("div",{class:"opener",onClick:l[5]||(l[5]=t=>e.toggle("preview",!1))},"πŸ–ΌοΈ Preview"),o("div",{class:"opener",onClick:l[6]||(l[6]=t=>e.toggle("settings",!0))},"πŸ› οΈ Settings"),o("div",{class:"opener",onClick:l[7]||(l[7]=t=>e.toggle("help",!0))},"ℹ️ Help")])]),o(v,{activePlayers:e.activePlayers,idlePlayers:e.idlePlayers},null,8,["activePlayers","idlePlayers"])])};var il=e({name:"replay",components:{PuzzleStatus:bt,Scores:mt,SettingsOverlay:Ct,PreviewOverlay:Et,HelpOverlay:Co},data:()=>({activePlayers:[],idlePlayers:[],finished:!1,duration:0,piecesDone:0,piecesTotal:0,skipNoAction:!0,overlay:"",connectionState:0,g:{player:{background:"",color:"",name:"",soundsEnabled:!1,soundsVolume:100},previewImageUrl:"",setHotkeys:e=>{},onBgChange:e=>{},onColorChange:e=>{},onNameChange:e=>{},onSoundsEnabledChange:e=>{},onSoundsVolumeChange:e=>{},replayOnSpeedUp:()=>{},replayOnSpeedDown:()=>{},replayOnPauseToggle:()=>{},replayOnSkipToggle:()=>{},connect:()=>{},disconnect:()=>{},unload:()=>{}},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.$watch((()=>this.g.player.soundsEnabled),(e=>{this.g.onSoundsEnabledChange(e)})),this.$watch((()=>this.g.player.soundsVolume),(e=>{this.g.onSoundsVolumeChange(e)})),this.g=await tl(`${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},toggleSoundsEnabled:()=>{this.g.player.soundsEnabled=!this.g.player.soundsEnabled}}))},unmounted(){this.g.unload(),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 rl={id:"replay"},dl=i("Skip no action phases: "),cl={class:"menu"},ul={class:"tabs"},pl=i("🧩 Puzzles");il.render=function(e,l,i,d,c,u){const g=a("settings-overlay"),h=a("preview-overlay"),m=a("help-overlay"),y=a("puzzle-status"),f=a("router-link"),v=a("scores");return s(),t("div",rl,[p(o(g,{onBgclick:l[1]||(l[1]=t=>e.toggle("settings",!0)),modelValue:e.g.player,"onUpdate:modelValue":l[2]||(l[2]=t=>e.g.player=t)},null,8,["modelValue"]),[[C,"settings"===e.overlay]]),p(o(h,{onBgclick:l[3]||(l[3]=t=>e.toggle("preview",!1)),img:e.g.previewImageUrl},null,8,["img"]),[[C,"preview"===e.overlay]]),p(o(m,{onBgclick:l[4]||(l[4]=t=>e.toggle("help",!0))},null,512),[[C,"help"===e.overlay]]),o(y,{finished:e.finished,duration:e.duration,piecesDone:e.piecesDone,piecesTotal:e.piecesTotal},{default:n((()=>[o("div",null,[o("div",null,r(e.replayText),1),o("div",null,[o("label",null,[dl,p(o("input",{type:"checkbox","onUpdate:modelValue":l[5]||(l[5]=t=>e.skipNoAction=t),onChange:l[6]||(l[6]=t=>e.g.replayOnSkipToggle())},null,544),[[x,e.skipNoAction]])])]),o("button",{class:"btn",onClick:l[7]||(l[7]=t=>e.g.replayOnSpeedUp())},"⏫"),o("button",{class:"btn",onClick:l[8]||(l[8]=t=>e.g.replayOnSpeedDown())},"⏬"),o("button",{class:"btn",onClick:l[9]||(l[9]=t=>e.g.replayOnPauseToggle())},"⏸️")])])),_:1},8,["finished","duration","piecesDone","piecesTotal"]),o("div",cl,[o("div",ul,[o(f,{class:"opener",to:{name:"index"},target:"_blank"},{default:n((()=>[pl])),_:1}),o("div",{class:"opener",onClick:l[10]||(l[10]=t=>e.toggle("preview",!1))},"πŸ–ΌοΈ Preview"),o("div",{class:"opener",onClick:l[11]||(l[11]=t=>e.toggle("settings",!0))},"πŸ› οΈ Settings"),o("div",{class:"opener",onClick:l[12]||(l[12]=t=>e.toggle("help",!0))},"ℹ️ Help")])]),o(v,{activePlayers:e.activePlayers,idlePlayers:e.idlePlayers},null,8,["activePlayers","idlePlayers"])])},(async()=>{const e=await fetch("/api/conf"),t=await e.json();const o=k({history:A(),routes:[{name:"index",path:"/",component:j},{name:"new-game",path:"/new-game",component:at},{name:"game",path:"/g/:id",component:ol},{name:"replay",path:"/replay/:id",component:il}]});o.beforeEach(((e,t)=>{t.name&&document.documentElement.classList.remove(`view-${String(t.name)}`),document.documentElement.classList.add(`view-${String(e.name)}`)}));const n=S(P);n.config.globalProperties.$config=t,n.config.globalProperties.$clientId=function(){let e=localStorage.getItem("ID");return e||(e=se.uniqId(),localStorage.setItem("ID",e)),e}(),n.use(o),n.mount("#app")})(); diff --git a/build/public/index.html b/build/public/index.html index 39701ad..15064ca 100644 --- a/build/public/index.html +++ b/build/public/index.html @@ -4,7 +4,7 @@ 🧩 jigsaw.hyottoko.club - + diff --git a/src/frontend/components/NewImageDialog.vue b/src/frontend/components/NewImageDialog.vue index 976b7b5..0666f46 100644 --- a/src/frontend/components/NewImageDialog.vue +++ b/src/frontend/components/NewImageDialog.vue @@ -49,10 +49,21 @@ gallery", if possible!
- - + +
- @@ -75,6 +86,12 @@ export default defineComponent({ autocompleteTags: { type: Function, }, + uploadProgress: { + type: Number, + }, + uploading: { + type: String, + }, }, emits: { bgclick: null, @@ -91,10 +108,19 @@ export default defineComponent({ } }, computed: { + uploadProgressPercent (): number { + return this.uploadProgress ? Math.round(this.uploadProgress * 100) : 0 + }, canPostToGallery (): boolean { + if (this.uploading) { + return false + } return !!(this.previewUrl && this.file) }, canSetupGameClick (): boolean { + if (this.uploading) { + return false + } return !!(this.previewUrl && this.file) }, }, diff --git a/src/frontend/views/NewGame.vue b/src/frontend/views/NewGame.vue index fe30443..0b1f0cb 100644 --- a/src/frontend/views/NewGame.vue +++ b/src/frontend/views/NewGame.vue @@ -44,8 +44,11 @@ in jigsawpuzzles.io v-if="dialog==='new-image'" :autocompleteTags="autocompleteTags" @bgclick="dialog=''" + :uploadProgress="uploadProgress" + :uploading="uploading" @postToGalleryClick="postToGalleryClick" - @setupGameClick="setupGameClick" /> + @setupGameClick="setupGameClick" + />