voxel-framework 0.13.2

A reusable voxel engine framework built on Bevy
Documentation
//! Test automation and inspection: scripted steps, screenshots and remote control.
//!
//! This module lets a program (a test script, a CI job, an AI agent) drive a
//! running game and look at the result without a person at the keyboard.
//!
//! Only [`AutomationId`] is always available. Everything else lives behind the
//! `automation` cargo feature, and even with the feature compiled in nothing
//! runs unless the game adds `AutomationPlugin::enabled(..)`. The framework
//! never reads command-line arguments or environment variables to turn it on:
//! the game decides, typically from a flag of its own.
//!
//! See `docs/automation.md` for the script format and the remote methods.

use bevy::prelude::*;

#[cfg(feature = "automation")]
mod runtime;

#[cfg(feature = "automation")]
pub use runtime::{
    AutomationCondition, AutomationConfig, AutomationPlugin, AutomationScript,
    AutomationScriptError, AutomationStep, DEFAULT_REMOTE_PORT, KeyAction, UiTarget,
};

/// Stable name for a UI element, used to find it from an automation script.
///
/// Attach it to your own buttons and panels so scripts do not depend on the
/// text shown to the player:
///
/// ```rust
/// use bevy::prelude::*;
/// use voxel_framework::prelude::*;
///
/// fn spawn_start_button(mut commands: Commands) {
///     commands.spawn((Button, Text::new("Start"), AutomationId::new("main_menu.start")));
/// }
/// ```
///
/// The component is a plain label. It is compiled regardless of the
/// `automation` feature, so tagging UI needs no `cfg`, and it does nothing on
/// its own.
#[derive(Component, Debug, Clone, PartialEq, Eq, Hash)]
pub struct AutomationId(pub String);

impl AutomationId {
    /// Creates an id from any string-like value.
    pub fn new(id: impl Into<String>) -> Self {
        Self(id.into())
    }

    /// The id as a string slice.
    pub fn as_str(&self) -> &str {
        &self.0
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn automation_id_keeps_its_text() {
        let id = AutomationId::new("pause.resume");
        assert_eq!(id.as_str(), "pause.resume");
        assert_eq!(id, AutomationId("pause.resume".to_string()));
    }
}