nightshade 0.13.3

A cross-platform data-oriented game engine.
Documentation
use crate::ecs::tilemap::components::Tilemap;
use crate::ecs::world::{Entity, World};
use nalgebra_glm::Vec2;

pub fn spawn_tilemap(
    world: &mut World,
    position: Vec2,
    tile_size: Vec2,
    grid_width: u32,
    grid_height: u32,
) -> Entity {
    let entity = world.spawn();
    world.core.add_components(entity, crate::ecs::VISIBILITY);
    world.sprite2d.add_components(entity, crate::ecs::TILEMAP);

    let tilemap = Tilemap::new(position, tile_size, grid_width, grid_height);

    if let Some(existing) = world.sprite2d.get_tilemap_mut(entity) {
        *existing = tilemap;
    }

    if let Some(visibility) = world.core.get_visibility_mut(entity) {
        visibility.visible = true;
    }

    entity
}