fix reloading
This commit is contained in:
parent
b070595a2f
commit
12edf80f5b
12
init.lua
12
init.lua
|
@ -9,6 +9,7 @@ wizards_api.wizards = {}
|
|||
|
||||
|
||||
|
||||
local runtime = false
|
||||
|
||||
function wizards_api.load_wizards(path)
|
||||
local files = core.get_dir_list(path, false)
|
||||
|
@ -28,7 +29,7 @@ function wizards_api.load_wizards(path)
|
|||
filename = "wizards_api_"..conf.name..part..".png",
|
||||
filepath = path.."/"..conf.name..part..".png",
|
||||
ephemeral = false,
|
||||
})
|
||||
}, (runtime and function(name) end or nil))
|
||||
end
|
||||
|
||||
wizards_api.wizards[conf.name] = conf
|
||||
|
@ -37,11 +38,13 @@ function wizards_api.load_wizards(path)
|
|||
for i,dir in ipairs(dirs) do
|
||||
wizards_api.load_wizards(path.."/"..dir)
|
||||
end
|
||||
for i,player in ipairs(core.get_connected_players()) do
|
||||
wizards_api.reset_wizard(player:get_player_name())
|
||||
end
|
||||
end
|
||||
|
||||
function wizards_api.clear_and_load_wizards(path)
|
||||
-- TODO: Handle players using a wizard about to be cleared.
|
||||
-- Maybe a boolean to have in-use wizards not cleared?
|
||||
for name,conf in pairs(wizards_api.wizards) do
|
||||
wizards_api.wizards[name] = nil
|
||||
end
|
||||
|
@ -123,7 +126,7 @@ do
|
|||
end
|
||||
|
||||
|
||||
function wizards_api.reload_wizard(playername)
|
||||
function wizards_api.reset_wizard(playername)
|
||||
local player = core.get_player_by_name(playername)
|
||||
local meta = player:get_meta()
|
||||
local wizname = meta:get("wizards_api_wizard") or "wizard_green"
|
||||
|
@ -180,8 +183,9 @@ end
|
|||
|
||||
core.register_on_mods_loaded(function()
|
||||
wizards_api.load_wizards(wizpath)
|
||||
runtime = true
|
||||
end)
|
||||
|
||||
core.register_on_joinplayer(function(player)
|
||||
wizards_api.reload_wizard(player:get_player_name())
|
||||
wizards_api.reset_wizard(player:get_player_name())
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue