1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-09-29 16:55:59 +00:00

Shorten clicks, ensure no lost actions.

This commit is contained in:
Thomas Harte 2024-05-24 15:23:45 -04:00
parent 6407ab0673
commit 7b90c36463

View File

@ -683,9 +683,7 @@ class ConcreteMachine:
std::vector<CursorAction> cursor_actions_; std::vector<CursorAction> cursor_actions_;
struct CursorActionBuilder { struct CursorActionBuilder {
CursorActionBuilder(std::vector<CursorAction> &actions) : actions_(actions) { CursorActionBuilder(std::vector<CursorAction> &actions) : actions_(actions) {}
actions_.clear();
}
CursorActionBuilder &wait(int duration) { CursorActionBuilder &wait(int duration) {
actions_.push_back(CursorAction::wait(duration)); actions_.push_back(CursorAction::wait(duration));
@ -693,13 +691,21 @@ class ConcreteMachine:
} }
CursorActionBuilder &move_to(int x, int y) { CursorActionBuilder &move_to(int x, int y) {
// Special case: if this sets a move_to when one is in progress,
// just update the target.
if(!actions_.empty() && actions_.back().type == CursorAction::Type::MoveTo) {
actions_.back().value.move_to.x = x;
actions_.back().value.move_to.y = y;
return *this;
}
actions_.push_back(CursorAction::move_to(x, y)); actions_.push_back(CursorAction::move_to(x, y));
return *this; return *this;
} }
CursorActionBuilder &click(int button) { CursorActionBuilder &click(int button) {
actions_.push_back(CursorAction::button(button, true)); actions_.push_back(CursorAction::button(button, true));
actions_.push_back(CursorAction::wait(12'000'000)); actions_.push_back(CursorAction::wait(6'000'000));
actions_.push_back(CursorAction::button(button, false)); actions_.push_back(CursorAction::button(button, false));
return *this; return *this;
} }