From 1e04b7f91d8e59f066e8992ec01a80ab971d5751 Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Wed, 21 Aug 2024 21:09:45 +0200 Subject: [PATCH] Improved stability of "addDescription()" functions with outdated languages closes #712 --- features/eid_api.lua | 21 +++++++++++++++++++++ features/eid_conditionals_funcs.lua | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/features/eid_api.lua b/features/eid_api.lua index f7c0928b..8420d18e 100644 --- a/features/eid_api.lua +++ b/features/eid_api.lua @@ -50,6 +50,7 @@ function EID:addCollectible(id, description, itemName, language) local modName = EID._currentMod -- Glitched Items exception so they don't have a mod name if id > 4294960000 then modName = nil end + EID:CreateDescriptionTableIfMissing("custom", language) EID.descriptions[language].custom["5.100." .. id] = {id, itemName, description, modName} end @@ -57,6 +58,7 @@ end function EID:addTrinket(id, description, itemName, language) itemName = itemName or nil language = language or "en_us" + EID:CreateDescriptionTableIfMissing("custom", language) EID.descriptions[language].custom["5.350." .. id] = {id, itemName, description, EID._currentMod} end @@ -64,6 +66,7 @@ end function EID:addCharacterInfo(characterId, description, playerName, language) playerName = playerName or "Modded Character" language = language or "en_us" + EID:CreateDescriptionTableIfMissing("CharacterInfo", language) EID.descriptions[language].CharacterInfo[characterId] = {playerName, description} end @@ -86,6 +89,7 @@ function EID:addGoldenTrinketMetadata(id, appendText, numbersToMultiply, maxMult EID.GoldenTrinketData[id] = {t = numbersToMultiply, mult = maxMultiplier, append = appendText and true} if appendText then + EID:CreateDescriptionTableIfMissing("goldenTrinketEffects", language) EID.descriptions[language].goldenTrinketEffects[id] = { appendText[1], appendText[1], appendText[2] or appendText[1] } end end @@ -101,6 +105,7 @@ end function EID:addCard(id, description, itemName, language) itemName = itemName or nil language = language or "en_us" + EID:CreateDescriptionTableIfMissing("custom", language) EID.descriptions[language].custom["5.300." .. id] = {id, itemName, description, EID._currentMod} end @@ -120,16 +125,20 @@ end function EID:addPill(id, description, itemName, language) itemName = itemName or nil language = language or "en_us" + EID:CreateDescriptionTableIfMissing("pills", language) + EID:CreateDescriptionTableIfMissing("horsepills", language) EID.descriptions[language].pills[id+1] = {id, itemName, description, EID._currentMod} -- Default the horsepill to the same description as the base pill, for mods that only define the base pill if EID.isRepentance and EID.descriptions[language].horsepills[id+1] == nil then EID.descriptions[language].horsepills[id+1] = {id, itemName, description, EID._currentMod} end end + function EID:addHorsePill(id, description, itemName, language) if not EID.isRepentance then return end itemName = itemName or nil language = language or "en_us" + EID:CreateDescriptionTableIfMissing("horsepills", language) EID.descriptions[language].horsepills[id+1] = {id, itemName, description, EID._currentMod} end @@ -148,6 +157,7 @@ end function EID:addBirthright(characterId, description, playerName, language) playerName = playerName or nil language = language or "en_us" + EID:CreateDescriptionTableIfMissing("birthright", language) EID.descriptions[language].birthright[characterId + 1] = {playerName, "", description} end @@ -251,6 +261,7 @@ function EID:addEntity(id, variant, subtype, entityName, description, language) if id == EntityType.ENTITY_EFFECT then EID.effectList[variant] = true end + EID:CreateDescriptionTableIfMissing("custom", language) EID.descriptions[language].custom[id .. "." .. variant .. "." .. subtype] = { subtype, entityName, @@ -2462,3 +2473,13 @@ function EID:ClosestPlayerTo(entity) return closestPlayer end + +-- Creates a description table for a given language to prevent outdated languages from breaking EID API functions for mods +function EID:CreateDescriptionTableIfMissing(tableName, language) + if language and not EID.descriptions[language] then + EID.descriptions[language] = {} + end + if tableName and not EID.descriptions[language][tableName] then + EID.descriptions[language][tableName] = {} + end +end diff --git a/features/eid_conditionals_funcs.lua b/features/eid_conditionals_funcs.lua index a01d4ab7..de4fd087 100644 --- a/features/eid_conditionals_funcs.lua +++ b/features/eid_conditionals_funcs.lua @@ -3,6 +3,7 @@ local modTextsAdded = 0 local function newModdedCondition(text, language) if text == nil then return nil end modTextsAdded = modTextsAdded + 1 + EID:CreateDescriptionTableIfMissing("ConditionalDescs", language) EID.descriptions[language].ConditionalDescs["Modded Conditional " .. modTextsAdded] = text return "Modded Conditional " .. modTextsAdded end @@ -64,6 +65,7 @@ function EID:addToGeneralCondition(ID, locTable, text, numberToDouble, newNumber newNumber = newNumber or numberToDouble * 2 text = { numberToDouble, newNumber, text } end + EID:CreateDescriptionTableIfMissing(locTable, language) EID.descriptions[language][locTable][ID] = text end @@ -110,6 +112,7 @@ function EID:addBFFSCondition(ID, text, numberToDouble, newNumber, language) -- We don't have to add a new condition for collectibles, because they're checked with a "5.100" condition EID:AddItemConditional(ID, 247, EID.CheckForBFFS, {locTable = "BFFSSynergies", replaceColor = "BlinkPink", noFallback = false, uniqueID = "BFFS"}) end + EID:CreateDescriptionTableIfMissing("BFFSSynergies", language) EID.descriptions[language].BFFSSynergies[ID] = text end @@ -129,6 +132,7 @@ function EID:addHiveMindCondition(ID, text, numberToDouble, newNumber, language, -- We don't have to add a new condition for collectibles, because they're checked with a "5.100" condition EID:AddItemConditional(ID, 248, EID.CheckForHiveMind, {locTable = "BFFSSynergies", replaceColor = "BlinkBlue", noFallback = false, uniqueID = "BFFS"}) end + EID:CreateDescriptionTableIfMissing("BFFSSynergies", language) EID.descriptions[language].BFFSSynergies[ID] = text end @@ -169,6 +173,7 @@ local function CopyTable(t1) local newTable = {}; for k, v in pairs(t1) do newTable[k] = v end return newTable end + -- Every single add conditional function ends up calling this function eventually. This is THE place to define variables every condition MUST have. function EID:AddConditional(IDs, funcText, modText, extraTable) if type(IDs) ~= "table" then IDs = { IDs } end