Save a “default” theme, inherited from other mods
Most likely minetest_game’s `default` mod.
This commit is contained in:
parent
f336172dfb
commit
07c7618d3d
34
init.lua
34
init.lua
|
@ -19,6 +19,7 @@ fs_themes.themes = {}
|
|||
local storage = minetest.get_mod_storage()
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
|
||||
-- Set a player’s theme by a registered theme’s name.
|
||||
-- If dont_save is provided, the player’s default theme won’t change.
|
||||
function fs_themes.set_theme(player, theme_name, dont_save)
|
||||
|
@ -34,16 +35,9 @@ function fs_themes.set_theme(player, theme_name, dont_save)
|
|||
end
|
||||
|
||||
|
||||
-- Register a theme, given a name and a formspec-file’s path.
|
||||
function fs_themes.register_theme(name, formspecs_file_path)
|
||||
local fs_file, open_err = io.open(formspecs_file_path, "r")
|
||||
if fs_file == nil then
|
||||
minetest.log("warning", string.format("Theme “%s” could not be opened: %s", name, open_err))
|
||||
return false
|
||||
end
|
||||
|
||||
local fs_file_contents = fs_file:read("*all")
|
||||
fs_themes.themes[name] = fs_file_contents
|
||||
-- Register a theme, given a name and a formspec string.
|
||||
function fs_themes.register_theme(name, formspec_str)
|
||||
fs_themes.themes[name] = formspec_str
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -61,11 +55,9 @@ minetest.register_chatcommand(
|
|||
ret = ret .. ", " .. name
|
||||
end
|
||||
end
|
||||
|
||||
if ret == nil then
|
||||
ret = "No themes are installed!"
|
||||
end
|
||||
|
||||
return true, ret
|
||||
end
|
||||
}
|
||||
|
@ -94,9 +86,14 @@ minetest.register_chatcommand(
|
|||
minetest.register_on_joinplayer(
|
||||
function(player)
|
||||
local player_name = player:get_player_name()
|
||||
local default_theme = minetest.settings:get("fs_default_theme") or "restaurant"
|
||||
local default_theme = minetest.settings:get("fs_default_theme")
|
||||
local player_theme = storage:get_string(player_name)
|
||||
|
||||
-- Set the “default” theme (inherited from whatever mods load before fs_themes)
|
||||
if not fs_themes.themes["default"] then
|
||||
fs_themes.themes["default"] = player:get_formspec_prepend()
|
||||
end
|
||||
|
||||
-- If a player has a preferred theme we cannot use, complain & use default.
|
||||
if player_theme ~= "" and not fs_themes.set_theme(player, player_theme) then
|
||||
minetest.chat_send_player(
|
||||
|
@ -106,7 +103,7 @@ minetest.register_on_joinplayer(
|
|||
storage:set_string(player_name, "")
|
||||
end
|
||||
|
||||
if player_theme == "" then
|
||||
if player_theme == "" and default_theme and default_theme ~= "" then
|
||||
fs_themes.set_theme(player, default_theme)
|
||||
end
|
||||
end
|
||||
|
@ -117,5 +114,12 @@ minetest.register_on_joinplayer(
|
|||
local theme_dir_path = modpath .. "/themes/"
|
||||
local theme_file_paths = minetest.get_dir_list(theme_dir_path, false)
|
||||
for _, file_name in pairs(theme_file_paths) do
|
||||
fs_themes.register_theme(file_name, theme_dir_path .. file_name)
|
||||
local fs_file, open_err = io.open(theme_dir_path .. file_name, "r")
|
||||
if fs_file == nil then
|
||||
minetest.log("warning", string.format("Theme “%s” could not be opened: %s", name, open_err))
|
||||
return false
|
||||
end
|
||||
|
||||
local fs_file_contents = fs_file:read("*all")
|
||||
fs_themes.register_theme(file_name, fs_file_contents)
|
||||
end
|
||||
|
|
|
@ -1 +1 @@
|
|||
fs_default_theme (Default theme for Formspecs) string restaurant
|
||||
fs_default_theme (Default theme for Formspecs) string
|
||||
|
|
Ŝarĝante…
Reference in New Issue