mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 06:21:50 +00:00
remove settings-related functions from core
This commit is contained in:
parent
5260062181
commit
a6301c8837
14 changed files with 119 additions and 120 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
function on_open()
|
function on_open()
|
||||||
document.langs_btn.text = string.format(
|
document.langs_btn.text = string.format(
|
||||||
"%s: %s", gui.str("Language", "settings"),
|
"%s: %s", gui.str("Language", "settings"),
|
||||||
gui.get_locales_info()[core.get_setting("ui.language")].name
|
gui.get_locales_info()[app.get_setting("ui.language")].name
|
||||||
)
|
)
|
||||||
sections = RadioGroup({
|
sections = RadioGroup({
|
||||||
audio=document.s_aud,
|
audio=document.s_aud,
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,25 @@
|
||||||
function create_setting(id, name, step, postfix)
|
function create_setting(id, name, step, postfix)
|
||||||
local info = core.get_setting_info(id)
|
local info = app.get_setting_info(id)
|
||||||
postfix = postfix or ""
|
postfix = postfix or ""
|
||||||
document.root:add(gui.template("track_setting", {
|
document.root:add(gui.template("track_setting", {
|
||||||
id=id,
|
id=id,
|
||||||
name=gui.str(name, "settings"),
|
name=gui.str(name, "settings"),
|
||||||
value=core.get_setting(id),
|
value=app.get_setting(id),
|
||||||
min=info.min,
|
min=info.min,
|
||||||
max=info.max,
|
max=info.max,
|
||||||
step=step,
|
step=step,
|
||||||
postfix=postfix
|
postfix=postfix
|
||||||
}))
|
}))
|
||||||
update_setting(core.get_setting(id), id, name, postfix)
|
update_setting(app.get_setting(id), id, name, postfix)
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_setting(x, id, name, postfix)
|
function update_setting(x, id, name, postfix)
|
||||||
core.set_setting(id, x)
|
app.set_setting(id, x)
|
||||||
-- updating label
|
-- updating label
|
||||||
document[id..".L"].text = string.format(
|
document[id..".L"].text = string.format(
|
||||||
"%s: %s%s",
|
"%s: %s%s",
|
||||||
gui.str(name, "settings"),
|
gui.str(name, "settings"),
|
||||||
core.str_setting(id),
|
app.str_setting(id),
|
||||||
postfix
|
postfix
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -54,7 +54,7 @@ function on_open()
|
||||||
create_setting("audio.volume-music", "Music", 0.01)
|
create_setting("audio.volume-music", "Music", 0.01)
|
||||||
document.root:add("<label context='settings'>@Microphone</label>")
|
document.root:add("<label context='settings'>@Microphone</label>")
|
||||||
document.root:add("<select id='input_device_select' "..
|
document.root:add("<select id='input_device_select' "..
|
||||||
"onselect='function(opt) core.set_setting(\"audio.input-device\", opt) end'/>")
|
"onselect='function(opt) app.set_setting(\"audio.input-device\", opt) end'/>")
|
||||||
document.root:add("<container id='input_volume_outer' color='#000000' size='4'>"
|
document.root:add("<container id='input_volume_outer' color='#000000' size='4'>"
|
||||||
.."<container id='input_volume_inner' color='#00FF00FF' pos='1' size='2'/>"
|
.."<container id='input_volume_inner' color='#00FF00FF' pos='1' size='2'/>"
|
||||||
.."</container>")
|
.."</container>")
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,12 @@ function refresh_sensitivity()
|
||||||
document.sensitivity_label.text = string.format(
|
document.sensitivity_label.text = string.format(
|
||||||
"%s: %s",
|
"%s: %s",
|
||||||
gui.str("Mouse Sensitivity", "settings"),
|
gui.str("Mouse Sensitivity", "settings"),
|
||||||
core.str_setting("camera.sensitivity")
|
app.str_setting("camera.sensitivity")
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function change_sensitivity(val)
|
function change_sensitivity(val)
|
||||||
core.set_setting("camera.sensitivity", val)
|
app.set_setting("camera.sensitivity", val)
|
||||||
refresh_sensitivity()
|
refresh_sensitivity()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -93,7 +93,7 @@ function refresh_binding_marks()
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_open()
|
function on_open()
|
||||||
document.sensitivity_track.value = core.get_setting("camera.sensitivity")
|
document.sensitivity_track.value = app.get_setting("camera.sensitivity")
|
||||||
refresh_sensitivity()
|
refresh_sensitivity()
|
||||||
|
|
||||||
local panel = document.bindings_panel
|
local panel = document.bindings_panel
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,14 @@ tostring_overrides["display.framerate"] = function(x)
|
||||||
end
|
end
|
||||||
|
|
||||||
function create_setting(id, name, step, postfix, tooltip, changeonrelease)
|
function create_setting(id, name, step, postfix, tooltip, changeonrelease)
|
||||||
local info = core.get_setting_info(id)
|
local info = app.get_setting_info(id)
|
||||||
postfix = postfix or ""
|
postfix = postfix or ""
|
||||||
tooltip = tooltip or ""
|
tooltip = tooltip or ""
|
||||||
changeonrelease = changeonrelease or ""
|
changeonrelease = changeonrelease or ""
|
||||||
document.root:add(gui.template("track_setting", {
|
document.root:add(gui.template("track_setting", {
|
||||||
id=id,
|
id=id,
|
||||||
name=gui.str(name, "settings"),
|
name=gui.str(name, "settings"),
|
||||||
value=core.get_setting(id),
|
value=app.get_setting(id),
|
||||||
min=info.min,
|
min=info.min,
|
||||||
max=info.max,
|
max=info.max,
|
||||||
step=step,
|
step=step,
|
||||||
|
|
@ -25,7 +25,7 @@ function create_setting(id, name, step, postfix, tooltip, changeonrelease)
|
||||||
tooltip=tooltip,
|
tooltip=tooltip,
|
||||||
changeonrelease=changeonrelease
|
changeonrelease=changeonrelease
|
||||||
}))
|
}))
|
||||||
update_setting(core.get_setting(id), id, name, postfix)
|
update_setting(app.get_setting(id), id, name, postfix)
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_setting(x, id, name, postfix)
|
function update_setting(x, id, name, postfix)
|
||||||
|
|
@ -34,13 +34,13 @@ function update_setting(x, id, name, postfix)
|
||||||
if func then
|
if func then
|
||||||
str = func(x)
|
str = func(x)
|
||||||
else
|
else
|
||||||
str = core.str_setting(id)
|
str = app.str_setting(id)
|
||||||
end
|
end
|
||||||
-- updating label
|
-- updating label
|
||||||
document[id..".L"].text = string.format(
|
document[id..".L"].text = string.format(
|
||||||
"%s: %s%s",
|
"%s: %s%s",
|
||||||
gui.str(name, "settings"),
|
gui.str(name, "settings"),
|
||||||
str,
|
str,
|
||||||
postfix
|
postfix
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -48,8 +48,8 @@ end
|
||||||
function create_checkbox(id, name, tooltip)
|
function create_checkbox(id, name, tooltip)
|
||||||
tooltip = tooltip or ''
|
tooltip = tooltip or ''
|
||||||
document.root:add(string.format(
|
document.root:add(string.format(
|
||||||
"<checkbox consumer='function(x) core.set_setting(\"%s\", x) end' checked='%s' tooltip='%s'>%s</checkbox>",
|
"<checkbox consumer='function(x) app.set_setting(\"%s\", x) end' checked='%s' tooltip='%s'>%s</checkbox>",
|
||||||
id, core.str_setting(id), gui.str(tooltip, "settings"), gui.str(name, "settings")
|
id, app.str_setting(id), gui.str(tooltip, "settings"), gui.str(name, "settings")
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -59,11 +59,11 @@ function on_open()
|
||||||
create_setting("display.framerate", "Framerate", 1, "", "", true)
|
create_setting("display.framerate", "Framerate", 1, "", "", true)
|
||||||
|
|
||||||
document.root:add(string.format(
|
document.root:add(string.format(
|
||||||
"<select context='settings' onselect='function(opt) core.set_setting(\"display.window-mode\", tonumber(opt)) end' selected='%s'>"..
|
"<select context='settings' onselect='function(opt) app.set_setting(\"display.window-mode\", tonumber(opt)) end' selected='%s'>"..
|
||||||
"<option value='0'>@Windowed</option>"..
|
"<option value='0'>@Windowed</option>"..
|
||||||
"<option value='1'>@Fullscreen</option>"..
|
"<option value='1'>@Fullscreen</option>"..
|
||||||
"<option value='2'>@Borderless</option>"..
|
"<option value='2'>@Borderless</option>"..
|
||||||
"</select>", core.get_setting("display.window-mode"))
|
"</select>", app.get_setting("display.window-mode"))
|
||||||
)
|
)
|
||||||
|
|
||||||
create_checkbox("camera.shaking", "Camera Shaking")
|
create_checkbox("camera.shaking", "Camera Shaking")
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
function create_setting(id, name, step, postfix, tooltip, changeonrelease)
|
function create_setting(id, name, step, postfix, tooltip, changeonrelease)
|
||||||
local info = core.get_setting_info(id)
|
local info = app.get_setting_info(id)
|
||||||
postfix = postfix or ""
|
postfix = postfix or ""
|
||||||
tooltip = tooltip or ""
|
tooltip = tooltip or ""
|
||||||
changeonrelease = changeonrelease or ""
|
changeonrelease = changeonrelease or ""
|
||||||
document.root:add(gui.template("track_setting", {
|
document.root:add(gui.template("track_setting", {
|
||||||
id=id,
|
id=id,
|
||||||
name=gui.str(name, "settings"),
|
name=gui.str(name, "settings"),
|
||||||
value=core.get_setting(id),
|
value=app.get_setting(id),
|
||||||
min=info.min,
|
min=info.min,
|
||||||
max=info.max,
|
max=info.max,
|
||||||
step=step,
|
step=step,
|
||||||
|
|
@ -14,15 +14,15 @@ function create_setting(id, name, step, postfix, tooltip, changeonrelease)
|
||||||
tooltip=tooltip,
|
tooltip=tooltip,
|
||||||
changeonrelease=changeonrelease
|
changeonrelease=changeonrelease
|
||||||
}))
|
}))
|
||||||
update_setting(core.get_setting(id), id, name, postfix)
|
update_setting(app.get_setting(id), id, name, postfix)
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_setting(x, id, name, postfix)
|
function update_setting(x, id, name, postfix)
|
||||||
-- updating label
|
-- updating label
|
||||||
document[id..".L"].text = string.format(
|
document[id..".L"].text = string.format(
|
||||||
"%s: %s%s",
|
"%s: %s%s",
|
||||||
gui.str(name, "settings"),
|
gui.str(name, "settings"),
|
||||||
core.str_setting(id),
|
app.str_setting(id),
|
||||||
postfix
|
postfix
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -30,8 +30,8 @@ end
|
||||||
function create_checkbox(id, name, tooltip)
|
function create_checkbox(id, name, tooltip)
|
||||||
tooltip = tooltip or ''
|
tooltip = tooltip or ''
|
||||||
document.root:add(string.format(
|
document.root:add(string.format(
|
||||||
"<checkbox consumer='function(x) core.set_setting(\"%s\", x) end' checked='%s' tooltip='%s'>%s</checkbox>",
|
"<checkbox consumer='function(x) app.set_setting(\"%s\", x) end' checked='%s' tooltip='%s'>%s</checkbox>",
|
||||||
id, core.str_setting(id), gui.str(tooltip, "settings"), gui.str(name, "settings")
|
id, app.str_setting(id), gui.str(tooltip, "settings"), gui.str(name, "settings")
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ function reset(category)
|
||||||
end
|
end
|
||||||
|
|
||||||
function reset_setting(name)
|
function reset_setting(name)
|
||||||
core.set_setting(name, core.get_setting_info(name).def)
|
app.set_setting(name, app.get_setting_info(name).def)
|
||||||
end
|
end
|
||||||
|
|
||||||
function reset_audio()
|
function reset_audio()
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
function on_open()
|
function on_open()
|
||||||
local worlds = world.get_list()
|
local worlds = world.get_list()
|
||||||
for _, info in ipairs(worlds) do
|
for _, info in ipairs(worlds) do
|
||||||
local major, minor = core.get_version()
|
local major, minor = app.get_version()
|
||||||
if info.version[1] > major or info.version[2] > minor then
|
if info.version[1] > major or info.version[2] > minor then
|
||||||
info.versionColor = "#A02010"
|
info.versionColor = "#A02010"
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<button
|
<button
|
||||||
onclick='core.set_setting("ui.language", "%{id}") menu:back()'>
|
onclick='app.set_setting("ui.language", "%{id}") menu:back()'>
|
||||||
%{name}
|
%{name}
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,6 @@
|
||||||
<label id='%{id}.L' margin='0,3,0,0'>%{name}: %{value}%{postfix}</label>
|
<label id='%{id}.L' margin='0,3,0,0'>%{name}: %{value}%{postfix}</label>
|
||||||
<trackbar
|
<trackbar
|
||||||
value='%{value}' min='%{min}' max='%{max}' step='%{step}' tooltip='%{tooltip}'
|
value='%{value}' min='%{min}' max='%{max}' step='%{step}' tooltip='%{tooltip}'
|
||||||
consumer='function(x) core.set_setting("%{id}", x) end' change-on-release='%{changeonrelease}'
|
consumer='function(x) app.set_setting("%{id}", x) end' change-on-release='%{changeonrelease}'
|
||||||
sub-consumer='function(x) update_setting(x, "%{id}", "%{name}", "%{postfix}") end'/>
|
sub-consumer='function(x) update_setting(x, "%{id}", "%{name}", "%{postfix}") end'/>
|
||||||
</panel>
|
</panel>
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ local function configure_SSAO()
|
||||||
end
|
end
|
||||||
events.on("core:setting.graphics.ssao.set", update_ssao_quality)
|
events.on("core:setting.graphics.ssao.set", update_ssao_quality)
|
||||||
|
|
||||||
update_ssao_quality(core.get_setting("graphics.ssao"))
|
update_ssao_quality(__vc_app.get_setting("graphics.ssao"))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update_hand()
|
local function update_hand()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
local enable_experimental = core.get_setting("debug.enable-experimental")
|
local enable_experimental = __vc_app.get_setting("debug.enable-experimental")
|
||||||
|
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
------ Extended kit of standard functions ------
|
------ Extended kit of standard functions ------
|
||||||
|
|
@ -24,12 +24,6 @@ function tb_frame_tostring(frame)
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
local core_set_setting = core.set_setting
|
|
||||||
function core.set_setting(name, value, ...)
|
|
||||||
core_set_setting(name, value, ...)
|
|
||||||
events.emit("core:setting."..name..".set", value)
|
|
||||||
end
|
|
||||||
|
|
||||||
local __vc__app_script_coroutine
|
local __vc__app_script_coroutine
|
||||||
|
|
||||||
local function complete_app_lib(app)
|
local function complete_app_lib(app)
|
||||||
|
|
@ -37,6 +31,7 @@ local function complete_app_lib(app)
|
||||||
local __core_reset_content = core.reset_content
|
local __core_reset_content = core.reset_content
|
||||||
local __core_reconfig_packs = core.reconfig_packs
|
local __core_reconfig_packs = core.reconfig_packs
|
||||||
local __app_tick = coroutine.yield
|
local __app_tick = coroutine.yield
|
||||||
|
local __app_set_setting = app.set_setting
|
||||||
core.load_content = nil
|
core.load_content = nil
|
||||||
core.reset_content = nil
|
core.reset_content = nil
|
||||||
|
|
||||||
|
|
@ -48,10 +43,12 @@ local function complete_app_lib(app)
|
||||||
app.close_world = core.close_world
|
app.close_world = core.close_world
|
||||||
app.reopen_world = core.reopen_world
|
app.reopen_world = core.reopen_world
|
||||||
app.delete_world = core.delete_world
|
app.delete_world = core.delete_world
|
||||||
app.get_setting = core.get_setting
|
|
||||||
app.set_setting = core.set_setting
|
app.set_setting = function(name, value, ...)
|
||||||
|
__app_set_setting(name, value, ...)
|
||||||
|
events.emit("core:setting."..name..".set", value)
|
||||||
|
end
|
||||||
app.tick = __app_tick
|
app.tick = __app_tick
|
||||||
app.get_setting_info = core.get_setting_info
|
|
||||||
|
|
||||||
local function call_in_app_script_co(func, ...)
|
local function call_in_app_script_co(func, ...)
|
||||||
if coroutine.running() ~= __vc__app_script_coroutine then
|
if coroutine.running() ~= __vc__app_script_coroutine then
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "api_lua.hpp"
|
#include "api_lua.hpp"
|
||||||
|
|
||||||
#include "io/io.hpp"
|
#include "io/io.hpp"
|
||||||
|
#include "io/settings_io.hpp"
|
||||||
#include "io/devices/MemoryDevice.hpp"
|
#include "io/devices/MemoryDevice.hpp"
|
||||||
#include "logic/scripting/scripting.hpp"
|
#include "logic/scripting/scripting.hpp"
|
||||||
#include "content/ContentControl.hpp"
|
#include "content/ContentControl.hpp"
|
||||||
|
|
@ -113,6 +114,73 @@ static int l_set_title(lua::State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Get a setting value
|
||||||
|
/// @param name The name of the setting
|
||||||
|
/// @return The value of the setting
|
||||||
|
static int l_get_setting(lua::State* L) {
|
||||||
|
auto name = lua::require_string(L, 1);
|
||||||
|
const auto value = engine->getSettingsHandler().getValue(name);
|
||||||
|
return lua::pushvalue(L, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Set a setting value
|
||||||
|
/// @param name The name of the setting
|
||||||
|
/// @param value The new value for the setting
|
||||||
|
static int l_set_setting(lua::State* L) {
|
||||||
|
auto name = lua::require_string(L, 1);
|
||||||
|
const auto value = lua::tovalue(L, 2);
|
||||||
|
engine->getSettingsHandler().setValue(name, value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Convert a setting value to a string
|
||||||
|
/// @param name The name of the setting
|
||||||
|
/// @return The string representation of the setting value
|
||||||
|
static int l_str_setting(lua::State* L) {
|
||||||
|
auto name = lua::require_string(L, 1);
|
||||||
|
const auto string = engine->getSettingsHandler().toString(name);
|
||||||
|
return lua::pushstring(L, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Get information about a setting
|
||||||
|
/// @param name The name of the setting
|
||||||
|
/// @return A table with information about the setting
|
||||||
|
static int l_get_setting_info(lua::State* L) {
|
||||||
|
auto name = lua::require_string(L, 1);
|
||||||
|
auto setting = engine->getSettingsHandler().getSetting(name);
|
||||||
|
lua::createtable(L, 0, 1);
|
||||||
|
if (auto number = dynamic_cast<NumberSetting*>(setting)) {
|
||||||
|
lua::pushnumber(L, number->getMin());
|
||||||
|
lua::setfield(L, "min");
|
||||||
|
lua::pushnumber(L, number->getMax());
|
||||||
|
lua::setfield(L, "max");
|
||||||
|
lua::pushnumber(L, number->getDefault());
|
||||||
|
lua::setfield(L, "def");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (auto integer = dynamic_cast<IntegerSetting*>(setting)) {
|
||||||
|
lua::pushinteger(L, integer->getMin());
|
||||||
|
lua::setfield(L, "min");
|
||||||
|
lua::pushinteger(L, integer->getMax());
|
||||||
|
lua::setfield(L, "max");
|
||||||
|
lua::pushinteger(L, integer->getDefault());
|
||||||
|
lua::setfield(L, "def");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (auto boolean = dynamic_cast<FlagSetting*>(setting)) {
|
||||||
|
lua::pushboolean(L, boolean->getDefault());
|
||||||
|
lua::setfield(L, "def");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (auto string = dynamic_cast<StringSetting*>(setting)) {
|
||||||
|
lua::pushstring(L, string->getDefault());
|
||||||
|
lua::setfield(L, "def");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
lua::pop(L);
|
||||||
|
throw std::runtime_error("unsupported setting type");
|
||||||
|
}
|
||||||
|
|
||||||
static int l_open_folder(lua::State* L) {
|
static int l_open_folder(lua::State* L) {
|
||||||
platform::open_folder(io::resolve(lua::require_string(L, 1)));
|
platform::open_folder(io::resolve(lua::require_string(L, 1)));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -147,6 +215,10 @@ const luaL_Reg applib[] = {
|
||||||
{"set_title", lua::wrap<l_set_title>},
|
{"set_title", lua::wrap<l_set_title>},
|
||||||
{"open_folder", lua::wrap<l_open_folder>},
|
{"open_folder", lua::wrap<l_open_folder>},
|
||||||
{"open_url", lua::wrap<l_open_url>},
|
{"open_url", lua::wrap<l_open_url>},
|
||||||
|
{"get_setting", lua::wrap<l_get_setting>},
|
||||||
|
{"set_setting", lua::wrap<l_set_setting>},
|
||||||
|
{"str_setting", lua::wrap<l_str_setting>},
|
||||||
|
{"get_setting_info", lua::wrap<l_get_setting_info>},
|
||||||
// for other functions see libcore.cpp and stdlib.lua
|
// for other functions see libcore.cpp and stdlib.lua
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "api_lua.hpp"
|
#include "api_lua.hpp"
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "assets/Assets.hpp"
|
#include "assets/Assets.hpp"
|
||||||
|
|
@ -10,7 +6,6 @@
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "engine/EnginePaths.hpp"
|
#include "engine/EnginePaths.hpp"
|
||||||
#include "io/io.hpp"
|
#include "io/io.hpp"
|
||||||
#include "io/settings_io.hpp"
|
|
||||||
#include "frontend/menu.hpp"
|
#include "frontend/menu.hpp"
|
||||||
#include "frontend/screens/MenuScreen.hpp"
|
#include "frontend/screens/MenuScreen.hpp"
|
||||||
#include "graphics/core/Texture.hpp"
|
#include "graphics/core/Texture.hpp"
|
||||||
|
|
@ -22,6 +17,10 @@
|
||||||
#include "world/generator/WorldGenerator.hpp"
|
#include "world/generator/WorldGenerator.hpp"
|
||||||
#include "window/Window.hpp"
|
#include "window/Window.hpp"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using namespace scripting;
|
using namespace scripting;
|
||||||
|
|
||||||
static int l_load_content(lua::State* L) {
|
static int l_load_content(lua::State* L) {
|
||||||
|
|
@ -162,73 +161,6 @@ static int l_reconfig_packs(lua::State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Get a setting value
|
|
||||||
/// @param name The name of the setting
|
|
||||||
/// @return The value of the setting
|
|
||||||
static int l_get_setting(lua::State* L) {
|
|
||||||
auto name = lua::require_string(L, 1);
|
|
||||||
const auto value = engine->getSettingsHandler().getValue(name);
|
|
||||||
return lua::pushvalue(L, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief Set a setting value
|
|
||||||
/// @param name The name of the setting
|
|
||||||
/// @param value The new value for the setting
|
|
||||||
static int l_set_setting(lua::State* L) {
|
|
||||||
auto name = lua::require_string(L, 1);
|
|
||||||
const auto value = lua::tovalue(L, 2);
|
|
||||||
engine->getSettingsHandler().setValue(name, value);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief Convert a setting value to a string
|
|
||||||
/// @param name The name of the setting
|
|
||||||
/// @return The string representation of the setting value
|
|
||||||
static int l_str_setting(lua::State* L) {
|
|
||||||
auto name = lua::require_string(L, 1);
|
|
||||||
const auto string = engine->getSettingsHandler().toString(name);
|
|
||||||
return lua::pushstring(L, string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief Get information about a setting
|
|
||||||
/// @param name The name of the setting
|
|
||||||
/// @return A table with information about the setting
|
|
||||||
static int l_get_setting_info(lua::State* L) {
|
|
||||||
auto name = lua::require_string(L, 1);
|
|
||||||
auto setting = engine->getSettingsHandler().getSetting(name);
|
|
||||||
lua::createtable(L, 0, 1);
|
|
||||||
if (auto number = dynamic_cast<NumberSetting*>(setting)) {
|
|
||||||
lua::pushnumber(L, number->getMin());
|
|
||||||
lua::setfield(L, "min");
|
|
||||||
lua::pushnumber(L, number->getMax());
|
|
||||||
lua::setfield(L, "max");
|
|
||||||
lua::pushnumber(L, number->getDefault());
|
|
||||||
lua::setfield(L, "def");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (auto integer = dynamic_cast<IntegerSetting*>(setting)) {
|
|
||||||
lua::pushinteger(L, integer->getMin());
|
|
||||||
lua::setfield(L, "min");
|
|
||||||
lua::pushinteger(L, integer->getMax());
|
|
||||||
lua::setfield(L, "max");
|
|
||||||
lua::pushinteger(L, integer->getDefault());
|
|
||||||
lua::setfield(L, "def");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (auto boolean = dynamic_cast<FlagSetting*>(setting)) {
|
|
||||||
lua::pushboolean(L, boolean->getDefault());
|
|
||||||
lua::setfield(L, "def");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (auto string = dynamic_cast<StringSetting*>(setting)) {
|
|
||||||
lua::pushstring(L, string->getDefault());
|
|
||||||
lua::setfield(L, "def");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
lua::pop(L);
|
|
||||||
throw std::runtime_error("unsupported setting type");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief Quit the game
|
/// @brief Quit the game
|
||||||
static int l_quit(lua::State*) {
|
static int l_quit(lua::State*) {
|
||||||
engine->quit();
|
engine->quit();
|
||||||
|
|
@ -278,10 +210,6 @@ const luaL_Reg corelib[] = {
|
||||||
{"close_world", lua::wrap<l_close_world>},
|
{"close_world", lua::wrap<l_close_world>},
|
||||||
{"delete_world", lua::wrap<l_delete_world>},
|
{"delete_world", lua::wrap<l_delete_world>},
|
||||||
{"reconfig_packs", lua::wrap<l_reconfig_packs>},
|
{"reconfig_packs", lua::wrap<l_reconfig_packs>},
|
||||||
{"get_setting", lua::wrap<l_get_setting>},
|
|
||||||
{"set_setting", lua::wrap<l_set_setting>},
|
|
||||||
{"str_setting", lua::wrap<l_str_setting>},
|
|
||||||
{"get_setting_info", lua::wrap<l_get_setting_info>},
|
|
||||||
{"quit", lua::wrap<l_quit>},
|
{"quit", lua::wrap<l_quit>},
|
||||||
{"capture_output", lua::wrap<l_capture_output>},
|
{"capture_output", lua::wrap<l_capture_output>},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,8 @@ static void create_libs(State* L, StateType stateType) {
|
||||||
|
|
||||||
if (stateType == StateType::SCRIPT) {
|
if (stateType == StateType::SCRIPT) {
|
||||||
openlib(L, "app", applib);
|
openlib(L, "app", applib);
|
||||||
|
lua::getglobal(L, "app");
|
||||||
|
lua::setglobal(L, "__vc_app");
|
||||||
} else if (stateType == StateType::BASE) {
|
} else if (stateType == StateType::BASE) {
|
||||||
openlib(L, "__vc_app", applib);
|
openlib(L, "__vc_app", applib);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue