annotate SkeletonKey/DynamicTypes.lua @ 16:cdd387d39137

filename refactor
author Nenue
date Fri, 29 Jul 2016 21:18:15 -0400
parents SkeletonKey/Cache.lua@32d64e42ec9b
children 500f9b2bd9ac
rev   line source
Nenue@6 1 -- KrakTool
Nenue@16 2 -- DynamicTypes.lua
Nenue@6 3 -- Created: 7/28/2016 3:28 PM
Nenue@6 4 -- %file-revision%
Nenue@16 5 -- Logic related to dynamic handlers
Nenue@6 6 local kb, print = LibStub('LibKraken').register(KeyBinder, 'PlayerInfo')
Nenue@6 7
Nenue@15 8 local PET_SPECIAL_SUBTEXT = 'Special Ability'
Nenue@6 9 local BINDING_TYPE_SPECIALIZATION = 3
Nenue@6 10 local BINDING_TYPE_CHARACTER = 2
Nenue@6 11 local BINDING_TYPE_GLOBAL = 1
Nenue@6 12 local professionMappings = {
Nenue@6 13 [5] = 3,
Nenue@6 14 [7] = 4,
Nenue@6 15 [9] = 5,
Nenue@6 16 [10] = 6
Nenue@6 17 }
Nenue@6 18
Nenue@6 19 kb.TalentCache = {}
Nenue@6 20 kb.ProfessionCache = {}
Nenue@6 21 kb.PetCache = {}
Nenue@6 22 kb.specInfo = {}
Nenue@6 23 kb.UpdateSpecInfo = function()
Nenue@6 24 kb.specInfo.id = GetSpecialization()
Nenue@6 25 kb.specInfo.globalID, kb.specInfo.name, kb.specInfo.desc, kb.specInfo.texture = GetSpecializationInfo(kb.specInfo.id)
Nenue@6 26 kb.loadedProfiles[BINDING_TYPE_CHARACTER][kb.specInfo.id] = kb.InitProfile(kb.loadedProfiles[BINDING_TYPE_CHARACTER][kb.specInfo.id], {
Nenue@6 27 specID = kb.specInfo.id})
Nenue@6 28
Nenue@6 29 kb.configHeaders[BINDING_TYPE_SPECIALIZATION] = kb.configTitle[BINDING_TYPE_SPECIALIZATION]:format(kb.specInfo.name)
Nenue@6 30 kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION] = kb.loadedProfiles[BINDING_TYPE_CHARACTER][kb.specInfo.id]
Nenue@14 31 kb.currentProfile = kb.loadedProfiles[kb.db.bindMode]
Nenue@14 32 print('|cFF00FF00bindMode:|r', kb.db.bindMode)
Nenue@6 33
Nenue@6 34 kb.profileOrder = {kb.loadedProfiles[BINDING_TYPE_GLOBAL], kb.loadedProfiles[BINDING_TYPE_CHARACTER], kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION]}
Nenue@6 35
Nenue@6 36 print('|cFF00FF00current spec:|r', kb.specInfo.id, 'of', GetNumSpecializations())
Nenue@6 37 end
Nenue@6 38
Nenue@6 39 kb.UpdateTalentInfo = function()
Nenue@6 40 if kb.talentsPushed then
Nenue@6 41 return
Nenue@6 42 end
Nenue@6 43
Nenue@6 44
Nenue@6 45 table.wipe(kb.TalentCache)
Nenue@6 46
Nenue@6 47 for row =1, MAX_TALENT_TIERS do
Nenue@6 48 for col = 1, NUM_TALENT_COLUMNS do
Nenue@6 49 local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1)
Nenue@6 50 local talentInfo = kb.TalentCache[spellID] or {}
Nenue@6 51 talentInfo.row = 1
Nenue@6 52 talentInfo.col = col
Nenue@6 53 talentInfo.name = talentName
Nenue@6 54 talentInfo.talentID = talentID
Nenue@6 55 talentInfo.selected = selected
Nenue@6 56 talentInfo.available = available
Nenue@6 57 talentInfo.spellID = spellID
Nenue@6 58 kb.TalentCache[spellID] = talentInfo
Nenue@13 59 kb.TalentCache[talentName] = talentInfo
Nenue@6 60 print('Talent ', row, col, spellID, talentName)
Nenue@6 61 end
Nenue@6 62 end
Nenue@6 63 kb.talentsPushed = true
Nenue@6 64 end
Nenue@6 65
Nenue@6 66 kb.UpdateProfessionInfo = function()
Nenue@6 67 table.wipe(kb.ProfessionCache)
Nenue@6 68 local profs = {GetProfessions() }
Nenue@6 69 local primaryNum = 0
Nenue@6 70 for i, index in ipairs(profs) do
Nenue@6 71 local profName, texture, rank, maxRank, numSpells, spellOffset = GetProfessionInfo(index)
Nenue@6 72 print(i, index, profName, numSpells, spellOffset)
Nenue@6 73 if not professionMappings[index] then
Nenue@6 74 primaryNum = primaryNum + 1
Nenue@6 75 end
Nenue@6 76 local profNum = professionMappings[index] or primaryNum
Nenue@6 77
Nenue@6 78
Nenue@6 79 kb.ProfessionCache[profNum] = kb.ProfessionCache[i] or {}
Nenue@6 80
Nenue@6 81 for j = 1, numSpells do
Nenue@6 82 local spellName, _, icon, _, _, _, spellID = GetSpellInfo(spellOffset+j, BOOKTYPE_PROFESSION)
Nenue@6 83
Nenue@6 84 local profInfo = {
Nenue@6 85 spellName = spellName,
Nenue@6 86 spellID = spellID,
Nenue@6 87 icon = icon,
Nenue@6 88 profOffset = i,
Nenue@6 89 profIndex = index,
Nenue@6 90 spellOffset = (spellOffset+j),
Nenue@6 91 spellNum = j
Nenue@6 92 }
Nenue@6 93 KeyBinderKey:SetAttribute("*type-profession_"..i .. '_' ..j, "spell")
Nenue@6 94 KeyBinderKey:SetAttribute("*spell-profession_"..i .. '_' ..j, spellName)
Nenue@6 95
Nenue@6 96 kb.ProfessionCache[i .. '_' .. j] = profInfo
Nenue@6 97 kb.ProfessionCache[spellName] = profInfo
Nenue@6 98 kb.ProfessionCache[spellID] = profInfo
Nenue@6 99 print(' |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j)
Nenue@6 100 end
Nenue@6 101
Nenue@6 102 end
Nenue@6 103
Nenue@6 104 end
Nenue@6 105
Nenue@6 106
Nenue@15 107
Nenue@6 108 kb.UpdatePetInfo = function()
Nenue@15 109 kb.PetCache.spell = kb.PetCache.spell or {}
Nenue@15 110 kb.PetCache.spellslot = kb.PetCache.spellslot or {}
Nenue@15 111 kb.PetCache.action = kb.PetCache.action or {}
Nenue@15 112 kb.PetCache.special = kb.PetCache.action or {}
Nenue@15 113 local hasPetSpells, petType = HasPetSpells()
Nenue@15 114 if PetHasSpellbook() then
Nenue@15 115 print('PET SPELLBOOK')
Nenue@15 116 local i = 1
Nenue@15 117 local specialNum = 0
Nenue@15 118 repeat
Nenue@15 119
Nenue@15 120 local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
Nenue@15 121 local spellName, subText = GetSpellBookItemName(i, BOOKTYPE_PET)
Nenue@15 122 local isPassive = IsPassiveSpell(i, BOOKTYPE_PET)
Nenue@15 123 if not isPassive then
Nenue@15 124 if spellName then
Nenue@15 125 kb.PetCache.spellslot[spellName] = {i, spellName, subText}
Nenue@15 126 print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
Nenue@15 127
Nenue@15 128 if subText == PET_SPECIAL_SUBTEXT then
Nenue@15 129 specialNum = specialNum + 1
Nenue@15 130 kb.PetCache.special[spellName] = {i, specialNum, spellID, subText }
Nenue@15 131 print('|cFF00FFFFspecial['..spellName..']|r', '=>', i, specialNum, spellID, subText)
Nenue@15 132 end
Nenue@15 133
Nenue@15 134 if spellID then
Nenue@15 135 kb.PetCache.spell[i] = {spellID, spellName, subText}
Nenue@15 136 print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
Nenue@15 137 end
Nenue@15 138 end
Nenue@15 139
Nenue@15 140
Nenue@15 141 end
Nenue@15 142
Nenue@15 143 i = i + 1
Nenue@15 144 until spellType == nil
Nenue@15 145 else
Nenue@15 146 print('NO PET SPELLBOOK')
Nenue@15 147 table.wipe(kb.PetCache.spell)
Nenue@15 148 table.wipe(kb.PetCache.spellslot)
Nenue@15 149 end
Nenue@15 150
Nenue@15 151 if PetHasActionBar() then
Nenue@15 152 print('PET ACTION BAR')
Nenue@15 153 for i = 1, 10 do
Nenue@15 154
Nenue@15 155
Nenue@15 156 local name, subtext, texture, isToken, isActive = GetPetActionInfo(i)
Nenue@15 157 if name then
Nenue@15 158 kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive }
Nenue@15 159
Nenue@15 160
Nenue@15 161 end
Nenue@15 162 print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
Nenue@15 163 end
Nenue@15 164 else
Nenue@15 165 print('NO PET ACTION BAR')
Nenue@15 166 table.wipe(kb.PetCache.action)
Nenue@15 167 end
Nenue@15 168
Nenue@15 169 kb.UpdateCacheButtons(kb.petFrames)
Nenue@15 170
Nenue@15 171 end
Nenue@15 172
Nenue@15 173 kb.SystemBinds = {}
Nenue@15 174 kb.UpdateSystemBinds = function()
Nenue@15 175 table.wipe(kb.SystemBinds)
Nenue@15 176 local n = GetNumBindings()
Nenue@15 177 for i=1, n do
Nenue@15 178 local command, key1, key2 = GetBinding(i)
Nenue@15 179 if key1 then
Nenue@15 180 kb.SystemBinds[key1] = command
Nenue@15 181 end
Nenue@15 182 if key2 then
Nenue@15 183 kb.SystemBinds[key2] = command
Nenue@15 184 end
Nenue@15 185 end
Nenue@15 186
Nenue@15 187 end
Nenue@15 188
Nenue@15 189 do
Nenue@15 190 local garbage = {}
Nenue@15 191 kb.UpdateCacheButtons = function(pending)
Nenue@15 192 for i, button in ipairs(pending) do
Nenue@15 193 if button.isDynamic then
Nenue@15 194 print('flushing button', button:GetID())
Nenue@15 195 kb.UpdateSlot(button, true)
Nenue@15 196 end
Nenue@15 197 end
Nenue@15 198 end
Nenue@15 199 end
Nenue@15 200
Nenue@15 201
Nenue@15 202 kb.RemoveCacheButton = function(pending, button)
Nenue@15 203 local found
Nenue@15 204 for index, frame in ipairs(pending) do
Nenue@15 205 if button == frame then
Nenue@15 206 found = index
Nenue@15 207 break
Nenue@15 208 end
Nenue@15 209 end
Nenue@15 210 if found then
Nenue@15 211 print('|cFFFF4400pruning', button:GetName(), 'from update queue')
Nenue@15 212 tremove(pending, found)
Nenue@15 213 end
Nenue@6 214
Nenue@6 215 end