Skip to content

Commit

Permalink
simplify ChatMessage handling + add error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Spappz committed Jan 30, 2025
1 parent e4f8210 commit 57489db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"error": {
"badModuleFlags": "Failed to read package flags for module {title} (<code>{id}</code>).",
"badModuleAnimations": "Failed to load animation sets for {title} (<code>{id}</code>). See console (<kbd>F12</kbd>) for more information.",
"badMessageFlags": "Failed to read module <code>ChatMessage</code> flags (received <code>{flags}</code>).",
"cantAccessFile": "Can't access file `{path}`.",
"schemaValidationFailed": "{number} animation sets failed validation! See console (<kbd>F12</kbd>) for more information."
}
Expand Down
15 changes: 10 additions & 5 deletions src/view/ChatMessage/index.ts
Original file line number Diff line number Diff line change
@@ -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(', '),
});
}
}

Expand Down

0 comments on commit 57489db

Please sign in to comment.