mirror of
https://github.com/minetest/minetest.git
synced 2024-11-26 17:43:45 +01:00
Add minetest.settings
to CSM API and allow CSMs to provide settingtypes.txt
(#12131)
Co-authored-by: sfan5 <sfan5@live.de> Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>
This commit is contained in:
parent
839600ed70
commit
6ec6acc539
@ -9,3 +9,4 @@ dofile(commonpath .. "mod_storage.lua")
|
||||
dofile(commonpath .. "chatcommands.lua")
|
||||
dofile(clientpath .. "chatcommands.lua")
|
||||
dofile(clientpath .. "death_formspec.lua")
|
||||
dofile(clientpath .. "misc.lua")
|
||||
|
7
builtin/client/misc.lua
Normal file
7
builtin/client/misc.lua
Normal file
@ -0,0 +1,7 @@
|
||||
function core.setting_get_pos(name)
|
||||
local value = core.settings:get(name)
|
||||
if not value then
|
||||
return nil
|
||||
end
|
||||
return core.string_to_pos(value)
|
||||
end
|
@ -405,6 +405,36 @@ local function parse_config_file(read_all, parse_mods)
|
||||
file:close()
|
||||
end
|
||||
end
|
||||
|
||||
-- Parse client mods
|
||||
local clientmods_category_initialized = false
|
||||
local clientmods = {}
|
||||
get_mods(core.get_clientmodpath(), "clientmods", clientmods)
|
||||
for _, mod in ipairs(clientmods) do
|
||||
local path = mod.path .. DIR_DELIM .. FILENAME
|
||||
local file = io.open(path, "r")
|
||||
if file then
|
||||
if not clientmods_category_initialized then
|
||||
fgettext_ne("Client Mods") -- not used, but needed for xgettext
|
||||
table.insert(settings, {
|
||||
name = "Client Mods",
|
||||
level = 0,
|
||||
type = "category",
|
||||
})
|
||||
clientmods_category_initialized = true
|
||||
end
|
||||
|
||||
table.insert(settings, {
|
||||
name = mod.name,
|
||||
level = 1,
|
||||
type = "category",
|
||||
})
|
||||
|
||||
parse_single_file(file, path, read_all, settings, 2, false)
|
||||
|
||||
file:close()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return settings
|
||||
|
@ -165,6 +165,9 @@ core.after(5, function()
|
||||
|
||||
print("[PREVIEW] Find node near: " .. dump(core.find_node_near({x=0, y=20, z=0}, 10,
|
||||
{"group:tree", "default:dirt", "default:stone"})))
|
||||
|
||||
print("[PREVIEW] Settings: preview_csm_test_setting = " ..
|
||||
tostring(core.settings:get_bool("preview_csm_test_setting", false)))
|
||||
end)
|
||||
|
||||
core.register_on_dignode(function(pos, node)
|
||||
|
1
clientmods/preview/settingtypes.txt
Normal file
1
clientmods/preview/settingtypes.txt
Normal file
@ -0,0 +1 @@
|
||||
preview_csm_test_setting (Test CSM setting) bool false
|
@ -938,6 +938,14 @@ Call these functions only at load time!
|
||||
* `minetest.display_chat_message(message)` returns true on success
|
||||
* Shows a chat message to the current player.
|
||||
|
||||
Setting-related
|
||||
---------------
|
||||
|
||||
* `minetest.settings`: Settings object containing all of the settings from the
|
||||
main config file (`minetest.conf`). Check lua_api.txt for class reference.
|
||||
* `minetest.setting_get_pos(name)`: Loads a setting from the main settings and
|
||||
parses it as a position (in the format `(1,2,3)`). Returns a position or nil.
|
||||
|
||||
Class reference
|
||||
---------------
|
||||
|
||||
|
@ -417,6 +417,12 @@ void ScriptApiSecurity::setLuaEnv(lua_State *L, int thread)
|
||||
|
||||
bool ScriptApiSecurity::isSecure(lua_State *L)
|
||||
{
|
||||
#ifndef SERVER
|
||||
auto script = ModApiBase::getScriptApiBase(L);
|
||||
// CSM keeps no globals backup but is always secure
|
||||
if (script->getType() == ScriptingType::Client)
|
||||
return true;
|
||||
#endif
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_GLOBALS_BACKUP);
|
||||
bool secure = !lua_isnil(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
@ -659,6 +659,9 @@ void ModApiUtil::InitializeClient(lua_State *L, int top)
|
||||
API_FCT(sha1);
|
||||
API_FCT(colorspec_to_colorstring);
|
||||
API_FCT(colorspec_to_bytes);
|
||||
|
||||
LuaSettings::create(L, g_settings, g_settings_path);
|
||||
lua_setfield(L, top, "settings");
|
||||
}
|
||||
|
||||
void ModApiUtil::InitializeAsync(lua_State *L, int top)
|
||||
|
@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "lua_api/l_nodemeta.h"
|
||||
#include "lua_api/l_localplayer.h"
|
||||
#include "lua_api/l_camera.h"
|
||||
#include "lua_api/l_settings.h"
|
||||
|
||||
ClientScripting::ClientScripting(Client *client):
|
||||
ScriptApiBase(ScriptingType::Client)
|
||||
@ -73,6 +74,7 @@ void ClientScripting::InitializeModApi(lua_State *L, int top)
|
||||
LuaLocalPlayer::Register(L);
|
||||
LuaCamera::Register(L);
|
||||
ModChannelRef::Register(L);
|
||||
LuaSettings::Register(L);
|
||||
|
||||
ModApiUtil::InitializeClient(L, top);
|
||||
ModApiClient::Initialize(L, top);
|
||||
|
Loading…
Reference in New Issue
Block a user