Skip to content

Commit b8d91d0

Browse files
committed
clang-tidy:
- fix name errors: namespace SDL -> sdl
1 parent cf604f8 commit b8d91d0

File tree

7 files changed

+226
-226
lines changed

7 files changed

+226
-226
lines changed

src/input/keyboard_input.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,38 @@ input::KeyboardInput::KeyboardInput() : input::Input{ "keyboard", InputType::Key
1414

1515
if (event.type == SDL_KEYDOWN) {
1616

17-
const auto key = SDL::Key{ event.key.keysym };
17+
const auto key = sdl::Key{ event.key.keysym };
1818

19-
if (key == SDL::Key{ SDLK_RETURN } or key == SDL::Key{ SDLK_SPACE }) {
19+
if (key == sdl::Key{ SDLK_RETURN } or key == sdl::Key{ SDLK_SPACE }) {
2020
return NavigationEvent::OK;
2121
}
2222

23-
if (key == SDL::Key{ SDLK_DOWN } or key == SDL::Key{ SDLK_s }) {
23+
if (key == sdl::Key{ SDLK_DOWN } or key == sdl::Key{ SDLK_s }) {
2424
return NavigationEvent::DOWN;
2525
}
2626

2727

28-
if (key == SDL::Key{ SDLK_UP } or key == SDL::Key{ SDLK_w }) {
28+
if (key == sdl::Key{ SDLK_UP } or key == sdl::Key{ SDLK_w }) {
2929
return NavigationEvent::UP;
3030
}
3131

3232

33-
if (key == SDL::Key{ SDLK_LEFT } or key == SDL::Key{ SDLK_a }) {
33+
if (key == sdl::Key{ SDLK_LEFT } or key == sdl::Key{ SDLK_a }) {
3434
return NavigationEvent::LEFT;
3535
}
3636

3737

38-
if (key == SDL::Key{ SDLK_RIGHT } or key == SDL::Key{ SDLK_d }) {
38+
if (key == sdl::Key{ SDLK_RIGHT } or key == sdl::Key{ SDLK_d }) {
3939
return NavigationEvent::RIGHT;
4040
}
4141

4242

43-
if (key == SDL::Key{ SDLK_ESCAPE } or key == SDL::Key{ SDLK_BACKSPACE }) {
43+
if (key == sdl::Key{ SDLK_ESCAPE } or key == sdl::Key{ SDLK_BACKSPACE }) {
4444
return NavigationEvent::BACK;
4545
}
4646

4747

48-
if (key == SDL::Key{ SDLK_TAB }) {
48+
if (key == sdl::Key{ SDLK_TAB }) {
4949
return NavigationEvent::TAB;
5050
}
5151
}
@@ -60,19 +60,19 @@ input::KeyboardInput::KeyboardInput() : input::Input{ "keyboard", InputType::Key
6060
switch (event) {
6161

6262
case NavigationEvent::OK:
63-
return fmt::format("{} or {}", SDL::Key{ SDLK_RETURN }, SDL::Key{ SDLK_SPACE });
63+
return fmt::format("{} or {}", sdl::Key{ SDLK_RETURN }, sdl::Key{ SDLK_SPACE });
6464
case NavigationEvent::DOWN:
65-
return fmt::format("{} or {}", SDL::Key{ SDLK_DOWN }, SDL::Key{ SDLK_s });
65+
return fmt::format("{} or {}", sdl::Key{ SDLK_DOWN }, sdl::Key{ SDLK_s });
6666
case NavigationEvent::UP:
67-
return fmt::format("{} or {}", SDL::Key{ SDLK_UP }, SDL::Key{ SDLK_w });
67+
return fmt::format("{} or {}", sdl::Key{ SDLK_UP }, sdl::Key{ SDLK_w });
6868
case NavigationEvent::LEFT:
69-
return fmt::format("{} or {}", SDL::Key{ SDLK_LEFT }, SDL::Key{ SDLK_a });
69+
return fmt::format("{} or {}", sdl::Key{ SDLK_LEFT }, sdl::Key{ SDLK_a });
7070
case NavigationEvent::RIGHT:
71-
return fmt::format("{} or {}", SDL::Key{ SDLK_RIGHT }, SDL::Key{ SDLK_d });
71+
return fmt::format("{} or {}", sdl::Key{ SDLK_RIGHT }, sdl::Key{ SDLK_d });
7272
case NavigationEvent::BACK:
73-
return fmt::format("{} or {}", SDL::Key{ SDLK_ESCAPE }, SDL::Key{ SDLK_BACKSPACE });
73+
return fmt::format("{} or {}", sdl::Key{ SDLK_ESCAPE }, sdl::Key{ SDLK_BACKSPACE });
7474
case NavigationEvent::TAB:
75-
return fmt::format("{}", SDL::Key{ SDLK_TAB });
75+
return fmt::format("{}", sdl::Key{ SDLK_TAB });
7676
default:
7777
utils::unreachable();
7878
}
@@ -97,7 +97,7 @@ void input::KeyboardGameInput::update(SimulationStep simulation_step_index) {
9797

9898
helper::optional<InputEvent> input::KeyboardGameInput::sdl_event_to_input_event(const SDL_Event& event) const {
9999
if (event.type == SDL_KEYDOWN and event.key.repeat == 0) {
100-
const auto key = SDL::Key{ event.key.keysym };
100+
const auto key = sdl::Key{ event.key.keysym };
101101
if (key == m_settings.rotate_left) {
102102
return InputEvent::RotateLeftPressed;
103103
}
@@ -120,7 +120,7 @@ helper::optional<InputEvent> input::KeyboardGameInput::sdl_event_to_input_event(
120120
return InputEvent::HoldPressed;
121121
}
122122
} else if (event.type == SDL_KEYUP) {
123-
const auto key = SDL::Key{ event.key.keysym };
123+
const auto key = sdl::Key{ event.key.keysym };
124124
if (key == m_settings.rotate_left) {
125125
return InputEvent::RotateLeftReleased;
126126
}
@@ -160,20 +160,20 @@ input::KeyboardGameInput::~KeyboardGameInput() {
160160

161161
[[nodiscard]] helper::expected<bool, std::string> input::KeyboardSettings::validate() const {
162162

163-
const std::vector<SDL::Key> to_use{ rotate_left, rotate_right, move_left, move_right, move_down,
163+
const std::vector<sdl::Key> to_use{ rotate_left, rotate_right, move_left, move_right, move_down,
164164
drop, hold, pause, open_settings };
165165

166166
return input::InputSettings::has_unique_members(to_use);
167167
}
168168

169-
SDL::Key json_helper::get_key(const nlohmann::json& j, const std::string& name) {
169+
sdl::Key json_helper::get_key(const nlohmann::json& j, const std::string& name) {
170170

171171
auto context = j.at(name);
172172

173173
std::string input;
174174
context.get_to(input);
175175

176-
const auto& value = SDL::Key::from_string(input);
176+
const auto& value = sdl::Key::from_string(input);
177177

178178
if (not value.has_value()) {
179179
throw nlohmann::json::type_error::create(
@@ -189,7 +189,7 @@ SDL::Key json_helper::get_key(const nlohmann::json& j, const std::string& name)
189189
) const {
190190

191191
if (event.type == SDL_KEYDOWN and event.key.repeat == 0) {
192-
const auto key = SDL::Key{ event.key.keysym };
192+
const auto key = sdl::Key{ event.key.keysym };
193193
if (key == m_settings.pause) {
194194
return MenuEvent::Pause;
195195
}

src/input/keyboard_input.hpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,30 @@ namespace input {
2727

2828
//TODO(Totto): don't default initialize all settings, but rather provide a static default setting, so that everything has to be set explicitly, or you can use the default explicitly
2929
struct KeyboardSettings {
30-
SDL::Key rotate_left;
31-
SDL::Key rotate_right;
32-
SDL::Key move_left;
33-
SDL::Key move_right;
34-
SDL::Key move_down;
35-
SDL::Key drop;
36-
SDL::Key hold;
30+
sdl::Key rotate_left;
31+
sdl::Key rotate_right;
32+
sdl::Key move_left;
33+
sdl::Key move_right;
34+
sdl::Key move_down;
35+
sdl::Key drop;
36+
sdl::Key hold;
3737

38-
SDL::Key pause;
39-
SDL::Key open_settings;
38+
sdl::Key pause;
39+
sdl::Key open_settings;
4040

4141

4242
[[nodiscard]] helper::expected<bool, std::string> validate() const;
4343

4444
[[nodiscard]] static KeyboardSettings default_settings() {
45-
return KeyboardSettings{ .rotate_left = SDL::Key{ SDLK_LEFT },
46-
.rotate_right = SDL::Key{ SDLK_RIGHT },
47-
.move_left = SDL::Key{ SDLK_a },
48-
.move_right = SDL::Key{ SDLK_d },
49-
.move_down = SDL::Key{ SDLK_s },
50-
.drop = SDL::Key{ SDLK_w },
51-
.hold = SDL::Key{ SDLK_TAB },
52-
.pause = SDL::Key{ SDLK_ESCAPE },
53-
.open_settings = SDL::Key{ SDLK_e } };
45+
return KeyboardSettings{ .rotate_left = sdl::Key{ SDLK_LEFT },
46+
.rotate_right = sdl::Key{ SDLK_RIGHT },
47+
.move_left = sdl::Key{ SDLK_a },
48+
.move_right = sdl::Key{ SDLK_d },
49+
.move_down = sdl::Key{ SDLK_s },
50+
.drop = sdl::Key{ SDLK_w },
51+
.hold = sdl::Key{ SDLK_TAB },
52+
.pause = sdl::Key{ SDLK_ESCAPE },
53+
.open_settings = sdl::Key{ SDLK_e } };
5454
}
5555
};
5656

@@ -83,7 +83,7 @@ namespace input {
8383
namespace json_helper {
8484

8585

86-
[[nodiscard]] SDL::Key get_key(const nlohmann::json& j, const std::string& name);
86+
[[nodiscard]] sdl::Key get_key(const nlohmann::json& j, const std::string& name);
8787

8888
} // namespace json_helper
8989

src/manager/event_dispatcher.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ struct EventDispatcher final {
1616
bool m_enabled{ true };
1717

1818
//TODO(Totto): factor out to some other place!
19-
std::vector<SDL::Key> allowed_input_keys{
20-
SDL::Key{ SDLK_RETURN },
21-
SDL::Key{ SDLK_BACKSPACE },
22-
SDL::Key{ SDLK_BACKSPACE, { SDL::Modifier::CTRL } },
23-
SDL::Key{ SDLK_DOWN },
24-
SDL::Key{ SDLK_UP },
25-
SDL::Key{ SDLK_LEFT },
26-
SDL::Key{ SDLK_RIGHT },
27-
SDL::Key{ SDLK_ESCAPE },
28-
SDL::Key{ SDLK_TAB },
29-
SDL::Key{ SDLK_c, { SDL::Modifier::CTRL } },
30-
SDL::Key{ SDLK_v, { SDL::Modifier::CTRL } }
19+
std::vector<sdl::Key> allowed_input_keys{
20+
sdl::Key{ SDLK_RETURN },
21+
sdl::Key{ SDLK_BACKSPACE },
22+
sdl::Key{ SDLK_BACKSPACE, { sdl::Modifier::CTRL } },
23+
sdl::Key{ SDLK_DOWN },
24+
sdl::Key{ SDLK_UP },
25+
sdl::Key{ SDLK_LEFT },
26+
sdl::Key{ SDLK_RIGHT },
27+
sdl::Key{ SDLK_ESCAPE },
28+
sdl::Key{ SDLK_TAB },
29+
sdl::Key{ SDLK_c, { sdl::Modifier::CTRL } },
30+
sdl::Key{ SDLK_v, { sdl::Modifier::CTRL } }
3131
};
3232

3333
public:
@@ -54,7 +54,7 @@ struct EventDispatcher final {
5454
switch (event.type) {
5555
case SDL_KEYDOWN:
5656
case SDL_KEYUP: {
57-
if (std::ranges::find(allowed_input_keys, SDL::Key{ event.key.keysym })
57+
if (std::ranges::find(allowed_input_keys, sdl::Key{ event.key.keysym })
5858
== allowed_input_keys.cend()) {
5959
return;
6060
}

src/manager/music_manager.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,21 +355,21 @@ helper::optional<double> MusicManager::change_volume(const std::int8_t steps) {
355355
bool MusicManager::handle_event(const std::shared_ptr<input::InputManager>&, const SDL_Event& event) {
356356

357357
if (event.type == SDL_KEYDOWN) {
358-
const auto key = SDL::Key{ event.key.keysym };
358+
const auto key = sdl::Key{ event.key.keysym };
359359

360360

361-
if (key.is_key(SDL::Key{ SDLK_PLUS }) or key.is_key(SDL::Key{ SDLK_KP_PLUS })) {
362-
const i8 steps = key.has_modifier(SDL::Modifier::CTRL) ? 100
363-
: key.has_modifier(SDL::Modifier::SHIFT) ? 10
361+
if (key.is_key(sdl::Key{ SDLK_PLUS }) or key.is_key(sdl::Key{ SDLK_KP_PLUS })) {
362+
const i8 steps = key.has_modifier(sdl::Modifier::CTRL) ? 100
363+
: key.has_modifier(sdl::Modifier::SHIFT) ? 10
364364
: 1;
365365

366366
change_volume(steps);
367367
return true;
368368
}
369369

370-
if (key.is_key(SDL::Key{ SDLK_MINUS }) or key.is_key(SDL::Key{ SDLK_KP_MINUS })) {
371-
const i8 steps = key.has_modifier(SDL::Modifier::CTRL) ? -100
372-
: key.has_modifier(SDL::Modifier::SHIFT) ? -10
370+
if (key.is_key(sdl::Key{ SDLK_MINUS }) or key.is_key(sdl::Key{ SDLK_KP_MINUS })) {
371+
const i8 steps = key.has_modifier(sdl::Modifier::CTRL) ? -100
372+
: key.has_modifier(sdl::Modifier::SHIFT) ? -10
373373
: -1;
374374
change_volume(steps);
375375
return true;

0 commit comments

Comments
 (0)