Skip to content

Commit

Permalink
2.5.0 for 6.2
Browse files Browse the repository at this point in the history
Signed-off-by: Alar of Daggerspine <[email protected]>
  • Loading branch information
Alar of Daggerspine committed Jun 21, 2015
1 parent 605258f commit febb97e
Show file tree
Hide file tree
Showing 17 changed files with 440 additions and 708 deletions.
12 changes: 2 additions & 10 deletions BuildingPage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,14 @@ followerTooltip="colore + nome del follower"
size= level
Plot=framde del piedistallino
Icon e IconRing contenuto e nordo dell'iconcina
--]]
local me,ns=...
local addon=ns.addon
--@debug@
if LibDebug then LibDebug() end
--@end-debug@
ns.Configure()
local addon=addon
local GBF=GarrisonBuildingFrame
local GBFMap=GBF.MapFrame
local G=C_Garrison
local CreateFrame=CreateFrame
local GARRISON_FOLLOWER_MAX_LEVEL=GARRISON_FOLLOWER_MAX_LEVEL
local L=ns.L
local D=ns.D
local C=ns.C
local new,del=ns.new,ns.del
local module=addon:NewSubClass("BuildingPage") --#module
function module:OnInitialize()
Expand Down
7 changes: 5 additions & 2 deletions Debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,12 @@ local function traitGen()
end
local trackedEvents={}
local function eventTrace ( self, event, ... )
if (event:find("GARRISON",1,true)) then
if (event=="VARIABLES_LOADED") then
trackedEvents=ATEINFO.trackedEvents or {}
elseif (event:find("GARRISON",1,true)) then
local signature="("..event
for i=1,select('#',...) do
signature=','..signature..type(select(i,...))
signature=','..signature.." ".. tostring(select(i,...))
end
signature=signature..")"
trackedEvents[event]=signature
Expand Down Expand Up @@ -385,6 +387,7 @@ function addon:DumpSinks()
table.sort(sorted,function(a,b) return a>b end)
self:cutePrint(scroll,sorted)
end
_G.GAC=addon
--[[
PlaySound("UI_Garrison_CommandTable_Open");
PlaySound("UI_Garrison_CommandTable_Close");
Expand Down
237 changes: 217 additions & 20 deletions FollowerCache.lua
Original file line number Diff line number Diff line change
@@ -1,35 +1,229 @@
local me,ns=...
local addon=ns.addon --#addon
local holdEvents,releaseEvents=addon.holdEvents,addon.releaseEvents
local xdump=ns.xdump
ns.Configure()
print("loaded")
local addon=addon --#addon
--local holdEvents,releaseEvents=addon.holdEvents,addon.releaseEvents
--upvalue
local C=ns.C
local G=C_Garrison
local GMF=GarrisonMissionFrame
local type=type
local select=select
local pairs=pairs
local tonumber=tonumber
local tinsert=tinsert
local Mbase = GarrisonMissionFrameFollowers
local tContains=tContains
local wipe=wipe
local Mbase = {}
local GARRISON_FOLLOWER_MAX_UPGRADE_QUALITY=GARRISON_FOLLOWER_MAX_UPGRADE_QUALITY
local GARRISON_FOLLOWER_MAX_LEVEL=GARRISON_FOLLOWER_MAX_LEVEL
local format=format
local tostring=tostring
local GetItemInfo=GetItemInfo
local index={}
local names={}
local sorted={}
local threats={}
local traits={}
local LE_FOLLOWER_TYPE_GARRISON_6_0=_G.LE_FOLLOWER_TYPE_GARRISON_6_0
local LE_FOLLOWER_TYPE_SHIPYARD_6_2=_G.LE_FOLLOWER_TYPE_SHIPYARD_6_2
local maxrank=GARRISON_FOLLOWER_MAX_UPGRADE_QUALITY*1000+GARRISON_FOLLOWER_MAX_LEVEL
local module=addon:NewSubClass('FollowerCache')
local cache={} --#cache
local EMPTY={}
function module:OnInitialized()
self:RegisterEvent("GARRISON_FOLLOWER_REMOVED","OnEvent")
self:RegisterEvent("GARRISON_FOLLOWER_ADDED","OnEvent")
self:RegisterEvent("GARRISON_FOLLOWER_LIST_UPDATE","OnEvent")
self:RegisterEvent("GARRISON_FOLLOWER_UPGRADED","OnEvent")
self:RegisterEvent("GARRISON_FOLLOWER_XP_CHANGED","OnEvent")
self.followerCache=cache:new(LE_FOLLOWER_TYPE_GARRISON_6_0)
self.shipCache=cache:new(LE_FOLLOWER_TYPE_SHIPYARD_6_2)
end
function module:OnEvent(event,...)
local followerID=...
if self.shipCache.cache[followerID].followerID then
self.shipCache:OnEvent(event,...)
elseif self.followerCache.cache[followerID].followerID then
self.followerCache:OnEvent(event,...)
else
self.followerCache:Wipe()
self.shipCache:Wipe()
end
print(event,...)
end
function cache:new(type)
local rc=setmetatable({type=type,names={},sorted={},threats={},traits={},cache={}},{__index=self})
setmetatable(rc.cache,{__index=function(t,k) return EMPTY end})
return rc
end
function cache:OnEvent(event,...)
print(event,...)
if event=="GARRISON_FOLLOWER_UPGRADED" or event=="GARRISON_FOLLOWER_XP_CHANGED" then
local followerID=...
if (self.cache[followerID]) then
self:AddExtraData(self.cache[followerID])
if event=="GARRISON_FOLLOWER_UPGRADED" then
self:AddAbilities(self.cache[followerID])
end
end
else
self:Wipe()
end
end
function cache:Wipe()
wipe(self.sorted)
wipe(self.names)
wipe(self.threats)
wipe(self.traits)
wipe(self.cache)
end
function cache:Refresh()
if next(self.cache) then return end
self:Wipe()
for _,follower in pairs(G.GetFollowers(self.type)) do
if follower.isCollected then
self:AddExtraData(follower)
self:AddAbilities(follower)
local i=follower.followerID
self.names[follower.name]=i
tinsert(self.sorted,i)
self.cache[i]=follower
end

end
end
function cache:AddAbilities(follower)
if (follower.abilities) then
local followerID=follower.followerID
for _,ability in pairs(follower.abilities) do
local t=self.traits[ability.id]
if t then
for i=1,#t do if t[i]==followerID then tremove(t,i) break end end
end
if (not ability.isTrait) then
for id,_ in pairs(ability.counters) do
local t=self.threats[id]
if t then
for i=1,#t do if t[i]==followerID then tremove(t,i) break end end
end
end
end
end
follower.abilities=nil
end
follower.abilities=G.GetFollowerAbilities(follower.followerID)
if (follower.abilities) then
local followerID=follower.followerID
for _,ability in pairs(follower.abilities) do
self.traits[ability.id]=self.traits[ability.id]or {}
tinsert(self.traits[ability.id],followerID)
if (not ability.isTrait) then
for id,_ in pairs(ability.counters) do
self.threats[id]=self.threats[id]or {}
tinsert(self.threats[id],followerID)
end
end
end
end

end
function cache:AddExtraData(follower)
follower.rank=follower.level < GARRISON_FOLLOWER_MAX_LEVEL and follower.level or follower.iLevel
follower.qLevel=follower.quality*1000+follower.level
follower.coloredname=C(follower.name,tostring(follower.quality))
follower.fullname=format("%3d %s",follower.rank,follower.coloredname)
follower.maxed=follower.qLevel>=maxrank
local weaponItemID, weaponItemLevel, armorItemID, armorItemLevel = G.GetFollowerItems(follower.followerID);
follower.weaponItemID=weaponItemID
follower.weaponItemLevel=weaponItemLevel
follower.armorItemID=armorItemID
follower.armorItemLevel=armorItemLevel
follower.weaponQuality=select(3,GetItemInfo(weaponItemID))
follower.armorQuality=select(3,GetItemInfo(armorItemID))
end

function cache:HasTrait(followerID,trait)
local list=self.traits[trait]
if list then return tContains(list,followerID) end
end
function cache:HasAbility(followerID,trait)
return self:HasTrait(followerID,trait)
end
function cache:CanCounter(followerID,threat)
local list=self.threats[threat]
if list then return tContains(list,followerID) end
end
function cache:GetFollowerData(followerID,key,default)
self:Refresh()
if type(followerID)~="string" then return self.cache end
if (followerID:sub(1,2)~="0x") then
followerID=self.names[followerID]
end
--@debug@
if LibDebug then LibDebug() end
assert(followerID)
--@end-debug@
--[===[@non-debug@
setfenv(1,setmetatable({print=function(...) print("x",...) end},{__index=_G}))
--@end-non-debug@]===]
local LE_FOLLOWER_TYPE_GARRISON_6_0=LE_FOLLOWER_TYPE_GARRISON_6_0
local LE_FOLLOWER_TYPE_SHIPYARD_6_2=LE_FOLLOWER_TYPE_SHIPYARD_6_2
if not followerID then
return key and default or EMPTY
end
if not key then
return self.cache[followerID]
else
return self.cache[followerID][key] or default
end
end
local sorters={}
sorters.leveldesc = function(a,b)
return (Mbase.followers[a].iLevel * 10 + Mbase.followers[a].level) > (Mbase.followers[b].iLevel * 10 + Mbase.followers[b].level)
end
sorters.levelasc = function(a,b)
return (Mbase.followers[a].iLevel * 10 + Mbase.followers[a].level) < (Mbase.followers[b].iLevel * 10 + Mbase.followers[b].level)
end


---@function
-- Iterator function
-- @param func type of sorting (can be mitted if we dont care)
--
function cache:GetFollowersIterator(func)
self:Refresh()
if type(func)=="function" then
table.sort(self.sorted,sorters[func])
end
local f=self.cache
return function(sorted,i)
i=i+1
local x = sorted[i]
if x then
local v=f[x] and f[x].followerID or nil
if v then
return i,v
end
end
end,self.sorted,0
end
function cache:GetFollowersWithTrait(trait)
self:Refresh()
return self.traits[trait]
end
function cache:GetFollowersWithCounterFor(threat)
self:refresh()
return self.threats[threat]
end

-- Addon level proxies
function addon:GetFollowerData(followerID,key,default)
return module.followerCache:GetFollowerData(followerID,key,default)
end
function addon:GetShipData(followerID,key,default)
return module.shipCache:GetFollowerData(followerID,key,default)
end
function addon:GetFollowersWithTrait(trait)
return module.followerCache:GetFollowersWithTrait(trait)
end
function addon:GetFollowersWithCounterFor(threat)
return module.followerCache:GetFollowersWithCounterFor(threat)
end
function addon:GetFollowersIterator(func)
return module.followerCache:GetFollowersIterator(func)
end
function addon:GetShipsIterator(func)
return module.shipCache:GetFollowersIterator(func)
end

--[=[
local function keyToIndex(key)
if (not Mbase.followers or not next(Mbase.followers)) then
Mbase.dirtyList=false
Expand Down Expand Up @@ -142,7 +336,7 @@ end
-- Iterator function
-- @param func type of sorting (can be mitted if we dont care)
--
function addon:GetFollowerIterator(func,followerTypeID)
function addon:GetFollowersIterator(func,followerTypeID)
keyToIndex()
if type(func)=="function" then
table.sort(sorted,sorters[func])
Expand All @@ -160,8 +354,11 @@ function addon:GetFollowerIterator(func,followerTypeID)
end,sorted,0
end
function addon:GetFollowersWithTrait(trait)
if not next(traits) then keyToIndex() end
return traits[trait]
end
function addon:GetFollowersWithCounterFor(threat)
if not next(traits) then keyToIndex() end
return threats[threat]
end
end
--]=]
Loading

0 comments on commit febb97e

Please sign in to comment.