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 -- Memory cache
magicalities.data = {} magicalities.data = {}
function magicalities.load_player_data(player_name) function magicalities.load_player_data(player_name)
local world = minetest.get_worldpath() local stdata = minetest.deserialize(storage:get_string(player_name))
local directory = world.."/magicalities"
minetest.mkdir(directory)
local filetag = player_name..".info.json" if not stdata then
local file = io.open(directory.."/"..filetag)
if not file then
magicalities.data[player_name] = { magicalities.data[player_name] = {
recipes = {}, recipes = {},
abilities = {}, abilities = {},
@ -30,27 +28,19 @@ function magicalities.load_player_data(player_name)
return return
end end
local str = "" magicalities.data[player_name] = stdata
for line in file:lines() do
str = str..line
end
file:close()
magicalities.data[player_name] = minetest.deserialize(str)
end end
function magicalities.save_player_data(player_name) 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() -- Do not save empty data
local directory = world.."/magicalities" if #data.recipes == 0 and #data.abilities == 0 and #data.protect == 0 and data.research == 0 then return end
minetest.mkdir(directory)
local filetag = player_name..".info.json" local str = minetest.serialize(data)
local data = minetest.serialize(magicalities.data[player_name])
minetest.safe_file_write(directory.."/"..filetag, data) storage:set_string(player_name, str)
end end
function magicalities.save_all_data() function magicalities.save_all_data()

View File

@ -116,6 +116,9 @@ end
function magicalities.wands.update_wand_desc(stack) function magicalities.wands.update_wand_desc(stack)
local meta = stack:get_meta() local meta = stack:get_meta()
local data_table = minetest.deserialize(meta:get_string("contents")) 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 wanddata = minetest.registered_items[stack:get_name()]
local description = wanddata.description local description = wanddata.description
@ -127,18 +130,21 @@ function magicalities.wands.update_wand_desc(stack)
local dataelem = magicalities.elements[elem] local dataelem = magicalities.elements[elem]
if amount > 0 then if amount > 0 then
if amount < 10 then amount = "0"..amount end if amount < 10 then amount = "0"..amount end
elems[#elems + 1] = "["..amount.."/"..capcontents.."] ".. local str = "["..amount.."/"..capcontents.."] "
minetest.colorize(dataelem.color, dataelem.description) 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
end end
local focus, def = magicalities.wands.get_wand_focus(stack)
local focusstr = "No Wand Focus" local focusstr = "No Wand Focus"
if focus then if focus then
focusstr = def.description focusstr = fdef.description
end end
strbld = strbld .. minetest.colorize("#a070e0", focusstr) .. "\n" strbld = strbld .. minetest.colorize("#5716ad", focusstr) .. "\n"
if #elems > 0 then if #elems > 0 then
table.sort(elems) table.sort(elems)
strbld = strbld .. "\n" .. table.concat(elems, "\n") strbld = strbld .. "\n" .. table.concat(elems, "\n")