Skip to content

Commit

Permalink
TastyText line length fix for love.js
Browse files Browse the repository at this point in the history
  • Loading branch information
niamu committed Nov 23, 2024
1 parent b8539a5 commit 56747b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/nodes/npc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ function Menu:keypressed( button, player )
elseif item.text == 'inventory' then
if self.host.props.inventory then
self:instahide()
self.host.props.inventory(self.host, player)
self.dialog = Dialog.new(self.responses[item.text], function() self:show() end)
self.dialog = Dialog.new(self.responses[item.text], function()
self.host.props.inventory(self.host, player)
self:show()
end)
else
self:hide()
self.dialog = Dialog.new(self.host.noinventory, function() self:show() end)
Expand Down
2 changes: 1 addition & 1 deletion src/tooltip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function Tooltip:draw(x, y, selectedItem, parent)
tastytext = fonts.tasty.new(itemStats, textX, textY + (descriptionWrap * lineHeight), textWidth, love.graphics.getFont(), fonts.colors, lineHeight)
statWrap = tastytext.lines
tastytext:draw()
drawSeparator(textX, textY + (descriptionWrap + statWrap) * lineHeight, textWidth)
drawSeparator(textX, textY + ((descriptionWrap + statWrap) * lineHeight), textWidth)
end

-- Lastly, insert our item information after everything else
Expand Down
8 changes: 7 additions & 1 deletion src/vendor/tastytext/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ function TastyText:_getMetaData()
local line_lengths = {}
local line_widths = {}
local length = 0
local lines = 1
for i = 1,#self.chunk_array do
local chunk = self.chunk_array[i]
if chunk.length then
Expand All @@ -244,7 +245,12 @@ function TastyText:_getMetaData()
(line_widths[chunk.line] or 0) + chunk.width
end
end
return #line_lengths,length,line_lengths,line_widths
-- NOTE: This is a love.js workaround.
-- Returning #line_lengths always results in 0 in love.js for some reason.
for k,v in pairs(line_lengths) do
lines = lines + 1
end
return lines,length,line_lengths,line_widths
end

function TastyText:_parseString(str)
Expand Down

0 comments on commit 56747b4

Please sign in to comment.