Skip to content

Commit

Permalink
IgnoreFilters on categories
Browse files Browse the repository at this point in the history
  • Loading branch information
Krowi authored and Krowi committed Nov 17, 2024
1 parent 057da1a commit 5a3f07d
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 66 deletions.
2 changes: 1 addition & 1 deletion Api/API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function KrowiAF_SelectAchievement(achievement)

local tabFilters = addon.Tabs[category:GetTree()[1].TabName].Filters;
achievement = filters.GetHighestAchievementWhenCollapseSeries(tabFilters, achievement);
if filters.Validate(tabFilters, achievement) < 0 then
if filters.Validate(tabFilters, achievement, category.IgnoreFilters) < 0 then
achievement.AlwaysVisible = true;
end

Expand Down
33 changes: 22 additions & 11 deletions Api/AchievementDataApi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ local _, addon = ...;
KrowiAF.AchievementData = {};

local achievementPatch;
function KrowiAF.SetAchievementPatch(...)
achievementPatch = KrowiAF.GetBuildVersion(...);
function KrowiAF.SetAchievementPatch(major, minor, patch)
achievementPatch = KrowiAF.GetBuildVersion(major, minor, patch);
end

function KrowiAF.AddAchievementData(id, faction, otherFactionAchievementId, isPvP, isRealmFirst)
local temporaryObtainables = {};
local function AddAchievementData(id, faction, otherFactionAchievementId, isPvP, isRealmFirst, temporaryObtainables)
addon.Data.Achievements[id] = addon.Objects.Achievement:New(id, achievementPatch, faction, otherFactionAchievementId, isPvP, isRealmFirst);
tinsert(addon.Data.AchievementIds, id);
if not temporaryObtainables then
return;
end
for _, temporaryObtainable in next, temporaryObtainables do
addon.Data.Achievements[id]:SetTemporaryObtainable(unpack(temporaryObtainable));
end
end

