Skip to content

Commit 502720b

Browse files
red-001paramat
authored andcommittedJun 16, 2017
Books: Also limit the max size of the title
This limits the max size of the full title of the book to `80` letters and the size of the part thats displayed in the tooltip to `35` letters.
1 parent 0157175 commit 502720b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed
 

‎mods/default/craftitems.lua

+9-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ local function book_on_use(itemstack, user)
7676
end
7777

7878
local max_text_size = 10000
79+
local max_title_size = 80
80+
local short_title_size = 35
7981
minetest.register_on_player_receive_fields(function(player, formname, fields)
8082
if formname ~= "default:book" then return end
8183
local inv = player:get_inventory()
@@ -101,9 +103,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
101103
end
102104

103105
if not data then data = {} end
104-
data.title = fields.title
106+
data.title = fields.title:sub(1, max_title_size)
105107
data.owner = player:get_player_name()
106-
data.description = "\""..fields.title.."\" by "..data.owner
108+
local short_title = data.title
109+
-- Don't bother triming the title if the trailing dots would make it longer
110+
if #short_title > short_title_size + 3 then
111+
short_title = short_title:sub(1, short_title_size) .. "..."
112+
end
113+
data.description = "\""..short_title.."\" by "..data.owner
107114
data.text = fields.text:sub(1, max_text_size)
108115
data.page = 1
109116
data.page_max = math.ceil((#data.text:gsub("[^\n]", "") + 1) / lpp)

0 commit comments

Comments
 (0)
Please sign in to comment.