@@ -27,6 +27,40 @@ const entityUpdater = {
2727 }
2828}
2929
30+ const batchConversionManager = ( data , type , button ) => {
31+ let batchConvert = initBatchConversion ( data , type ) ;
32+ button . on ( 'click' , ( ) => createWarningDialog ( batchConvert ) ) ;
33+ }
34+
35+ const batchCompendiumManager = ( data , type , button ) => {
36+ let batchConvert = batchCompendiumUpdater ( game . packs . keys ( ) ) ;
37+ button . on ( 'click' , ( ) => createWarningDialog ( batchConvert ) ) ;
38+ }
39+
40+ const batchCompendiumUpdaterMap = {
41+ 'dnd5e' : {
42+ 'scenes' : batchConversionManager ,
43+ 'actors' : batchConversionManager ,
44+ 'items' : batchConversionManager ,
45+ 'tables' : batchConversionManager ,
46+ 'journal' : batchConversionManager ,
47+ 'compendium' : batchCompendiumManager
48+ } ,
49+ 'pf2e' : {
50+
51+ }
52+ }
53+
54+ const onRenderSideBar = ( app , html ) => {
55+ if ( ! game . user . hasRole ( 4 ) ) return ;
56+ let button = $ ( `<button><i class='fas fa-exchange-alt'></i>Metrify all the ${ app ?. options ?. id } </button>` ) ;
57+ const type = app ?. options ?. id ;
58+ if ( batchCompendiumUpdaterMap [ game . system . id ] [ type ] )
59+ batchCompendiumUpdaterMap [ game . system . id ] [ type ] ( type === 'compendium' ? game . packs . keys ( ) : game [ type ] , type , button ) ;
60+ if ( app ?. options ?. id !== 'combat' && app ?. options ?. id !== 'playlists' && ! app ?. options ?. id . includes ( 'popout' ) )
61+ html . find ( ".directory-footer" ) . append ( button ) ;
62+ }
63+
3064const addButton = ( element , entity , type , html ) => {
3165 if ( ! game . user . hasRole ( 4 ) ) return ;
3266 if ( element . length !== 1 ) return ;
@@ -56,38 +90,21 @@ const onRenderJurnalSheet = (obj, html) => {
5690 addButton ( element , obj . object , "sheet" ) ;
5791}
5892
59- const onRenderSideBar = ( app , html ) => {
60- if ( ! game . user . hasRole ( 4 ) ) return ;
61- let button = $ ( `<button><i class='fas fa-exchange-alt'></i>Metrify all the ${ app ?. options ?. id } </button>` ) ;
62- let batchConvert
63- switch ( app ?. options ?. id ) {
64- case "scenes" :
65- batchConvert = initBatchConversion ( game . scenes , app ?. options ?. id ) ;
66- button . on ( 'click' , ( ) => createWarningDialog ( batchConvert ) ) ;
67- break ;
68- case "compendium" :
69- batchConvert = batchCompendiumUpdater ( game . packs . keys ( ) ) ;
70- button . on ( 'click' , ( ) => createWarningDialog ( batchConvert ) ) ;
71- break ;
72- case "actors" :
73- batchConvert = initBatchConversion ( game . actors , app ?. options ?. id ) ;
74- button . on ( 'click' , ( ) => createWarningDialog ( batchConvert ) ) ;
75- break ;
76- case "items" :
77- batchConvert = initBatchConversion ( game . items , app ?. options ?. id ) ;
78- button . on ( 'click' , ( ) => createWarningDialog ( batchConvert ) ) ;
79- break ;
80- case "tables" :
81- batchConvert = initBatchConversion ( game . tables , app ?. options ?. id ) ;
82- button . on ( 'click' , ( ) => createWarningDialog ( batchConvert ) ) ;
83- break ;
84- case "journal" :
85- batchConvert = initBatchConversion ( game . journal , app ?. options ?. id ) ;
86- button . on ( 'click' , ( ) => createWarningDialog ( batchConvert ) ) ;
87- break ;
88- }
89- if ( app ?. options ?. id !== 'combat' && app ?. options ?. id !== 'playlists' && ! app ?. options ?. id . includes ( 'popout' ) )
90- html . find ( ".directory-footer" ) . append ( button ) ;
93+ const onRenderRollTable = ( obj , html ) => {
94+ let element = html . find ( ".window-header .window-title" ) ;
95+ addButton ( element , obj . object , 'rolltable' )
96+ }
97+
98+ const onCompendiumRender = ( obj , html ) => {
99+ let element = html . find ( ".window-header .window-title" ) ;
100+ addButton ( element , obj . collection , 'compendium' , obj ) ;
101+
102+ /*
103+ Intended for debugging the relinking function
104+ let button = $(`<a class="popout" style><i class="fas fa-ruler"></i>Relink</a>`);
105+ button.on('click', () => relinkCompendium(obj.collection))
106+ element.after(button)
107+ */
91108}
92109
93110const createWarningDialog = ( callFunction ) => {
@@ -109,23 +126,6 @@ const createWarningDialog = (callFunction) => {
109126 } ) . render ( true ) ;
110127}
111128
112- const onRenderRollTable = ( obj , html ) => {
113- let element = html . find ( ".window-header .window-title" ) ;
114- addButton ( element , obj . object , 'rolltable' )
115- }
116-
117- const onCompendiumRender = ( obj , html ) => {
118- let element = html . find ( ".window-header .window-title" ) ;
119- addButton ( element , obj . collection , 'compendium' , obj ) ;
120-
121- /*
122- Intended for debugging the relinking function
123- let button = $(`<a class="popout" style><i class="fas fa-ruler"></i>Relink</a>`);
124- button.on('click', () => relinkCompendium(obj.collection))
125- element.after(button)
126- */
127- }
128-
129129export {
130130 onCompendiumRender ,
131131 onRenderActorSheet ,
0 commit comments