forked from minetest/minetest_game
Books: Ensure backward compatibility for older written books
This commit is contained in:
parent
7a29d26e3e
commit
6749da1070
@ -14,17 +14,19 @@ minetest.register_craftitem("default:paper", {
|
|||||||
local function book_on_use(itemstack, user)
|
local function book_on_use(itemstack, user)
|
||||||
local player_name = user:get_player_name()
|
local player_name = user:get_player_name()
|
||||||
local data = minetest.deserialize(itemstack:get_metadata())
|
local data = minetest.deserialize(itemstack:get_metadata())
|
||||||
local formspec, title, text, text_len, page, page_max, cpp, owner =
|
local formspec, title, text, owner = "", "", "", player_name
|
||||||
"", "", "", 1, 1, 1, 1, player_name
|
local page, page_max, cpp = 1, 1, 650
|
||||||
|
|
||||||
if data then
|
if data then
|
||||||
title = data.title
|
title = data.title
|
||||||
text = data.text
|
text = data.text
|
||||||
owner = data.owner
|
owner = data.owner
|
||||||
text_len = data.text_len
|
|
||||||
page = data.page
|
if data.page then
|
||||||
page_max = data.page_max
|
page = data.page
|
||||||
cpp = data.chars_per_page
|
page_max = data.page_max
|
||||||
|
cpp = data.chars_per_page
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if owner == player_name then
|
if owner == player_name then
|
||||||
@ -41,11 +43,11 @@ local function book_on_use(itemstack, user)
|
|||||||
"label[0.5,0.5;by " .. owner .. "]" ..
|
"label[0.5,0.5;by " .. owner .. "]" ..
|
||||||
"tablecolumns[color;text]" ..
|
"tablecolumns[color;text]" ..
|
||||||
"tableoptions[background=#00000000;highlight=#00000000;border=false]" ..
|
"tableoptions[background=#00000000;highlight=#00000000;border=false]" ..
|
||||||
"table[0.4,0;7,0.5;title;#FFFF00," .. minetest.formspec_escape(title) .. "]"..
|
"table[0.4,0;7,0.5;title;#FFFF00," .. minetest.formspec_escape(title) .. "]" ..
|
||||||
"textarea[0.5,1.5;7.5,7;;".. minetest.formspec_escape(text:sub(
|
"textarea[0.5,1.5;7.5,7;;" .. minetest.formspec_escape(text:sub(
|
||||||
(cpp * page) - cpp, cpp * page)) .. ";]" ..
|
(cpp * page) - cpp, cpp * page)) .. ";]" ..
|
||||||
"button[2.4,7.6;0.8,0.8;book_prev;<]" ..
|
"button[2.4,7.6;0.8,0.8;book_prev;<]" ..
|
||||||
"label[3.2,7.7;Page " .. page .. " of " .. page_max .. "]"..
|
"label[3.2,7.7;Page " .. page .. " of " .. page_max .. "]" ..
|
||||||
"button[4.9,7.6;0.8,0.8;book_next;>]"
|
"button[4.9,7.6;0.8,0.8;book_next;>]"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -96,6 +98,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
|
|
||||||
elseif fields.book_next or fields.book_prev then
|
elseif fields.book_next or fields.book_prev then
|
||||||
local data = minetest.deserialize(stack:get_metadata())
|
local data = minetest.deserialize(stack:get_metadata())
|
||||||
|
if not data.page then return end
|
||||||
|
|
||||||
if fields.book_next then
|
if fields.book_next then
|
||||||
data.page = data.page + 1
|
data.page = data.page + 1
|
||||||
if data.page > data.page_max then
|
if data.page > data.page_max then
|
||||||
|
Loading…
Reference in New Issue
Block a user