@@ -122,7 +122,7 @@ async function buildMonsterFromFile(file: File): Promise<Monster> {
122122
123123 resolve ( importedMonster ) ;
124124 } catch ( e ) {
125- console . error ( e )
125+ console . error ( e ) ;
126126 reject ( e ) ;
127127 }
128128 } ;
@@ -157,20 +157,62 @@ const spellMap: { [key: string]: string } = {
157157function getSpells ( monster : any ) : any [ ] {
158158 if ( ! monster . spellcasting || ! monster . spellcasting . length ) return [ ] ;
159159
160- return [
161- monster . spellcasting [ 0 ] . headerEntries . join ( "\n" ) ,
162- ...Object . entries ( monster . spellcasting [ 0 ] . spells ) . map (
163- ( [ level , { slots, spells } ] ) => {
164- let name = `${ spellMap [ level ] } ` ;
165- name += slots != undefined ? ` (${ slots } slots)` : "" ;
160+ const spells = monster . spellcasting [ 0 ] . spells ?? { } ;
161+ const will = monster . spellcasting [ 0 ] . will ?? [ ] ;
162+ const daily = monster . spellcasting [ 0 ] . daily ?? { } ;
166163
167- const sp = spells
164+ const ret = [ ( monster . spellcasting [ 0 ] . headerEntries ?? [ ] ) . join ( "\n" ) ] ;
165+
166+ if ( spells ) {
167+ try {
168+ ret . push (
169+ ...Object . entries ( spells ) . map (
170+ ( [ level , { slots, spells } ] ) => {
171+ let name = `${ spellMap [ level ] } ` ;
172+ name += slots != undefined ? ` (${ slots } slots)` : "" ;
173+
174+ const sp = spells
175+ . join ( ", " )
176+ . replace ( / \{ @ s p e l l ( [ \s \S ] + ?) \} / g, `$1` ) ;
177+ return { [ name ] : sp } ;
178+ }
179+ )
180+ ) ;
181+ } catch ( e ) {
182+ throw new Error ( "There was an error parsing the spells." ) ;
183+ }
184+ }
185+ if ( will ) {
186+ try {
187+ ret . push ( {
188+ "At will" : will
168189 . join ( ", " )
169- . replace ( / \{ @ s p e l l ( [ \s \S ] + ?) \} / g, `$1` ) ;
170- return { [ name ] : sp } ;
171- }
172- )
173- ] ;
190+ . replace ( / \{ @ s p e l l ( [ \s \S ] + ?) \} / g, `$1` )
191+ } )
192+ } catch ( e ) {
193+ throw new Error ( "There was an error parsing the at-will spells." )
194+ }
195+ }
196+ if ( daily ) {
197+ try {
198+ ret . push (
199+ ...Object . entries ( daily ) . map (
200+ ( [ num , spells ] ) => {
201+ let name = `Daily (${ num } )` ;
202+
203+ const sp = spells
204+ . join ( ", " )
205+ . replace ( / \{ @ s p e l l ( [ \s \S ] + ?) \} / g, `$1` ) ;
206+ return { [ name ] : sp } ;
207+ }
208+ )
209+ ) ;
210+ } catch ( e ) {
211+ throw new Error ( "There was an error parsing the daily spells." ) ;
212+ }
213+ }
214+
215+ return ret ;
174216}
175217
176218function getAlignmentString ( alignment : any ) {
0 commit comments