Check string limits correctly

This commit is contained in:
Jean-Patrick Guerrero 2022-07-01 17:15:10 +02:00
parent bd356e4a40
commit 1627172cce

View File

@ -38,7 +38,7 @@ local function weird_desc(str)
end end
local function snip(str, limit) local function snip(str, limit)
return #str > limit and fmt("%s...", sub(str, 1, limit - 3)) or str return fmt("%s...", sub(str, 1, limit - 3))
end end
local function get_desc(item) local function get_desc(item)
@ -175,11 +175,11 @@ local function get_award_list(data, fs, ctn_len, yextra, award_list, awards_unlo
local desc_lim, _desc = 39 local desc_lim, _desc = 39
local icon_size = 1.1 local icon_size = 1.1
if #title > title_lim then if utf8_len(title) > title_lim then
_title = snip(title, title_lim) _title = snip(title, title_lim)
end end
if #desc > desc_lim then if utf8_len(desc) > desc_lim then
_desc = snip(desc, desc_lim) _desc = snip(desc, desc_lim)
end end
@ -318,7 +318,7 @@ local function get_waypoint_fs(fs, data, player, yextra, ctn_len)
local waypoint_name, lim = v.name, 18 local waypoint_name, lim = v.name, 18
if #v.name > lim then if utf8_len(v.name) > lim then
waypoint_name = snip(waypoint_name, lim) waypoint_name = snip(waypoint_name, lim)
end end
@ -1189,12 +1189,12 @@ local function get_header(fs, data)
local Y1 = data.yoffset + 0.47 local Y1 = data.yoffset + 0.47
local Y2 = Y1 + 0.5 local Y2 = Y1 + 0.5
if #desc > desc_lim then if utf8_len(desc) > desc_lim then
tooltip(X, Y1 - 0.1, 5.7, 0.24, desc) tooltip(X, Y1 - 0.1, 5.7, 0.24, desc)
desc = snip(desc, desc_lim) desc = snip(desc, desc_lim)
end end
if #tech_name > name_lim then if utf8_len(tech_name) > name_lim then
tooltip(X, Y2 - 0.1, 5.7, 0.24, tech_name) tooltip(X, Y2 - 0.1, 5.7, 0.24, tech_name)
tech_name = snip(tech_name, name_lim) tech_name = snip(tech_name, name_lim)
end end