This commit is contained in:
a 2022-07-03 11:37:06 -05:00
parent e70d407ccb
commit b8e9c94166
5 changed files with 41 additions and 11 deletions

View File

@ -20,7 +20,6 @@ const updateTable = ():TableRecipe | undefined => {
const hot = (hotTableComponent.value.hotInstance as Handsontable) const hot = (hotTableComponent.value.hotInstance as Handsontable)
const build = it.BuildTable() const build = it.BuildTable()
hot.updateSettings(build.settings) hot.updateSettings(build.settings)
hot.updateData(build.data)
return build return build
} }
} }

View File

@ -3,6 +3,7 @@ import numbro from 'numbro';
import { textRenderer } from "handsontable/renderers" import { textRenderer } from "handsontable/renderers"
import { TricksterInventory, TricksterItem } from "./trickster" import { TricksterInventory, TricksterItem } from "./trickster"
import Core from "handsontable/core"; import Core from "handsontable/core";
import { RefStore } from "../state/state";
export const BasicColumns = [ export const BasicColumns = [
@ -52,6 +53,7 @@ const c = (a:ColumnName | ColumnInfo):ColumnName => {
} }
} }
export const LazyColumn = c; export const LazyColumn = c;
export const ColumnSorter = (a:ColumnName | ColumnInfo, b: ColumnName | ColumnInfo):number => { export const ColumnSorter = (a:ColumnName | ColumnInfo, b: ColumnName | ColumnInfo):number => {
let n1 = ColumnNames.indexOf(c(a)) let n1 = ColumnNames.indexOf(c(a))
let n2 = ColumnNames.indexOf(c(b)) let n2 = ColumnNames.indexOf(c(b))
@ -64,6 +66,8 @@ export const ColumnSorter = (a:ColumnName | ColumnInfo, b: ColumnName | ColumnI
export interface ColumnInfo { export interface ColumnInfo {
name: ColumnName name: ColumnName
displayName:string displayName:string
options?:(item:TricksterItem, r:RefStore)=>string[]
renderer?:any renderer?:any
filtering?:boolean filtering?:boolean
writable?:boolean writable?:boolean
@ -97,10 +101,28 @@ class Name implements ColumnInfo {
name:ColumnName = "Name" name:ColumnName = "Name"
displayName = "Name" displayName = "Name"
filtering = true filtering = true
renderer = nameRenderer
getter(item:TricksterItem):(string|number){ getter(item:TricksterItem):(string|number){
return item.item_name return item.item_name
} }
} }
function nameRenderer(instance:any, td:any, row:any, col:any, prop:any, value:any, cellProperties:any) {
const stringifiedValue = Handsontable.helper.stringify(value);
let showText = stringifiedValue;
const div= document.createElement('div');
div.innerHTML = showText
div.title = showText
div.style.maxWidth = "20ch"
div.style.textOverflow = "ellipsis"
div.style.overflow= "hidden"
div.style.whiteSpace= "nowrap"
Handsontable.dom.addEvent(div, 'mousedown', event =>{
event!.preventDefault();
});
Handsontable.dom.empty(td);
td.appendChild(div);
td.classList.add("htLeft")
}
class Count implements ColumnInfo { class Count implements ColumnInfo {
name:ColumnName = "Count" name:ColumnName = "Count"
@ -116,11 +138,23 @@ class Move implements ColumnInfo {
name:ColumnName = "Move" name:ColumnName = "Move"
displayName = "Target" displayName = "Target"
writable = true writable = true
options = getMoveTargets
getter(item:TricksterItem):(string|number){ getter(item:TricksterItem):(string|number){
return "-" return "-"
} }
} }
const getMoveTargets = (item:TricksterItem, r:RefStore):string[] => {
let out:string[] = [];
for(const k of r.invs.value.keys()) {
out.push(k)
}
out.push("")
out.push("")
out.push("!TRASH")
return out
}
class MoveCount implements ColumnInfo { class MoveCount implements ColumnInfo {
name:ColumnName = "MoveCount" name:ColumnName = "MoveCount"
displayName = "Move #" displayName = "Move #"
@ -140,7 +174,6 @@ function moveCountRenderer(instance:Core, td:any, row:number, col:number, prop:a
const cellFormatPattern = numericFormat && numericFormat.pattern; const cellFormatPattern = numericFormat && numericFormat.pattern;
const className = cellProperties.className || ''; const className = cellProperties.className || '';
const classArr = className.length ? className.split(' ') : []; const classArr = className.length ? className.split(' ') : [];
if (typeof cellCulture !== 'undefined' && !numbro.languages()[cellCulture]) { if (typeof cellCulture !== 'undefined' && !numbro.languages()[cellCulture]) {
const shortTag:any = cellCulture.replace('-', ''); const shortTag:any = cellCulture.replace('-', '');
const langData = (numbro as any)[shortTag]; const langData = (numbro as any)[shortTag];
@ -149,7 +182,6 @@ function moveCountRenderer(instance:Core, td:any, row:number, col:number, prop:a
numbro.registerLanguage(langData); numbro.registerLanguage(langData);
} }
} }
const totalCount = Number(instance.getCell(row,col-1)?.innerHTML) const totalCount = Number(instance.getCell(row,col-1)?.innerHTML)
numbro.setLanguage(cellCulture); numbro.setLanguage(cellCulture);
const num = numbro(newValue) const num = numbro(newValue)
@ -168,7 +200,6 @@ function moveCountRenderer(instance:Core, td:any, row:number, col:number, prop:a
if (classArr.indexOf('htNumeric') < 0) { if (classArr.indexOf('htNumeric') < 0) {
classArr.push('htNumeric'); classArr.push('htNumeric');
} }
cellProperties.className = classArr.join(' '); cellProperties.className = classArr.join(' ');
td.dir = 'ltr'; td.dir = 'ltr';
@ -177,7 +208,6 @@ function moveCountRenderer(instance:Core, td:any, row:number, col:number, prop:a
newValue = "" newValue = ""
} }
textRenderer(instance, td, row, col, prop, newValue, cellProperties); textRenderer(instance, td, row, col, prop, newValue, cellProperties);
} }
class Equip implements ColumnInfo { class Equip implements ColumnInfo {

View File

@ -14,6 +14,7 @@
//} //}
import { ColumnSet } from "./table" import { ColumnSet } from "./table"
import { dummyChar, TricksterInventory } from "./trickster"
export const ARRAY_SEPERATOR = "," export const ARRAY_SEPERATOR = ","
@ -46,4 +47,7 @@ export const StoreColSet = {
Murder: (s:ColumnSet):string=>Array.from(s.s.values()).join(as), Murder: (s:ColumnSet):string=>Array.from(s.s.values()).join(as),
Revive: (s:string):ColumnSet=>new ColumnSet(s.split(as)) Revive: (s:string):ColumnSet=>new ColumnSet(s.split(as))
} }
export const StoreInvs = {
Murder: (s:Map<string,TricksterInventory>):string=>Array.from(s.keys()).join(as),
Revive: (s:string):Map<string,TricksterInventory>=>new Map(s.split(as).map((x)=>[x, dummyChar(x)])),
}

View File

@ -165,10 +165,6 @@ export const DefaultSettings = ():HotTableProps=>{
filters: true, filters: true,
manualRowMove: false, manualRowMove: false,
manualColumnMove: false, manualColumnMove: false,
autoColumnSize: {
syncLimit: 1000,
useHeaders: true,
},
allowInsertRow: false, allowInsertRow: false,
allowInsertColumn: false, allowInsertColumn: false,
allowRemoveRow: false, allowRemoveRow: false,

View File

@ -2,7 +2,7 @@ import { defineStore, storeToRefs } from 'pinia'
import { getCookie, setCookie } from 'typescript-cookie' import { getCookie, setCookie } from 'typescript-cookie'
import { useCookies } from 'vue3-cookies' import { useCookies } from 'vue3-cookies'
import { BasicColumns, ColumnInfo, ColumnName, Columns, DetailsColumns, MoveColumns } from '../lib/columns' import { BasicColumns, ColumnInfo, ColumnName, Columns, DetailsColumns, MoveColumns } from '../lib/columns'
import { Reviver, StoreColSet, StoreStr, StoreStrSet } from '../lib/storage' import { Reviver, StoreColSet, StoreInvs, StoreStr, StoreStrSet } from '../lib/storage'
import { ColumnSet } from '../lib/table' import { ColumnSet } from '../lib/table'
import { TricksterInventory } from '../lib/trickster' import { TricksterInventory } from '../lib/trickster'
import { nameCookie} from '../session_storage' import { nameCookie} from '../session_storage'
@ -36,6 +36,7 @@ export const useStore = defineStore('state', {
}) })
export const StoreReviver = { export const StoreReviver = {
invs: StoreInvs,
accounts: StoreStrSet, accounts: StoreStrSet,
activeTable: StoreStr, activeTable: StoreStr,
screen: StoreStr, screen: StoreStr,