codecraft 0.1.2

A minimalist 3D game engine built on parts of Bevy (ECS, color) with wgpu and winit: OpenPBR materials, clustered lighting, a yakui-drawn UI, audio and gamepad haptics; its binary maps any folder, and the symbols of its Rust files, as a 3D wall of boxes
Documentation
use crate::ecs::{Component, Entity, World};
use crate::scene::SceneEntity;
use crate::scene::Spawn;
use crate::ui::Color;
use crate::ui::icons::path;
use crate::{Category, SceneObject};

/// The ground grid: an infinite plane of lines drawn by the shader, a pixel wide at any distance.
///
/// ```no_run
/// # use codecraft::{AppState, gizmos};
/// # fn demo(app: &mut AppState) {
/// app.spawn(gizmos::grid());
/// # }
/// ```
#[derive(Component, Clone, Copy, Debug)]
pub struct Grid {
    pub spacing: f32,
    pub major_every: f32,
    pub height: f32,
    pub fade_from: f32,
    pub fade_to: f32,
    pub line: Color,
    pub major_line: Color,
    /// The axis lines through the origin, coloured as in Blender.
    pub x_axis: Color,
    pub z_axis: Color,
}

impl Default for Grid {
    fn default() -> Self {
        Self {
            spacing: 1.0,
            major_every: 10.0,
            height: 0.0,
            fade_from: 30.0,
            fade_to: 90.0,
            line: Color::srgba(0.45, 0.45, 0.50, 0.45),
            major_line: Color::srgba(0.62, 0.62, 0.68, 0.75),
            x_axis: Color::srgba(0.80, 0.25, 0.30, 0.95),
            z_axis: Color::srgba(0.25, 0.42, 0.85, 0.95),
        }
    }
}

impl Grid {
    pub fn spacing(mut self, units: f32) -> Self {
        self.spacing = units;
        self
    }

    pub fn at_height(mut self, y: f32) -> Self {
        self.height = y;
        self
    }

    pub fn fade(mut self, from: f32, to: f32) -> Self {
        self.fade_from = from;
        self.fade_to = to;
        self
    }
}

pub fn grid() -> Grid {
    Grid::default()
}

impl Spawn for Grid {
    type Output = Entity;

    fn spawn(self, world: &mut World) -> Entity {
        world
            .spawn((
                self,
                SceneEntity,
                // The nine-cell grid icon is not compiled in.
                SceneObject::new("Grid", path::GRID_FOUR, Category::Utilities),
            ))
            .id()
    }
}