Improved pluralization by enabling each language to provide their own pluralization algorithm

This commit is contained in:
Wofsauge committed 2025-04-11 00:31:24 +02:00
1 parent 59e1ed454e
commit 6e5610cce1
29 files changed
+229 -136

No files matched your search

+14 -1
View File
@@ -3199,14 +3199,27 @@ function EID:HasPathToPosition(startPos, endPos)
return pathfinderObj:GetPath() ~= nil
end
---Applies language specific modifiers that aim to pluralize a text
---@param text string
---@param amount integer
function EID:TryPluralizeString(text, amount)
local func = EID:getDescriptionEntry("PluralizeFunction")
if type(func) == "function" then
return func(text,amount)
end
return text
end
---Prints a message in both the console and the Log file, to make important messages from EID stand out everywhere
---@param str string
function EID:WriteDebugMsg(str)
print(str)
Isaac.DebugString(str)
end
---Prints an error message in both the console and the Log file, to make important messages from EID stand out everywhere
---@param str string
function EID:WriteErrorMsg(str)
EID:WriteDebugMsg("EID ERROR: " .. str)
end
end
+6 -5
View File
@@ -326,18 +326,19 @@ local function HealthUpCallback(descObj)
-- find/replace Health Up lines
local numHearts = EID.HealthUpData[typeVarSub] or 1
local text = EID:getDescriptionEntry("RedToX", "Red to " .. heartType)
local plural = ""; if numHearts ~= 1 and numHearts ~= -1 then plural = EID:getDescriptionEntry("Pluralize") end
local pos = 1
while pos <= #text do
-- replace {1} with the number of hearts and {2} with the plural character
local toFind = EID:ReplaceVariableStr(text[pos], {numHearts, plural})
local toFind = EID:ReplaceVariableStr(text[pos], numHearts)
if text[pos + 1] then
local replaceWith = EID:ReplaceVariableStr(text[pos + 1], {numHearts, plural})
local replaceWith = EID:ReplaceVariableStr(text[pos + 1], numHearts)
descObj.Description = EID:SimpleReplace(descObj.Description, tostring(toFind), replaceWith, 1)
end
pos = pos + 2
end
-- pluralize
descObj.Description = EID:TryPluralizeString(descObj.Description, numHearts)
-- remove HealingRed lines entirely for Soul/Black/None health chars
descObj.Description = descObj.Description .. "#" -- gsub finds final lines better if the desc ends with a line break
@@ -1081,8 +1082,8 @@ if EID.isRepentance then
descriptionText = descriptionText .. GetFlagString(2, "TearFlagNames", tearFlags2, procChance1, procChance2, procChance3)
descriptionText = descriptionText .. GetFlagString(3, "TearFlagNames", tearFlags3, procChance1, procChance2, procChance3)
local plural = amount > 1 and EID:getDescriptionEntry("Pluralize") or ""
descriptionText = EID:ReplaceVariableStr(descriptionText, "pluralize", plural)
-- pluralize
descriptionText = EID:TryPluralizeString(descriptionText, amount)
-- Put everything together
EID:appendToDescription(descObj, descriptionText)
+11 -6
View File
@@ -23,19 +23,24 @@ local actions = { [0] = "use_active_item", "add_temporary_effect", "convert_enti
local triggers = { [0] = "active", "tear_fire", "enemy_hit", "enemy_kill", "damage_taken", "room_clear", "entity_spawned", "pickup_collected", "chain" }
local function entityToName(Type, Variant, plural)
plural = plural or false
-- -1 is often used as an "any of this type", even if there's only one of that type, so converting it to 0 can help find names
-- the string.format is in case this receives the type/variant as a Lua float
local e = string.format("%d",Type) .. "." .. string.format("%d",Variant)
local eWithZero = string.gsub(e, "-1", "0")
local localizedNames = EID:getDescriptionEntry("GlitchedItemText")
local pluralize = EID:getDescriptionEntry("Pluralize")
local name = localizedNames[e] or localizedNames[eWithZero] or EID:GetEntityXMLName(Type, Variant, 0) or e
--print out entities with no name yet
if name == e then Isaac.DebugString("No name found for " .. e .. " (could be modded)")
elseif plural then name = name .. pluralize end
if name == e then Isaac.DebugString("No name found for " .. e .. " (could be modded)") end
-- pluralize Entity name
if plural then
name = name .."{pluralize}"
name = EID:TryPluralizeString(name, 2)
-- remove temporary variable, if language did not replace it
name = EID:ReplaceVariableStr(name, "pluralize", "")
end
return name
end
@@ -54,7 +59,6 @@ function EID:CheckGlitchedItemConfig(id)
local localizedNames = EID:getDescriptionEntry("GlitchedItemText")
local localizedNamesEnglish = EID:getDescriptionEntryEnglish("GlitchedItemText")
local pluralize = EID:getDescriptionEntry("Pluralize")
local attributes = "#"
-- Check the base item config for the Hearts/Bombs/Coins/Keys this item adds,
@@ -85,9 +89,10 @@ function EID:CheckGlitchedItemConfig(id)
local prefix = "↑ "
if val > 0 then s = "+" .. s else prefix = "↓ " end
attributes = attributes .. prefix .. EID:ReplaceVariableStr(localizedNames[v] or localizedNamesEnglish[v], 1, s)
if val ~= 1 and val ~= -1 then attributes = attributes .. pluralize end
attributes = attributes .. "#"
end
-- pluralize
attributes = EID:TryPluralizeString(attributes, val)
end
end