diff --git a/elepower_tome/init.lua b/elepower_tome/init.lua
index 30d6d22..b14cc36 100644
--- a/elepower_tome/init.lua
+++ b/elepower_tome/init.lua
@@ -4,13 +4,13 @@
-- | _|| / -_) '_ \/ _ \ V V / -_) '_| --
-- |___|_\___| .__/\___/\_/\_/\___|_| --
-- |_| --
--- _____ --
--- |_ _|__ _ __ ___ --
--- | |/ _ \ ' \/ -_) --
--- |_|\___/_|_|_\___| --
+-- _____ --
+-- |_ _|__ _ __ ___ --
+-- | |/ _ \ ' \/ -_) --
+-- |_|\___/_|_|_\___| --
---------------------------------------------------
-- --
----------------------------------------------------
+---------------------------------------------------
-- Global variable for mod
eletome = rawget(_G, "eletome") or {}
@@ -36,11 +36,11 @@ minetest.register_craftitem("elepower_tome:tome", {
inventory_image = "elepower_tome.png",
groups = {book = 1, flammable = 3},
on_use = function(itemstack, user, pointed_thing)
-
+
local eletome_bg = eletome.tome_bg
- local eletome_contents = eletome.contents_page()
+ local eletome_contents = eletome.contents_page()
minetest.show_formspec(user:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_contents)
-
+
end,
})
@@ -53,7 +53,7 @@ end)
-- Player tome meta - setup back button meta
minetest.register_on_joinplayer(function(player)
local pmeta = player:get_meta()
- local back = {}
+ local back = {}
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
end)
@@ -63,19 +63,19 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "elepower_tome:tome" then
return
end
-
- -- Back Button
+
+ -- Back Button
local pmeta = player:get_meta()
local back = minetest.deserialize(pmeta:get_string("elepower_tome_back"))
local show_back = ""
-
+
if fields.quit == "true" then
back = {}
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
-
- elseif fields.back then
+
+ elseif fields.back then
local prev_page = #back-1
-
+
if prev_page <= 0 then
-- must be going back to contents
fields = {}
@@ -85,61 +85,60 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
else
fields = back[prev_page]
table.remove(back,#back)
- table.remove(back,#back-1)
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
end
else
table.insert(back,fields)
- pmeta:set_string("elepower_tome_back", minetest.serialize(back))
+ pmeta:set_string("elepower_tome_back", minetest.serialize(back))
end
-
+
if #back > 0 then
show_back = eletome.back_button
end
-
+
-- Clicked contents button on any page.
if fields.content then
local eletome_bg = eletome.tome_bg..show_back
local eletome_contents = eletome.contents_page()
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_contents)
end
-
+
-- Clicked a craft link on contents
- if fields.craft_click then
+ if fields.craft_click then
local eletome_bg = eletome.tome_bg..show_back
local eletome_craft = eletome.craft_page(fields.craft_click)
-
+
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_craft)
- end
+ end
-- Clicked craft bwd/fwd button on craft sub-page
- if fields.craft_bwd_fwd then
+ if fields.craft_bwd_fwd then
local page_num = string.match(fields.craft_bwd_fwd , "%s(%w+)%s")
-- eletome.craft_page() expects description in format "something:craft_description"
local craft_value = "cd:"..fields.description
-
+
local eletome_bg = eletome.tome_bg..show_back
local eletome_craft = eletome.craft_page(craft_value,page_num)
-
+
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_craft)
end
-
+
-- Clicked Machine page
- if fields.machine then
+ if fields.machine then
local eletome_bg = eletome.tome_bg..show_back
local eletome_machine = eletome.machines(fields.machine)
-
+
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_machine)
- end
+ end
-- Clicked Machine bwd/fwd button on Machine page
- if fields.mach_bwd_fwd then
+ if fields.mach_bwd_fwd then
local page_num = string.match(fields.mach_bwd_fwd, "%s(%w+)%s")
local mach_value = fields.description
-
+
local eletome_bg = eletome.tome_bg..show_back
local eletome_machine = eletome.machines(mach_value,page_num)
-
+
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_machine)
end
@@ -147,28 +146,28 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.instructions then
local eletome_bg = eletome.tome_bg..show_back
local eletome_instruct = eletome.instructions_page(fields.description)
-
- minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_instruct)
+
+ minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_instruct)
end
-- Clicked Large Image page
if fields.large_image then
local eletome_bg = eletome.tome_bg..show_back
local eletome_lrg_img = eletome.large_image_page(fields.description)
-
- minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_lrg_img)
+
+ minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_lrg_img)
end
-- Clicked Help page
if fields.help then
local eletome_bg = eletome.tome_bg..show_back
local eletome_how_use = eletome.how_use_page(fields.help)
- minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_how_use)
+ minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_how_use)
end
-- Clicked How to use page
if fields.description == "action:machine-ele_user" then
-
+
local how_use = false
local node_name
for k,v in pairs(eletome.ai.nodes) do
@@ -178,26 +177,26 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
node_name = k
end
end
-
+
end
-
+
if how_use then
local eletome_bg = eletome.tome_bg..show_back
local eletome_how_use = eletome.how_use_page(node_name)
- minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_how_use)
+ minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_how_use)
end
- end
-
---minetest.debug(dump(fields))
+ end
+
+--minetest.debug(dump(fields))
end)
-
+
-------------------
-- Page Defaults --
-------------------
eletome.tome_bg = "formspec_version[4]size[18,11]"..
"bgcolor[#003782;true]".. -- fails (my understanding limitation)
- "box[0.0,0.0;18,11;#003782]".. -- workaround the above
+ "box[0.0,0.0;18,11;#003782]".. -- workaround the above
"box[0.5,0.5;8.5,10;#d1caaeFF]"..
"box[9.0,0.5;8.5,10;#d1caaeFF]"..
"style_type[button;bgcolor=#003782]"..
@@ -208,30 +207,28 @@ eletome.tome_bg = "formspec_version[4]size[18,11]"..
"style[fake_prev_page;textcolor=#777777]"..
"button[12.5,0;2.5,0.5;fake_prev_page;<< Prev]"..
"style[fake_next_page;textcolor=#777777]"..
- "button[15,0;2.5,0.5;fake_prev_page;Next >>]"..
+ "button[15,0;2.5,0.5;fake_prev_page;Next >>]"..
"button_exit[17.5,0;0.5,0.5;X;X]"
-
-eletome.back_button = "style[back;textcolor=#ffffff]".."button[2.5,0;2.5,0.5;back;Back]"
+
+eletome.back_button = "style[back;textcolor=#ffffff]".."button[2.5,0;2.5,0.5;back;Back]"
eletome.font_color = "#1f1f1fFF"
eletome.y_space_line = 0.4
-eletome.char_per_line = 60
+eletome.char_per_line = 60
eletome.tooltip_color = "#30434c;#f9f9f9"
-- Common style components - some end duplicates but kept for ease of reading/updating later
-- s = start ie pre text
-- e = end ie post text
--- Used for hypertext
+-- Used for hypertext
eletome.common_styles = {
- style_h0s = "",
- style_h1s = "",
- style_h2s = "",
- style_h3s = "", -- approximate default "label" size
- style_h4s = ""
-
+ style_h0s = "",
+ style_h1s = "",
+ style_h2s = "",
+ style_h3s = "", -- approximate default "label" size
+ style_h4s = ""
}
-
\ No newline at end of file