use crate::script_engine::InstructionHandler;
#[cfg(feature = "scripts_control_flow")]
mod control_flow;
#[cfg(feature = "scripts_mode")]
mod mode;
#[cfg(feature = "scripts_keyboard")]
mod keyboard;
#[cfg(feature = "scripts_mouse")]
pub mod mouse; #[cfg(feature = "scripts_timing")]
mod timing;
#[cfg(feature = "scripts_terminator")]
mod terminator;
#[cfg(all(feature = "scripts_window", feature = "script_process_context"))]
mod window;
#[cfg(feature = "scripts_terminator")]
pub use terminator::TerminatorHandler;
#[cfg(all(feature = "scripts_window", feature = "script_process_context"))]
pub use window::ActiveHandler;
pub struct InstructionBuilder {
handlers: Vec<Box<dyn InstructionHandler>>,
}
impl InstructionBuilder {
pub fn new() -> Self {
Self {
handlers: Vec::new(),
}
}
#[cfg(feature = "scripts_control_flow")]
pub fn with_control_flow(mut self) -> Self {
self.handlers.push(Box::new(control_flow::LoopHandler));
self.handlers.push(Box::new(terminator::TerminatorHandler));
self.handlers.push(Box::new(control_flow::ContinueHandler));
self.handlers.push(Box::new(control_flow::BreakHandler));
self
}
#[cfg(feature = "scripts_mode")]
pub fn with_mode(mut self) -> Self {
self.handlers.push(Box::new(mode::ModeHandler));
self
}
#[cfg(feature = "scripts_keyboard")]
pub fn with_keyboard(mut self) -> Self {
self.handlers.push(Box::new(keyboard::KeyClickHandler));
self.handlers.push(Box::new(keyboard::KeyDownHandler));
self.handlers.push(Box::new(keyboard::KeyUpHandler));
self
}
#[cfg(feature = "scripts_mouse")]
pub fn with_mouse(mut self) -> Self {
self.handlers.push(Box::new(mouse::ClickHandler));
self.handlers.push(Box::new(mouse::MoveHandler));
self.handlers.push(Box::new(mouse::MoveRelHandler));
self.handlers.push(Box::new(mouse::ScrollUpHandler));
self.handlers.push(Box::new(mouse::ScrollDownHandler));
self.handlers.push(Box::new(mouse::PressHandler));
self.handlers.push(Box::new(mouse::ReleaseHandler));
self
}
#[cfg(feature = "scripts_timing")]
pub fn with_timing(mut self) -> Self {
self.handlers.push(Box::new(timing::SleepHandler));
self.handlers.push(Box::new(timing::TimeHandler));
self
}
#[cfg(all(feature = "scripts_window", feature = "script_process_context"))]
pub fn with_window(mut self) -> Self {
self.handlers.push(Box::new(window::ActiveHandler));
self
}
pub fn build(self) -> Vec<Box<dyn InstructionHandler>> {
self.handlers
}
}
impl Default for InstructionBuilder {
fn default() -> Self {
Self::new()
}
}
pub struct BuiltinInstructions;
impl BuiltinInstructions {
pub fn all() -> Vec<Box<dyn InstructionHandler>> {
let mut builder = InstructionBuilder::new();
#[cfg(feature = "scripts_control_flow")]
{
builder = builder.with_control_flow();
}
#[cfg(feature = "scripts_mode")]
{
builder = builder.with_mode();
}
#[cfg(feature = "scripts_keyboard")]
{
builder = builder.with_keyboard();
}
#[cfg(feature = "scripts_mouse")]
{
builder = builder.with_mouse();
}
#[cfg(feature = "scripts_timing")]
{
builder = builder.with_timing();
}
#[cfg(all(feature = "scripts_window", feature = "script_process_context"))]
{
builder = builder.with_window();
}
#[cfg(feature = "scripts_terminator")]
{
}
builder.build()
}
#[cfg(feature = "scripts_control_flow")]
pub fn minimal() -> Vec<Box<dyn InstructionHandler>> {
InstructionBuilder::new().with_control_flow().build()
}
pub fn builder() -> InstructionBuilder {
InstructionBuilder::new()
}
}
pub fn register_all(registry: &mut crate::script_engine::instruction::InstructionRegistry) {
#[cfg(feature = "scripts_control_flow")]
{
control_flow::init_loop_terminator();
registry.register(control_flow::LoopHandler).ok();
registry.register(terminator::TerminatorHandler).ok();
registry.register(control_flow::ContinueHandler).ok();
registry.register(control_flow::BreakHandler).ok();
}
#[cfg(feature = "scripts_mode")]
{
registry.register(mode::ModeHandler).ok();
}
#[cfg(feature = "scripts_keyboard")]
{
registry.register(keyboard::KeyClickHandler).ok();
registry.register(keyboard::KeyDownHandler).ok();
registry.register(keyboard::KeyUpHandler).ok();
}
#[cfg(feature = "scripts_mouse")]
{
registry.register(mouse::ClickHandler).ok();
registry.register(mouse::MoveHandler).ok();
registry.register(mouse::MoveRelHandler).ok();
registry.register(mouse::ScrollUpHandler).ok();
registry.register(mouse::ScrollDownHandler).ok();
registry.register(mouse::PressHandler).ok();
registry.register(mouse::ReleaseHandler).ok();
}
#[cfg(feature = "scripts_timing")]
{
timing::init_time_terminator();
registry.register(timing::SleepHandler).ok();
registry.register(timing::TimeHandler).ok();
}
}