Sub PopulateMySpellBook(ListOfMaps As List, HeaderList As List, MySpellJustificationMap As Map)
Dim LoadDir As String : LoadDir = File.DirRootExternal & "/dnd"
Dim BackupDir As String : BackupDir = File.DirRootExternal & "/dnd"
Dim FileName As String
Log("Started Spellbook")
FileName = "MySpellBook.csv"
If File.Exists(LoadDir, FileName) Then 'If MySpellBook exists, load it.
'Load MySpellBook list.
LoadCSVFromFile(LoadDir, FileName, MySpellBookListOfMaps, MySpellBookListHeader, MySpellBookJustificationMap)
Else 'Load the big spell list, My Classes list and populate MySpellBook.
Dim BigSpellsListOfMaps As List : BigSpellsListOfMaps.Initialize()
Dim BigSpellsListHeader As List : BigSpellsListHeader.Initialize()
Dim BigSpellsJustificationMap As Map : BigSpellsJustificationMap.Initialize()
Dim BigClassesListOfMaps As List : BigClassesListOfMaps.Initialize()
Dim C As Int
Dim MyClasses(MyClassesListOfMaps.Size) As String
Dim RowMap As Map : RowMap.Initialize
Dim ClassCounter As Int
Dim AClassSpellsLevelsMap As Map : AClassSpellsLevelsMap.Initialize
Dim SpellName As String
Dim Level As Int
Dim Class As String
Dim LevelAll As String
Dim ClassesWithSpellsAndLevelsMap As Map : ClassesWithSpellsAndLevelsMap.Initialize
Dim TempMap As Map : TempMap.Initialize
Dim sf As StringFunctions : sf.Initialize
Dim SpellwithClassesAndLevelsMap As Map : SpellwithClassesAndLevelsMap.Initialize
Dim su As StringUtils
'Load the Big Spell List. It has all the spells for all the classes.
FileName = "BigSpellsList.csv"
LoadCSVFromFile(LoadDir, FileName, BigSpellsListOfMaps, BigSpellsListHeader, BigSpellsJustificationMap)
'Create spellclasseslevels.csv
FileName = "spellclasseslevels.csv"
If File.Exists(LoadDir, FileName) = False Then
For i = 1 To BigSpellsListOfMaps.Size - 1 'Iterate through BigSpellsListOfMaps
Dim TempMap As Map : TempMap.Initialize
TempMap = BigSpellsListOfMaps.Get(i) 'Get one line from BigSpellsListOfMaps. This is a map containing one spell and all its fields.
LevelAll = TempMap.Get("Level All") 'Get the contents of the Level All field from the map.
Log("LevelAll = " & LevelAll)
Dim OneClassAndLevel As List : OneClassAndLevel.Initialize
OneClassAndLevel = sf.StringArrayToList(LevelAll,False,False)
'Log("OneClassAndLevel" & OneClassAndLevel)
' For Each OneClassAndLevel As String In LevelAll
' Class = sf.Left(OneClassAndLevel,sf.Len(OneClassAndLevel)-2)
' Level = sf.Right(OneClassAndLevel,1)
' SpellName = TempMap.Get("Title")
' SpellwithClassesAndLevelsMap.Put(Class, Level)
' Next
SpellwithClassesAndLevelsMap.Put("SpellName", SpellName)
SpellsClassLevelsList.Add(SpellwithClassesAndLevelsMap)
Next
su.SaveCSV(LoadDir, FileName , "," , SpellsClassLevelsList)
End If