Skip to content

Commit

Permalink
Merge pull request #340 from StarArawn/atlas-ci
Browse files Browse the repository at this point in the history
Fixed warning when running the atlas feature. Make sure we CI features.
  • Loading branch information
StarArawn authored Nov 13, 2022
2 parents fafb761 + 77177a9 commit cf1bf2c
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 182 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ jobs:
with:
command: check
args: --all-targets

- name: Run cargo check feature atlas
uses: actions-rs/cargo@v1
with:
command: check
args: --all-targets --features atlas

# test:
# name: Tests
Expand Down Expand Up @@ -63,3 +69,4 @@ jobs:
with:
toolchain: stable
- run: cargo build --examples
- run: cargo build --examples --features atlas
3 changes: 2 additions & 1 deletion .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
args: --all -- --check

clippy:
name: Clippy
Expand All @@ -50,3 +50,4 @@ jobs:
with:
command: clippy
args: --no-deps -- -D warnings

1 change: 1 addition & 0 deletions examples/helpers/camera.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bevy::{input::Input, math::Vec3, prelude::*, render::camera::Camera};

// A simple camera system for moving and zooming the camera.
#[allow(dead_code)]
pub fn movement(
time: Res<Time>,
keyboard_input: Res<Input<KeyCode>>,
Expand Down
197 changes: 105 additions & 92 deletions examples/texture_container.rs
Original file line number Diff line number Diff line change
@@ -1,107 +1,120 @@
use bevy::prelude::*;
use bevy_ecs_tilemap::helpers::hex_grid::axial::AxialPos;
use bevy_ecs_tilemap::prelude::*;
use rand::prelude::SliceRandom;
use rand::thread_rng;
mod helpers;

const MAP_RADIUS: u32 = 10;
const MAP_DIAMETER: u32 = 2 * MAP_RADIUS + 1;
const MAP_CENTER: TilePos = TilePos {
x: MAP_RADIUS + 1,
y: MAP_RADIUS + 1,
};
// const TILE_SIZE: TilemapTileSize = TilemapTileSize { x: 48.0, y: 54.0 };
const TILE_SIZE: TilemapTileSize = TilemapTileSize { x: 48.0, y: 56.0 };
const COORD_SYS: HexCoordSystem = HexCoordSystem::Row;
#[cfg(not(feature = "atlas"))]
mod no_atlas {
use super::helpers;
use bevy::prelude::*;
use bevy_ecs_tilemap::helpers::hex_grid::axial::AxialPos;
use bevy_ecs_tilemap::prelude::*;
use rand::prelude::SliceRandom;
use rand::thread_rng;
const MAP_RADIUS: u32 = 10;
const MAP_DIAMETER: u32 = 2 * MAP_RADIUS + 1;
const MAP_CENTER: TilePos = TilePos {
x: MAP_RADIUS + 1,
y: MAP_RADIUS + 1,
};
// const TILE_SIZE: TilemapTileSize = TilemapTileSize { x: 48.0, y: 54.0 };
const TILE_SIZE: TilemapTileSize = TilemapTileSize { x: 48.0, y: 56.0 };
const COORD_SYS: HexCoordSystem = HexCoordSystem::Row;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
#[cfg(not(feature = "atlas"))]
fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());

// Most of the work is happening bevy side. In this case, using the `ktx2` feature. If this
// feature is not turned on, that the image won't properly be interpreted as a texture
// container. The other alternative is `dds`.
// let texture_vec = TilemapTexture::TextureContainer(asset_server.load("hex-tiles.ktx2"));
// Most of the work is happening bevy side. In this case, using the `ktx2` feature. If this
// feature is not turned on, that the image won't properly be interpreted as a texture
// container. The other alternative is `dds`.
// let texture_vec = TilemapTexture::TextureContainer(asset_server.load("hex-tiles.ktx2"));

// Optionally you can also load in KTX2's as regular single textures:
let texture_vec = TilemapTexture::Vector(vec![
asset_server.load("hex-tile-0.ktx2"),
asset_server.load("hex-tile-1.ktx2"),
asset_server.load("hex-tile-2.ktx2"),
]);
// Optionally you can also load in KTX2's as regular single textures:
let texture_vec = TilemapTexture::Vector(vec![
asset_server.load("hex-tile-0.ktx2"),
asset_server.load("hex-tile-1.ktx2"),
asset_server.load("hex-tile-2.ktx2"),
]);

let map_size = TilemapSize {
x: MAP_DIAMETER,
y: MAP_DIAMETER,
};
let map_size = TilemapSize {
x: MAP_DIAMETER,
y: MAP_DIAMETER,
};

let mut tile_storage = TileStorage::empty(map_size);
let tilemap_entity = commands.spawn_empty().id();
let tilemap_id = TilemapId(tilemap_entity);
let mut tile_storage = TileStorage::empty(map_size);
let tilemap_entity = commands.spawn_empty().id();
let tilemap_id = TilemapId(tilemap_entity);

let tile_positions = generate_hexagon(
AxialPos::from_tile_pos_given_coord_system(&MAP_CENTER, COORD_SYS),
MAP_RADIUS,
)
.into_iter()
.map(|axial_pos| axial_pos.as_tile_pos_given_coord_system(COORD_SYS));
let tile_positions = generate_hexagon(
AxialPos::from_tile_pos_given_coord_system(&MAP_CENTER, COORD_SYS),
MAP_RADIUS,
)
.into_iter()
.map(|axial_pos| axial_pos.as_tile_pos_given_coord_system(COORD_SYS));

let mut rng = thread_rng();
let weighted_tile_choices = [
(TileTextureIndex(0), 0.8),
(TileTextureIndex(1), 0.1),
(TileTextureIndex(2), 0.1),
];
for position in tile_positions {
let texture = weighted_tile_choices
.choose_weighted(&mut rng, |choice| choice.1)
.unwrap()
.0;
let tile_entity = commands
.spawn_empty()
.insert(TileBundle {
position,
tilemap_id,
texture_index: texture,
..Default::default()
})
.id();
tile_storage.set(&position, tile_entity);
}
let mut rng = thread_rng();
let weighted_tile_choices = [
(TileTextureIndex(0), 0.8),
(TileTextureIndex(1), 0.1),
(TileTextureIndex(2), 0.1),
];
for position in tile_positions {
let texture = weighted_tile_choices
.choose_weighted(&mut rng, |choice| choice.1)
.unwrap()
.0;
let tile_entity = commands
.spawn_empty()
.insert(TileBundle {
position,
tilemap_id,
texture_index: texture,
..Default::default()
})
.id();
tile_storage.set(&position, tile_entity);
}

let tile_size = TILE_SIZE;
let grid_size = TILE_SIZE.into();
let map_type = TilemapType::Hexagon(COORD_SYS);
let tile_size = TILE_SIZE;
let grid_size = TILE_SIZE.into();
let map_type = TilemapType::Hexagon(COORD_SYS);

commands.entity(tilemap_entity).insert(TilemapBundle {
grid_size,
map_type,
tile_size,
size: map_size,
storage: tile_storage,
texture: texture_vec,
transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0),
..Default::default()
});
commands.entity(tilemap_entity).insert(TilemapBundle {
grid_size,
map_type,
tile_size,
size: map_size,
storage: tile_storage,
texture: texture_vec,
transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0),
..Default::default()
});
}

pub fn main() {
App::new()
.add_plugins(
DefaultPlugins
.set(WindowPlugin {
window: WindowDescriptor {
width: 1270.0,
height: 720.0,
title: String::from("Using TilemapTexture::TextureContainer"),
..Default::default()
},
..default()
})
.set(ImagePlugin::default_nearest()),
)
.add_plugin(TilemapPlugin)
.add_startup_system(startup)
.add_system(helpers::camera::movement)
.run();
}
}

fn main() {
App::new()
.add_plugins(
DefaultPlugins
.set(WindowPlugin {
window: WindowDescriptor {
width: 1270.0,
height: 720.0,
title: String::from("Using TilemapTexture::TextureContainer"),
..Default::default()
},
..default()
})
.set(ImagePlugin::default_nearest()),
)
.add_plugin(TilemapPlugin)
.add_startup_system(startup)
.add_system(helpers::camera::movement)
.run();
#[cfg(feature = "atlas")]
panic!("Atlas feature does not support texture containers!");

#[cfg(not(feature = "atlas"))]
no_atlas::main();
}
Loading

0 comments on commit cf1bf2c

Please sign in to comment.