1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

Migrate existing keycode-based keybindings (#16049)

Co-authored-by: grorp <gregor.parzefall@posteo.de>
Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
y5nw 2025-05-14 22:15:15 +02:00 committed by GitHub
parent 600763dffc
commit 57c1ab905c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 140 additions and 13 deletions

View file

@ -777,10 +777,13 @@ static bool read_config_file(const Settings &cmd_args)
}
// If no path found, use the first one (menu creates the file)
if (g_settings_path.empty())
if (g_settings_path.empty()) {
g_settings_path = filenames[0];
g_first_run = true;
}
}
infostream << "Global configuration file: " << g_settings_path << std::endl;
infostream << "Global configuration file: " << g_settings_path
<< (g_first_run ? " (first run)" : "") << std::endl;
return true;
}

View file

@ -1089,6 +1089,9 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(open_dir);
API_FCT(share_file);
API_FCT(do_async_callback);
lua_pushboolean(L, g_first_run);
lua_setfield(L, top, "is_first_run");
}
/******************************************************************************/

View file

@ -35,11 +35,10 @@ int ModApiMenuCommon::l_irrlicht_device_supports_touch(lua_State *L)
}
int ModApiMenuCommon::l_are_keycodes_equal(lua_State *L)
int ModApiMenuCommon::l_normalize_keycode(lua_State *L)
{
auto k1 = luaL_checkstring(L, 1);
auto k2 = luaL_checkstring(L, 2);
lua_pushboolean(L, KeyPress(k1) == KeyPress(k2));
auto keystr = luaL_checkstring(L, 1);
lua_pushstring(L, KeyPress(keystr).sym().c_str());
return 1;
}
@ -49,7 +48,7 @@ void ModApiMenuCommon::Initialize(lua_State *L, int top)
API_FCT(gettext);
API_FCT(get_active_driver);
API_FCT(irrlicht_device_supports_touch);
API_FCT(are_keycodes_equal);
API_FCT(normalize_keycode);
}

View file

@ -13,7 +13,7 @@ private:
static int l_gettext(lua_State *L);
static int l_get_active_driver(lua_State *L);
static int l_irrlicht_device_supports_touch(lua_State *L);
static int l_are_keycodes_equal(lua_State *L);
static int l_normalize_keycode(lua_State *L);
public:
static void Initialize(lua_State *L, int top);

View file

@ -22,6 +22,7 @@
Settings *g_settings = nullptr;
static SettingsHierarchy g_hierarchy;
std::string g_settings_path;
bool g_first_run = false;
std::unordered_map<std::string, const FlagDesc *> Settings::s_flags;

View file

@ -18,6 +18,8 @@ struct NoiseParams;
// Global objects
extern Settings *g_settings; // Same as Settings::getLayer(SL_GLOBAL);
extern std::string g_settings_path;
/// Is set to true if the engine runs for the first time
extern bool g_first_run;
// Type for a settings changed callback function
typedef void (*SettingsChangedCallback)(const std::string &name, void *data);