add more cheating-related rules

This commit is contained in:
MihailRis 2024-11-06 18:54:20 +03:00
parent 22fa082fc6
commit 6602584c13
5 changed files with 65 additions and 20 deletions

View File

@ -230,6 +230,21 @@ function __vc_create_hud_rules()
_rules.create("show-content-access", hud._is_content_access(), function(value) _rules.create("show-content-access", hud._is_content_access(), function(value)
hud._set_content_access(value) hud._set_content_access(value)
end) end)
_rules.create("allow-flight", true, function(value)
input.set_enabled("player.flight", value)
end)
_rules.create("allow-noclip", true, function(value)
input.set_enabled("player.noclip", value)
end)
_rules.create("allow-destruct", true, function(value)
input.set_enabled("player.attack", value)
end)
_rules.create("allow-cheat-movement", true, function(value)
input.set_enabled("player.cheat", value)
end)
_rules.create("allow-debug-cheats", true, function(value)
hud._set_debug_cheats(value)
end)
end end
-- --------- Deprecated functions ------ -- -- --------- Deprecated functions ------ --

View File

@ -42,7 +42,8 @@ static std::shared_ptr<Label> create_label(wstringsupplier supplier) {
std::shared_ptr<UINode> create_debug_panel( std::shared_ptr<UINode> create_debug_panel(
Engine* engine, Engine* engine,
Level* level, Level* level,
Player* player Player* player,
bool allowDebugCheats
) { ) {
auto panel = std::make_shared<Panel>(glm::vec2(300, 200), glm::vec4(5.0f), 2.0f); auto panel = std::make_shared<Panel>(glm::vec2(300, 200), glm::vec4(5.0f), 2.0f);
panel->setId("hud.debug-panel"); panel->setId("hud.debug-panel");
@ -162,6 +163,7 @@ std::shared_ptr<UINode> create_debug_panel(
box->setTextSupplier([=]() { box->setTextSupplier([=]() {
return util::to_wstring(player->getPosition()[ax], 2); return util::to_wstring(player->getPosition()[ax], 2);
}); });
if (allowDebugCheats) {
box->setTextConsumer([=](const std::wstring& text) { box->setTextConsumer([=](const std::wstring& text) {
try { try {
glm::vec3 position = player->getPosition(); glm::vec3 position = player->getPosition();
@ -170,8 +172,11 @@ std::shared_ptr<UINode> create_debug_panel(
} catch (std::exception& _){ } catch (std::exception& _){
} }
}); });
}
box->setOnEditStart([=]() { box->setOnEditStart([=]() {
boxRef->setText(std::to_wstring(static_cast<int>(player->getPosition()[ax]))); boxRef->setText(
std::to_wstring(static_cast<int>(player->getPosition()[ax]))
);
}); });
box->setSize(glm::vec2(230, 27)); box->setSize(glm::vec2(230, 27));
@ -188,13 +193,13 @@ std::shared_ptr<UINode> create_debug_panel(
util::lfill(std::to_wstring(minute), 2, L'0'); util::lfill(std::to_wstring(minute), 2, L'0');
return L"time: "+timeString; return L"time: "+timeString;
})); }));
{ if (allowDebugCheats) {
auto bar = std::make_shared<TrackBar>(0.0f, 1.0f, 1.0f, 0.005f, 8); auto bar = std::make_shared<TrackBar>(0.0f, 1.0f, 1.0f, 0.005f, 8);
bar->setSupplier([&]() {return worldInfo.daytime;}); bar->setSupplier([&]() {return worldInfo.daytime;});
bar->setConsumer([&](double val) {worldInfo.daytime = val;}); bar->setConsumer([&](double val) {worldInfo.daytime = val;});
panel->add(bar); panel->add(bar);
} }
{ if (allowDebugCheats) {
auto bar = std::make_shared<TrackBar>(0.0f, 1.0f, 0.0f, 0.005f, 8); auto bar = std::make_shared<TrackBar>(0.0f, 1.0f, 0.0f, 0.005f, 8);
bar->setSupplier([&]() {return worldInfo.fog;}); bar->setSupplier([&]() {return worldInfo.fog;});
bar->setConsumer([&](double val) {worldInfo.fog = val;}); bar->setConsumer([&](double val) {worldInfo.fog = val;});

View File

@ -62,7 +62,8 @@ bool Hud::showGeneratorMinimap = false;
extern std::shared_ptr<UINode> create_debug_panel( extern std::shared_ptr<UINode> create_debug_panel(
Engine* engine, Engine* engine,
Level* level, Level* level,
Player* player Player* player,
bool allowDebugCheats
); );
HudElement::HudElement( HudElement::HudElement(
@ -149,7 +150,8 @@ std::shared_ptr<InventoryView> Hud::createHotbar() {
static constexpr uint WORLDGEN_IMG_SIZE = 128U; static constexpr uint WORLDGEN_IMG_SIZE = 128U;
Hud::Hud(Engine* engine, LevelFrontend* frontend, Player* player) Hud::Hud(Engine* engine, LevelFrontend* frontend, Player* player)
: assets(engine->getAssets()), : engine(engine),
assets(engine->getAssets()),
gui(engine->getGUI()), gui(engine->getGUI()),
frontend(frontend), frontend(frontend),
player(player), player(player),
@ -175,12 +177,14 @@ Hud::Hud(Engine* engine, LevelFrontend* frontend, Player* player)
uicamera->perspective = false; uicamera->perspective = false;
uicamera->flipped = true; uicamera->flipped = true;
debugPanel = create_debug_panel(engine, frontend->getLevel(), player); debugPanel = create_debug_panel(
engine, frontend->getLevel(), player, allowDebugCheats
);
debugPanel->setZIndex(2); debugPanel->setZIndex(2);
gui->add(debugPanel);
gui->add(darkOverlay); gui->add(darkOverlay);
gui->add(hotbarView); gui->add(hotbarView);
gui->add(debugPanel);
gui->add(contentAccessPanel); gui->add(contentAccessPanel);
auto dplotter = std::make_shared<Plotter>(350, 250, 2000, 16); auto dplotter = std::make_shared<Plotter>(350, 250, 2000, 16);
@ -638,3 +642,14 @@ bool Hud::isContentAccess() const {
void Hud::setContentAccess(bool flag) { void Hud::setContentAccess(bool flag) {
showContentPanel = flag; showContentPanel = flag;
} }
void Hud::setDebugCheats(bool flag) {
allowDebugCheats = flag;
gui->remove(debugPanel);
debugPanel = create_debug_panel(
engine, frontend->getLevel(), player, allowDebugCheats
);
debugPanel->setZIndex(2);
gui->add(debugPanel);
}

View File

@ -69,6 +69,7 @@ public:
}; };
class Hud : public util::ObjectsKeeper { class Hud : public util::ObjectsKeeper {
Engine* engine;
Assets* assets; Assets* assets;
std::unique_ptr<Camera> uicamera; std::unique_ptr<Camera> uicamera;
gui::GUI* gui; gui::GUI* gui;
@ -107,7 +108,8 @@ class Hud : public util::ObjectsKeeper {
blockid_t currentblockid = 0; blockid_t currentblockid = 0;
/// @brief Show content access panel /// @brief Show content access panel
bool showContentPanel = true; bool showContentPanel = true;
/// @brief Provide cheat controllers to the debug panel
bool allowDebugCheats = true;
/// @brief UI element will be dynamicly positioned near to inventory or in screen center /// @brief UI element will be dynamicly positioned near to inventory or in screen center
std::shared_ptr<gui::UINode> secondUI = nullptr; std::shared_ptr<gui::UINode> secondUI = nullptr;
@ -178,6 +180,8 @@ public:
void setContentAccess(bool flag); void setContentAccess(bool flag);
void setDebugCheats(bool flag);
static bool showGeneratorMinimap; static bool showGeneratorMinimap;
/// @brief Runtime updating debug visualization texture /// @brief Runtime updating debug visualization texture

View File

@ -146,6 +146,11 @@ static int l_set_content_access(lua::State* L) {
return 0; return 0;
} }
static int l_set_debug_cheats(lua::State* L) {
hud->setDebugCheats(lua::toboolean(L, 1));
return 0;
}
const luaL_Reg hudlib[] = { const luaL_Reg hudlib[] = {
{"open_inventory", lua::wrap<l_open_inventory>}, {"open_inventory", lua::wrap<l_open_inventory>},
{"close_inventory", lua::wrap<l_close_inventory>}, {"close_inventory", lua::wrap<l_close_inventory>},
@ -161,4 +166,5 @@ const luaL_Reg hudlib[] = {
{"get_player", lua::wrap<l_get_player>}, {"get_player", lua::wrap<l_get_player>},
{"_is_content_access", lua::wrap<l_is_content_access>}, {"_is_content_access", lua::wrap<l_is_content_access>},
{"_set_content_access", lua::wrap<l_set_content_access>}, {"_set_content_access", lua::wrap<l_set_content_access>},
{"_set_debug_cheats", lua::wrap<l_set_debug_cheats>},
{NULL, NULL}}; {NULL, NULL}};