diff --git a/CHANGELOG.md b/CHANGELOG.md index 713605648..8ff05da80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Next Release +- Brought back support for the "Custom Moves" folder ([#1023](https://github.com/ben/foundry-ironsworn/pull/1023)) + ## 1.24.0 This is a major update that includes Sundered Isles content, but also brings along a host of changes: diff --git a/src/module/datasworn2/finding.ts b/src/module/datasworn2/finding.ts index 409df6418..8913576bf 100644 --- a/src/module/datasworn2/finding.ts +++ b/src/module/datasworn2/finding.ts @@ -62,10 +62,13 @@ interface PackAndIndex { export async function getPackAndIndexForCompendiumKey( ruleset: DataswornRulesetKey, - type: keyof typeof COMPENDIUM_KEY_MAP + type: keyof typeof COMPENDIUM_KEY_MAP, + additionalFields?: string[] ): Promise { const pack = game.packs.get(COMPENDIUM_KEY_MAP[type][ruleset]) - const index = await pack?.getIndex({ fields: ['flags'] }) + const index = await pack?.getIndex({ + fields: ['flags', ...((additionalFields ?? []) as any[])] + }) return { pack, index } } diff --git a/src/module/features/custommoves.ts b/src/module/features/custommoves.ts index 3b9aabd43..a2975903f 100644 --- a/src/module/features/custommoves.ts +++ b/src/module/features/custommoves.ts @@ -5,6 +5,10 @@ import { } from '../datasworn2' import { DataswornRulesetKey, IronswornSettings } from '../helpers/settings' import type { Move, MoveCategory } from '@datasworn/core/dist/Datasworn' +import { moveTriggerIsRollable } from '../rolls/preroll-dialog' +import { compact } from 'lodash-es' +import { IronswornItem } from '../item/item' +import { SFMoveModel } from '../item/subtypes/sfmove' interface DisplayMoveRuleset { displayName: string @@ -22,6 +26,9 @@ export interface DisplayMove { color: string | null displayName: string uuid: string + triggerText?: string + isRollable: boolean + oracles: string[] ds?: Move } @@ -29,7 +36,10 @@ const INDEXES: Record = {} async function ensureIndex(rsKey: DataswornRulesetKey) { const compendiumKey = COMPENDIUM_KEY_MAP.move[rsKey] if (INDEXES[compendiumKey] == null) { - const { index } = await getPackAndIndexForCompendiumKey(rsKey, 'move') + const { index } = await getPackAndIndexForCompendiumKey(rsKey, 'move', [ + 'system.Trigger', + 'system.dsOracleIds' + ]) INDEXES[compendiumKey] = index } } @@ -55,6 +65,9 @@ export async function createMoveTreeForRuleset( color: move.color ?? null, displayName: move.name, uuid: indexEntry.uuid, // TODO: move.uuid + triggerText: indexEntry.system?.Trigger?.Text, + isRollable: moveTriggerIsRollable(indexEntry?.system?.Trigger), + oracles: indexEntry.system?.dsOracleIds ?? [], ds: move } }) @@ -62,12 +75,48 @@ export async function createMoveTreeForRuleset( } } +function customFolderMoveCategory(): DisplayMoveRuleset | undefined { + const name = game.i18n.localize('IRONSWORN.MOVES.Custom Moves') + const rootFolder = game.items?.directory?.folders.find((x) => x.name === name) + if (!rootFolder) return undefined + + const category: DisplayMoveCategory = { + displayName: name, + color: (rootFolder as any).color?.css ?? null, + moves: [] + } + + for (const item of rootFolder.contents) { + if (!(item instanceof IronswornItem)) continue + if (item.type !== 'sfmove') continue + const system = item.system as SFMoveModel + + category.moves.push({ + displayName: item.name ?? '(unnamed)', + uuid: item.uuid, + color: null, + isRollable: moveTriggerIsRollable(system.Trigger), + oracles: system.dsOracleIds ?? [], + triggerText: system.Trigger?.Text + }) + } + if (category.moves.length === 0) return undefined + + return { + displayName: name, + categories: [category] + } +} + export async function createMergedMoveTree(): Promise { // Pre-load compendium indexes await Promise.all(IronswornSettings.enabledRulesets.map(ensureIndex)) - return await Promise.all( - IronswornSettings.enabledRulesets.map(createMoveTreeForRuleset) - ) + return compact([ + ...(await Promise.all( + IronswornSettings.enabledRulesets.map(createMoveTreeForRuleset) + )), + customFolderMoveCategory() + ]) } // TODO dataforged has a key for move colours...., but they appear to have changed significantly since the last time i updated them! they'll be fixed for 2.0, but until then, here's a workaround. diff --git a/src/module/rolls/preroll-dialog.ts b/src/module/rolls/preroll-dialog.ts index 2fac7bb38..35dba06e0 100644 --- a/src/module/rolls/preroll-dialog.ts +++ b/src/module/rolls/preroll-dialog.ts @@ -58,10 +58,8 @@ function rollableOptions(trigger: SFMoveTrigger) { ) } -export function moveHasRollableOptions(move: IronswornItem<'sfmove'>) { - if (!move.assert('sfmove')) return false - const options = rollableOptions(move.system.Trigger) - return options.length > 0 +export function moveTriggerIsRollable(trigger?: SFMoveTrigger) : boolean { + return !!trigger && rollableOptions(trigger).length > 0 } export function getStatData( diff --git a/src/module/vue/components/buttons/btn-sendmovetochat.vue b/src/module/vue/components/buttons/btn-sendmovetochat.vue index 632ace4ca..7ffe34a4d 100644 --- a/src/module/vue/components/buttons/btn-sendmovetochat.vue +++ b/src/module/vue/components/buttons/btn-sendmovetochat.vue @@ -13,22 +13,22 @@ diff --git a/src/module/vue/components/move/move-content.vue b/src/module/vue/components/move/move-content.vue new file mode 100644 index 000000000..f447a5844 --- /dev/null +++ b/src/module/vue/components/move/move-content.vue @@ -0,0 +1,71 @@ + + + + + diff --git a/src/module/vue/components/sf-moverow.vue b/src/module/vue/components/move/sf-moverow.vue similarity index 72% rename from src/module/vue/components/sf-moverow.vue rename to src/module/vue/components/move/sf-moverow.vue index e6c0bc6a6..2803ec5c3 100644 --- a/src/module/vue/components/sf-moverow.vue +++ b/src/module/vue/components/move/sf-moverow.vue @@ -5,7 +5,7 @@ class="movesheet-row" :class="$style.wrapper" data-tooltip-direction="LEFT" - :base-id="`move_row_${item._id}`" + :base-id="`move_row_${move.uuid}`" :content-wrapper-class="$style.contentWrapper" :toggle-wrapper-is="`h${headingLevel}`" :toggle-section-class="[$style.toggleSection, toggleSectionClass]" @@ -15,8 +15,7 @@ :toggle-wrapper-class="$style.toggleWrapper" :toggle-label="move?.displayName" :data-highlighted="dataHighlight" - :data-move-id="item._id" - :data-move-uuid="$item.uuid" + :data-move-uuid="move.uuid" >