feat: expand editor scripting asset and viewport flow
This commit is contained in:
@@ -5,16 +5,55 @@
|
||||
#include "Core/PlaySessionController.h"
|
||||
|
||||
#include <XCEngine/Core/Math/Vector3.h>
|
||||
#include <XCEngine/Input/InputManager.h>
|
||||
|
||||
namespace XCEngine::Editor {
|
||||
namespace {
|
||||
|
||||
GameViewInputFrameEvent CreateGameViewInputFrame(
|
||||
bool focused,
|
||||
bool hovered,
|
||||
std::initializer_list<XCEngine::Input::KeyCode> keys = {},
|
||||
std::initializer_list<XCEngine::Input::MouseButton> mouseButtons = {},
|
||||
XCEngine::Math::Vector2 mousePosition = XCEngine::Math::Vector2::Zero(),
|
||||
XCEngine::Math::Vector2 mouseDelta = XCEngine::Math::Vector2::Zero(),
|
||||
float mouseWheel = 0.0f) {
|
||||
GameViewInputFrameEvent event = {};
|
||||
event.focused = focused;
|
||||
event.hovered = hovered;
|
||||
event.mousePosition = mousePosition;
|
||||
event.mouseDelta = mouseDelta;
|
||||
event.mouseWheel = mouseWheel;
|
||||
|
||||
for (const XCEngine::Input::KeyCode key : keys) {
|
||||
const size_t index = static_cast<size_t>(key);
|
||||
if (index < event.keyDown.size()) {
|
||||
event.keyDown[index] = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (const XCEngine::Input::MouseButton button : mouseButtons) {
|
||||
const size_t index = static_cast<size_t>(button);
|
||||
if (index < event.mouseButtonDown.size()) {
|
||||
event.mouseButtonDown[index] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
class PlaySessionControllerTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
XCEngine::Input::InputManager::Get().Shutdown();
|
||||
m_context.GetSceneManager().NewScene("Play Session Scene");
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
m_controller.Detach(m_context);
|
||||
XCEngine::Input::InputManager::Get().Shutdown();
|
||||
}
|
||||
|
||||
EditorContext m_context;
|
||||
PlaySessionController m_controller;
|
||||
};
|
||||
@@ -120,5 +159,82 @@ TEST_F(PlaySessionControllerTest, PauseResumeAndStepRequestsDrivePlayStateMachin
|
||||
m_context.GetEventBus().Unsubscribe<PlayModeResumedEvent>(resumedSubscription);
|
||||
}
|
||||
|
||||
TEST_F(PlaySessionControllerTest, GameViewInputFramesDoNotAffectInputManagerOutsidePlayMode) {
|
||||
m_controller.Attach(m_context);
|
||||
|
||||
m_context.GetEventBus().Publish(CreateGameViewInputFrame(
|
||||
true,
|
||||
true,
|
||||
{XCEngine::Input::KeyCode::A},
|
||||
{XCEngine::Input::MouseButton::Left},
|
||||
XCEngine::Math::Vector2(120.0f, 48.0f),
|
||||
XCEngine::Math::Vector2(3.0f, -2.0f),
|
||||
1.0f));
|
||||
|
||||
m_controller.Update(m_context, 0.016f);
|
||||
|
||||
auto& inputManager = XCEngine::Input::InputManager::Get();
|
||||
EXPECT_FALSE(inputManager.IsKeyDown(XCEngine::Input::KeyCode::A));
|
||||
EXPECT_FALSE(inputManager.IsMouseButtonDown(XCEngine::Input::MouseButton::Left));
|
||||
EXPECT_EQ(inputManager.GetMousePosition(), XCEngine::Math::Vector2::Zero());
|
||||
EXPECT_FLOAT_EQ(inputManager.GetMouseScrollDelta(), 0.0f);
|
||||
|
||||
m_controller.Detach(m_context);
|
||||
}
|
||||
|
||||
TEST_F(PlaySessionControllerTest, GameViewInputFramesDriveAndReleaseRuntimeInputDuringPlayMode) {
|
||||
auto* editorEntity = m_context.GetSceneManager().CreateEntity("Persistent");
|
||||
ASSERT_NE(editorEntity, nullptr);
|
||||
|
||||
m_controller.Attach(m_context);
|
||||
ASSERT_TRUE(m_controller.StartPlay(m_context));
|
||||
|
||||
m_context.GetEventBus().Publish(CreateGameViewInputFrame(
|
||||
true,
|
||||
true,
|
||||
{XCEngine::Input::KeyCode::A, XCEngine::Input::KeyCode::Space},
|
||||
{XCEngine::Input::MouseButton::Left},
|
||||
XCEngine::Math::Vector2(120.0f, 48.0f),
|
||||
XCEngine::Math::Vector2(3.0f, -2.0f),
|
||||
1.0f));
|
||||
|
||||
m_controller.Update(m_context, 0.016f);
|
||||
|
||||
auto& inputManager = XCEngine::Input::InputManager::Get();
|
||||
EXPECT_TRUE(inputManager.IsKeyDown(XCEngine::Input::KeyCode::A));
|
||||
EXPECT_TRUE(inputManager.IsKeyPressed(XCEngine::Input::KeyCode::A));
|
||||
EXPECT_TRUE(inputManager.IsKeyDown(XCEngine::Input::KeyCode::Space));
|
||||
EXPECT_TRUE(inputManager.IsMouseButtonDown(XCEngine::Input::MouseButton::Left));
|
||||
EXPECT_TRUE(inputManager.IsMouseButtonClicked(XCEngine::Input::MouseButton::Left));
|
||||
EXPECT_EQ(inputManager.GetMousePosition(), XCEngine::Math::Vector2(120.0f, 48.0f));
|
||||
EXPECT_EQ(inputManager.GetMouseDelta(), XCEngine::Math::Vector2(3.0f, -2.0f));
|
||||
EXPECT_FLOAT_EQ(inputManager.GetMouseScrollDelta(), 1.0f);
|
||||
|
||||
m_context.GetEventBus().Publish(CreateGameViewInputFrame(
|
||||
true,
|
||||
true,
|
||||
{XCEngine::Input::KeyCode::A, XCEngine::Input::KeyCode::Space},
|
||||
{XCEngine::Input::MouseButton::Left},
|
||||
XCEngine::Math::Vector2(120.0f, 48.0f)));
|
||||
|
||||
m_controller.Update(m_context, 0.016f);
|
||||
|
||||
EXPECT_TRUE(inputManager.IsKeyDown(XCEngine::Input::KeyCode::A));
|
||||
EXPECT_FALSE(inputManager.IsKeyPressed(XCEngine::Input::KeyCode::A));
|
||||
EXPECT_TRUE(inputManager.IsMouseButtonDown(XCEngine::Input::MouseButton::Left));
|
||||
EXPECT_FALSE(inputManager.IsMouseButtonClicked(XCEngine::Input::MouseButton::Left));
|
||||
EXPECT_EQ(inputManager.GetMouseDelta(), XCEngine::Math::Vector2::Zero());
|
||||
EXPECT_FLOAT_EQ(inputManager.GetMouseScrollDelta(), 0.0f);
|
||||
|
||||
m_context.GetEventBus().Publish(GameViewInputFrameEvent{});
|
||||
m_controller.Update(m_context, 0.016f);
|
||||
|
||||
EXPECT_FALSE(inputManager.IsKeyDown(XCEngine::Input::KeyCode::A));
|
||||
EXPECT_FALSE(inputManager.IsKeyDown(XCEngine::Input::KeyCode::Space));
|
||||
EXPECT_FALSE(inputManager.IsMouseButtonDown(XCEngine::Input::MouseButton::Left));
|
||||
|
||||
m_controller.Detach(m_context);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace XCEngine::Editor
|
||||
|
||||
Reference in New Issue
Block a user