Skip to content

Commit

Permalink
Merge pull request #639 from WowRarity/635-holiday-texture-fix
Browse files Browse the repository at this point in the history
Fix the availability check for items that require holiday events
  • Loading branch information
rdw-software authored Sep 10, 2023
2 parents 5961ea3 + 19f9dbc commit 96b5bb1
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Core/GUI/MainWindow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ local function addGroup(group, requiresGroup)
end
end
elseif v.questId and v.holidayTexture then
if Rarity.holiday_textures[v.holidayTexture] == nil then
if not Rarity.HolidayEvents.IsItemAvailableToday(v) then
status = colorize(L["Unavailable"], gray)
elseif v.christmasOnly and dt.month == 12 and dt.day < 25 then
status = colorize(L["Unavailable"], gray)
Expand Down Expand Up @@ -1088,7 +1088,7 @@ local function addGroup(group, requiresGroup)
status = colorize(L["Unavailable"], gray)
end
end
elseif v.holidayTexture and Rarity.holiday_textures[v.holidayTexture] == nil then
elseif v.holidayTexture and not Rarity.HolidayEvents.IsItemAvailableToday(v) then
status = colorize(L["Unavailable"], gray)
end
if v.pickpocket then
Expand Down
64 changes: 64 additions & 0 deletions Core/HolidayEvents.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
local _, addonTable = ...

local CONSTANTS = Rarity.Enum
local pairs = pairs

local HolidayEvents = {
fileDataTexturesToLegacyIconPath = {
[CONSTANTS.ART_TEXTURES.BREWFEST] = CONSTANTS.HOLIDAY_TEXTURES.BREWFEST,
[CONSTANTS.ART_TEXTURES.BREWFEST_END] = CONSTANTS.HOLIDAY_TEXTURES.BREWFEST,
[CONSTANTS.ART_TEXTURES.BREWFEST_ONGOING] = CONSTANTS.HOLIDAY_TEXTURES.BREWFEST,
[CONSTANTS.ART_TEXTURES.BREWFEST_START] = CONSTANTS.HOLIDAY_TEXTURES.BREWFEST,

[CONSTANTS.ART_TEXTURES.DMF_ELWYNN_END] = CONSTANTS.HOLIDAY_TEXTURES.DARKMOON_FAIRE,
[CONSTANTS.ART_TEXTURES.DMF_ELWYNN_ONGOING] = CONSTANTS.HOLIDAY_TEXTURES.DARKMOON_FAIRE,
[CONSTANTS.ART_TEXTURES.DMF_ELWYNN_START] = CONSTANTS.HOLIDAY_TEXTURES.DARKMOON_FAIRE,
[CONSTANTS.ART_TEXTURES.DMF_MULGORE_END] = CONSTANTS.HOLIDAY_TEXTURES.DARKMOON_FAIRE,
[CONSTANTS.ART_TEXTURES.DMF_MULGORE_ONGOING] = CONSTANTS.HOLIDAY_TEXTURES.DARKMOON_FAIRE,
[CONSTANTS.ART_TEXTURES.DMF_MULGORE_START] = CONSTANTS.HOLIDAY_TEXTURES.DARKMOON_FAIRE,
[CONSTANTS.ART_TEXTURES.DMF_ONGOING] = CONSTANTS.HOLIDAY_TEXTURES.DARKMOON_FAIRE,
[CONSTANTS.ART_TEXTURES.DMF_TEROKKAR_END] = CONSTANTS.HOLIDAY_TEXTURES.DARKMOON_FAIRE,
[CONSTANTS.ART_TEXTURES.DMF_TEROKKAR_ONGOING] = CONSTANTS.HOLIDAY_TEXTURES.DARKMOON_FAIRE,
[CONSTANTS.ART_TEXTURES.DMF_TEROKKAR_START] = CONSTANTS.HOLIDAY_TEXTURES.DARKMOON_FAIRE,

[CONSTANTS.ART_TEXTURES.HALLOWS_END] = CONSTANTS.HOLIDAY_TEXTURES.HALLOWS_END,
[CONSTANTS.ART_TEXTURES.HALLOWS_ONGOING] = CONSTANTS.HOLIDAY_TEXTURES.HALLOWS_END,
[CONSTANTS.ART_TEXTURES.HALLOWS_START] = CONSTANTS.HOLIDAY_TEXTURES.HALLOWS_END,

[CONSTANTS.ART_TEXTURES.HARVEST_END] = CONSTANTS.HOLIDAY_TEXTURES.PILGRIMS_BOUNTY,
[CONSTANTS.ART_TEXTURES.HARVEST_ONGOING] = CONSTANTS.HOLIDAY_TEXTURES.PILGRIMS_BOUNTY,
[CONSTANTS.ART_TEXTURES.HARVEST_START] = CONSTANTS.HOLIDAY_TEXTURES.PILGRIMS_BOUNTY,

[CONSTANTS.ART_TEXTURES.LOVE_END] = CONSTANTS.HOLIDAY_TEXTURES.LOVE_IS_IN_THE_AIR,
[CONSTANTS.ART_TEXTURES.LOVE_ONGOING] = CONSTANTS.HOLIDAY_TEXTURES.LOVE_IS_IN_THE_AIR,
[CONSTANTS.ART_TEXTURES.LOVE_START] = CONSTANTS.HOLIDAY_TEXTURES.LOVE_IS_IN_THE_AIR,

[CONSTANTS.ART_TEXTURES.MIDSUMMER_END] = CONSTANTS.HOLIDAY_TEXTURES.MIDSUMMER_FESTIVAL,
[CONSTANTS.ART_TEXTURES.MIDSUMMER_ONGOING] = CONSTANTS.HOLIDAY_TEXTURES.MIDSUMMER_FESTIVAL,
[CONSTANTS.ART_TEXTURES.MIDSUMMER_START] = CONSTANTS.HOLIDAY_TEXTURES.MIDSUMMER_FESTIVAL,

[CONSTANTS.ART_TEXTURES.WINTERVEIL_END] = CONSTANTS.HOLIDAY_TEXTURES.WINTERS_VEIL,
[CONSTANTS.ART_TEXTURES.WINTERVEIL_IEND] = CONSTANTS.HOLIDAY_TEXTURES.WINTERS_VEIL,
[CONSTANTS.ART_TEXTURES.WINTERVEIL_ONGOING] = CONSTANTS.HOLIDAY_TEXTURES.WINTERS_VEIL,
[CONSTANTS.ART_TEXTURES.WINTERVEIL_START] = CONSTANTS.HOLIDAY_TEXTURES.WINTERS_VEIL,
},
}

