From 5f8484f8baec7422b68fcac44e273442fd3f592e Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 20 Mar 2023 06:25:20 -0700 Subject: [PATCH 01/12] Update oracle node types to use UUIDs --- src/module/features/customoracles.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/module/features/customoracles.ts b/src/module/features/customoracles.ts index 8c7a76083..54876a701 100644 --- a/src/module/features/customoracles.ts +++ b/src/module/features/customoracles.ts @@ -11,7 +11,7 @@ import { cachedDocumentsForPack } from './pack-cache' export interface IOracleTreeNode { dataforgedNode?: IOracle | IOracleCategory - tables: Array<() => RollTable> + tables: string[] // UUIDs displayName: string children: IOracleTreeNode[] forceExpanded?: boolean @@ -107,9 +107,9 @@ export async function walkOracle( const node: IOracleTreeNode = { ...emptyNode(), dataforgedNode: oracle, - tables: compact([table != null ? () => table : undefined]), + tables: compact([table?.uuid]), displayName: - table?.name || + table?.name ?? game.i18n.localize(`IRONSWORN.OracleCategories.${oracle.Name}`) } @@ -127,7 +127,7 @@ export async function walkOracle( node.children.push({ ...emptyNode(), displayName: name, - tables: [() => subtable] + tables: [subtable.uuid] }) } } @@ -155,7 +155,7 @@ async function augmentWithFolderContents(node: IOracleTreeNode) { // Add this folder const newNode: IOracleTreeNode = { ...emptyNode(), - displayName: folder.name || '(folder)' + displayName: folder.name ?? '(folder)' } parent.children.push(newNode) @@ -168,7 +168,7 @@ async function augmentWithFolderContents(node: IOracleTreeNode) { for (const table of folder.contents) { newNode.children.push({ ...emptyNode(), - tables: [() => table as RollTable], + tables: [table.uuid], displayName: table.name ?? '(table)' }) } @@ -177,14 +177,14 @@ async function augmentWithFolderContents(node: IOracleTreeNode) { walkFolder(node, rootFolder) } -export function findPathToNodeByTableId( +export function findPathToNodeByTableUuid( rootNode: IOracleTreeNode, - tableId: string + tableUuid: string ): IOracleTreeNode[] { const ret: IOracleTreeNode[] = [] function walk(node: IOracleTreeNode) { ret.push(node) - const foundTable = node.tables.find((x) => x().id === tableId) + const foundTable = node.tables.find((x) => x === tableUuid) if (foundTable != null) return true for (const child of node.children) { if (walk(child)) return true From 534a6041fe1dd70c2ec71a3e31232d2763a8e173 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Fri, 24 Mar 2023 20:13:47 -0700 Subject: [PATCH 02/12] Resolve some issues --- src/module/rolls/oracle-roll-message.ts | 9 ++++----- src/module/vue/components/buttons/btn-oracle.vue | 2 +- src/module/vue/components/oracle-tree-node.vue | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/module/rolls/oracle-roll-message.ts b/src/module/rolls/oracle-roll-message.ts index 879c34b32..25eba6adf 100644 --- a/src/module/rolls/oracle-roll-message.ts +++ b/src/module/rolls/oracle-roll-message.ts @@ -6,7 +6,7 @@ import { createIronswornOracleTree, createStarforgedOracleTree, findPathToNodeByDfId, - findPathToNodeByTableId + findPathToNodeByTableUuid } from '../features/customoracles' export interface TableRow { @@ -172,16 +172,15 @@ export class OracleRollMessage { } private async oraclePath(): Promise { - if (!this.tableUuid) return undefined - const uuid = _parseUuid(this.tableUuid) + if (this.tableUuid == null) return undefined const [starforgedRoot, ironswornRooot] = await Promise.all([ createStarforgedOracleTree(), createIronswornOracleTree() ]) const pathElements = - findPathToNodeByTableId(starforgedRoot, uuid.documentId!) ?? - findPathToNodeByTableId(ironswornRooot, uuid.documentId!) + findPathToNodeByTableUuid(starforgedRoot, this.tableUuid) ?? + findPathToNodeByTableUuid(ironswornRooot, this.tableUuid) pathElements.shift() // no display name for root node pathElements.pop() // last node is the table we rolled return pathElements.map((x) => x.displayName).join(' / ') diff --git a/src/module/vue/components/buttons/btn-oracle.vue b/src/module/vue/components/buttons/btn-oracle.vue index 43f07ed85..62ca5669b 100644 --- a/src/module/vue/components/buttons/btn-oracle.vue +++ b/src/module/vue/components/buttons/btn-oracle.vue @@ -39,7 +39,7 @@ async function rollOracle() { if (props.overrideClick && props.onClick) return $emit('click') const randomTable = sample(props.node.tables) - const orm = await OracleRollMessage.fromTableUuid(randomTable?.()?.uuid ?? '') + const orm = await OracleRollMessage.fromTableUuid(randomTable ?? '') orm.createOrUpdate() } diff --git a/src/module/vue/components/oracle-tree-node.vue b/src/module/vue/components/oracle-tree-node.vue index 0e6a8a13b..4d0d24f50 100644 --- a/src/module/vue/components/oracle-tree-node.vue +++ b/src/module/vue/components/oracle-tree-node.vue @@ -24,7 +24,7 @@ From 35a66919378c03518ff4399a1c406b8b17ed6d0e Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Sat, 25 Mar 2023 06:22:05 -0700 Subject: [PATCH 03/12] Expandable oracles --- .../vue/components/rules-text/oracle-table.vue | 12 ++++++++---- .../vue/components/rules-text/rules-text-oracle.vue | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/module/vue/components/rules-text/oracle-table.vue b/src/module/vue/components/rules-text/oracle-table.vue index a0cae8d6b..74d6f33ed 100644 --- a/src/module/vue/components/rules-text/oracle-table.vue +++ b/src/module/vue/components/rules-text/oracle-table.vue @@ -1,8 +1,8 @@