|
| 1 | +import {registerConfigs} from "./config.js"; |
| 2 | + |
| 3 | +export default class Burble{ |
| 4 | + static ID = 'fox-burble'; |
| 5 | + static NAME = 'Burble'; |
| 6 | + |
| 7 | + static SETTINGS = { |
| 8 | + SPEECH_FONT: 'speech-font', |
| 9 | + ON_OFF: 'on-off' |
| 10 | + } |
| 11 | + |
| 12 | + static loadCSS() { |
| 13 | + // Get HTML head element |
| 14 | + if (game.settings.get(Burble.ID,Burble.SETTINGS.ON_OFF)){ |
| 15 | + |
| 16 | + var head = document.getElementsByTagName('HEAD')[0]; |
| 17 | + |
| 18 | + var link = document.createElement('link'); |
| 19 | + link.rel = 'stylesheet'; |
| 20 | + link.type = 'text/css'; |
| 21 | + link.href = './modules/fox-burble/styles/main.css'; |
| 22 | + head.appendChild(link); |
| 23 | + |
| 24 | + if (game.settings.get(Burble.ID,Burble.SETTINGS.SPEECH_FONT) != 'default'){ |
| 25 | + var link = document.createElement('link'); |
| 26 | + link.rel = 'stylesheet'; |
| 27 | + link.type = 'text/css'; |
| 28 | + link.href = `./modules/fox-burble/styles/${game.settings.get(Burble.ID,Burble.SETTINGS.SPEECH_FONT)}.css`; |
| 29 | + head.appendChild(link); |
| 30 | + } |
| 31 | + |
| 32 | + //console.log(`GAME SYSTEM: ${game.system.id}`); |
| 33 | + if (['dnd4e','blades-in-the-dark'].includes(game.system.id)){ |
| 34 | + var link = document.createElement('link'); |
| 35 | + link.rel = 'stylesheet'; |
| 36 | + link.type = 'text/css'; |
| 37 | + link.href = `./modules/fox-burble/styles/${game.system.id}.css`; |
| 38 | + head.appendChild(link); |
| 39 | + |
| 40 | + if (game.settings.get("dnd4e","darkMode")){ |
| 41 | + link = document.createElement('link'); |
| 42 | + link.rel = 'stylesheet'; |
| 43 | + link.type = 'text/css'; |
| 44 | + link.href = './modules/fox-burble/styles/dnd4e_dark.css'; |
| 45 | + head.appendChild(link); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +Hooks.once('init', () => { |
| 54 | + registerConfigs(); |
| 55 | + Burble.loadCSS(); |
| 56 | +}); |
| 57 | + |
| 58 | +Hooks.on('renderChatMessage', async function(message, html, data){ |
| 59 | + if(!game.settings.get(Burble.ID,Burble.SETTINGS.ON_OFF)) return; |
| 60 | + |
| 61 | + console.log(data); |
| 62 | + html[0].classList.add('burble'); |
| 63 | + if(data?.cssClass=="emote") return; |
| 64 | + |
| 65 | + if(message.isRoll){ |
| 66 | + html[0].classList.add('roll'); |
| 67 | + if(message.flags?.core?.initiativeRoll){ |
| 68 | + html[0].classList.add('notice'); |
| 69 | + }else if(message.content.startsWith('<div class="table-draw')){ |
| 70 | + html[0].classList.add('roll-table','notice'); |
| 71 | + } |
| 72 | + }else if( data?.cssClass=="ic" || (!message.speaker?.actor && !message.content.startsWith("<"))){ |
| 73 | + html[0].classList.add('speech'); |
| 74 | + }else{ |
| 75 | + html[0].classList.add('notice'); |
| 76 | + if(message?.flavor == 'Item Piles'){ |
| 77 | + html[0].classList.add('item-piles'); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + if(!message.speaker?.token && !html[0].classList.contains('narrator-chat')){ |
| 82 | + html[0].classList.add('system-message'); |
| 83 | + } |
| 84 | + |
| 85 | + //Special for D&D4e compatibility |
| 86 | + if (['dnd4e'].includes(game.system.id)){ |
| 87 | + |
| 88 | + if(message.isRoll){ |
| 89 | + if(data.message?.rolls[0].search("RollWithOriginalExpression") > 0){ |
| 90 | + html[0].classList.add('notice'); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + if(message.content.startsWith('<div class="dnd4e')){ |
| 95 | + let cardContainer; |
| 96 | + let buttonElement; |
| 97 | + let panelElement; |
| 98 | + |
| 99 | + if(message.content.startsWith('<div class="dnd4e chat-card')){ |
| 100 | + html[0].classList.add('chat-card'); |
| 101 | + html[0].classList.remove('notice'); |
| 102 | + cardContainer = html.find(".chat-card")[0]; |
| 103 | + buttonElement = html.find(".card-buttons")[0]; |
| 104 | + panelElement = html.find(".effects-tray")[0]; |
| 105 | + }else if(message.content.startsWith('<div class="dnd4e dot-report')){ |
| 106 | + html[0].classList.add('dot-report'); |
| 107 | + cardContainer = html.find(".dot-report")[0].parentElement; |
| 108 | + buttonElement = html.find(".chatDamageButtons")[0]; |
| 109 | + panelElement = html.find(".effects-tray")[0]; |
| 110 | + } |
| 111 | + |
| 112 | + if(buttonElement){ |
| 113 | + cardContainer.appendChild(buttonElement); |
| 114 | + } |
| 115 | + if(panelElement){ |
| 116 | + cardContainer.appendChild(panelElement); |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | +}); |
0 commit comments