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