Skip to content

Commit

Permalink
Merge pull request #3159 from Ghabry/enum-tags
Browse files Browse the repository at this point in the history
Enum tags: Preparation for liblcf update
  • Loading branch information
fdelapena authored Dec 1, 2023
2 parents 3d91997 + 89b2c88 commit ec039e6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 25 deletions.
19 changes: 9 additions & 10 deletions src/game_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "cmdline_parser.h"
#include "filefinder.h"
#include "input_buttons.h"
#include "keys.h"
#include "output.h"
#include "input.h"
#include <lcf/inireader.h>
Expand Down Expand Up @@ -377,7 +378,7 @@ void Game_Config::LoadFromStream(Filesystem_Stream::InputStream& is) {
for (int i = 0; i < Input::BUTTON_COUNT; ++i) {
auto button = static_cast<Input::InputButton>(i);

auto name = Input::kButtonNames.tag(button);
auto name = Input::kInputButtonNames.tag(button);
if (ini.HasValue("input", name)) {
auto values = ini.GetString("input", name, "");
mappings.RemoveAll(button);
Expand All @@ -390,9 +391,8 @@ void Game_Config::LoadFromStream(Filesystem_Stream::InputStream& is) {
if (Input::IsProtectedButton(button)) {
// Check for protected (important) buttons if they have more than zero mappings
for (const auto& key: keys) {
const auto& kNames = Input::Keys::kNames;
auto it = std::find(kNames.begin(), kNames.end(), key);
if (it != Input::Keys::kNames.end()) {
Input::Keys::InputKey k;
if (Input::Keys::kInputKeyNames.etag(key.c_str(), k)) {
has_mapping = true;
break;
}
Expand All @@ -406,10 +406,9 @@ void Game_Config::LoadFromStream(Filesystem_Stream::InputStream& is) {

// Load mappings from ini
for (const auto& key: keys) {
const auto& kNames = Input::Keys::kNames;
auto it = std::find(kNames.begin(), kNames.end(), key);
if (it != Input::Keys::kNames.end()) {
mappings.Add({button, static_cast<Input::Keys::InputKey>(std::distance(kNames.begin(), it))});
Input::Keys::InputKey k;
if (Input::Keys::kInputKeyNames.etag(key.c_str(), k)) {
mappings.Add({button, k});
}
}
}
Expand Down Expand Up @@ -466,7 +465,7 @@ void Game_Config::WriteToStream(Filesystem_Stream::OutputStream& os) const {
for (int i = 0; i < Input::BUTTON_COUNT; ++i) {
auto button = static_cast<Input::InputButton>(i);

auto name = Input::kButtonNames.tag(button);
auto name = Input::kInputButtonNames.tag(button);
os << name << "=";

std::stringstream ss;
Expand All @@ -478,7 +477,7 @@ void Game_Config::WriteToStream(Filesystem_Stream::OutputStream& os) const {
first = false;

auto key = static_cast<Input::Keys::InputKey>(ki->second);
auto kname = Input::Keys::kNames.tag(key);
auto kname = Input::Keys::kInputKeyNames.tag(key);
os << kname;
}

Expand Down
10 changes: 5 additions & 5 deletions src/input_buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace Input {
BUTTON_COUNT
};

constexpr auto kButtonNames = lcf::makeEnumTags<InputButton>(
constexpr auto kInputButtonNames = lcf::makeEnumTags<InputButton>(
"UP",
"DOWN",
"LEFT",
Expand Down Expand Up @@ -133,7 +133,7 @@ namespace Input {
"TOGGLE_ZOOM",
"BUTTON_COUNT");

constexpr auto kButtonHelp = lcf::makeEnumTags<InputButton>(
constexpr auto kInputButtonHelp = lcf::makeEnumTags<InputButton>(
"Up Direction",
"Down Direction",
"Left Direction",
Expand Down Expand Up @@ -231,7 +231,7 @@ namespace Input {
NUM_DIRECTIONS = 10,
};

static constexpr auto kNames = lcf::makeEnumTags<InputDirection>(
static constexpr auto kInputDirectionNames = lcf::makeEnumTags<InputDirection>(
"NONE",
"DOWNLEFT",
"DOWN",
Expand All @@ -251,7 +251,7 @@ namespace Input {
using ButtonMapping = ButtonMappingArray::pair_type;

inline std::ostream& operator<<(std::ostream& os, ButtonMapping bm) {
os << "{ " << kButtonNames.tag(bm.first) << ", " << Keys::kNames.tag(bm.second) << " }";
os << "{ " << kInputButtonNames.tag(bm.first) << ", " << Keys::kInputKeyNames.tag(bm.second) << " }";
return os;
}

Expand All @@ -261,7 +261,7 @@ namespace Input {
using DirectionMapping = DirectionMappingArray::pair_type;

inline std::ostream& operator<<(std::ostream& os, DirectionMapping dm) {
os << "{ " << Direction::kNames.tag(dm.first) << ", " << kButtonNames.tag(dm.second) << " }";
os << "{ " << Direction::kInputDirectionNames.tag(dm.first) << ", " << kInputButtonNames.tag(dm.second) << " }";
return os;
}

Expand Down
8 changes: 4 additions & 4 deletions src/input_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ void Input::LogSource::Update() {
}
if (Main_Data::game_system->GetFrameCounter() == last_read_frame) {
for (const auto& key : keys) {
auto it = std::find(Input::kButtonNames.begin(), Input::kButtonNames.end(), key);
if (it != Input::kButtonNames.end()) {
pressed_buttons[std::distance(Input::kButtonNames.begin(), it)] = true;
Input::InputButton btn;
if (Input::kInputButtonNames.etag(key.c_str(), btn)) {
pressed_buttons[(int)btn] = true;
}
}
last_read_frame = -1;
Expand Down Expand Up @@ -193,7 +193,7 @@ void Input::Source::Record() {
continue;
}

*record_log << ',' << Input::kButtonNames[i];
*record_log << ',' << Input::kInputButtonNames[i];
}

*record_log << '\n';
Expand Down
2 changes: 1 addition & 1 deletion src/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ namespace Input {
KEYS_COUNT
};

constexpr auto kNames = lcf::makeEnumTags<InputKey>(
constexpr auto kInputKeyNames = lcf::makeEnumTags<InputKey>(
"NONE",
"BACKSPACE",
"TAB",
Expand Down
2 changes: 1 addition & 1 deletion src/scene_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ bool Scene_Settings::RefreshInputEmergencyReset() {
}
Input::ResetAllMappings();
} else {
Output::Info("Button {} reset to default", Input::kButtonNames.tag(input_window->GetInputButton()));
Output::Info("Button {} reset to default", Input::kInputButtonNames.tag(input_window->GetInputButton()));
Output::Info("To reset all buttons hold 3 seconds longer");
if (input_window->GetActive()) {
input_window->SetIndex(0);
Expand Down
2 changes: 1 addition & 1 deletion src/window_input_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void Window_InputSettings::Refresh() {
if (custom_name != custom_names.end()) {
items.push_back(custom_name->second);
} else {
items.push_back(Input::Keys::kNames.tag(key));
items.push_back(Input::Keys::kInputKeyNames.tag(key));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/window_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void Window_Settings::RefreshButtonList() {
for (auto b: buttons) {
auto button = static_cast<Input::InputButton>(b);

std::string name = Input::kButtonNames.tag(button);
std::string name = Input::kInputButtonNames.tag(button);

// Improve readability of the names
bool first_letter = true;
Expand All @@ -436,7 +436,7 @@ void Window_Settings::RefreshButtonList() {
}
}

std::string help = Input::kButtonHelp.tag(button);
std::string help = Input::kInputButtonHelp.tag(button);
std::string value;

// Append as many buttons as fit on the screen, then add ...
Expand All @@ -453,7 +453,7 @@ void Window_Settings::RefreshButtonList() {
if (custom_name != custom_names.end()) {
cur_value = custom_name->second;
} else {
cur_value = Input::Keys::kNames.tag(ki->second);
cur_value = Input::Keys::kInputKeyNames.tag(ki->second);
}

int cur_value_size = Text::GetSize(*Font::Default(), cur_value + ",").width;
Expand Down

0 comments on commit ec039e6

Please sign in to comment.