1- function ftag_desc ( functional_tags , tag ) {
1+ class SpellCompendium {
2+ static ftag_desc ( functional_tags , tag ) {
23 return functional_tags [
34 Object . keys ( functional_tags ) . find ( f_tag => tag . includes ( f_tag ) )
45 ] ;
56}
67
78// Generate full-sized spell description
8- function spellCard ( spellData , functional_tags ) {
9+ static spellCard ( spellData , functional_tags ) {
910 const card = document . createElement ( 'table' ) ;
1011 const cardBody = card . appendChild ( document . createElement ( 'tbody' ) ) ;
1112 card . className = 'spell' ;
@@ -34,7 +35,7 @@ function spellCard(spellData, functional_tags) {
3435 tagsD . className = 'spelltags' ;
3536 tagsH . textContent = 'Tags:' ;
3637 tagsD . innerHTML = spellData . tags
37- . map ( tag => Object . keys ( functional_tags ) . some ( f_tag => tag . includes ( f_tag ) ) ? `<span class='fTag' title='${ ftag_desc ( functional_tags , tag ) } '>${ tag } </span>` : tag )
38+ . map ( tag => Object . keys ( functional_tags ) . some ( f_tag => tag . includes ( f_tag ) ) ? `<span class='fTag' title='${ SpellCompendium . ftag_desc ( functional_tags , tag ) } '>${ tag } </span>` : tag )
3839 . join ( ', ' )
3940 ;
4041
@@ -80,7 +81,7 @@ function spellCard(spellData, functional_tags) {
8081}
8182
8283// Generate spell table entry
83- function spellBrief ( spellData , functional_tags ) {
84+ static spellBrief ( spellData , functional_tags ) {
8485 const brief = document . createElement ( 'tr' ) ;
8586 brief . id = `spell_${ spellData . name . replaceAll ( ' ' , '_' ) } ` ;
8687
@@ -90,7 +91,7 @@ function spellBrief(spellData, functional_tags) {
9091 spellData . range ,
9192 spellData . duration ,
9293 spellData . tags
93- . map ( tag => Object . keys ( functional_tags ) . some ( f_tag => tag . includes ( f_tag ) ) ? `<span class='fTag' title='${ ftag_desc ( functional_tags , tag ) } '>${ tag } </span>` : tag )
94+ . map ( tag => Object . keys ( functional_tags ) . some ( f_tag => tag . includes ( f_tag ) ) ? `<span class='fTag' title='${ SpellCompendium . ftag_desc ( functional_tags , tag ) } '>${ tag } </span>` : tag )
9495 . join ( ', ' )
9596 ] . forEach ( data => {
9697 const td = brief . appendChild ( document . createElement ( 'td' ) ) ;
@@ -99,7 +100,7 @@ function spellBrief(spellData, functional_tags) {
99100 } ) ;
100101
101102 brief . onclick = function ( ) {
102- const card = spellCard ( spellData , functional_tags ) ;
103+ const card = SpellCompendium . spellCard ( spellData , functional_tags ) ;
103104 const compendiumRight = document . getElementById ( 'compendium_right' ) ;
104105 compendiumRight . replaceChild ( card , compendiumRight . firstElementChild ) ;
105106 } ;
@@ -108,21 +109,21 @@ function spellBrief(spellData, functional_tags) {
108109}
109110
110111// Generate spell table
111- function generate_brief_spell_table ( SpellDatabase , tag_select , tier_select , functional_tags ) {
112+ static generate_brief_spell_table ( SpellDatabase , tag_select , tier_select , functional_tags ) {
112113 const oldTable = document . querySelector ( '#spelltable' ) ;
113114 const newTable = oldTable . cloneNode ( false ) ;
114115
115116 SpellDatabase . forEach ( spell => {
116117 if ( tag_select . size > 0 && ! spell . tags . some ( tag => tag_select . has ( tag ) ) ) return ;
117118 if ( tier_select . size > 0 && ! tier_select . has ( spell . tier ) ) return ;
118- newTable . appendChild ( spellBrief ( spell , functional_tags ) ) ;
119+ newTable . appendChild ( SpellCompendium . spellBrief ( spell , functional_tags ) ) ;
119120 } ) ;
120121
121122 oldTable . parentNode . replaceChild ( newTable , oldTable ) ;
122123}
123124
124125// Download spell
125- function downloadSpell ( ) {
126+ static downloadSpell ( ) {
126127 const spell = document . querySelector ( "#compendium_right table" ) ;
127128 if ( spell ) {
128129 html2canvas ( spell , { allowTaint : true } ) . then ( function ( canvas ) {
@@ -139,7 +140,7 @@ function downloadSpell() {
139140
140141}
141142
142- function tag_buttons ( tag_list , tag_set , container , render_callback ) {
143+ static tag_buttons ( tag_list , tag_set , container , render_callback ) {
143144 Object . entries ( tag_list ) . sort ( ( a , b ) => {
144145 if ( a [ 1 ] == b [ 1 ] ) {
145146 return ( a [ 0 ] == b [ 0 ] ) ? 0 : ( a [ 0 ] > b [ 0 ] ) ? 1 : - 1 ;
@@ -179,7 +180,7 @@ function tag_buttons(tag_list, tag_set, container, render_callback) {
179180 } ) ;
180181}
181182
182- function main ( ) {
183+ static render ( ) {
183184 const compendiumLeft = document . getElementById ( 'compendium_left' ) ;
184185 const compendiumRight = document . getElementById ( 'compendium_right' ) ;
185186 const compendiumSchoolList = document . getElementById ( 'left_school_tags' ) ;
@@ -224,11 +225,11 @@ function main() {
224225
225226 const tag_select = new Set ( ) ;
226227 const tier_select = new Set ( ) ;
227- const gen_spelltable = ( ) => generate_brief_spell_table ( SpellDatabase , tag_select , tier_select , functional_tags ) ;
228+ const gen_spelltable = ( ) => SpellCompendium . generate_brief_spell_table ( SpellDatabase , tag_select , tier_select , functional_tags ) ;
228229
229230 // TAGS
230- tag_buttons ( school_tag_list , tag_select , compendiumSchoolList , gen_spelltable ) ;
231- tag_buttons ( tag_list , tag_select , compendiumTagList , gen_spelltable ) ;
231+ SpellCompendium . tag_buttons ( school_tag_list , tag_select , compendiumSchoolList , gen_spelltable ) ;
232+ SpellCompendium . tag_buttons ( tag_list , tag_select , compendiumTagList , gen_spelltable ) ;
232233
233234 // TIERS
234235 for ( let i = 1 ; i <= 9 ; i ++ ) {
@@ -251,15 +252,16 @@ function main() {
251252 }
252253 }
253254
254- compendiumRight . appendChild ( spellCard ( SpellDatabase [ 0 ] , functional_tags ) ) ;
255+ compendiumRight . appendChild ( SpellCompendium . spellCard ( SpellDatabase [ 0 ] , functional_tags ) ) ;
255256 gen_spelltable ( ) ;
256257
257258 const downloadButton = compendiumRight
258259 . appendChild ( document . createElement ( 'center' ) )
259260 . appendChild ( document . createElement ( 'button' ) ) ;
260261 downloadButton . textContent = "SAVE (.png)" ;
261262 downloadButton . style . textAlign = 'center' ;
262- downloadButton . onclick = downloadSpell ;
263+ downloadButton . onclick = SpellCompendium . downloadSpell ;
264+ }
263265}
264266
265- main ( ) ;
267+ SpellCompendium . render ( ) ;
0 commit comments