Implemented an initial cut at the event router. Its job is to take the random events from SFML and translate them into nice clean orderly events to the Gui::FSM.

This commit is contained in:
Zed A. Shaw 2025-06-04 12:19:24 -04:00
parent 5c47a0151c
commit 0674908e49
8 changed files with 184 additions and 6 deletions

56
tests/event_router.cpp Normal file
View file

@ -0,0 +1,56 @@
#include <catch2/catch_test_macros.hpp>
#include <fmt/core.h>
#include <string>
#include "event_router.hpp"
using namespace fmt;
using enum routing::Event;
using enum routing::State;
using EventScript = std::vector<routing::Event>;
void run_script(routing::Router& router, routing::State expected, EventScript script) {
for(auto ev : script) {
router.event(ev);
}
REQUIRE(router.in_state(expected));
}
TEST_CASE("basic router operations test", "[event_router]") {
routing::Router router;
// start goes to idle
run_script(router, IDLE, {
STARTED
});
// simulate drag and drop
run_script(router, IDLE, {
MOUSE_DOWN,
MOUSE_MOVE,
MOUSE_UP,
KEY_PRESS
});
// moving the mouse outside dnd
run_script(router, IDLE, {
MOUSE_MOVE,
KEY_PRESS,
MOUSE_MOVE
});
// regular mouse click
run_script(router, IDLE, {
MOUSE_DOWN,
MOUSE_UP
});
// possible bad key press in a move?
run_script(router, IDLE, {
MOUSE_DOWN,
MOUSE_MOVE,
KEY_PRESS,
MOUSE_UP,
});
}