diff options
| author | untodesu <kirill@untode.su> | 2025-06-29 22:24:42 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-06-29 22:24:42 +0500 |
| commit | 6cd00aacfa22fed6a54a9b812f6b069ad16feec0 (patch) | |
| tree | b77f4e665da3dd235cdb01e7e6ea78c1c02ecf2e /game/client/toggles.cc | |
| parent | f440914e1ae453768d09383f332bc7844e0a700e (diff) | |
| download | voxelius-6cd00aacfa22fed6a54a9b812f6b069ad16feec0.tar.bz2 voxelius-6cd00aacfa22fed6a54a9b812f6b069ad16feec0.zip | |
Move game sources into src subdirectory
Diffstat (limited to 'game/client/toggles.cc')
| -rw-r--r-- | game/client/toggles.cc | 154 |
1 files changed, 0 insertions, 154 deletions
diff --git a/game/client/toggles.cc b/game/client/toggles.cc deleted file mode 100644 index f40d6ed..0000000 --- a/game/client/toggles.cc +++ /dev/null @@ -1,154 +0,0 @@ -#include "client/pch.hh" - -#include "client/toggles.hh" - -#include "core/config.hh" - -#include "client/chat.hh" -#include "client/const.hh" -#include "client/gamepad.hh" -#include "client/glfw.hh" -#include "client/globals.hh" -#include "client/language.hh" - -struct ToggleInfo final { - const char* description; - int glfw_keycode; - bool is_enabled; -}; - -bool toggles::is_sequence_await = false; - -static ToggleInfo toggle_infos[TOGGLE_COUNT]; - -static void print_toggle_state(const ToggleInfo& info) -{ - if(info.description) { - if(info.is_enabled) { - client_chat::print(std::format("[toggles] {} ON", info.description)); - } else { - client_chat::print(std::format("[toggles] {} OFF", info.description)); - } - } -} - -static void toggle_value(ToggleInfo& info, toggle_type type) -{ - if(info.is_enabled) { - info.is_enabled = false; - globals::dispatcher.trigger(ToggleDisabledEvent { type }); - } else { - info.is_enabled = true; - globals::dispatcher.trigger(ToggleEnabledEvent { type }); - } - - print_toggle_state(info); -} - -static void on_glfw_key(const GlfwKeyEvent& event) -{ - if(globals::gui_keybind_ptr) { - // The UI keybind subsystem has the authority - // over debug toggles and it hogs the input keys - return; - } - - if(event.key == DEBUG_KEY) { - if(event.action == GLFW_PRESS) { - toggles::is_sequence_await = true; - ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard; - return; - } - - if(event.action == GLFW_RELEASE) { - toggles::is_sequence_await = false; - ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; - return; - } - } - - if((event.action == GLFW_PRESS) && toggles::is_sequence_await) { - if(event.key == GLFW_KEY_L) { - // This causes the language subsystem - // to re-parse the JSON file essentially - // causing the game to soft-reload language - language::set(language::get_current()); - return; - } - - for(toggle_type i = 0; i < TOGGLE_COUNT; ++i) { - if(event.key == toggle_infos[i].glfw_keycode) { - toggle_value(toggle_infos[i], i); - return; - } - } - } -} - -void toggles::init(void) -{ - toggle_infos[TOGGLE_WIREFRAME].description = "wireframe"; - toggle_infos[TOGGLE_WIREFRAME].glfw_keycode = GLFW_KEY_Z; - toggle_infos[TOGGLE_WIREFRAME].is_enabled = false; - - toggle_infos[TOGGLE_FULLBRIGHT].description = "fullbright"; - toggle_infos[TOGGLE_FULLBRIGHT].glfw_keycode = GLFW_KEY_J; - toggle_infos[TOGGLE_FULLBRIGHT].is_enabled = false; - - toggle_infos[TOGGLE_CHUNK_AABB].description = "chunk Borders"; - toggle_infos[TOGGLE_CHUNK_AABB].glfw_keycode = GLFW_KEY_G; - toggle_infos[TOGGLE_CHUNK_AABB].is_enabled = false; - - toggle_infos[TOGGLE_METRICS_UI].description = nullptr; - toggle_infos[TOGGLE_METRICS_UI].glfw_keycode = GLFW_KEY_V; - toggle_infos[TOGGLE_METRICS_UI].is_enabled = false; - - toggle_infos[TOGGLE_USE_GAMEPAD].description = "gamepad input"; - toggle_infos[TOGGLE_USE_GAMEPAD].glfw_keycode = GLFW_KEY_P; - toggle_infos[TOGGLE_USE_GAMEPAD].is_enabled = false; - - toggle_infos[TOGGLE_PM_FLIGHT].description = "flight mode"; - toggle_infos[TOGGLE_PM_FLIGHT].glfw_keycode = GLFW_KEY_F; - toggle_infos[TOGGLE_PM_FLIGHT].is_enabled = false; - -#ifndef NDEBUG - toggle_infos[TOGGLE_WIREFRAME].is_enabled = true; -#endif - - globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>(); -} - -void toggles::init_late(void) -{ - for(toggle_type i = 0; i < TOGGLE_COUNT; ++i) { - if(toggle_infos[i].is_enabled) { - globals::dispatcher.trigger(ToggleEnabledEvent { i }); - } else { - globals::dispatcher.trigger(ToggleDisabledEvent { i }); - } - } -} - -bool toggles::get(toggle_type type) -{ - if(type < TOGGLE_COUNT) { - return toggle_infos[type].is_enabled; - } else { - return false; - } -} - -void toggles::set(toggle_type type, bool value) -{ - if(type < TOGGLE_COUNT) { - if(value) { - toggle_infos[type].is_enabled = true; - globals::dispatcher.trigger(ToggleEnabledEvent { type }); - } else { - toggle_infos[type].is_enabled = false; - globals::dispatcher.trigger(ToggleDisabledEvent { type }); - } - - print_toggle_state(toggle_infos[type]); - } -} |
