diff --git a/book.lua b/book.lua index 4aee149..53d273e 100644 --- a/book.lua +++ b/book.lua @@ -1,5 +1,84 @@ local page_cache = {} +local recipe_cache = {} +local group_cache = {} + +local function resolve_group(group) + if group_cache[group] then return group_cache[group] end + local remove_group = group:sub(7) + local found + for v in pairs(minetest.registered_items) do + if minetest.get_item_group(v, remove_group) > 0 then + found = v + break + end + end + if not found then return "" end + group_cache[group] = found + return found +end + +local function fromtable_output(tbl, out) + local res + for _,v in pairs(tbl) do + if v.output == out then + res = v + break + end + end + return res +end + +local function generate_recipe_hypertext(item, recipe_type) + if recipe_cache[recipe_type .. "/" .. item] then return recipe_cache[recipe_type .. "/" .. item] end + + local lines = {} + + if recipe_type == 'cauldron' then + local x = fromtable_output(magicalities.cauldron.recipes, item) + if not x then return "" end + local rec = x.requirements + local y = {} + + for _,v in pairs(x.items) do + table.insert(y, "") + end + + table.insert(lines, "
" .. table.concat(y, "") .. "
") + table.insert(lines, "
") + table.insert(lines, "
") + + if rec then + local p = {} + for rec,v in pairs(rec) do + table.insert(p, v .. " " .. magicalities.elements[rec].description) + end + table.insert(lines, "
" .. table.concat(p, " | ") .. "
") + end + end + + if #lines > 0 then + local ht = table.concat(lines, "\n") + recipe_cache[recipe_type .. "/" .. item] = ht + return ht + end +end + +local function line_special (line) + local types = {"cauldron"} + local matched = false + + for _,v in pairs(types) do + matched = line:match("^<"..v) ~= nil + if matched then break end + end + + if not matched then return line end + local tyt = line:match("^<([%w]*)") + local itm = line:match("name=([^>]*)") + if not tyt or not itm then return "" end + return generate_recipe_hypertext(itm, tyt) +end local function book_formspec(user, page, scrollindex) if page then @@ -75,6 +154,7 @@ local function book_read(book, user, pointed_thing) end local function cache_book_pages() + recipe_cache = {} local file = io.open(minetest.get_modpath("magicalities").."/book.txt") local all = {} local previous = "" @@ -86,6 +166,7 @@ local function cache_book_pages() previous = line since = 0 elseif previous ~= "" then + line = line_special(line) if since > 0 then line = '\n'..line end @@ -173,4 +254,9 @@ minetest.register_chatcommand("mgcbookcache", { end }) -cache_book_pages() +local initial = true +minetest.register_on_joinplayer(function () + if not initial then return end + initial = false + cache_book_pages() +end) diff --git a/book.txt b/book.txt index 98917a8..5ee7ad2 100644 --- a/book.txt +++ b/book.txt @@ -32,16 +32,10 @@ Right-Click on the Cauldron with a Bucket of Water in order to fill it wi The Gold-Capped Wand is an improved version of the Steel-Capped Wand. It can contain up to 50 of each element instead of the Steel Wand's 25. #2magicalities:transterra The Transterra is a stone that can be used to create or remove nodes from the world. It is made in the Cauldron. -
-
-
-
1 Earth | 1 Dark
+ #2magicalities:tellium Tellium is a metal that can be used to create magical tools. It is made in the Cauldron. -
-
-
-
5 Fire | 5 Earth
+ #2magicalities:element_ring The Elemental Ring can show you what elements a crystal contains and their quantities. #2magicalities:focus_blank diff --git a/crystals.lua b/crystals.lua index 3e961b4..df84b3f 100644 --- a/crystals.lua +++ b/crystals.lua @@ -89,6 +89,11 @@ local function crystal_rightclick(pos, node, clicker, itemstack, pointed_thing) local player = clicker:get_player_name() local meta = minetest.get_meta(pos) + -- Protect crystals + if minetest.is_protected(pos, player) then + return itemstack + end + -- Add contents to the crystal local contents = minetest.deserialize(meta:get_string("contents")) if not contents then diff --git a/storage.lua b/storage.lua index f7b8ed1..e091fdb 100644 --- a/storage.lua +++ b/storage.lua @@ -15,18 +15,20 @@ local storage = minetest.get_mod_storage() -- Memory cache magicalities.data = {} +local data_default = { + recipes = {}, + abilities = {}, + protect = {}, + research = 0, +} + -- Storage actions function magicalities.load_player_data(player_name) local stdata = minetest.deserialize(storage:get_string(player_name)) if not stdata then - magicalities.data[player_name] = { - recipes = {}, - abilities = {}, - protect = {}, - research = 0, - } + magicalities.data[player_name] = table.copy(data_default) return end @@ -53,6 +55,22 @@ end -- System Actions +minetest.register_chatcommand("mgcstoragereset", { + func = function (name, params) + magicalities.data[name] = table.copy(data_default) + magicalities.save_player_data(name) + return true, "Deleted player storage successfully." + end +}) + +minetest.register_chatcommand("mgcstoragesave", { + privs = {basic_privs = 1}, + func = function (name, params) + magicalities.save_all_data() + return true, "Saved all magicalities data." + end +}) + minetest.register_on_shutdown(magicalities.save_all_data) minetest.register_on_joinplayer(function (player) diff --git a/table.lua b/table.lua index 7c1fca0..cde2b34 100644 --- a/table.lua +++ b/table.lua @@ -1,6 +1,5 @@ -magicalities.arcane = {} -magicalities.arcane.recipes = {} +magicalities.arcane = { recipes = {} } local fmspecelems = { ["earth"] = {2.98, 0.15}, diff --git a/textures/magicalities_gui_slot.png b/textures/magicalities_gui_slot.png new file mode 100644 index 0000000..a8e8b88 Binary files /dev/null and b/textures/magicalities_gui_slot.png differ