local function ParseAddAchievementData(id, faction, otherFactionAchievementId, isPvP, isRealmFirst)
local temporaryObtainables;
if addon.Util.IsTable(faction) then
temporaryObtainables = faction;
faction = nil;
Expand All @@ -26,18 +37,18 @@ function KrowiAF.AddAchievementData(id, faction, otherFactionAchievementId, isPv
isRealmFirst = nil;
end

if temporaryObtainables.IsPvP then
if temporaryObtainables and temporaryObtainables.IsPvP then
isPvP = true;
temporaryObtainables.IsPvP = nil;
end
if temporaryObtainables.IsRealmFirst then
if temporaryObtainables and temporaryObtainables.IsRealmFirst then
isRealmFirst = true;
temporaryObtainables.IsRealmFirst = nil;
end

addon.Data.Achievements[id] = addon.Objects.Achievement:New(id, achievementPatch, faction, otherFactionAchievementId, isPvP, isRealmFirst);
tinsert(addon.Data.AchievementIds, id);
for _, temporaryObtainable in next, temporaryObtainables do
addon.Data.Achievements[id]:SetTemporaryObtainable(unpack(temporaryObtainable));
end
return id, faction, otherFactionAchievementId, isPvP, isRealmFirst, temporaryObtainables;
end

function KrowiAF.AddAchievementData(id, faction, otherFactionAchievementId, isPvP, isRealmFirst)
AddAchievementData(ParseAddAchievementData(id, faction, otherFactionAchievementId, isPvP, isRealmFirst));
end
51 changes: 33 additions & 18 deletions Api/CategoryDataApi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ local _, addon = ...;

KrowiAF.CategoryData = {};

function KrowiAF.AddCategoryData(id, name, canMerge)
addon.Data.Categories[id] = addon.Objects.Category:New(id, name, canMerge);
end

function KrowiAF.AddIfNewCategoryData(id, name, canMerge)
if addon.Data.Categories[id] then
addon.Data.Categories[id]:PostNewFix(name);
return;
end
KrowiAF.AddCategoryData(id, name, canMerge);
end

local function AddToTab(id, tabName)
addon.Data.Categories[id]:SetTabName(tabName);
addon.Tabs[tabName].Categories = addon.Data.Categories[id].Children;
Expand All @@ -28,20 +16,47 @@ local function AddAchievements(categoryId, achievementIds)
end
end

function KrowiAF.AddIfNewCategoryData(id, name, canMerge)
if addon.Data.Categories[id] then
addon.Data.Categories[id]:PostNewFix(name);
return;
end
addon.Data.Categories[id] = addon.Objects.Category:New(id, name, canMerge);
end

local ParseCategory;
local function ParseChild(category, index)
if addon.Util.IsTable(category[index]) and category[index].IsTab then
AddToTab(category[1], category[index].TabName);
local categoryData = category[index];

if not addon.Util.IsTable(categoryData) then
return;
end

if categoryData.IsTab then
AddToTab(category[1], categoryData.TabName);
end

if categoryData.IgnoreFactionFilter then
addon.Data.Categories[category[1]].IgnoreFilters = addon.Data.Categories[category[1]].IgnoreFilters or {};
addon.Data.Categories[category[1]].IgnoreFilters.FactionFilter = true;
end

if categoryData.IgnoreCollapsedChainFilter then
addon.Data.Categories[category[1]].IgnoreFilters = addon.Data.Categories[category[1]].IgnoreFilters or {};
addon.Data.Categories[category[1]].IgnoreFilters.CollapsedChainFilter = true;
end

if categoryData.IsTab or categoryData.IgnoreFactionFilter or categoryData.IgnoreCollapsedChainFilter then
return;
end

if addon.Util.IsTable(category[index]) and #category[index] > 2 and addon.Util.IsString(category[index][2]) then
ParseCategory(category[index], addon.Data.Categories[category[1]]);
if #categoryData > 2 and addon.Util.IsString(categoryData[2]) then
ParseCategory(categoryData, addon.Data.Categories[category[1]]);
return;
end

if addon.Util.IsTable(category[index]) and (#category[index] == 1 or addon.Util.IsNumber(category[index][2])) then
AddAchievements(category[1], category[index]);
if (#categoryData == 1 or addon.Util.IsNumber(categoryData[2])) then
AddAchievements(category[1], categoryData);
return;
end
end
Expand Down
62 changes: 39 additions & 23 deletions Filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ function filters:Load()
end

-- [[ Validation ]] --
local completedCache, ignoreCollapseSeriesCache, pointsCache;
local completedCache, pointsCache;
local validations = {
{ -- 1
Validate = function(_filters, achievement) return not _filters.Completion.Completed and completedCache; end
Validate = function(_filters, achievement, ignoreFilters) return not _filters.Completion.Completed and completedCache; end
},
{ -- 2
Validate = function(_filters, achievement) return not _filters.Completion.NotCompleted and not completedCache; end
Validate = function(_filters, achievement, ignoreFilters) return not _filters.Completion.NotCompleted and not completedCache; end
},
{ -- 3
Validate = function(_filters, achievement)
Validate = function(_filters, achievement, ignoreFilters)
if _filters.Obtainability.CurrentObtainable then
return;
end
Expand All @@ -136,7 +136,7 @@ local validations = {
end
},
{ -- 4
Validate = function(_filters, achievement)
Validate = function(_filters, achievement, ignoreFilters)
if _filters.Obtainability.PastObtainable then
return;
end
Expand All @@ -147,7 +147,7 @@ local validations = {
end
},
{ -- 5
Validate = function(_filters, achievement)
Validate = function(_filters, achievement, ignoreFilters)
if _filters.Obtainability.FutureObtainable then
return;
end
Expand All @@ -158,17 +158,32 @@ local validations = {
end
},
{ -- 6
Validate = function(_filters, achievement) return not _filters.Faction.Neutral and achievement.Faction == nil; end
Validate = function(_filters, achievement, ignoreFilters)
if ignoreFilters.FactionFilter then
return false;
end
return not _filters.Faction.Neutral and achievement.Faction == nil;
end
},
{ -- 7
Validate = function(_filters, achievement) return not _filters.Faction.Alliance and achievement.Faction == addon.Objects.Faction.Alliance; end
Validate = function(_filters, achievement, ignoreFilters)
if ignoreFilters.FactionFilter then
return false;
end
return not _filters.Faction.Alliance and achievement.Faction == addon.Objects.Faction.Alliance;
end
},
{ -- 8
Validate = function(_filters, achievement) return not _filters.Faction.Horde and achievement.Faction == addon.Objects.Faction.Horde; end
Validate = function(_filters, achievement, ignoreFilters)
if ignoreFilters.FactionFilter then
return false;
end
return not _filters.Faction.Horde and achievement.Faction == addon.Objects.Faction.Horde;
end
},
{ -- 9
Validate = function(_filters, achievement)
if _filters.CollapseSeries and ignoreCollapseSeriesCache ~= true then
Validate = function(_filters, achievement, ignoreFilters)
if _filters.CollapseSeries and ignoreFilters.CollapsedChainFilter ~= true then
local _, nextCompleted = addon.GetNextAchievement(achievement);
if nextCompleted then
return true;
Expand All @@ -185,30 +200,30 @@ local validations = {
end
},
{ -- 10
Validate = function(_filters, achievement) return not _filters.Excluded and achievement.IsExcluded end
Validate = function(_filters, achievement, ignoreFilters) return not _filters.Excluded and achievement.IsExcluded end
},
{ -- 11
Validate = function(_filters, achievement)
Validate = function(_filters, achievement, ignoreFilters)
if not addon.Options.db.profile.ShowPlaceholdersFilter and achievement.DoesNotExist then
return true;
end
return not filters.db.profile.ShowPlaceholders and achievement.DoesNotExist;
end
},
{ -- 12
Validate = function(_filters, achievement) return not _filters.Special.RealmFirst and achievement.IsRealmFirst; end
Validate = function(_filters, achievement, ignoreFilters) return not _filters.Special.RealmFirst and achievement.IsRealmFirst; end
},
{ -- 13
Validate = function(_filters, achievement) return not _filters.Special.FeatsOfStrength and pointsCache == 0 and not achievement.IsRealmFirst and not achievement.IsTracking; end
Validate = function(_filters, achievement, ignoreFilters) return not _filters.Special.FeatsOfStrength and pointsCache == 0 and not achievement.IsRealmFirst and not achievement.IsTracking; end
},
{ -- 14
Validate = function(_filters, achievement) return not _filters.Tracking and achievement.IsTracking; end
Validate = function(_filters, achievement, ignoreFilters) return not _filters.Tracking and achievement.IsTracking; end
},
{ -- 15
Validate = function(_filters, achievement) return not _filters.Special.PvP and achievement.IsPvP; end
Validate = function(_filters, achievement, ignoreFilters) return not _filters.Special.PvP and achievement.IsPvP; end
},
{ -- 16
Validate = function(_filters, achievement)
Validate = function(_filters, achievement, ignoreFilters)
if not achievement.BuildVersion then
return false;
end
Expand All @@ -217,7 +232,7 @@ local validations = {
},
};

function filters.Validate(_filters, achievement, ignoreCollapseSeries)
function filters.Validate(_filters, achievement, ignoreFilters, ignoreCollapseSeries)
if _filters.Ignore then
return 3;
end
Expand All @@ -231,20 +246,21 @@ function filters.Validate(_filters, achievement, ignoreCollapseSeries)
else
completedCache = completed;
end
ignoreCollapseSeriesCache = ignoreCollapseSeries;
ignoreFilters = ignoreFilters or {};
ignoreFilters.CollapsedChainFilter = ignoreFilters.CollapsedChainFilter or ignoreCollapseSeries;
if _filters.Completion.AlwaysShowCompleted and completedCache then
return 4; -- Special filter that overwrites the rest
end
for i, validation in next, validations do
if validation.Validate(_filters, achievement) then -- If true, DO NOT show achievement
if validation.Validate(_filters, achievement, ignoreFilters) then -- If true, DO NOT show achievement
return -i;
end
end
return 1;
end

function filters:AutoValidate(achievement, ignoreCollapseSeries)
return self.Validate(self:GetFilters(), achievement, ignoreCollapseSeries);
function filters:AutoValidate(achievement, ignoreFilters, ignoreCollapseSeries)
return self.Validate(self:GetFilters(), achievement, ignoreFilters, ignoreCollapseSeries);
end

function filters:GetFilters(category)
Expand Down
4 changes: 2 additions & 2 deletions Globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ function addon.GetAchievementsInZone(mapID, getAll)
return achievements;
end

function addon.GetAchievementNumbers(_filters, achievement, numOfAch, numOfCompAch, numOfNotObtAch) -- , numOfIncompAch
function addon.GetAchievementNumbers(_filters, achievement, numOfAch, numOfCompAch, numOfNotObtAch, ignoreFilters) -- , numOfIncompAch
if achievement.AlwaysVisible then
return numOfAch, numOfCompAch, numOfNotObtAch; -- , numOfIncompAch
end
local filters = addon.Filters;
if filters and filters.Validate(_filters, achievement, true) > 0 then -- If set to false we lag the game
if filters and filters.Validate(_filters, achievement, ignoreFilters, true) > 0 then -- If set to false we lag the game
numOfAch = numOfAch + 1;
local _, _, _, completed = addon.GetAchievementInfo(achievement.Id);
local state;
Expand Down
10 changes: 5 additions & 5 deletions Gui/WindowFrames/AchievementsFrame/AchievementsFrameMixin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ function KrowiAF_AchievementsFrameMixin:OnHide()
self:UnregisterEvent("ACHIEVEMENT_EARNED");
end

local function Validate(achievements, displayAchievements, defaultOrder)
local function Validate(achievements, displayAchievements, defaultOrder, ignoreFilters)
if not achievements then
return;
end
local filters = addon.Filters;
for _, achievement in next, achievements do
if filters:AutoValidate(achievement) > 0 then -- Greater than 0 means it can be shown
if filters:AutoValidate(achievement, ignoreFilters) > 0 then -- Greater than 0 means it can be shown
tinsert(displayAchievements, achievement);
end
defaultOrder[achievement] = #displayAchievements;
Expand All @@ -151,8 +151,8 @@ local function GetFilteredAchievements(category)
local displayAchievements = {};
local defaultOrder = {};

Validate(category.Achievements, displayAchievements, defaultOrder);
Validate(category.MergedAchievements, displayAchievements, defaultOrder);
Validate(category.Achievements, displayAchievements, defaultOrder, category.IgnoreFilters);
Validate(category.MergedAchievements, displayAchievements, defaultOrder, category.IgnoreFilters);

if #displayAchievements == 0 then
return displayAchievements;
Expand Down Expand Up @@ -244,7 +244,7 @@ function KrowiAF_AchievementsFrameMixin:ForceUpdate()
for _, tab in next, addon.Tabs do
tabButton = tab.Button;
if tabButton.SelectedAchievement then
if addon.Filters.Validate(tabButton.Filters, tabButton.SelectedAchievement) < 0 then
if addon.Filters.Validate(tabButton.Filters, tabButton.SelectedAchievement, tabButton.SelectedCategory.IgnoreFilters) < 0 then
tabButton.SelectedAchievement = nil;
end
end
Expand Down
2 changes: 1 addition & 1 deletion Krowi_AchievementFilter.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: Krowi's |cFF1D92C2Achievement Filter|r
## X-Prefix: KrowiAF
## X-Acronym: KAF
## Version: 79.0-beta2
## Version: 79.0-beta3
## Author: Krowi-Frostmane EU
## SavedVariables: KrowiAF_DebugTable, KrowiAF_Options, KrowiAF_SavedData, KrowiAF_Filters, KrowiAF_SearchOptions, KrowiAF_Achievements
## OptionalDeps: BetterWardrobe, ElvUI, GW2_UI, InstanceAchievementTracker
Expand Down
2 changes: 1 addition & 1 deletion Krowi_AchievementFilter_Cata.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: Krowi's |cFF1D92C2Achievement Filter|r
## X-Prefix: KrowiAF
## X-Acronym: KAF
## Version: 79.0-beta2
## Version: 79.0-beta3
## Author: Krowi-Frostmane EU
## SavedVariables: KrowiAF_DebugTable, KrowiAF_Options, KrowiAF_SavedData, KrowiAF_Filters, KrowiAF_SearchOptions, KrowiAF_Achievements
## Notes: Filters your achievements.
Expand Down
8 changes: 4 additions & 4 deletions Objects/Category.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ function category:GetPath()
return path;
end

local function GetFilteredAchievementNumbers(achievements, filters, numOfAch, numOfCompAch, numOfNotObtAch) -- , numOfIncompAch
local function GetFilteredAchievementNumbers(achievements, filters, numOfAch, numOfCompAch, numOfNotObtAch, ignoreFilters) -- , numOfIncompAch
if not achievements then
return numOfAch, numOfCompAch, numOfNotObtAch;
end
for _, achievement in next, achievements do
numOfAch, numOfCompAch, numOfNotObtAch = addon.GetAchievementNumbers(filters, achievement, numOfAch, numOfCompAch, numOfNotObtAch); -- , numOfIncompAch
numOfAch, numOfCompAch, numOfNotObtAch = addon.GetAchievementNumbers(filters, achievement, numOfAch, numOfCompAch, numOfNotObtAch, ignoreFilters); -- , numOfIncompAch
end
return numOfAch, numOfCompAch, numOfNotObtAch;
end
Expand Down Expand Up @@ -180,8 +180,8 @@ function category:GetAchievementNumbers()
filters2 = filters:GetFilters(self);
end

numOfAch, numOfCompAch, numOfNotObtAch = GetFilteredAchievementNumbers(self.Achievements, filters2, numOfAch, numOfCompAch, numOfNotObtAch); -- , numOfIncompAch
numOfAch, numOfCompAch, numOfNotObtAch = GetFilteredAchievementNumbers(self.MergedAchievements, filters2, numOfAch, numOfCompAch, numOfNotObtAch); -- , numOfIncompAch
numOfAch, numOfCompAch, numOfNotObtAch = GetFilteredAchievementNumbers(self.Achievements, filters2, numOfAch, numOfCompAch, numOfNotObtAch, self.IgnoreFilters); -- , numOfIncompAch
numOfAch, numOfCompAch, numOfNotObtAch = GetFilteredAchievementNumbers(self.MergedAchievements, filters2, numOfAch, numOfCompAch, numOfNotObtAch, self.IgnoreFilters); -- , numOfIncompAch

local mergeSmallCategories = false;
if filters then
Expand Down

0 comments on commit 5a3f07d

Please sign in to comment.