feat: add validation for badapple inputs

This commit is contained in:
2026-02-08 19:46:33 +08:00
parent 2d627a923d
commit e23edaa2e7
5 changed files with 55 additions and 8 deletions

View File

@@ -2,8 +2,9 @@
#include "ui/managers/debug/DebugData.h"
#include "input/InputState.h"
#include "scenes/base/SceneEvent.h"
struct CoreData {
DebugData debugData;
InputState inputState;
SceneType sceneType = SceneType::MainMenuScene;
};

View File

@@ -31,7 +31,7 @@ bool GameApplication::initialize() {
// 输入管理
m_inputManager = std::make_unique<InputManager>(m_coreData.inputState);
m_inputManager = std::make_unique<InputManager>(m_coreData);
// 窗口管理
m_windowManager = std::make_unique<WindowManager>();

View File

@@ -1,7 +1,8 @@
#include "InputManager.h"
InputManager::InputManager(InputState& inputState) :
m_currentInputState(inputState)
InputManager::InputManager(CoreData& coreData) :
m_currentInputState(coreData.inputState),
m_coreData(coreData)
{
}
@@ -31,10 +32,49 @@ SDL_AppResult InputManager::handleInputEvent(const SDL_Event* event) {
static_cast<float>(event->motion.y)};
break;
case SDL_EVENT_KEY_DOWN:
if (event->key.key == SDLK_F11) {
m_currentInputState.isFullscreen = !m_currentInputState.isFullscreen;
switch(event->key.key) {
case SDLK_F11:
m_currentInputState.isFullscreen = !m_currentInputState.isFullscreen;
break;
case SDLK_B:
if (m_coreData.sceneType == SceneType::MainMenuScene) {
m_isStartBadApple = true;
m_badapple.push_back('b');
}
break;
case SDLK_A:
if (m_isStartBadApple) {
m_badapple.push_back('a');
}
break;
case SDLK_D:
if (m_isStartBadApple) {
m_badapple.push_back('d');
}
break;
case SDLK_P:
if (m_isStartBadApple) {
m_badapple.push_back('p');
}
break;
case SDLK_L:
if (m_isStartBadApple) {
m_badapple.push_back('l');
}
break;
case SDLK_E:
if (m_isStartBadApple) {
m_badapple.push_back('e');
if (m_badapple == "badapple") {
m_currentInputState.isBadApplePress = true;
}
m_badapple.clear();
}
break;
}
break;
}
return SDL_APP_CONTINUE;
}

View File

@@ -1,14 +1,18 @@
#pragma once
#include <SDL3/SDL.h>
#include "core/CoreData.h"
#include "InputState.h"
class InputManager {
public:
InputManager(InputState& inputState);
InputManager(CoreData& coreData);
SDL_AppResult handleInputEvent(const SDL_Event* event);
InputState GetInputState() const;
private:
InputState& m_currentInputState;
CoreData& m_coreData;
bool m_isStartBadApple = false;
std::string m_badapple; // 彩蛋
};

View File

@@ -1,6 +1,7 @@
#pragma once
#include <utility>
#include <glm/glm.hpp>
#include <string>
struct InputState
{
glm::vec2 mouseCilckOn;
@@ -8,4 +9,5 @@ struct InputState
glm::vec2 mouseCurrentPosition;
glm::ivec2 mouseCurrentLogicalPosition;
bool isFullscreen = false;
bool isBadApplePress = false;
};