2022-01-05 22:46:26 +01:00
import { BoLUtility } from "./bol-utility.js" ;
2021-07-08 10:12:12 +02:00
export default function registerHooks ( ) {
2022-01-05 22:46:26 +01:00
/ * *
* Ready hook loads tables , and override 's foundry' s entity link functions to provide extension to pseudo entities
* /
Hooks . once ( "ready" , async ( ) => {
console . info ( "BOL | System Initialized." ) ;
} ) ;
2021-12-24 04:51:14 +01:00
Hooks . on ( "renderPause" , ( ( _app , html ) => {
html . find ( "img" ) . attr ( "src" , "systems/bol/ui/pause2.webp" )
} ) )
2022-01-05 22:46:26 +01:00
2022-03-27 22:56:43 +02:00
Hooks . on ( 'renderChatLog' , ( log , html , data ) => BoLUtility . chatListeners ( html ) )
Hooks . on ( 'renderChatMessage' , ( message , html , data ) => BoLUtility . chatMessageHandler ( message , html , data ) )
2022-01-05 22:46:26 +01:00
2021-12-22 05:12:40 +01:00
/ * *
* Create a macro when dropping an entity on the hotbar
* Item - open roll dialog for item
* Actor - open actor sheet
* Journal - open journal sheet
* /
Hooks . on ( "hotbarDrop" , async ( bar , data , slot ) => {
console . log ( data . type ) ;
// Create item macro if rollable item - weapon, spell, prayer, trait, or skill
if ( data . type == "Item" ) {
let item = data . data ;
console . log ( item ) ;
// let command = `let onlyDamage = false;\nlet customLabel = "";\nlet skillDescription = "";\nlet dmgDescription = "";\n\nif (event) {\n if (event.shiftKey) onlyDamage = true;\n}\n\ngame.cof.macros.rollItemMacro("${item._id}", "${item.name}", "${item.type}", 0, 0, 0, onlyDamage, customLabel, skillDescription, dmgDescription);`;
2021-07-08 10:12:12 +02:00
2021-12-22 05:12:40 +01:00
// let macro = game.macros.entities.find(m => (m.name === item.name) && (m.command === command));
// if (!macro) {
// macro = await Macro.create({
// name: item.name,
// type : "script",
// img: item.img,
// command : command
// }, {displaySheet: false})
// }
// game.user.assignHotbarMacro(macro, slot);
}
// Create a macro to open the actor sheet of the actor dropped on the hotbar
else if ( data . type == "Actor" ) {
let actor = game . actors . get ( data . id ) ;
let command = ` /* \n Personnalisez la macro selon vos besoins en suivant les exemples suivants : \n game.bol.macros.rollMacro('attribute', 'vigor|agility|mind|appeal', adv, mod); \n game.bol.macros.rollMacro('aptitude', 'init|melee|ranged|def', adv, mod); \n */ \n game.bol.macros.rollMacro('attribute', 'vigor', 0, 0); ` ;
let macro = game . macros . entities . find ( m => ( m . name === actor . name ) && ( m . command === command ) ) ;
if ( ! macro ) {
macro = await Macro . create ( {
2023-04-04 13:41:22 +02:00
name : actor . name ,
2021-12-22 05:12:40 +01:00
type : "script" ,
img : "icons/svg/dice-target.svg" ,
command : command
} , { displaySheet : false } )
game . user . assignHotbarMacro ( macro , slot ) ;
}
}
// Create a macro to open the journal sheet of the journal dropped on the hotbar
else if ( data . type == "JournalEntry" ) {
let journal = game . journal . get ( data . id ) ;
console . log ( journal ) ;
let command = ` game.journal.get(" ${ data . id } ").sheet.render(true) `
let macro = game . macros . entities . find ( m => ( m . name === journal . name ) && ( m . command === command ) ) ;
if ( ! macro ) {
macro = await Macro . create ( {
2023-04-04 13:41:22 +02:00
name : journal . name ,
2021-12-22 05:12:40 +01:00
type : "script" ,
2023-04-04 13:41:22 +02:00
img : ( journal . img ) ? journal . img : "icons/svg/book.svg" ,
2021-12-22 05:12:40 +01:00
command : command
} , { displaySheet : false } )
game . user . assignHotbarMacro ( macro , slot ) ;
}
}
return false ;
} ) ;
2022-11-25 20:47:28 +01:00
/********************************************************************************** */
Hooks . on ( "renderActorDirectory" , ( app , html , data ) => {
if ( game . user . isGM ) {
const button = document . createElement ( 'button' ) ;
button . style . width = '95%' ;
button . innerHTML = game . i18n . localize ( "BOL.ui.pclistbutton" )
button . addEventListener ( 'click' , ( ) => {
game . bol . charSummary . render ( true )
} )
html . find ( '.header-actions' ) . after ( button )
}
} )
2021-07-08 10:12:12 +02:00
}