From 8ef7ea6a95de60822a9d22a548275d002c7165ee Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Sun, 8 Sep 2024 08:01:57 -0700 Subject: [PATCH 1/6] Drop final custom-truth saves --- .../vue/components/truth/custom-truth.vue | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/module/vue/components/truth/custom-truth.vue b/src/module/vue/components/truth/custom-truth.vue index 38a02e06a..6e7e2e11a 100644 --- a/src/module/vue/components/truth/custom-truth.vue +++ b/src/module/vue/components/truth/custom-truth.vue @@ -5,20 +5,22 @@ type="radio" :name="radioGroup" class="nogrow" - @change="select" /> + @change="select" + /> + @save="emitHtml" + /> From d48b430b4354dad3ee9b87036c80e2d7cc16d1b8 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Sun, 8 Sep 2024 08:02:25 -0700 Subject: [PATCH 2/6] Vue models for top-level composition --- .../vue/components/truth/truth-category.vue | 9 ++++-- .../vue/components/truth/truth-selectable.vue | 2 ++ src/module/vue/sf-truths.vue | 28 +++++++++++-------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/module/vue/components/truth/truth-category.vue b/src/module/vue/components/truth/truth-category.vue index f410257cc..1da3ccfaf 100644 --- a/src/module/vue/components/truth/truth-category.vue +++ b/src/module/vue/components/truth/truth-category.vue @@ -44,6 +44,8 @@ const props = defineProps<{ je: () => IronswornJournalEntry }>() +const model = defineModel() + type NonTruthPage = IronswornJournalPage> const truthPages = props.je()?.pageTypes.truth @@ -57,16 +59,19 @@ const state = reactive<{ title?: string text?: string html?: string + custom?: boolean }>({}) -function valueChange(title: string, text: string) { +async function valueChange(title: string, text: string) { state.title = title state.text = text state.html = undefined + model.value = await selectedValue() } -function customValueChange(html: string) { +async function customValueChange(html: string) { state.title = undefined state.text = undefined state.html = html + model.value = await selectedValue() } async function selectedValue() { diff --git a/src/module/vue/components/truth/truth-selectable.vue b/src/module/vue/components/truth/truth-selectable.vue index d726cc191..a8d6fb4bb 100644 --- a/src/module/vue/components/truth/truth-selectable.vue +++ b/src/module/vue/components/truth/truth-selectable.vue @@ -104,6 +104,8 @@ async function selectAndRandomize() { ) suboptions.value[selectedIndex]?.click() } + + emitValue() } defineExpose({ selectAndRandomize }) diff --git a/src/module/vue/sf-truths.vue b/src/module/vue/sf-truths.vue index 201e171a6..886c57d09 100644 --- a/src/module/vue/sf-truths.vue +++ b/src/module/vue/sf-truths.vue @@ -33,6 +33,7 @@ ref="categoryComponents" :key="(truth.je()._id as string)" :je="truth.je" + v-model="categoryModels[truth.ds._id]" /> @@ -57,6 +58,11 @@ const props = defineProps<{ }>() const categoryComponents = ref<(typeof TruthCategory)[]>([]) +const categoryModels = ref< + Record +>( + Object.fromEntries(props.data.truths.map((x) => [x.ds._id, { valid: false }])) +) function scrollToCategory(i: number) { categoryComponents.value[i]?.scrollIntoView() @@ -65,19 +71,17 @@ function scrollToCategory(i: number) { const $localEmitter = inject($LocalEmitterKey) async function saveTruths() { // Fetch values from the category components - const allValues = await Promise.all( - categoryComponents.value.map((x) => x.selectedValue()) - ) - const values = allValues.filter((x) => x.valid) + const contentSections: string[] = [] + for (const t of props.data.truths) { + const model = categoryModels.value[t.ds._id] + if (model.valid) + contentSections.push( + `

${model.title}

+ ${model.html}` + ) + } - const content = values - .map( - ({ title, html }) => ` -

${title}

- ${html} - ` - ) - .join('\n\n') + const content = contentSections.join('\n\n') const title = game.i18n.localize('IRONSWORN.JOURNALENTRYPAGES.TypeTruth') const journal = await IronswornJournalEntry.create({ From 71b97f614be76a25d986d6cfe650f061e7b37124 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Sun, 8 Sep 2024 08:18:25 -0700 Subject: [PATCH 3/6] Avoid DS IDs if possible --- src/module/vue/sf-truths.vue | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/module/vue/sf-truths.vue b/src/module/vue/sf-truths.vue index 886c57d09..8f9053de3 100644 --- a/src/module/vue/sf-truths.vue +++ b/src/module/vue/sf-truths.vue @@ -33,7 +33,7 @@ ref="categoryComponents" :key="(truth.je()._id as string)" :je="truth.je" - v-model="categoryModels[truth.ds._id]" + v-model="categoryModels[truth.je()._id]" /> @@ -61,7 +61,9 @@ const categoryComponents = ref<(typeof TruthCategory)[]>([]) const categoryModels = ref< Record >( - Object.fromEntries(props.data.truths.map((x) => [x.ds._id, { valid: false }])) + Object.fromEntries( + props.data.truths.map((x) => [x.je()._id, { valid: false }]) + ) ) function scrollToCategory(i: number) { @@ -73,7 +75,7 @@ async function saveTruths() { // Fetch values from the category components const contentSections: string[] = [] for (const t of props.data.truths) { - const model = categoryModels.value[t.ds._id] + const model = categoryModels.value[t.je()._id] if (model.valid) contentSections.push( `

${model.title}

From 452e09dc11870dbb6c953eac3841eba50a96fda3 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Sun, 8 Sep 2024 08:18:31 -0700 Subject: [PATCH 4/6] Clean up console logs --- src/module/vue/components/truth/custom-truth.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/module/vue/components/truth/custom-truth.vue b/src/module/vue/components/truth/custom-truth.vue index 6e7e2e11a..d36090fab 100644 --- a/src/module/vue/components/truth/custom-truth.vue +++ b/src/module/vue/components/truth/custom-truth.vue @@ -40,7 +40,6 @@ function select() { // Do not emit change events from the editor if we've been unmounted let emitChanges = true onBeforeUnmount(() => { - console.log('onBeforeUnmount') emitChanges = false }) @@ -48,7 +47,6 @@ const $emit = defineEmits<{ change: [string] }>() function emitHtml() { - console.log({ emitChanges }) if (emitChanges) $emit('change', state.html) } From 9ab6872e1de52e7a33d936c26fd80ed24ce84f02 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Sun, 8 Sep 2024 08:23:05 -0700 Subject: [PATCH 5/6] Fix section titles and `[object object]` turds --- src/module/vue/components/truth/truth-category.vue | 14 +++++++++----- .../vue/components/truth/truth-selectable.vue | 10 ++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/module/vue/components/truth/truth-category.vue b/src/module/vue/components/truth/truth-category.vue index 1da3ccfaf..4068534fb 100644 --- a/src/module/vue/components/truth/truth-category.vue +++ b/src/module/vue/components/truth/truth-category.vue @@ -77,17 +77,21 @@ async function customValueChange(html: string) { async function selectedValue() { let html = state.html if (!html) { - html = ` - ${await enrichMarkdown(`**${state.title}**`)} - ${await enrichMarkdown(state.text)} - ` + if (state.title) { + html = ` + ${await enrichMarkdown(`**${state.title}**`)} + ${await enrichMarkdown(state.text)} + ` + } else { + html = await enrichMarkdown(state.text) + } } html += nonTruthPages?.map((x) => x.text.content).join('\n\n') return { title: props.je()?.name, html: html.trim(), - valid: !!(state.title || state.html) + valid: true } } diff --git a/src/module/vue/components/truth/truth-selectable.vue b/src/module/vue/components/truth/truth-selectable.vue index a8d6fb4bb..58d5eaa75 100644 --- a/src/module/vue/components/truth/truth-selectable.vue +++ b/src/module/vue/components/truth/truth-selectable.vue @@ -73,7 +73,13 @@ const $emit = defineEmits<{ change: [string, string] // title, text }>() function emitValue() { - let text = `${pageSystem.Description} ${suboption ?? ''}\n\n_${ + // Some pages (i.e. Classic) don't have a title + let title = props.page.name ?? '' + if (title?.startsWith('truth.option')) { + title = '' + } + + let text = `${pageSystem.Description} ${suboption.value ?? ''}\n\n_${ pageSystem.Quest }_` @@ -83,7 +89,7 @@ function emitValue() { template.Description.replace(/{{table>.*?}}/, `> ${suboption.value}`) + `\n\n_${pageSystem.Quest}_` } - $emit('change', props.page.name ?? '???', text.trim()) + $emit('change', title, text.trim()) } const suboptions = ref([]) From f76188db2db5d5624bfe7aaed92c6a3f848d6eed Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Sun, 8 Sep 2024 08:25:32 -0700 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3788ae9c0..16fc8651a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Next Release - Cursed die support when rolling oracles ([#1026](https://github.com/ben/foundry-ironsworn/pull/1026)) +- Fix an issue with the truths dialog resulting in blank outputs ([#1027](https://github.com/ben/foundry-ironsworn/pull/1027)) ## 1.24.2