From d31a7d6050c28f5879bcc1046906f60c04349175 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Wed, 28 Aug 2019 17:15:55 +0300 Subject: [PATCH] focus requirements in wand description --- storage.lua | 34 ++++++++++++---------------------- wands.lua | 16 +++++++++++----- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/storage.lua b/storage.lua index 3d19068..96ea201 100644 --- a/storage.lua +++ b/storage.lua @@ -9,18 +9,16 @@ } ]] +-- Modstorage +local storage = minetest.get_mod_storage() + -- Memory cache magicalities.data = {} function magicalities.load_player_data(player_name) - local world = minetest.get_worldpath() - local directory = world.."/magicalities" - minetest.mkdir(directory) + local stdata = minetest.deserialize(storage:get_string(player_name)) - local filetag = player_name..".info.json" - local file = io.open(directory.."/"..filetag) - - if not file then + if not stdata then magicalities.data[player_name] = { recipes = {}, abilities = {}, @@ -30,27 +28,19 @@ function magicalities.load_player_data(player_name) return end - local str = "" - for line in file:lines() do - str = str..line - end - - file:close() - - magicalities.data[player_name] = minetest.deserialize(str) + magicalities.data[player_name] = stdata end function magicalities.save_player_data(player_name) - if not magicalities.data[player_name] then return nil end + if not magicalities.data[player_name] then return end + local data = magicalities.data[player_name] - local world = minetest.get_worldpath() - local directory = world.."/magicalities" - minetest.mkdir(directory) + -- Do not save empty data + if #data.recipes == 0 and #data.abilities == 0 and #data.protect == 0 and data.research == 0 then return end - local filetag = player_name..".info.json" - local data = minetest.serialize(magicalities.data[player_name]) + local str = minetest.serialize(data) - minetest.safe_file_write(directory.."/"..filetag, data) + storage:set_string(player_name, str) end function magicalities.save_all_data() diff --git a/wands.lua b/wands.lua index c8908fe..38d1d8c 100644 --- a/wands.lua +++ b/wands.lua @@ -116,6 +116,9 @@ end function magicalities.wands.update_wand_desc(stack) local meta = stack:get_meta() local data_table = minetest.deserialize(meta:get_string("contents")) + if not data_table then data_table = {} end + + local focus, fdef = magicalities.wands.get_wand_focus(stack) local wanddata = minetest.registered_items[stack:get_name()] local description = wanddata.description @@ -127,18 +130,21 @@ function magicalities.wands.update_wand_desc(stack) local dataelem = magicalities.elements[elem] if amount > 0 then if amount < 10 then amount = "0"..amount end - elems[#elems + 1] = "["..amount.."/"..capcontents.."] ".. - minetest.colorize(dataelem.color, dataelem.description) + local str = "["..amount.."/"..capcontents.."] " + str = str .. minetest.colorize(dataelem.color, dataelem.description) + if focus and fdef and fdef['_wand_requirements'] and fdef['_wand_requirements'][elem] ~= nil then + str = str .. minetest.colorize("#5716ad", " ("..fdef['_wand_requirements'][elem]..") ") + end + elems[#elems + 1] = str end end - local focus, def = magicalities.wands.get_wand_focus(stack) local focusstr = "No Wand Focus" if focus then - focusstr = def.description + focusstr = fdef.description end - strbld = strbld .. minetest.colorize("#a070e0", focusstr) .. "\n" + strbld = strbld .. minetest.colorize("#5716ad", focusstr) .. "\n" if #elems > 0 then table.sort(elems) strbld = strbld .. "\n" .. table.concat(elems, "\n")