Skip to content

Commit

Permalink
Merge pull request #1016 from ben/si-truths
Browse files Browse the repository at this point in the history
Datasworn for truths
  • Loading branch information
ben authored Aug 23, 2024
2 parents c40f6d7 + 50e5c0f commit bb6fd20
Show file tree
Hide file tree
Showing 21 changed files with 159 additions and 928 deletions.
5 changes: 1 addition & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IronswornActor } from './module/actor/actor'
import * as dataforgedHelpers from './module/dataforged'
import { importFromDatasworn } from './module/datasworn'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { starforged, ironsworn } from 'dataforged'
import { starforged } from 'dataforged'
import type { Emitter, EventType } from 'mitt'
import Mitt from 'mitt'
import {
Expand All @@ -13,7 +13,6 @@ import {
import { AssetCompendiumBrowser } from './module/item/asset-compendium-browser'
import { FirstStartDialog } from './module/applications/firstStartDialog'
import { SFSettingTruthsDialogVue } from './module/applications/vueSfSettingTruthsDialog'
import { WorldTruthsDialog } from './module/applications/worldTruthsDialog'
import { OracleWindow } from './module/applications/oracle-window'
import {
getOracleTree,
Expand All @@ -39,7 +38,6 @@ export interface IronswornConfig {
applications: {
// Dialogs
FirstStartDialog: typeof FirstStartDialog
ISSettingTruthsDialog: typeof WorldTruthsDialog
SFSettingTruthsDialog: typeof SFSettingTruthsDialogVue
AssetCompendiumBrowser: typeof AssetCompendiumBrowser
OracleWindow: typeof OracleWindow
Expand Down Expand Up @@ -75,7 +73,6 @@ export const IRONSWORN: IronswornConfig = {

applications: {
FirstStartDialog,
ISSettingTruthsDialog: WorldTruthsDialog,
SFSettingTruthsDialog: SFSettingTruthsDialogVue,
AssetCompendiumBrowser,
OracleWindow,
Expand Down
26 changes: 20 additions & 6 deletions src/module/applications/firstStartDialog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { registerDefaultOracleTrees } from '../features/customoracles'
import { IronswornSettings, RULESETS } from '../helpers/settings'
import { SFSettingTruthsDialogVue } from './vueSfSettingTruthsDialog'
import { WorldTruthsDialog } from './worldTruthsDialog'

export class FirstStartDialog extends FormApplication<FormApplicationOptions> {
constructor() {
Expand All @@ -16,7 +16,7 @@ export class FirstStartDialog extends FormApplication<FormApplicationOptions> {
resizable: false,
classes: ['ironsworn', 'sheet', 'first-start'],
width: 650,
height: 560
height: 685
} as FormApplicationOptions)
}

Expand All @@ -28,8 +28,6 @@ export class FirstStartDialog extends FormApplication<FormApplicationOptions> {
super.activateListeners(html)
// eslint-disable-next-line @typescript-eslint/no-misused-promises
html.find('button.ironsworn__save').on('click', async (ev) => {
console.log(html)

// Update default character sheet
const defaultSheet = html.find('input[name=sheet]:checked').val()
const setting = game.settings.get('core', 'sheetClasses')
Expand All @@ -45,11 +43,27 @@ export class FirstStartDialog extends FormApplication<FormApplicationOptions> {
)
await IronswornSettings.enableOnlyRulesets(...checkedRulesets)

// If you chose SI, probably you want 'hold' enabled
await IronswornSettings.set(
'character-hold',
checkedRulesets.includes('sundered_isles')
)

// Update the live content
void registerDefaultOracleTrees()

// Launch truths dialog
const truthsFlavor = html.find('input[name=truths]:checked').val()
if (truthsFlavor) {
// @ts-expect-error coercing this string to a DataswornRulesetKey
void new SFSettingTruthsDialogVue(truthsFlavor).render(true)
}

if (IronswornSettings.get('show-first-start-dialog')) {
if (defaultSheet === 'StarforgedCharacterSheet') {
void new SFSettingTruthsDialogVue().render(true)
void new SFSettingTruthsDialogVue('starforged').render(true)
} else {
void new WorldTruthsDialog().render(true)
void new SFSettingTruthsDialogVue('classic').render(true)
}
}
await IronswornSettings.set('show-first-start-dialog', false)
Expand Down
34 changes: 20 additions & 14 deletions src/module/applications/vueSfSettingTruthsDialog.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import type { Starforged } from 'dataforged'
import { starforged } from 'dataforged'
import { DataswornTree } from '../datasworn2'
import { DataswornRulesetKey } from '../helpers/settings'
import { IronswornJournalEntry } from '../journal/journal-entry'
import sfTruthsVue from '../vue/sf-truths.vue'
import { VueAppMixin } from '../vue/vueapp.js'

const DS_TRUTH_COMPENDIUM_KEYS = {
classic: 'foundry-ironsworn.ironsworntruths',
starforged: 'foundry-ironsworn.starforgedtruths',
sundered_isles: 'foundry-ironsworn.sunderedislestruths'
}

export class SFSettingTruthsDialogVue extends VueAppMixin(FormApplication) {
constructor() {
constructor(protected truthset: DataswornRulesetKey) {
super({})
}

Expand Down Expand Up @@ -33,26 +39,26 @@ export class SFSettingTruthsDialogVue extends VueAppMixin(FormApplication) {
getData(
options?: Partial<FormApplicationOptions> | undefined
): MaybePromise<object>
async getData(options?: unknown) {
const pack = game.packs.get('foundry-ironsworn.starforgedtruths')
async getData(_options?: unknown) {
const pack = game.packs.get(DS_TRUTH_COMPENDIUM_KEYS[this.truthset])
const documents = (await pack?.getDocuments()) as IronswornJournalEntry[]
if (!documents) throw new Error("can't load truth JEs")

// Avoid rollupjs's over-aggressive tree shaking
const dfTruths = ((starforged as any).default as Starforged)[
'Setting Truths'
]
const truths = dfTruths.map((df) => ({
df,
// Get the order from DS
const dsTruths = DataswornTree.get(this.truthset)?.truths
if (!dsTruths) throw new Error("can't find DS truths")

const truths = Object.values(dsTruths).map((ds) => ({
ds,
je: documents.find(
(x) => x.getFlag('foundry-ironsworn', 'dfid') === df.$id
(x) => x.getFlag('foundry-ironsworn', 'dsid') === ds._id

Check failure on line 54 in src/module/applications/vueSfSettingTruthsDialog.ts

View workflow job for this annotation

GitHub Actions / static-check

Object is of type 'unknown'.
)
}))

return {
...(await super.getData()),
truths: truths.map(({ df, je }) => ({
df,
truths: truths.map(({ ds, je }) => ({
ds,
je: () => je // Prevent vue from wrapping this in Reactive
}))
}
Expand Down
95 changes: 0 additions & 95 deletions src/module/applications/worldTruthsDialog.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/module/datasworn2/import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ for (const collection of collections) {
txt.replace(/{{table>.*?}}/, '(roll below)').trim()
return {
type: 'truth',
name: o.summary ?? '',
name: o.summary ?? o._id,
system: {
Subtable: firstOracle?.rows?.map((row) => ({
dfid: LegacyToDataswornIds[row._id],
Expand All @@ -605,6 +605,7 @@ for (const collection of collections) {
Description: renderLinksInStr(
stripTableEmbeds(o.description ?? '')
),
Summary: renderLinksInStr(o.summary ?? ''),
Quest: renderLinksInStr(o.quest_starter),
'Roll template': {
Description: o.description
Expand Down
10 changes: 6 additions & 4 deletions src/module/datasworn2/import/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { hash, lookupLegacyId } from '../ids'
export const markdownRenderer = new Showdown.Converter({ tables: true })

const MARKDOWN_LINK_RE = /\[(.*?)\]\((.*?)\)/g

// These are Foundry keys for these, not the paths to the JSON files
const COMPENDIUM_KEY_MAP = {
asset: {
classic: 'ironswornassets',
Expand Down Expand Up @@ -40,10 +42,10 @@ const COMPENDIUM_KEY_MAP = {
sundered_isles: 'sunderedislesnpcs'
},
delve_site_theme: {
delve: 'delve-themes'
delve: 'ironsworndelvethemes'
},
delve_site_domain: {
delve: 'delve-domains'
delve: 'ironsworndelvedomains'
},
truth: {
classic: 'ironsworntruths',
Expand All @@ -53,7 +55,7 @@ const COMPENDIUM_KEY_MAP = {
}

export function renderLinksInStr(str: string): string {
return str.replace(MARKDOWN_LINK_RE, (match, text, url) => {
return str.replace(MARKDOWN_LINK_RE, (match, text: string, url: string) => {
if (!url.startsWith('datasworn:')) return match
url = url.substring('datasworn:'.length)
const parsed = IdParser.parse(url)
Expand Down Expand Up @@ -85,7 +87,7 @@ export function renderLinksInStr(str: string): string {
if (parsed.primaryTypeId === 'oracle_collection') {
return `<a class="entity-link oracle-category-link" data-dfid="${legacyId}" data-dsid="${url}"><i class="fa fa-caret-right"></i> ${text}</a>`
}
const urlHash = hash(legacyId || url)
const urlHash = hash(legacyId)
return `@Compendium[foundry-ironsworn.${compendiumKey}.${urlHash}]{${text}}`
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/module/features/custommoves.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IMove, IMoveCategory } from 'dataforged'
import { ISMoveCategories, SFMoveCategories } from '../dataforged/data'
import type { IronswornItem } from '../item/item'
import { cachedDocumentsForPack } from './pack-cache'
import { cachedDocumentsForPack, PackContents } from './pack-cache'

export interface MoveCategory {
color: string | null
Expand Down
15 changes: 7 additions & 8 deletions src/module/features/customoracles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import type { IOracle, IOracleCategory } from 'dataforged'
import { cloneDeep, compact } from 'lodash-es'
import { DataswornTree } from '../datasworn2'
import { IronswornSettings } from '../helpers/settings'
import { DataswornRulesetKey, IronswornSettings } from '../helpers/settings'
import {
DS_ORACLE_COMPENDIUM_KEYS,
OracleTable
Expand Down Expand Up @@ -146,12 +146,10 @@ export function findPathToNodeByDfId(rootNode: IOracleTreeNode, dfid: string) {
return ret
}

type OracleCategory = 'classic' | 'delve' | 'starforged' | 'sundered_isles'

const ORACLES: Record<string, IOracleTreeNode> = {}

export function registerOracleTreeInternal(
category: OracleCategory,
category: DataswornRulesetKey,
rootNode: IOracleTreeNode
) {
ORACLES[category] = rootNode
Expand Down Expand Up @@ -203,7 +201,8 @@ async function generateTreeFromDsData(
ruleset: RulesetId
): Promise<IOracleTreeNode> {
const pack = game.packs.get(DS_ORACLE_COMPENDIUM_KEYS[ruleset])
const index = await pack.getIndex({ fields: ['flags'] })
const index = await pack?.getIndex({ fields: ['flags'] })
if (!index) return emptyNode()

const rp = DataswornTree.get(ruleset)
return {
Expand All @@ -227,7 +226,7 @@ export async function registerDefaultOracleTrees() {

// Available in browser
export function registerOracleTree(
category: OracleCategory,
category: DataswornRulesetKey,
rootNode: IOracleTreeNode
) {
// Check if internal registrations have been done
Expand All @@ -242,12 +241,12 @@ export function registerOracleTree(
registerOracleTreeInternal(category, rootNode)
}

export function getOracleTree(category: OracleCategory): IOracleTreeNode {
export function getOracleTree(category: DataswornRulesetKey): IOracleTreeNode {
return cloneDeep(ORACLES[category])
}

export async function getOracleTreeWithCustomOracles(
category: OracleCategory
category: DataswornRulesetKey
): Promise<IOracleTreeNode> {
const rootNode = getOracleTree(category)

Expand Down
2 changes: 1 addition & 1 deletion src/module/features/pack-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { OracleTable } from '../roll-table/oracle-table'

const ONE_MINUTE_IN_MS = 60 * 1000

type PackContents = Array<
export type PackContents = Array<
StoredDocument<
| Scene
| IronswornActor
Expand Down
Loading

0 comments on commit bb6fd20

Please sign in to comment.