From 77846cfb61a3e4793d3fae5c1cc23fb68851c9ac Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Mon, 25 Mar 2024 17:13:57 +0100 Subject: Avoid accessing static members through instances Fixed with clang-tidy `readability-static-accessed-through-instance` check. --- src/game.cpp | 60 ++++++++++++++++++++++----------------------- src/gui/inventorywindow.cpp | 2 +- src/gui/setup_keyboard.cpp | 10 ++++---- src/gui/viewport.cpp | 4 +-- src/utils/stringutils.cpp | 4 +-- 5 files changed, 40 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index d2bd1430..b66e5253 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -415,11 +415,11 @@ void Game::handleInput() gcn::Window *requestedWindow = nullptr; if (setupWindow->isVisible() && - keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) + keyboard.getNewKeyIndex() > KeyboardConfig::KEY_NO_VALUE) { keyboard.setNewKey((int) event.key.keysym.sym); keyboard.callbackNewKey(); - keyboard.setNewKeyIndex(keyboard.KEY_NO_VALUE); + keyboard.setNewKeyIndex(KeyboardConfig::KEY_NO_VALUE); return; } @@ -440,7 +440,7 @@ void Game::handleInput() } // Mode switch to emotes - if (keyboard.isKeyActive(keyboard.KEY_EMOTE)) + if (keyboard.isKeyActive(KeyboardConfig::KEY_EMOTE)) { // Emotions int emotion = keyboard.getKeyEmoteOffset(event.key.keysym.sym); @@ -456,7 +456,7 @@ void Game::handleInput() && !gui->getFocusHandler()->getModalFocused()) { NpcDialog *dialog = NpcDialog::getActive(); - if (keyboard.isKeyActive(keyboard.KEY_OK) + if (keyboard.isKeyActive(KeyboardConfig::KEY_OK) && (!dialog || !dialog->isTextInputFocused())) { // Close the Browser if opened @@ -468,16 +468,16 @@ void Game::handleInput() else if (dialog) dialog->action(gcn::ActionEvent(nullptr, "ok")); } - if (keyboard.isKeyActive(keyboard.KEY_TOGGLE_CHAT)) + if (keyboard.isKeyActive(KeyboardConfig::KEY_TOGGLE_CHAT)) { if (chatWindow->requestChatFocus()) used = true; } if (dialog) { - if (keyboard.isKeyActive(keyboard.KEY_MOVE_UP)) + if (keyboard.isKeyActive(KeyboardConfig::KEY_MOVE_UP)) dialog->move(1); - else if (keyboard.isKeyActive(keyboard.KEY_MOVE_DOWN)) + else if (keyboard.isKeyActive(KeyboardConfig::KEY_MOVE_DOWN)) dialog->move(-1); } } @@ -486,12 +486,12 @@ void Game::handleInput() if (!chatWindow->isInputFocused() || (event.key.keysym.mod & KMOD_ALT)) { - if (keyboard.isKeyActive(keyboard.KEY_PREV_CHAT_TAB)) + if (keyboard.isKeyActive(KeyboardConfig::KEY_PREV_CHAT_TAB)) { chatWindow->prevTab(); return; } - else if (keyboard.isKeyActive(keyboard.KEY_NEXT_CHAT_TAB)) + else if (keyboard.isKeyActive(KeyboardConfig::KEY_NEXT_CHAT_TAB)) { chatWindow->nextTab(); return; @@ -503,10 +503,10 @@ void Game::handleInput() bool wearOutfit = false; bool copyOutfit = false; - if (keyboard.isKeyActive(keyboard.KEY_WEAR_OUTFIT)) + if (keyboard.isKeyActive(KeyboardConfig::KEY_WEAR_OUTFIT)) wearOutfit = true; - if (keyboard.isKeyActive(keyboard.KEY_COPY_OUTFIT)) + if (keyboard.isKeyActive(KeyboardConfig::KEY_COPY_OUTFIT)) copyOutfit = true; if (wearOutfit || copyOutfit) @@ -767,8 +767,8 @@ void Game::handleInput() // Ignore input if either "ignore" key is pressed // Stops the character moving about if the user's window manager // uses "ignore+arrow key" to switch virtual desktops. - if (keyboard.isKeyActive(keyboard.KEY_IGNORE_INPUT_1) || - keyboard.isKeyActive(keyboard.KEY_IGNORE_INPUT_2)) + if (keyboard.isKeyActive(KeyboardConfig::KEY_IGNORE_INPUT_1) || + keyboard.isKeyActive(KeyboardConfig::KEY_IGNORE_INPUT_2)) { return; } @@ -776,29 +776,29 @@ void Game::handleInput() unsigned char direction = 0; // Translate pressed keys to movement and direction - if (keyboard.isKeyActive(keyboard.KEY_MOVE_UP) || + if (keyboard.isKeyActive(KeyboardConfig::KEY_MOVE_UP) || (joystick && joystick->isUp())) { direction |= Being::UP; } - else if (keyboard.isKeyActive(keyboard.KEY_MOVE_DOWN) || + else if (keyboard.isKeyActive(KeyboardConfig::KEY_MOVE_DOWN) || (joystick && joystick->isDown())) { direction |= Being::DOWN; } - if (keyboard.isKeyActive(keyboard.KEY_MOVE_LEFT) || + if (keyboard.isKeyActive(KeyboardConfig::KEY_MOVE_LEFT) || (joystick && joystick->isLeft())) { direction |= Being::LEFT; } - else if (keyboard.isKeyActive(keyboard.KEY_MOVE_RIGHT) || + else if (keyboard.isKeyActive(KeyboardConfig::KEY_MOVE_RIGHT) || (joystick && joystick->isRight())) { direction |= Being::RIGHT; } - if (keyboard.isKeyActive(keyboard.KEY_EMOTE) && direction != 0) + if (keyboard.isKeyActive(KeyboardConfig::KEY_EMOTE) && direction != 0) { if (local_player->getDirection() != direction) { @@ -813,18 +813,18 @@ void Game::handleInput() } // Attacking monsters - if (keyboard.isKeyActive(keyboard.KEY_ATTACK) || + if (keyboard.isKeyActive(KeyboardConfig::KEY_ATTACK) || (joystick && joystick->buttonPressed(0))) { if (local_player->getTarget()) local_player->attack(local_player->getTarget(), true); } - if (keyboard.isKeyActive(keyboard.KEY_TARGET_ATTACK)) + if (keyboard.isKeyActive(KeyboardConfig::KEY_TARGET_ATTACK)) { Being *target = local_player->getTarget(); - bool newTarget = !keyboard.isKeyActive(keyboard.KEY_TARGET); + bool newTarget = !keyboard.isKeyActive(KeyboardConfig::KEY_TARGET); // A set target has highest priority if (!target) { @@ -836,19 +836,19 @@ void Game::handleInput() } // Target the nearest player/monster/npc - if ((keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER) || - keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) || - keyboard.isKeyActive(keyboard.KEY_TARGET_NPC) || + if ((keyboard.isKeyActive(KeyboardConfig::KEY_TARGET_PLAYER) || + keyboard.isKeyActive(KeyboardConfig::KEY_TARGET_CLOSEST) || + keyboard.isKeyActive(KeyboardConfig::KEY_TARGET_NPC) || (joystick && joystick->buttonPressed(3))) && - !keyboard.isKeyActive(keyboard.KEY_TARGET)) + !keyboard.isKeyActive(KeyboardConfig::KEY_TARGET)) { ActorSprite::Type currentTarget = ActorSprite::UNKNOWN; - if (keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) || + if (keyboard.isKeyActive(KeyboardConfig::KEY_TARGET_CLOSEST) || (joystick && joystick->buttonPressed(3))) currentTarget = ActorSprite::MONSTER; - else if (keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER)) + else if (keyboard.isKeyActive(KeyboardConfig::KEY_TARGET_PLAYER)) currentTarget = ActorSprite::PLAYER; - else if (keyboard.isKeyActive(keyboard.KEY_TARGET_NPC)) + else if (keyboard.isKeyActive(KeyboardConfig::KEY_TARGET_NPC)) currentTarget = ActorSprite::NPC; Being *target = actorSpriteManager->findNearestLivingBeing(local_player, @@ -880,8 +880,8 @@ void Game::handleInput() } // Stop attacking if the right key is pressed - if (!keyboard.isKeyActive(keyboard.KEY_ATTACK) - && keyboard.isKeyActive(keyboard.KEY_TARGET)) + if (!keyboard.isKeyActive(KeyboardConfig::KEY_ATTACK) + && keyboard.isKeyActive(KeyboardConfig::KEY_TARGET)) { local_player->stopAttack(); } diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 450ddfe5..048f83f5 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -277,7 +277,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) if (event.getButton() == gcn::MouseEvent::LEFT) { - if (instances.size() > 1 && keyboard.isKeyActive(keyboard.KEY_EMOTE)) + if (instances.size() > 1 && keyboard.isKeyActive(KeyboardConfig::KEY_EMOTE)) { Item *item = mItems->getSelectedItem(); diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index ee6e340f..f40a8109 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -51,7 +51,7 @@ class KeyListModel : public gcn::ListModel /** * Returns the number of elements in container. */ - int getNumberOfElements() override { return keyboard.KEY_TOTAL; } + int getNumberOfElements() override { return KeyboardConfig::KEY_TOTAL; } /** * Returns element from container. @@ -161,7 +161,7 @@ void Setup_Keyboard::action(const gcn::ActionEvent &event) int i(mKeyList->getSelected()); keyboard.setNewKeyIndex(i); refreshAssignedKey(mKeyList->getSelected()); - keyboard.setNewKey(keyboard.KEY_NO_VALUE); + keyboard.setNewKey(KeyboardConfig::KEY_NO_VALUE); mAssignKeyButton->setEnabled(true); } else if (event.getId() == "makeDefault") @@ -174,7 +174,7 @@ void Setup_Keyboard::action(const gcn::ActionEvent &event) void Setup_Keyboard::refreshAssignedKey(int index) { std::string caption; - if (keyboard.getKeyValue(index) == keyboard.KEY_NO_VALUE) + if (keyboard.getKeyValue(index) == KeyboardConfig::KEY_NO_VALUE) caption = keyboard.getKeyCaption(index) + ": "; else { @@ -198,7 +198,7 @@ void Setup_Keyboard::newKeyCallback(int index) void Setup_Keyboard::refreshKeys() { - for (int i = 0; i < keyboard.KEY_TOTAL; i++) + for (int i = 0; i < KeyboardConfig::KEY_TOTAL; i++) { refreshAssignedKey(i); } @@ -209,6 +209,6 @@ void Setup_Keyboard::keyUnresolved() if (mKeySetting) { newKeyCallback(keyboard.getNewKeyIndex()); - keyboard.setNewKeyIndex(keyboard.KEY_NO_VALUE); + keyboard.setNewKeyIndex(KeyboardConfig::KEY_NO_VALUE); } } diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 9c1d2c9f..8fcca014 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -480,10 +480,10 @@ void Viewport::mousePressed(gcn::MouseEvent &event) { if (local_player->withinRange(mHoverBeing, local_player->getAttackRange()) - || keyboard.isKeyActive(keyboard.KEY_ATTACK)) + || keyboard.isKeyActive(KeyboardConfig::KEY_ATTACK)) { local_player->attack(mHoverBeing, - !keyboard.isKeyActive(keyboard.KEY_TARGET)); + !keyboard.isKeyActive(KeyboardConfig::KEY_TARGET)); } else { diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index d9c65dd7..17f5c453 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -242,7 +242,7 @@ std::string getHostNameFromURL(const std::string &url) // Parse out any "http://", "ftp://", ect... size_t pos = myHostName.find("://"); - if (pos == myHostName.npos) + if (pos == std::string::npos) { logger->log("Warning: no protocol was specified for the url: %s", url.c_str()); @@ -257,7 +257,7 @@ std::string getHostNameFromURL(const std::string &url) // Remove possible trailing port (i.e.: localhost:8000 -> localhost) pos = myHostName.find(":"); - if (pos != myHostName.npos) + if (pos != std::string::npos) myHostName = myHostName.substr(0, pos); // remove possible other junk -- cgit v1.2.3-70-g09d2