Update Books to dev

Trying to fix a problem with pages not forming when text is copyied and pasted, or from the older version of book.
This commit is contained in:
Elkien3 2017-10-04 19:08:21 -05:00
parent d494404e1a
commit 29d4dd77b1

View File

@ -73,12 +73,16 @@ local function book_on_use(itemstack, user)
return itemstack
end
local max_text_size = 10000
local max_title_size = 80
local short_title_size = 35
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "default:book" then return end
local inv = player:get_inventory()
local stack = player:get_wielded_item()
if fields.save and fields.title ~= "" and fields.text ~= "" then
if fields.save and fields.title and fields.text
and fields.title ~= "" and fields.text ~= "" then
local new_stack, data
if stack:get_name() ~= "default:book_written" then
local count = stack:get_count()
@ -97,11 +101,15 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
if not data then data = {} end
data.title = fields.title
data.title = fields.title:sub(1, max_title_size)
data.owner = player:get_player_name()
data.description = "\""..fields.title.."\" by "..data.owner
data.text = fields.text
data.text_len = #data.text
local short_title = data.title
-- Don't bother triming the title if the trailing dots would make it longer
if #short_title > short_title_size + 3 then
short_title = short_title:sub(1, short_title_size) .. "..."
end
data.description = "\""..short_title.."\" by "..data.owner
data.text = fields.text:sub(1, max_text_size)
data.page = 1
data.page_max = math.ceil((#data.text:gsub("[^\n]", "") + 1) / lpp)