diff --git a/lang/en.json b/lang/en.json index c9754c1f..93eaae25 100644 --- a/lang/en.json +++ b/lang/en.json @@ -44,6 +44,7 @@ "error": { "badModuleFlags": "Failed to read package flags for module {title} ({id}).", "badModuleAnimations": "Failed to load animation sets for {title} ({id}). See console (F12) for more information.", + "badMessageFlags": "Failed to read module ChatMessage flags (received {flags}).", "cantAccessFile": "Can't access file `{path}`.", "schemaValidationFailed": "{number} animation sets failed validation! See console (F12) for more information." } diff --git a/src/view/ChatMessage/index.ts b/src/view/ChatMessage/index.ts index 6ca26bed..bee9ae2d 100644 --- a/src/view/ChatMessage/index.ts +++ b/src/view/ChatMessage/index.ts @@ -1,20 +1,25 @@ import type { ChatMessagePF2e } from 'foundry-pf2e'; import { FVTTVersion } from '#standard/fvtt'; -import { info } from '../../utils'; +import { ErrorMsg, info } from '../../utils'; import CrosshairPicker from './CrosshairPicker.svelte'; import TourNag from './TourNag.svelte'; function assignSvelteComponent(element: HTMLElement, message: ChatMessagePF2e, component: string) { - if (!message.flags['pf2e-graphics']) return; - if (message.flags['pf2e-graphics']._svelteComponent) return; + const moduleFlags = message.flags['pf2e-graphics']; + if (!moduleFlags) return; + if (moduleFlags._svelteComponent) return; if (component === 'CrosshairPicker') { - message.flags['pf2e-graphics']._svelteComponent = new CrosshairPicker({ + moduleFlags._svelteComponent = new CrosshairPicker({ target: element, props: { message }, }); } else if (component === 'TourNag') { - message.flags['pf2e-graphics']._svelteComponent = new TourNag({ target: element, props: { message } }); + moduleFlags._svelteComponent = new TourNag({ target: element, props: { message } }); + } else { + throw ErrorMsg.send('pf2e-graphics.load.error.badMessageFlags', { + flags: Object.keys(moduleFlags).join(', '), + }); } }