From ac86dee3a6c6c6d422624a7d7ae6df3165565481 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Mon, 7 Mar 2022 23:44:36 -0500 Subject: [PATCH] tests: Add a library defining the file format for Ruffle test input. I intend to share this code across both Ruffle and FlashTAS (another project that allows running input tests on Flash Player), hence why it's a separate library from Ruffle's tests crate. --- Cargo.lock | 7 ++++++ Cargo.toml | 1 + tests/input-format/Cargo.toml | 9 ++++++++ tests/input-format/src/lib.rs | 40 +++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 tests/input-format/Cargo.toml create mode 100644 tests/input-format/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 9e12fe818..556edac51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2987,6 +2987,13 @@ dependencies = [ "serde", ] +[[package]] +name = "ruffle-input-format" +version = "0.1.0" +dependencies = [ + "serde", +] + [[package]] name = "ruffle_core" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 0b32ba121..8a37ffc6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ members = [ "render/webgl", "tests", + "tests/input-format", ] resolver = "2" diff --git a/tests/input-format/Cargo.toml b/tests/input-format/Cargo.toml new file mode 100644 index 000000000..800d4d74b --- /dev/null +++ b/tests/input-format/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "ruffle-input-format" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { version = "1.0.136", features = ["derive"] } \ No newline at end of file diff --git a/tests/input-format/src/lib.rs b/tests/input-format/src/lib.rs new file mode 100644 index 000000000..639e78939 --- /dev/null +++ b/tests/input-format/src/lib.rs @@ -0,0 +1,40 @@ +use serde::{Deserialize, Serialize}; + +/// Position of a mouse cursor on the screen. +/// +/// Mouse cursor positions are sized relative to the Flash stage's dimensions, +/// regardless of the native window's size or pixel density. For example, a +/// (640x480) stage movie on a 2x display (on platforms that report physical +/// pixels) or at 2x the size will see mouse clicks at its bottom right corner +/// on (1280x960), relative to the window. That coordinate needs to be scaled +/// down to match the desired stage. +#[derive(Serialize, Deserialize)] +pub struct MousePosition(f64, f64); + +/// Which mouse button is being pressed or released. +#[derive(Serialize, Deserialize)] +pub enum MouseButton { + Left, + Middle, + Right, +} + +/// All automated event types supported by FlashTAS. +/// +/// A FlashTAS input file consists of a string of `AutomatedEvent`s which are +/// played back by FlashTAS. +#[derive(Serialize, Deserialize)] +pub enum AutomatedEvent { + /// End the current frame's input and wait for the next frame before + /// continuing to inject input. + Wait, + + /// Move the mouse to a new cursor position. + MouseMove(MousePosition), + + /// Click a mouse button. + MouseDown(MousePosition, MouseButton), + + /// Release a mouse button. + MouseUp(MousePosition, MouseButton), +}