work in progress
This commit is contained in:
60
designer/src/testing/action_player.h
Normal file
60
designer/src/testing/action_player.h
Normal file
@@ -0,0 +1,60 @@
|
||||
// Action player for replaying recorded UI interactions
|
||||
#pragma once
|
||||
|
||||
#include "action_recorder.h"
|
||||
#include <functional>
|
||||
|
||||
namespace mosis {
|
||||
class IKernel;
|
||||
}
|
||||
|
||||
namespace mosis::testing {
|
||||
|
||||
// Callback for when an action is executed
|
||||
using ActionCallback = std::function<void(const Action&, size_t index)>;
|
||||
|
||||
// Plays back recorded actions
|
||||
class ActionPlayer {
|
||||
public:
|
||||
ActionPlayer() = default;
|
||||
|
||||
// Set the kernel for executing actions
|
||||
void SetKernel(IKernel* kernel) { m_kernel = kernel; }
|
||||
|
||||
// Load actions to play
|
||||
void LoadActions(const std::vector<Action>& actions);
|
||||
void LoadFromFile(const std::string& path);
|
||||
|
||||
// Playback control
|
||||
void Play();
|
||||
void Pause();
|
||||
void Stop();
|
||||
void Reset();
|
||||
|
||||
// Step through one action at a time
|
||||
void StepForward();
|
||||
|
||||
// Update (call each frame)
|
||||
void Update(double delta_time_ms);
|
||||
|
||||
// State
|
||||
bool IsPlaying() const { return m_playing; }
|
||||
bool IsFinished() const { return m_current_index >= m_actions.size(); }
|
||||
size_t GetCurrentIndex() const { return m_current_index; }
|
||||
size_t GetActionCount() const { return m_actions.size(); }
|
||||
|
||||
// Callbacks
|
||||
void SetActionCallback(ActionCallback callback) { m_action_callback = callback; }
|
||||
|
||||
private:
|
||||
void ExecuteAction(const Action& action);
|
||||
|
||||
IKernel* m_kernel = nullptr;
|
||||
std::vector<Action> m_actions;
|
||||
size_t m_current_index = 0;
|
||||
double m_elapsed_time_ms = 0;
|
||||
bool m_playing = false;
|
||||
ActionCallback m_action_callback;
|
||||
};
|
||||
|
||||
} // namespace mosis::testing
|
||||
Reference in New Issue
Block a user