Merge branch 'develop'
This commit is contained in:
commit
4c638a198a
@ -61,6 +61,31 @@ LUI.MenuBuilder.m_types_build["settings_menu"] = function(a1)
|
||||
})
|
||||
end
|
||||
|
||||
if (Engine.InFrontend()) then
|
||||
local dev = "@LUA_MENU_SWITCH_TO_DEVELOP"
|
||||
local main = "@LUA_MENU_SWITCH_TO_MAIN"
|
||||
|
||||
local text = nil
|
||||
local branch = updater.getcurrentbranch()
|
||||
|
||||
local oppositebranch = nil
|
||||
|
||||
if (branch == updater.develop) then
|
||||
text = main
|
||||
oppositebranch = updater.main
|
||||
else
|
||||
text = dev
|
||||
oppositebranch = updater.develop
|
||||
end
|
||||
|
||||
menu:AddButton(text, function()
|
||||
updater.setbranch(oppositebranch)
|
||||
LUI.tryupdating(false)
|
||||
end, nil, true, nil, {
|
||||
desc_text = Engine.Localize("@LUA_MENU_SWITCH_BRANCH_DESC")
|
||||
})
|
||||
end
|
||||
|
||||
createdivider(menu, "@LUA_MENU_DRAWING")
|
||||
|
||||
LUI.Options.CreateOptionButton(
|
||||
|
@ -65,6 +65,9 @@
|
||||
"LUA_MENU_MODE3": "Debug shader",
|
||||
"LUA_MENU_INTRO": "Intro movie",
|
||||
"LUA_MENU_INTRO_DESC": "Show or skip intro movie with companies' logos on startup.",
|
||||
"LUA_MENU_SWITCH_TO_DEVELOP": "Switch to the ^3Develop^7 branch",
|
||||
"LUA_MENU_SWITCH_TO_MAIN": "Switch to the ^3Main^7 branch",
|
||||
"LUA_MENU_SWITCH_BRANCH_DESC": "Switch the h2-mod branch (develop: latest changes, main: latest stable release).",
|
||||
|
||||
"MENU_MUSIC_VOLUME": "Music Volume",
|
||||
"MENU_MUSIC_VOLUME_DESC": "Move the slider to adjust the volume of the music.",
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "config.hpp"
|
||||
#include "console.hpp"
|
||||
#include "language.hpp"
|
||||
#include "updater.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/io.hpp>
|
||||
@ -35,6 +36,7 @@ namespace config
|
||||
{define_field("disable_custom_fonts", field_type::boolean, false)},
|
||||
{define_field("language", field_type::string, language::get_default_language(), language::is_valid_language)},
|
||||
{define_field("motd_last_seen", field_type::number_unsigned, 0)},
|
||||
{define_field("branch", field_type::string, updater::get_git_branch(), updater::is_valid_git_branch)},
|
||||
};
|
||||
|
||||
std::string get_config_file_path()
|
||||
|
@ -446,6 +446,20 @@ namespace ui_scripting
|
||||
updater_table["getlasterror"] = updater::get_last_error;
|
||||
updater_table["getcurrentfile"] = updater::get_current_file;
|
||||
|
||||
updater_table["getcurrentbranch"] = []()
|
||||
{
|
||||
const auto branch = updater::get_current_branch();
|
||||
return static_cast<int>(branch);
|
||||
};
|
||||
|
||||
updater_table["setbranch"] = [](const std::uint32_t branch)
|
||||
{
|
||||
updater::set_branch(static_cast<updater::git_branch>(branch));
|
||||
};
|
||||
|
||||
updater_table["develop"] = static_cast<int>(updater::branch_develop);
|
||||
updater_table["main"] = static_cast<int>(updater::branch_main);
|
||||
|
||||
auto mods_table = table();
|
||||
lua["mods"] = mods_table;
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "console.hpp"
|
||||
#include "command.hpp"
|
||||
#include "database.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
#include "version.h"
|
||||
|
||||
@ -72,11 +73,33 @@ namespace updater
|
||||
|
||||
utils::concurrency::container<update_data_t> update_data;
|
||||
|
||||
std::unordered_map<std::string, git_branch> git_branches =
|
||||
{
|
||||
{"develop", branch_develop},
|
||||
{"main", branch_main},
|
||||
};
|
||||
|
||||
std::string get_branch_name(const git_branch branch)
|
||||
{
|
||||
for (const auto& [name, b] : git_branches)
|
||||
{
|
||||
if (branch == b)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
throw std::runtime_error("invalid branch");
|
||||
}
|
||||
|
||||
std::string select(const std::string& main, const std::string& develop)
|
||||
{
|
||||
if (GIT_BRANCH == "develop"s)
|
||||
switch (updater::get_current_branch())
|
||||
{
|
||||
case branch_develop:
|
||||
return develop;
|
||||
case branch_main:
|
||||
return main;
|
||||
}
|
||||
|
||||
return main;
|
||||
@ -579,6 +602,45 @@ namespace updater
|
||||
return !utils::io::directory_exists(folder) || utils::io::directory_is_empty(folder);
|
||||
}
|
||||
|
||||
bool is_valid_git_branch(const std::string& branch)
|
||||
{
|
||||
return git_branches.contains(branch);
|
||||
}
|
||||
|
||||
std::string get_git_branch()
|
||||
{
|
||||
return GIT_BRANCH;
|
||||
}
|
||||
|
||||
git_branch get_current_branch()
|
||||
{
|
||||
const auto get_branch_name = []()
|
||||
-> std::string
|
||||
{
|
||||
const auto branch_opt = config::get<std::string>("branch");
|
||||
if (!branch_opt.has_value())
|
||||
{
|
||||
return GIT_BRANCH;
|
||||
}
|
||||
|
||||
return branch_opt.value();
|
||||
};
|
||||
|
||||
const auto branch_name = get_branch_name();
|
||||
return git_branches.at(branch_name);
|
||||
}
|
||||
|
||||
void set_branch(const git_branch branch)
|
||||
{
|
||||
if (branch >= branch_count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto name = get_branch_name(branch);
|
||||
config::set("branch", name);
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
|
@ -4,6 +4,13 @@
|
||||
|
||||
namespace updater
|
||||
{
|
||||
enum git_branch
|
||||
{
|
||||
branch_develop,
|
||||
branch_main,
|
||||
branch_count
|
||||
};
|
||||
|
||||
std::optional<std::string> get_server_file(const std::string& endpoint);
|
||||
|
||||
void relaunch();
|
||||
@ -29,4 +36,9 @@ namespace updater
|
||||
void cancel_update();
|
||||
|
||||
bool should_force_update();
|
||||
|
||||
bool is_valid_git_branch(const std::string& branch);
|
||||
std::string get_git_branch();
|
||||
git_branch get_current_branch();
|
||||
void set_branch(const git_branch branch);
|
||||
}
|
Loading…
Reference in New Issue
Block a user