mirror of
https://github.com/Xevion/smart-rgb.git
synced 2025-12-06 01:16:24 -06:00
38 lines
1.8 KiB
Rust
38 lines
1.8 KiB
Rust
use borders_core::game::terrain::data::{MapManifest, MapMetadata, TerrainData, TileType};
|
|
use borders_core::game::world::tilemap::TileMap;
|
|
|
|
fn create_test_terrain(width: usize, height: usize) -> TerrainData {
|
|
let tile_types = vec![TileType { name: "water".to_string(), color_base: "blue".to_string(), color_variant: 0, conquerable: false, navigable: true, expansion_time: 255, expansion_cost: 255 }, TileType { name: "land".to_string(), color_base: "green".to_string(), color_variant: 0, conquerable: true, navigable: false, expansion_time: 50, expansion_cost: 50 }];
|
|
|
|
let mut terrain_data_raw = vec![0; width * height];
|
|
terrain_data_raw[5] = 0x80; // Make position 5 land
|
|
terrain_data_raw[10] = 0x85; // Make position 10 land with magnitude 5
|
|
|
|
let tiles: Vec<u8> = terrain_data_raw.iter().map(|&byte| if byte & 0x80 != 0 { 1 } else { 0 }).collect();
|
|
|
|
let terrain_data = TileMap::from_vec(width as u16, height as u16, terrain_data_raw);
|
|
|
|
TerrainData { _manifest: MapManifest { map: MapMetadata { size: glam::U16Vec2::new(width as u16, height as u16), num_land_tiles: 2 }, name: "Test".to_string(), nations: Vec::new() }, terrain_data, tiles, tile_types }
|
|
}
|
|
|
|
#[test]
|
|
fn test_is_land() {
|
|
let terrain = create_test_terrain(10, 10);
|
|
assert!(!terrain.is_land(glam::U16Vec2::new(0, 0)));
|
|
assert!(terrain.is_land(glam::U16Vec2::new(5, 0)));
|
|
}
|
|
|
|
#[test]
|
|
fn test_is_conquerable() {
|
|
let terrain = create_test_terrain(10, 10);
|
|
assert!(!terrain.is_conquerable(glam::U16Vec2::new(0, 0)));
|
|
assert!(terrain.is_conquerable(glam::U16Vec2::new(5, 0)));
|
|
}
|
|
|
|
#[test]
|
|
fn test_is_navigable() {
|
|
let terrain = create_test_terrain(10, 10);
|
|
assert!(terrain.is_navigable(glam::U16Vec2::new(0, 0)));
|
|
assert!(!terrain.is_navigable(glam::U16Vec2::new(5, 0)));
|
|
}
|