1
0
forked from a/lifeto-shop
lifeto-shop/src/components/CharacterInventory.vue

125 lines
3.5 KiB
Vue
Raw Normal View History

2022-07-01 01:27:18 +00:00
<template>
2022-07-07 07:54:36 +00:00
<button
type="button"
id="logoutButton"
v-on:click="send_orders()"
>ayy lmao button</button>
2022-07-03 10:25:12 +00:00
<HotTable
2022-07-01 01:27:18 +00:00
ref="hotTableComponent"
2022-07-03 10:25:12 +00:00
:settings="DefaultSettings()"
></HotTable>
2022-07-01 01:27:18 +00:00
</template>
2022-07-03 10:25:12 +00:00
<script lang="ts" setup>
2022-07-07 07:54:36 +00:00
import { onMounted, ref } from 'vue';
2022-07-03 10:25:12 +00:00
import { HotTable, HotColumn } from '@handsontable/vue3';
2022-07-01 01:27:18 +00:00
2022-07-07 07:54:36 +00:00
const storeRefs = useStoreRef()
const {invs, activeTable, columns, tags, dirty, chars, currentSearch, orders} = storeRefs
2022-07-03 10:25:12 +00:00
const hotTableComponent = ref<any>(null)
2022-07-07 07:54:36 +00:00
const hott = ():Handsontable =>{
return hotTableComponent.value.hotInstance as any
}
const session = storage.GetSession()
const api:LTOApi = getLTOState(LTOApiv0, session, useStoreRef())
const manager = new OrderSender(storeRefs)
2022-07-03 10:25:12 +00:00
2022-07-03 15:50:41 +00:00
const updateTable = ():TableRecipe | undefined => {
2022-07-03 10:25:12 +00:00
if (invs.value.has(activeTable.value)) {
const chardat = invs.value.get(activeTable.value)
if (chardat) {
2022-07-03 17:05:59 +00:00
const it = new InventoryTable(chardat, {
columns: columns.value,
tags: tags.value,
2022-07-07 07:54:36 +00:00
accounts: Array.from(chars.value.keys()),
2022-07-03 17:05:59 +00:00
} as InventoryTableOptions)
2022-07-03 10:25:12 +00:00
const build = it.BuildTable()
2022-07-07 07:54:36 +00:00
hott().updateSettings(build.settings)
2022-07-03 15:50:41 +00:00
return build
2022-07-03 10:25:12 +00:00
}
}
2022-07-03 15:50:41 +00:00
return undefined
2022-07-03 10:25:12 +00:00
}
2022-07-07 07:54:36 +00:00
watch(currentSearch, ()=>{
filterTable()
})
const send_orders = () => {
if(hott()) {
const headers = hott().getColHeader()
const dat = hott().getData()
const idxNumber = headers.indexOf(Columns.MoveCount.displayName)
const idxTarget = headers.indexOf(Columns.Move.displayName)
const origin = activeTable
const pending:OrderDetails[] = [];
for(const row of dat) {
const nm = Number(row[idxNumber].replace("x",""))
const target = (row[idxTarget] as string).replaceAll("-","").trim()
if(!isNaN(nm) && nm > 0 && target.length > 0){
const info:OrderDetails = {
item_uid: row[0].toString(),
count: nm,
origin_path: origin.value,
target_path: target,
}
pending.push(info)
}
}
log.debug("OrderDetails", pending)
for(const d of pending){
const order = manager.send(d)
order.tick(storeRefs, api)
}
saveStore();
}
}
onMounted(()=>{
window.setInterval(tick_orders, 1000)
})
const tick_orders = () => {
if(orders && storeRefs && api){
orders.value.tick(storeRefs, api)
}
}
const filterTable = () => {
if(hott()){
const fp = hott().getPlugin('filters')
fp.removeConditions(2)
fp.addCondition(2,'contains', [currentSearch.value])
fp.filter()
}
}
2022-07-01 01:27:18 +00:00
// register Handsontable's modules
registerAllModules();
2022-07-03 15:50:41 +00:00
watch([columns.value.dirty, tags.value.dirty, activeTable, dirty], () => {
2022-07-07 07:54:36 +00:00
log.debug(`${dirty.value} rendering inventory`, activeTable.value)
2022-07-03 15:50:41 +00:00
let u = updateTable()
2022-07-07 07:54:36 +00:00
saveStore()
2022-07-03 10:25:12 +00:00
})
2022-07-01 01:27:18 +00:00
</script>
2022-07-03 10:25:12 +00:00
<script lang="ts">
import { defineComponent, computed, PropType, defineProps, defineEmits, watch} from 'vue';
import { registerAllModules } from 'handsontable/registry';
2022-07-03 17:05:59 +00:00
import { DefaultSettings, InventoryTable, InventoryTableOptions, TableRecipe } from '../lib/table';
2022-07-03 10:25:12 +00:00
import { Columns, ColumnByNames, ColumnInfo } from '../lib/columns';
2022-07-07 07:54:36 +00:00
import { TricksterItem} from '../lib/trickster';
2022-07-03 10:25:12 +00:00
import Handsontable from 'handsontable';
2022-07-03 15:50:41 +00:00
import { useStoreRef, saveStore } from '../state/state';
2022-07-03 10:25:12 +00:00
import { storage } from '../session_storage';
2022-07-07 07:54:36 +00:00
import { getLTOState, LTOApi, LTOApiv0 } from '../lib/lifeto';
import log, { info } from 'loglevel';
import { OrderDetails, OrderSender } from '../lib/lifeto/order_manager';
2022-07-03 10:25:12 +00:00
</script>
<style src="handsontable/dist/handsontable.full.css">
</style>