2 lines
8.0 KiB
JavaScript
2 lines
8.0 KiB
JavaScript
import{C as u,s as p}from"./CalcPreviewItem-D129i7Vp.js";import{n as f,U as h}from"./index-DDNMzpZj.js";import{C as g}from"./Checkbox-Dc2UYqO9.js";import{D as _}from"./Dropdown-Cks-nQIq.js";import{C as v}from"./CalcPreviewList-DA8bWgJp.js";class F{constructor(t,s){this.name=t,this.element=s}}const I=Object.freeze({fire:"fire",water:"water",earth:"earth",wind:"wind",light:"light",dark:"dark"});let q=class{constructor(t,s){this.name=t,this.items=s}};class x{constructor(t){this.from=-1,this.to=0,this.fold=!1,this.materials=Array.from({length:t},s=>({}))}}const d=(e,t)=>e.category===t.category?e.max>t.max:e.category>t.category;class m{constructor(t,s){this.name=t,this.items=s}}const C={components:{Checkbox:g,Dropdown:_,CalcPreviewItem:u,CalcPreviewList:v},props:{unitsProgress:{type:Object,required:!0},unitsData:{type:Object,required:!0},unitsLabel:{type:String,required:!0},unitsSplitMats:{type:Boolean,required:!0},unitsHideCompletedMats:{type:Boolean,required:!0},unitsDisplayList:{type:Number,default:0}},data(){return{unit_index:-1}},methods:{addUnit(){this.$set(this.progress,this.unit_index,new x(this.unitsData.materials.length)),this.unit_index=-1},removeUnit(e){this.$delete(this.progress,e)},getItemProgressFor(e,t,s){let a=[];if(t.item)a.push(t.item);else if(t.group)switch(p.groups[t.group].type){case"element":{const r=p.groups[t.group][this.unitsData.units[e].element];r instanceof Array?a=r:a.push(r)}break;case"summon":{const r=p.groups[t.group][e];r instanceof Array?a=r:a.push(r)}break}else console.log("Unknown type of item for:"),console.log(t);let o=[];for(let r of a){this.progress[e].materials[s][r]===void 0&&this.$set(this.progress[e].materials[s],r,0);let i=t.q/a.length;t.q%a.length>0&&(i<5?i=Math.ceil(i):i=Math.floor(i)),p.items[r]===void 0&&console.log(r+" does not exist."),o.push({item:r,group:t.group,name:p.items[r].name,category:p.items[r].category,max:i,animated:p.items[r].animated})}return o},getMaterialsFor(e){const t=[];for(;this.unitsData.materials.length>this.progress[e].materials.length;)this.progress[e].materials.push({});if(this.splitMats)this.unitsData.materials.slice(this.progress[e].from+1,this.progress[e].to+1).forEach((s,a)=>{t.push(new m(s.name,Object.values(s.items.flatMap(o=>this.getItemProgressFor(e,o,a+this.progress[e].from+1)).reduce((o,r)=>(o.hasOwnProperty(r.item)?o[r.item].max+=r.max:o[r.item]=r,o),{})).sort(d)))});else{const s={};this.unitsData.materials.slice(this.progress[e].from+1,this.progress[e].to+1).forEach((a,o)=>{a.items.flatMap(r=>this.getItemProgressFor(e,r,o+this.progress[e].from+1)).forEach(r=>{s.hasOwnProperty(r.item)?s[r.item].max+=r.max:s[r.item]=r})}),t.push(new m("Materials",Object.values(s))),t[0].items.sort(d)}return t},selectFromStep(e){this.$nextTick().then(()=>{this.progress[e].from>=this.progress[e].to&&(this.progress[e].to=this.progress[e].from+1)})},filterCompletedItems(e,t,s){return this.hideCompletedMats?s.filter(a=>this.getQuantityForItem(e,t,a.item)<a.max):s},toggleFolded(e){this.$set(e,"fold",!e.fold)},getQuantityForItem(e,t,s){return this.splitMats?this.progress[e].materials[t+this.progress[e].from+1][s]:this.progress[e].materials.slice(t+this.progress[e].from+1,t+this.progress[e].to+1).reduce((a,o)=>o.hasOwnProperty(s)?a+o[s]:a,0)},setQuantityForItem(e,t,s,a){if(this.splitMats)this.progress[e].materials[t+this.progress[e].from+1][s.item]=a;else{let o=a;this.progress[e].materials.slice(t+this.progress[e].from+1,t+this.progress[e].to+1).forEach((r,i)=>{if(r.hasOwnProperty(s.item)){const n=this.unitsData.materials[t+this.progress[e].from+i+1].items.find(l=>l.item?l.item==s.item:l.group==s.group);if(n){const l=n.q,c=Math.min(o,l);this.progress[e].materials[t+this.progress[e].from+i+1][s.item]=c,o-=c}}})}}},computed:{getUnitToAdd(){return h.filterObject(this.unitsData.units,([e,t])=>!this.progress.hasOwnProperty(e))},getUnits(){return this.unitsData.units},getUnitsMaterials(){return this.unitsData.materials},localQuantity:{get(){return this.quantity},set(e){this.$emit("update:quantity",e)}},progress:{get(){return this.unitsProgress},set(e){this.$emit("update:unitsProgress",e)}},splitMats:{get(){return this.unitsSplitMats},set(e){this.$emit("update:unitsSplitMats",e)}},hideCompletedMats:{get(){return this.unitsHideCompletedMats},set(e){this.$emit("update:unitsHideCompletedMats",e)}},displayList:{get(){return this.unitsDisplayList},set(e){this.$emit("update:unitsDisplayList",e)}}}};var b=function(){var t=this,s=t._self._c;return s("div",{staticClass:"flex flex-col items-center lg:w-3/4"},[s("div",{staticClass:"flex flex-row flex-wrap gap-4 items-center"},[s("span",[Object.keys(t.getUnitToAdd).length>0?s("dropdown",{model:{value:t.unit_index,callback:function(a){t.unit_index=t._n(a)},expression:"unit_index"}},[s("option",{attrs:{disabled:"",hidden:""},domProps:{value:-1}},[t._v("--- Select "+t._s(t.unitsLabel)+" ---")]),t._l(t.getUnitToAdd,function(a,o){return s("option",{key:a.summon,domProps:{value:o}},[t._v(" "+t._s(a.name)+" ")])})],2):t._e(),Object.keys(t.getUnitToAdd).length>0?s("button",{staticClass:"btn btn-blue",attrs:{disabled:t.unit_index<0},on:{click:function(a){return t.addUnit()}}},[t._v(" Add ")]):t._e()],1),s("checkbox",{model:{value:t.splitMats,callback:function(a){t.splitMats=a},expression:"splitMats"}},[t._v("Split materials for each step")]),s("checkbox",{model:{value:t.hideCompletedMats,callback:function(a){t.hideCompletedMats=a},expression:"hideCompletedMats"}},[t._v("Hide completed materials")]),s("label",[t._v("Display: "),s("dropdown",{model:{value:t.displayList,callback:function(a){t.displayList=t._n(a)},expression:"displayList"}},[s("option",{domProps:{value:0}},[t._v("Grid")]),s("option",{domProps:{value:1}},[t._v("List")])])],1)],1),t._l(t.progress,function(a,o){return s("div",{key:o,staticClass:"flex flex-col mt-8 border-4 border-secondary rounded p-1 lg:p-4 bg-tertiary w-full"},[s("span",{staticClass:"flex flex-row justify-between text-3xl font-bold"},[s("div"),s("a",{staticClass:"cursor-pointer",on:{click:function(r){return t.toggleFolded(t.progress[o])}}},[t._v(" "+t._s(t.getUnits[o].name)+" "),t.progress[o].fold?s("fa-icon",{staticClass:"ml-2",attrs:{icon:["fas","angle-right"]}}):s("fa-icon",{staticClass:"ml-2",attrs:{icon:["fas","angle-down"]}})],1),s("a",{staticClass:"cursor-pointer",attrs:{title:"Remove"},on:{click:function(r){return t.removeUnit(o)}}},[s("fa-icon",{staticClass:"ml-2",attrs:{icon:["fas","trash"]}})],1)]),t.progress[o].fold?t._e():s("span",{staticClass:"flex flex-col mt-6"},[s("div",{staticClass:"flex flex-row flex-wrap self-center items-center gap-2"},[s("span",[t._v("Completed step")]),s("dropdown",{on:{change:function(r){return t.selectFromStep(o)}},model:{value:t.progress[o].from,callback:function(r){t.$set(t.progress[o],"from",t._n(r))},expression:"progress[unitKey].from"}},[s("option",{domProps:{value:-1}},[t._v("-- Nothing --")]),t._l(t.getUnitsMaterials.slice(0,-1),function(r,i){return s("option",{key:r.name,domProps:{value:i}},[t._v(" "+t._s(r.name)+" ")])})],2),s("span",[t._v("Target step")]),s("dropdown",{model:{value:t.progress[o].to,callback:function(r){t.$set(t.progress[o],"to",t._n(r))},expression:"progress[unitKey].to"}},t._l(t.getUnitsMaterials,function(r,i){return s("option",{key:r.name,attrs:{disabled:t.progress[o].from>=i},domProps:{value:i}},[t._v(" "+t._s(r.name)+" ")])}),0)],1),t._l(t.getMaterialsFor(o),function(r,i){return s("div",{key:i},[s("h2",{staticClass:"my-4"},[t._v(t._s(r.name))]),t.displayList==0?s("div",{staticClass:"flex flex-row flex-wrap gap-1"},t._l(t.filterCompletedItems(o,i,r.items),function(n,l){return s("calc-preview-item",{key:l,staticClass:"border-secondary border rounded",attrs:{tag:n.item,name:n.name,quantity:t.getQuantityForItem(o,i,n.item),max:n.max,animated:n.animated},on:{"update:quantity":c=>t.setQuantityForItem(o,i,n,c)}})}),1):s("div",{staticClass:"flex flex-col"},t._l(t.filterCompletedItems(o,i,r.items),function(n,l){return s("calc-preview-list",{key:l,attrs:{tag:n.item,name:n.name,quantity:t.getQuantityForItem(o,i,n.item),max:n.max,animated:n.animated},on:{"update:quantity":c=>t.setQuantityForItem(o,i,n,c)}})}),1)])})],2)])})],2)},w=[],M=f(C,b,w,!1,null,null);const L=M.exports;export{L as C,I as E,q as M,F as U};
|