focus requirements in wand description

This commit is contained in:
Evert Prants 2019-08-28 17:15:55 +03:00
parent fcd74fd0f2
commit d31a7d6050
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 23 additions and 27 deletions

View File

@ -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()

View File

@ -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")