Skip to content

Commit ed7e336

Browse files
authored
Merge pull request #894 from ben/multiple-tables-display
Multiple tables display
2 parents 29d64dd + 2e92e52 commit ed7e336

File tree

3 files changed

+74
-25
lines changed

3 files changed

+74
-25
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Next Release
44

5+
- Display all oracle tables in the preview area ([#894](https://github.com/ben/foundry-ironsworn/pull/894))
6+
57
## 1.22.5
68

79
- Add compendium folders for oracles, moves, and assets

src/module/vue/components/oracle-tree-node.vue

+60-24
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
class="flexcol nogrow movesheet-row"
55
:class="{ hidden: node?.forceHidden, highlighted: state.highlighted }"
66
data-tooltip-direction="LEFT"
7-
:data-tourid="`oracle-${node.dataforgedNode?.$id}`">
7+
:data-tourid="`oracle-${node.dataforgedNode?.$id}`"
8+
>
89
<!-- TODO: split this into two components, yo -->
910
<!-- Leaf node -->
1011
<div v-if="isLeaf">
@@ -18,17 +19,24 @@
1819
nogrow
1920
class="show-oracle-info"
2021
icon="fa:eye"
21-
@click="toggleDescription()" />
22+
@click="toggleDescription()"
23+
/>
2224
</h4>
2325
<CollapseTransition>
24-
<RulesTextOracle
25-
v-if="state.descriptionExpanded"
26-
:class="$style.content"
27-
:table-rows="state.tableRows"
28-
:table-description="state.tableDescription"
29-
:source="node.dataforgedNode?.Source"
30-
@moveclick="moveclick"
31-
@oracleclick="oracleclick" />
26+
<div v-if="state.descriptionExpanded">
27+
<h4 v-if="state.singleDescription" v-html="state.singleDescription" />
28+
<RulesTextOracle
29+
v-for="table in state.tables"
30+
:key="table.id"
31+
:class="$style.content"
32+
:title="state.tables.length > 1 ? table.title : undefined"
33+
:table-rows="table.rows"
34+
:table-description="table.description"
35+
:source="node.dataforgedNode?.Source"
36+
@moveclick="moveclick"
37+
@oracleclick="oracleclick"
38+
/>
39+
</div>
3240
</CollapseTransition>
3341
</div>
3442

@@ -43,7 +51,8 @@
4351
name="caret-right"
4452
:rotate="
4553
state.manuallyExpanded ? FontAwesome.Rotate['90deg'] : undefined
46-
" />
54+
"
55+
/>
4756
</template>
4857
</IronBtn>
4958
</h4>
@@ -52,13 +61,15 @@
5261
<div
5362
v-show="state.manuallyExpanded"
5463
class="flexcol"
55-
:class="$style.indent">
64+
:class="$style.indent"
65+
>
5666
<oracle-tree-node
5767
v-for="child in node?.children"
5868
:key="child.displayName"
5969
ref="children"
6070
:node="child"
61-
@oracleclick="oracleclick" />
71+
@oracleclick="oracleclick"
72+
/>
6273
</div>
6374
</CollapseTransition>
6475
</div>
@@ -78,14 +89,20 @@ import FontIcon from './icon/font-icon.vue'
7889
import IronIcon from './icon/iron-icon.vue'
7990
import type { OracleTable } from '../../roll-table/oracle-table'
8091
import type { LegacyTableRow } from '../../roll-table/roll-table-types'
92+
import { enrichHtml } from '../vue-plugin'
8193
8294
const props = defineProps<{ node: IOracleTreeNode }>()
8395
8496
const state = reactive({
8597
manuallyExpanded: props.node.forceExpanded ?? false,
8698
descriptionExpanded: false,
87-
tableRows: [] as Array<LegacyTableRow>,
88-
tableDescription: '',
99+
singleDescription: undefined as string | undefined,
100+
tables: [] as Array<{
101+
id: string
102+
title: string
103+
rows: Array<LegacyTableRow>
104+
description: string
105+
}>,
89106
highlighted: false
90107
})
91108
@@ -96,15 +113,34 @@ const isLeaf = computed(() => {
96113
})
97114
98115
async function toggleDescription() {
99-
if (!state.tableDescription) {
100-
const table = (await fromUuid(props.node.tables[0])) as OracleTable
101-
state.tableRows = table.results.map((row: any) => ({
102-
low: row.range[0],
103-
high: row.range[1],
104-
text: row.text,
105-
selected: false
106-
}))
107-
state.tableDescription = (table as any).description ?? ''
116+
if (state.tables.length === 0) {
117+
state.tables = await Promise.all(
118+
props.node.tables.map(async (tableUuid) => {
119+
const tableData = (await fromUuid(tableUuid)) as OracleTable
120+
return {
121+
id: tableUuid,
122+
title: tableData.name ?? '',
123+
rows: tableData.results.map((row: any) => ({
124+
low: row.range[0],
125+
high: row.range[1],
126+
text: row.text,
127+
selected: false
128+
})),
129+
description: tableData.description
130+
}
131+
})
132+
)
133+
134+
// If all descriptions match, collapse them into one
135+
if (
136+
state.tables.every((t) => t.description === state.tables[0].description)
137+
) {
138+
state.singleDescription = enrichHtml(state.tables[0].description)
139+
for (const t of state.tables) {
140+
t.description = ''
141+
}
142+
}
143+
108144
await nextTick()
109145
}
110146
state.descriptionExpanded = !state.descriptionExpanded

src/module/vue/components/rules-text/rules-text-oracle.vue

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<template>
22
<RulesText class="rules-text-oracle" :source="source" type="slot">
33
<template #default>
4+
<h4>{{ props.title }}</h4>
45
<OracleTable
56
:table-description="tableDescription"
6-
:table-rows="tableRows" />
7+
:table-rows="tableRows"
8+
/>
79
</template>
810
<template #before-main>
911
<slot name="before-main"></slot>
@@ -17,13 +19,22 @@
1719
</RulesText>
1820
</template>
1921

22+
<style lang="less" scoped>
23+
h4 {
24+
text-transform: uppercase;
25+
margin-top: 0.5rem;
26+
font-weight: bold;
27+
}
28+
</style>
29+
2030
<script setup lang="ts">
2131
import RulesText from './rules-text.vue'
2232
import OracleTable from './oracle-table.vue'
2333
import type { ISource } from 'dataforged'
2434
import type { LegacyTableRow } from '../../../roll-table/roll-table-types'
2535
2636
const props = defineProps<{
37+
title?: string
2738
tableRows: LegacyTableRow[]
2839
tableDescription: string
2940
source?: ISource

0 commit comments

Comments
 (0)