Skip to content

Commit

Permalink
make the LFGPGI cache local
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils89 committed Aug 1, 2024
1 parent acff258 commit 2241254
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions core/LFGPlayerInfo.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
local _, GW = ...

-- Thanks to Windtools

GW.LFGPI = {}
-- Variables
local roleOrder = {
[1] = "TANK",
[2] = "HEALER",
[3] = "DAMAGER"
}
local cache = {}

local function GetRoleOrder()
return roleOrder
Expand Down Expand Up @@ -42,33 +42,30 @@ for classID = 1, 13 do
end
end

-- Cache
GW.LFGPI.cache = {}

local function ClearCache()
for _, role in ipairs(roleOrder) do
GW.LFGPI.cache[role] = {
cache[role] = {
totalAmount = 0,
playerList = {}
}
end
end

local function AddPlayer(role, class, spec)
if not GW.LFGPI.cache[role] then
if not cache[role] then
GW.Debug("warning", format("cache not been initialized correctly, the role:%s is nil.", role))
end

if not GW.LFGPI.cache[role].playerList[class] then
GW.LFGPI.cache[role].playerList[class] = {}
if not cache[role].playerList[class] then
cache[role].playerList[class] = {}
end

if not GW.LFGPI.cache[role].playerList[class][spec] then
GW.LFGPI.cache[role].playerList[class][spec] = 0
if not cache[role].playerList[class][spec] then
cache[role].playerList[class][spec] = 0
end

GW.LFGPI.cache[role].playerList[class][spec] = GW.LFGPI.cache[role].playerList[class][spec] + 1
GW.LFGPI.cache[role].totalAmount = GW.LFGPI.cache[role].totalAmount + 1
cache[role].playerList[class][spec] = cache[role].playerList[class][spec] + 1
cache[role].totalAmount = cache[role].totalAmount + 1
end

-- Main logic
Expand Down Expand Up @@ -123,7 +120,7 @@ local function GetPartyInfo(resultId)
for _, role in ipairs(roleOrder) do
dataTable[role] = {}

local members = GW.LFGPI.cache[role]
local members = cache[role]

for class, numberOfPlayersSortBySpec in pairs(members.playerList) do
for spec, numberOfPlayers in pairs(numberOfPlayersSortBySpec) do
Expand Down

0 comments on commit 2241254

Please sign in to comment.