@@ -257,54 +257,56 @@ export default function registerHooks() {
257
257
} ) ;
258
258
} ) ;
259
259
260
- Hooks . on ( "changeSidebarTab" , ( app ) => {
261
- const shouldRender =
262
- app . tabName === "journal" &&
263
- Object . keys ( CONFIG . fbl . adventureSites . types ) . length &&
264
- ! app . element . find ( "#create-adventure-site" ) . length ;
260
+ for ( const hook of [ "renderSidebarTab" , "changeSidebarTab" ] ) {
261
+ Hooks . on ( hook , ( app ) => {
262
+ const shouldRender =
263
+ app . tabName === "journal" &&
264
+ Object . keys ( CONFIG . fbl . adventureSites . types ) . length &&
265
+ ! app . element . find ( "#create-adventure-site" ) . length ;
265
266
266
- if ( ! shouldRender ) return ;
267
+ if ( ! shouldRender ) return ;
267
268
268
- const adventureSiteButton = $ (
269
- `<button id="create-adventure-site"><i class="fas fa-castle"></i> Create Adventure Site</button>` ,
270
- ) ;
271
- adventureSiteButton . on ( "click" , ( ) => {
272
- adventureSiteCreateDialog ( ) ;
269
+ const adventureSiteButton = $ (
270
+ `<button id="create-adventure-site"><i class="fas fa-castle"></i> Create Adventure Site</button>` ,
271
+ ) ;
272
+ adventureSiteButton . on ( "click" , ( ) => {
273
+ adventureSiteCreateDialog ( ) ;
274
+ } ) ;
275
+
276
+ app . element . find ( ".header-actions" ) . append ( adventureSiteButton ) ;
273
277
} ) ;
278
+ }
274
279
275
- app . element . find ( ".header-actions" ) . append ( adventureSiteButton ) ;
276
- } ) ;
277
- }
280
+ Hooks . on ( "renderJournalSheet" , ( app , html ) => {
281
+ const type = app . object . getFlag ( "forbidden-lands" , "adventureSiteType" ) ;
282
+ const isDungeon = [ "dungeon" , "ice_cave" , "elven_ruin" ] . includes ( type ) ;
283
+ if ( ! isDungeon ) return ;
278
284
279
- Hooks . on ( "renderJournalSheet" , ( app , html ) => {
280
- const type = app . object . getFlag ( "forbidden-lands" , "adventureSiteType" ) ;
281
- const isDungeon = [ "dungeon" , "ice_cave" , "elven_ruin" ] . includes ( type ) ;
282
- if ( ! isDungeon ) return ;
285
+ const button = $ (
286
+ `<button type="button" class="create" data-action="add-room"><i class="fas fa-plus-circle"></i> ${ t ( "ADVENTURE_SITE.ADD_ROOM" ) } </button>` ,
287
+ ) ;
283
288
284
- const button = $ (
285
- `<button type="button" class="create" data-action="add-room"><i class="fas fa-plus-circle"></i> ${ t ( "ADVENTURE_SITE.ADD_ROOM" ) } </button>` ,
286
- ) ;
289
+ button . on ( "click" , async ( ) => {
290
+ const path = CONFIG . fbl . adventureSites . types [ type ] ;
291
+ const room = await CONFIG . fbl . adventureSites ?. generate (
292
+ path ,
293
+ `${ type } _rooms` ,
294
+ ) ;
295
+ const pageName = $ ( room )
296
+ . find ( "h4, strong" )
297
+ ?. first ( )
298
+ . text ( )
299
+ . replace ( / [ ^ \p{ L} ] + / u, " " )
300
+ . trim ( ) ;
301
+ await app . object . createEmbeddedDocuments ( "JournalEntryPage" , [
302
+ {
303
+ name : pageName ,
304
+ title : { level : 2 , show : false } ,
305
+ text : { content : `<div class="adventure-site">${ room } </div>` } ,
306
+ } ,
307
+ ] ) ;
308
+ } ) ;
287
309
288
- button . on ( "click" , async ( ) => {
289
- const path = CONFIG . fbl . adventureSites . types [ type ] ;
290
- const room = await CONFIG . fbl . adventureSites ?. generate (
291
- path ,
292
- `${ type } _rooms` ,
293
- ) ;
294
- const pageName = $ ( room )
295
- . find ( "h4, strong" )
296
- ?. first ( )
297
- . text ( )
298
- . replace ( / [ ^ \p{ L} ] + / u, " " )
299
- . trim ( ) ;
300
- await app . object . createEmbeddedDocuments ( "JournalEntryPage" , [
301
- {
302
- name : pageName ,
303
- title : { level : 2 , show : false } ,
304
- text : { content : `<div class="adventure-site">${ room } </div>` } ,
305
- } ,
306
- ] ) ;
310
+ html . find ( '[data-action="createPage"]' ) . after ( button ) ;
307
311
} ) ;
308
-
309
- html . find ( '[data-action="createPage"]' ) . after ( button ) ;
310
- } ) ;
312
+ }
0 commit comments