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

60 lines
1.8 KiB
Vue
Raw Normal View History

2022-07-01 01:27:18 +00:00
<template>
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>
import { ref } from 'vue';
import { HotTable, HotColumn } from '@handsontable/vue3';
2022-07-01 01:27:18 +00:00
2022-07-03 15:50:41 +00:00
const {invs, activeTable, columns, tags, dirty} = useStoreRef()
2022-07-03 10:25:12 +00:00
const hotTableComponent = ref<any>(null)
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,
accounts: Array.from(invs.value.keys()),
} as InventoryTableOptions)
2022-07-03 10:25:12 +00:00
const hot = (hotTableComponent.value.hotInstance as Handsontable)
const build = it.BuildTable()
hot.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-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], () => {
log.debug(`${dirty.value} rendering inventory`, activeTable.value)
let u = updateTable()
if(u != undefined){
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';
import { TricksterItem, SampleData } from '../lib/trickster';
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';
import { LTOApi, LTOApiv0 } from '../lib/lifeto';
2022-07-03 15:50:41 +00:00
import log from 'loglevel';
2022-07-03 10:25:12 +00:00
</script>
<style src="handsontable/dist/handsontable.full.css">
</style>