Delete crates/border-wars/src/map/renderer.rs
All checks were successful
Rust Checks / checks (push) Successful in 1m12s
Rust Checks / checks (pull_request) Successful in 1m11s

This commit is contained in:
CoCo_Sol 2024-02-21 17:53:04 +00:00
parent b77061fed2
commit c34fc16753

View file

@ -1,56 +0,0 @@
//! All functions related to the rendering of the map.
use bevy::prelude::*;
use super::Tile;
use crate::map::TilePosition;
/// A plugin to render the map.
pub struct RendererPlugin;
impl Plugin for RendererPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup_camera).add_systems(
Update,
render_map.run_if(in_state(crate::CurrentScene::Game)),
);
}
}
/// Sets up the camera.
fn setup_camera(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
}
impl Tile {
/// Returns the texture handle of the tile.
pub fn get_texture(&self, asset_server: &AssetServer) -> Handle<Image> {
match self {
Tile::Grass => asset_server.load("tiles/grass.png"),
Tile::Forest => asset_server.load("tiles/forest.png"),
Tile::Hill => asset_server.load("tiles/hill.png"),
}
}
}
/// Renders the map.
fn render_map(
query: Query<(Entity, &TilePosition, &Tile), Changed<Tile>>,
mut commands: Commands,
asset_server: Res<AssetServer>,
) {
for (entity, position, tile) in query.iter() {
let pixel_position_ratio = position.to_pixel_coordinates();
let pixel_position = (50. * pixel_position_ratio.x, pixel_position_ratio.y * 30.);
commands.entity(entity).insert(SpriteBundle {
transform: Transform::from_translation(Vec3 {
x: pixel_position.0,
y: pixel_position.1,
z: 0.,
}),
texture: tile.get_texture(&*asset_server),
..default()
});
}
}