Refactoring: "Pandoras Box" stage highlight modifier
This commit is contained in:
1 parent
744834f300
commit
f6d96b9d8c
2 files changed
+55
-51
No files matched your search
@@ -173,7 +173,7 @@ EID.ItemReminderDescriptionModifier = {
|
|||||||
local inAscent = EID.isRepentance and (level:IsAscent() or level:IsPreAscent())
|
local inAscent = EID.isRepentance and (level:IsAscent() or level:IsPreAscent())
|
||||||
local final = not level:IsNextStageAvailable()
|
local final = not level:IsNextStageAvailable()
|
||||||
|
|
||||||
if EID:IsGreedMode() and not EID.PandorasGreedConditional then
|
if EID:IsGreedMode() then
|
||||||
skip = 1
|
skip = 1
|
||||||
if stageNum == 5 then skip = 0 -- Depths 2 -> Womb 1
|
if stageNum == 5 then skip = 0 -- Depths 2 -> Womb 1
|
||||||
elseif stageNum == 7 or stageNum == 10 then skip = 2
|
elseif stageNum == 7 or stageNum == 10 then skip = 2
|
||||||
|
|||||||
+54
-50
@@ -134,68 +134,72 @@ local function BlackRuneCallback(descObj)
|
|||||||
return VoidCallback(descObj, true)
|
return VoidCallback(descObj, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Map each text block of Pandora's Box to the AbsoluteStage number it's watching for
|
-- Map each text block of Pandora's Box to the AbsoluteStage number. Second entry is the block used for Alt-Stages
|
||||||
-- Exception: 9 (???) should also watch for 12 (The Void)
|
local pandoraStages = {
|
||||||
-- Localizations must have their text blocks in this order:
|
[1] = { 1, 1 }, -- B1
|
||||||
-- B1, B2, C1, C2, D1, D2, W1, W2, ???/The Void, Sheol, Cathedral, Dark Room, The Chest, Home
|
[2] = { 2, 2 }, -- B2
|
||||||
local pandorasStages = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 11, 13 }
|
[3] = { 3, 3 }, -- C1
|
||||||
-- Stage numbers where whether it's alt or not matters for Pandora's Box
|
[4] = { 4, 4 }, -- C2
|
||||||
local altStages = { [10] = false, [11] = true, [12] = false, [13] = true }
|
[5] = { 5, 5 }, -- D1
|
||||||
-- Greed Mode Absolute Stage / Pandora's Box Behavior: 1: B2, 3: C2, 5: D2, 7: W1, 10: Sheol, 0: Chest
|
[6] = { 6, 6 }, -- D2
|
||||||
local greedStages = { -1, 1, -1, 3, -1, 5, 7, -1, -1, 10, -1, -1, 0, -1 }
|
[7] = { 7, 7 }, -- W1
|
||||||
EID.PandorasGreedConditional = false -- helper variable to let item reminder know that we have the 6-entry greed pandora desc
|
[8] = { 8, 8 }, -- W2
|
||||||
|
[9] = { 9, 9 }, -- ???
|
||||||
|
[10] = { 10, 11 }, -- Sheol, Cathedral
|
||||||
|
[11] = { 12, 13 }, -- Dark Room, Chest
|
||||||
|
[12] = { 9, 9 }, -- Void
|
||||||
|
[13] = { 14, 14 }, -- Home
|
||||||
|
}
|
||||||
|
local pandoraGreedStages = {
|
||||||
|
[1] = { 2, 2, 1 }, -- Basement
|
||||||
|
[2] = { 4, 4, 2 }, -- Cellar
|
||||||
|
[3] = { 6, 6, 3 }, -- Depths
|
||||||
|
[4] = { 8, 8, 4 }, -- Womb
|
||||||
|
[5] = { 10, 10, 5 }, -- Sheol
|
||||||
|
[6] = { 13, 13, 6 }, -- Shop
|
||||||
|
[7] = { 13, 13, 6 }, -- Chest
|
||||||
|
}
|
||||||
|
|
||||||
local function PandorasBoxCallback(descObj)
|
local function PandorasBoxCallback(descObj)
|
||||||
local pandoraCount = 0
|
local hasModifier = game:IsGreedMode() and EID:getDescriptionEntry("ConditionalDescs", "5.100.297 (Greed)", true)
|
||||||
|
|
||||||
local level = game:GetLevel()
|
local level = game:GetLevel()
|
||||||
local stageNum = level:GetAbsoluteStage()
|
local stageNum = game:IsGreedMode() and level:GetStage() or level:GetAbsoluteStage()
|
||||||
local altStage = level:IsAltStage()
|
|
||||||
local doMarkup = false
|
local stageTable = game:IsGreedMode() and pandoraGreedStages or pandoraStages
|
||||||
-- Greed Mode has different Pandora's Box rules and stage numbers
|
local textBlockToUse = stageTable[stageNum][hasModifier and 3 or level:IsAltStage() and 2 or 1]
|
||||||
local stageCheck = game:IsGreedMode() and greedStages or pandorasStages
|
|
||||||
local altCheck = game:IsGreedMode() and {} or altStages
|
|
||||||
|
|
||||||
-- floor result information must be separated by line breaks or semicolons in localizations
|
-- floor result information must be separated by line breaks or semicolons in localizations
|
||||||
local totalCount = 0
|
local levelDescriptions = {}
|
||||||
for w in string.gmatch(descObj.Description, "([^#;]+)") do
|
local hasVoidEntry = false
|
||||||
if totalCount > 0 or string.find(w,"2") then
|
for lvlDesc in string.gmatch(descObj.Description, "([^#;]+)") do
|
||||||
totalCount = totalCount + 1
|
table.insert(levelDescriptions, lvlDesc)
|
||||||
|
if lvlDesc:find("???") then
|
||||||
|
hasVoidEntry = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local skip9and12 = false
|
|
||||||
EID.PandorasGreedConditional = false
|
|
||||||
-- many localizations do not have the ???/Void entry and the Dark Room entry
|
|
||||||
-- this seemed better than forcing them to have it
|
|
||||||
if totalCount == (EID.isRepentance and 12 or 11) then
|
|
||||||
skip9and12 = true
|
|
||||||
-- If the localization has a simplified Greed Mode desc, it will only have 6 entries
|
|
||||||
elseif totalCount == 6 then
|
|
||||||
EID.PandorasGreedConditional = true
|
|
||||||
greedStages = { 1, 3, 5, 7, 10, 0 }
|
|
||||||
end
|
|
||||||
|
|
||||||
for w in string.gmatch(descObj.Description, "([^#;]+)") do
|
-- Some languages are missing the ???/Void entry or more. We account for that
|
||||||
doMarkup = false
|
if not hasVoidEntry and not hasModifier then
|
||||||
-- the first captured group to care about is the one that contains a 2 (2 soul hearts)
|
-- void entry is supposed to be highlighted, but its missing, or the description is lacking multiple entries
|
||||||
if pandoraCount > 0 or string.find(w,"2") then
|
if textBlockToUse == 9 or (#levelDescriptions < 15 and textBlockToUse > 9) then
|
||||||
pandoraCount = pandoraCount + 1
|
return descObj
|
||||||
if skip9and12 and (pandoraCount == 9 or pandoraCount == 12) then
|
|
||||||
pandoraCount = pandoraCount + 1
|
|
||||||
end
|
end
|
||||||
if (altCheck[pandoraCount] == nil or altStage == altCheck[pandoraCount]) then
|
-- void entry is missing and a later entry should be highlighted. We adjust the id accordingly
|
||||||
if stageCheck[pandoraCount] == stageNum then doMarkup = true
|
if textBlockToUse > 9 then
|
||||||
--special exception for ???/The Void
|
textBlockToUse = textBlockToUse - 1
|
||||||
elseif pandoraCount == 9 and stageNum == 12 then doMarkup = true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if doMarkup then
|
|
||||||
-- gsub behaves very poorly with punctuation so you need a punctuation-escaping gsub helper...
|
-- look up the line to highlight. skip the first 2 lines, because they are generic item infos
|
||||||
descObj.Description = string.gsub(descObj.Description, w:gsub("([^%w])", "%%%1"), "{{ColorBagComplete}}" .. w .. "{{CR}}")
|
local textBlockToHighlight = levelDescriptions[textBlockToUse + 2]
|
||||||
end
|
if textBlockToHighlight then
|
||||||
-- don't check any lines of the description after Home
|
-- Escape the content of the string, because gsub() expects pattern definitions
|
||||||
if pandoraCount == (EID.isRepentance and 14 or 13) then break end
|
local clearedTextBlock = string.gsub(textBlockToHighlight, "%p", "%%%0")
|
||||||
end
|
local replacementText = "{{ColorBagComplete}}" .. textBlockToHighlight .. "{{CR}}"
|
||||||
|
descObj.Description = string.gsub(descObj.Description, clearedTextBlock, replacementText)
|
||||||
end
|
end
|
||||||
|
|
||||||
return descObj
|
return descObj
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user