Cache our formatted lines to avoid calling fitTextToWidth

This commit is contained in:
Buurazu authored and GitHub committed 2022-01-23 03:28:07 -05:00
1 parent 34ea5395eb
commit 2381835798
1 file changed
+20 -4
+20 -4
View File
@@ -441,6 +441,10 @@ end
---------------------------------------------------------------------------
---------------------------Printing Functions------------------------------
local previousFormattedLines = {}
local previousBulletpoints = {}
local previousDesc = ""
function EID:printDescription(desc)
local textScale = Vector(EID.Scale, EID.Scale)
local renderPos = EID:getTextPosition()
@@ -576,6 +580,11 @@ function EID:printDescription(desc)
end
end
end
if previousDesc ~= desc.Description then
previousFormattedLines = {}
previousBulletpoints = {}
previousDesc = desc.Description
end
EID:printBulletPoints(desc.Description, renderPos)
end
@@ -583,12 +592,20 @@ function EID:printBulletPoints(description, renderPos)
local textboxWidth = tonumber(EID.Config["TextboxWidth"])
local textScale = Vector(EID.Scale, EID.Scale)
description = EID:replaceShortMarkupStrings(description)
if #previousFormattedLines == 0 then
for line in string.gmatch(description, "([^#]+)") do
local formatedLines = EID:fitTextToWidth(line, textboxWidth, EID.BreakUtf8CharsLanguage[EID.Config["Language"]])
previousBulletpoints[#previousFormattedLines+1] = true
for _,v in ipairs(EID:fitTextToWidth(line, textboxWidth, EID.BreakUtf8CharsLanguage[EID.Config["Language"]])) do
table.insert(previousFormattedLines, v)
end
end
end
local textColor = EID:getTextColor()
for i, lineToPrint in ipairs(formatedLines) do
for i, lineToPrint in ipairs(previousFormattedLines) do
-- render bulletpoint
if i == 1 then
if previousBulletpoints[i] then
textColor = EID:getTextColor()
local bpIcon = EID:handleBulletpointIcon(lineToPrint)
if EID:getIcon(bpIcon) ~= EID.InlineIcons["ERROR"] then
lineToPrint = string.gsub(lineToPrint, bpIcon .. " ", "", 1)
@@ -602,7 +619,6 @@ function EID:printBulletPoints(description, renderPos)
renderPos.Y = renderPos.Y + EID.lineHeight * EID.Scale
end
end
end
---------------------------------------------------------------------------
----------------------------Handle New Room--------------------------------
local isMirrorRoom = false