11import { MODULE_ID } from '../constants' ;
2-
3- Hooks . once ( 'init' , ( ) => {
4- game . settings . register ( MODULE_ID , 'tweak.inspiration.toggle' , {
5- name : `Toggle Chat Inspiration Icon` ,
6- hint : 'Toggle on/off the icon' ,
7- scope : 'world' ,
8- config : true ,
9- type : Boolean ,
10- default : false
11- } ) ;
12- game . settings . register ( MODULE_ID , 'tweak.inspiration.icon' , {
13- name : `Chat Inspiration Icon` ,
14- hint : 'asset file for inspiration icon' ,
15- scope : 'world' ,
16- config : true ,
17- type : String ,
18- default : 'systems/dnd5e/icons/spells/heal-sky-3.jpg' ,
19- filePicker : true
20- } ) ;
21- } ) ;
22-
23- class InspirationSettings {
24- static getToggle ( ) {
25- return game . settings . get ( MODULE_ID , 'tweak.inspiration.toggle' ) ;
26- }
27- static getIcon ( ) {
28- return game . settings . get ( MODULE_ID , 'tweak.inspiration.icon' ) ;
29- }
30- }
2+ import InspirationSettings from './Settings' ;
313
324Hooks . on ( 'renderChatMessage' , ( app , html , data ) => {
335 if ( InspirationSettings . getToggle ( ) ) {
@@ -37,20 +9,36 @@ Hooks.on('renderChatMessage', (app, html, data) => {
379 if ( actor ) {
3810 const inspiration = actor . data . data . attributes . inspiration ;
3911 if ( inspiration ) {
40- const img = document . createElement ( 'img' ) ;
41- img . width = 36 ;
42- img . height = 36 ;
43- img . src = InspirationSettings . getIcon ( ) ;
44- img . style . border = 'none' ;
45- img . style . flex = 'none' ;
46-
4712 const chatElement = html [ 0 ] ;
4813 const header = chatElement . querySelector ( 'header' ) ;
4914
50- if ( header . children [ 0 ] instanceof HTMLImageElement ) {
51- header . insertBefore ( img , header . children [ 1 ] ) ;
15+ if ( InspirationSettings . getBadge ( ) ) {
16+ const img = document . createElement ( 'img' ) ;
17+ img . width = 16 ;
18+ img . height = 16 ;
19+ img . src = `modules/${ MODULE_ID } /assets/inspiration-icon.svg` ;
20+ img . alt = 'inspiration' ;
21+ img . title = 'inspiration' ;
22+ img . style . border = 'none' ;
23+ img . style . position = 'relative' ;
24+ img . style . marginLeft = '5px' ;
25+ img . style . top = '3px' ;
26+
27+ header . children [ 0 ] . appendChild ( img ) ;
5228 } else {
53- header . prepend ( img ) ;
29+ const img = document . createElement ( 'img' ) ;
30+ img . width = 36 ;
31+ img . height = 36 ;
32+ img . src = InspirationSettings . getIcon ( ) ;
33+ img . style . border = 'none' ;
34+ img . style . flex = 'none' ;
35+ img . style . margin = '0 3px 5px 0' ;
36+
37+ if ( header . children [ 0 ] instanceof HTMLImageElement ) {
38+ header . insertBefore ( img , header . children [ 1 ] ) ;
39+ } else {
40+ header . prepend ( img ) ;
41+ }
5442 }
5543 }
5644 }
0 commit comments