Skip to content

Commit

Permalink
Reputation nil check + refactor list
Browse files Browse the repository at this point in the history
  • Loading branch information
DJScias committed Sep 7, 2024
1 parent 12499c8 commit 8b3ace3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 45 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [6.1.9] - 2024-09-07

### Changed
- Rewrote the reputation list coding. This should work a bit more straightforward and solves some quirks.
- For example: Brann Bronzebread being part of "The Severed Threads" (which he's not last I checked).

### Fixed
- Nil check for `factionData` in `GetFactionActive`.

## [6.1.8] - 2024-09-06

### Fixed
Expand Down
106 changes: 61 additions & 45 deletions modules/reputation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -476,26 +476,28 @@ function module:GetFactionActive(givenFactionID)

while numFactions >= 1 do
local factionData = C_Reputation.GetFactionDataByIndex(numFactions);
local factionID, isHeader, isCollapsed = factionData.factionID, factionData.isHeader, factionData.isCollapsed;
if factionData then
local factionID, isHeader, isCollapsed = factionData.factionID, factionData.isHeader, factionData.isCollapsed;

if factionID == 0 and isHeader and isCollapsed then
inactiveCollapsed = true;
C_Reputation.ExpandFactionHeader(numFactions);
numFactions = C_Reputation.GetNumFactions();
else
if factionID == givenFactionID then
isActive = C_Reputation.IsFactionActive(numFactions);
break;
if factionID == 0 and isHeader and isCollapsed then
inactiveCollapsed = true;
C_Reputation.ExpandFactionHeader(numFactions);
numFactions = C_Reputation.GetNumFactions();
else
if factionID == givenFactionID then
isActive = C_Reputation.IsFactionActive(numFactions);
break;
end

numFactions = numFactions - 1;
end

numFactions = numFactions - 1;
end
end

if inactiveCollapsed then
for factionIndex = numFactions, 1, -1 do
local factionID = C_Reputation.GetFactionDataByIndex(factionIndex).factionID;
if factionID == 0 then
local faction = C_Reputation.GetFactionDataByIndex(factionIndex);
if faction and faction.factionID == 0 then
C_Reputation.CollapseFactionHeader(factionIndex);
end
end
Expand Down Expand Up @@ -696,7 +698,7 @@ function module:GetReputationsMenu(currentMenu)
local factions = {};

local previous, current = nil, nil;
local depth = 0;
local tier = 0;

local collapsedHeaders = {};

Expand Down Expand Up @@ -738,44 +740,24 @@ function module:GetReputationsMenu(currentMenu)
end
end

-- Open up collapsed headers temporarily
if isHeader and isCollapsed then
C_Reputation.ExpandFactionHeader(factionIndex);
tinsert(collapsedHeaders, factionData.factionID);
numFactions = C_Reputation.GetNumFactions();
end

if isHeader and isChild and current then -- Second tier header
if depth == 2 then
-- 2nd tier has some quirks which we fix here:
-- If 2nd but not a child, it's 1st tier.
-- If 2nd tier but a child, but also a header (with or without rep), it's 1st tier.
if tier == 2 then
if not isChild or (isChild and (isHeader or hasRep)) then
current = previous;
previous = nil;
end

if not hasRep then
tinsert(current, {
name = name,
isHeader = true,
menuList = {},
})
else
tinsert(current, {
name = string.format("%s (%s)%s", name, standingText, progressText),
isHeaderWithRep = true,
factionID = factionID,
isWatched = isWatched,
menuList = {},
})
tier = 1;
end
end

previous = current;
current = current[#current].menuList;
tinsert(current, {
name = name,
isSubMenuTitle = true,
})

depth = 2

elseif isHeader then -- First tier header
if isHeader and not hasRep and not isChild then -- Expansion 1st tier header
tinsert(factions, {
name = name,
isMajorHeader = true;
Expand All @@ -788,8 +770,42 @@ function module:GetReputationsMenu(currentMenu)
isMajorHeaderTitle = true,
})

depth = 1
elseif not isHeader then -- First and second tier faction
tier = 1;
elseif tier == 1 then -- 2nd tier header/expansions
if not isHeader then -- Simple faction, no header business.
tinsert(current, {
name = string.format("%s (%s)%s", name, standingText, progressText),
isFaction = true,
factionID = factionID,
isWatched = isWatched,
})
else
if not hasRep then
tinsert(current, {
name = name,
isHeader = true,
menuList = {},
})
else
tinsert(current, {
name = string.format("%s (%s)%s", name, standingText, progressText),
isHeaderWithRep = true,
factionID = factionID,
isWatched = isWatched,
menuList = {},
})
end

previous = current;
current = current[#current].menuList;
tinsert(current, {
name = name,
isSubMenuTitle = true,
})

tier = 2;
end
elseif tier == 2 then -- 3rd tier header
tinsert(current, {
name = string.format("%s (%s)%s", name, standingText, progressText),
isFaction = true,
Expand Down

0 comments on commit 8b3ace3

Please sign in to comment.