nightshade 0.8.0

A cross-platform data-oriented game engine.
Documentation
pub mod drag_math;
mod modal_transform;
mod update;

pub use modal_transform::{
    cancel_modal_transform, confirm_modal_transform, handle_numeric_input_for_transform,
    start_modal_transform, update_modal_transform,
};
pub use update::update_gizmo;

use super::context::{self, EditorContext};
use crate::prelude::*;

pub fn recreate_gizmo_for_mode(context: &mut EditorContext, world: &mut World) {
    use crate::ecs::gizmos;

    if let Some(old_gizmo) = context.gizmo_interaction.active.take() {
        gizmos::destroy_gizmo(world, &old_gizmo);
    }

    context.gizmo_interaction.hover_axis = None;
    context.gizmo_interaction.drag_mode = crate::ecs::gizmos::GizmoDragMode::None;
}

pub fn update_gizmo_mode_for_coordinate_space(context: &mut EditorContext, world: &mut World) {
    let new_mode = match (context.gizmo_interaction.mode, context.coordinate_space) {
        (
            crate::ecs::gizmos::GizmoMode::GlobalTranslation
            | crate::ecs::gizmos::GizmoMode::LocalTranslation,
            context::CoordinateSpace::World,
        ) => crate::ecs::gizmos::GizmoMode::GlobalTranslation,
        (
            crate::ecs::gizmos::GizmoMode::GlobalTranslation
            | crate::ecs::gizmos::GizmoMode::LocalTranslation,
            context::CoordinateSpace::Local,
        ) => crate::ecs::gizmos::GizmoMode::LocalTranslation,
        _ => context.gizmo_interaction.mode,
    };

    if new_mode != context.gizmo_interaction.mode {
        context.gizmo_interaction.mode = new_mode;
        recreate_gizmo_for_mode(context, world);
    }
}