function HolidayEvents.IsItemAvailableToday(item)
if not item.holidayTexture then
return true
end

for artTextureID, _ in pairs(Rarity.holiday_textures) do
local legacyTextureIconPath = HolidayEvents.fileDataTexturesToLegacyIconPath[artTextureID]
local isRequiredHolidayEventActive = (legacyTextureIconPath == item.holidayTexture)
if isRequiredHolidayEventActive then
return true
end
end

return false
end

Rarity.HolidayEvents = HolidayEvents
return HolidayEvents
43 changes: 36 additions & 7 deletions DB/SharedConstants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,49 @@ C.SORT_METHODS = {

C.COVENANT_IDS = { KYRIAN = 1, VENTHYR = 2, NIGHT_FAE = 3, NECROLORD = 4 }

-- These are now obsolete, but still used for items. TBD: Can move over to a different format or will it break things?
C.HOLIDAY_TEXTURES = {
WINTERS_VEIL = "Calendar_WinterVeil",
DARKMOON_FAIRE = "calendar_darkmoonfaireterokkar",
DAY_OF_THE_DEAD = "Calendar_DayOfTheDead",
BREWFEST = "Calendar_Brewfest",
HALLOWS_END = "Calendar_HallowsEnd",
PILGRIMS_BOUNTY = "Calendar_HarvestFestival",
WOW_ANNIVERSARY = "calendar_anniversary",
LOVE_IS_IN_THE_AIR = "Calendar_LoveInTheAir",
LUNAR_FESTIVAL = "Calendar_LunarFestival",
NOBLEGARDEN = "Calendar_Noblegarden",
CHILDRENS_WEEK = "Calendar_ChildrensWeek",
MIDSUMMER_FESTIVAL = "Calendar_Midsummer",
FIREWORKS = "calendar_fireworks", -- What is this used for?
PIRATES_DAY = "Calendar_PiratesDay",
}

-- Copied from https://www.townlong-yak.com/framexml/live/Helix/ArtTextureID.lua
C.ART_TEXTURES = {
BREWFEST = 235439,
BREWFEST_END = 235440,
BREWFEST_ONGOING = 235441,
BREWFEST_START = 235442,
DMF_ELWYNN_END = 235446,
DMF_ELWYNN_ONGOING = 235447,
DMF_ELWYNN_START = 235448,
DMF_MULGORE_END = 235449,
DMF_MULGORE_ONGOING = 235450,
DMF_MULGORE_START = 235451,
DMF_ONGOING = 235452,
DMF_TEROKKAR_END = 235453,
DMF_TEROKKAR_ONGOING = 235454,
DMF_TEROKKAR_START = 235455,
HALLOWS_END = 235460,
HALLOWS_ONGOING = 235461,
HALLOWS_START = 235462,
HARVEST_END = 235463,
HARVEST_ONGOING = 235464,
HARVEST_START = 235465,
LOVE_END = 235466,
LOVE_ONGOING = 235467,
LOVE_START = 235468,
MIDSUMMER_END = 235472,
MIDSUMMER_ONGOING = 235473,
MIDSUMMER_START = 235474,
WINTERVEIL_END = 235482,
WINTERVEIL_IEND = 235483,
WINTERVEIL_ONGOING = 235484,
WINTERVEIL_START = 235485,
}

C.ARCHAEOLOGY_RACES = {
Expand Down Expand Up @@ -287,3 +315,4 @@ addonTable.constants = C

-- More consistent with Blizzard's method as of Shadowlands (global Enum table); it's probably easier to use, as well
Rarity.Enum = C
return C
1 change: 1 addition & 0 deletions Rarity.toc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Core\Debugging.lua
Core\Detection.lua
Core\EventHandlers.lua
Core\GUI.lua
Core\HolidayEvents.lua
Core\Profiling.lua
Core\Serialization.lua
Core\Session.lua
Expand Down
42 changes: 42 additions & 0 deletions Tests/test-holiday-events.spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local SharedConstants = loadfile("DB/SharedConstants.lua")("Rarity", {})
local HolidayEvents = loadfile("Core/HolidayEvents.lua")("Rarity", {})

describe("HolidayEvents", function()
describe("IsItemAvailableToday", function()
before(function()
Rarity.holiday_textures = {}
end)

local DARKMOON_FAIRE_ITEM = {
holidayTexture = SharedConstants.HOLIDAY_TEXTURES.DARKMOON_FAIRE,
}
local ITEM_WITHOUT_HOLIDAY_TEXTURE = {}

it("should return true if the item requires an active holiday event that is currently enabled", function()
Rarity.holiday_textures[SharedConstants.ART_TEXTURES.DMF_ONGOING] = true
assertTrue(HolidayEvents.IsItemAvailableToday(DARKMOON_FAIRE_ITEM))
end)

it("should return false if the item requires a specific holiday event to be active, but it is not", function()
assertFalse(HolidayEvents.IsItemAvailableToday(DARKMOON_FAIRE_ITEM))
end)

it(
"should return false if only holiday events other than the one required by the item are currently active",
function()
Rarity.holiday_textures[SharedConstants.ART_TEXTURES.LOVE_ONGOING] = true
assertFalse(HolidayEvents.IsItemAvailableToday(DARKMOON_FAIRE_ITEM))
end
)

it("should return true if there are active holiday events other than the one required by the item", function()
Rarity.holiday_textures[SharedConstants.ART_TEXTURES.LOVE_ONGOING] = true
Rarity.holiday_textures[SharedConstants.ART_TEXTURES.DMF_ONGOING] = true
assertTrue(HolidayEvents.IsItemAvailableToday(DARKMOON_FAIRE_ITEM))
end)

it("should return true if the item doesn't require any holiday event to be active", function()
assertTrue(HolidayEvents.IsItemAvailableToday(ITEM_WITHOUT_HOLIDAY_TEXTURE))
end)
end)
end)
1 change: 1 addition & 0 deletions Tests/unit-test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require("Tests.RarityCoreSetup")

local specFiles = {
"Tests/test-database.spec.lua",
"Tests/test-holiday-events.spec.lua",
"Tests/test-serialization.spec.lua",
}

Expand Down

0 comments on commit 96b5bb1

Please sign in to comment.