refactor file locations for readability
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_platform::collections::HashMap;
|
||||
use bevy_platform::time::Instant;
|
||||
|
||||
pub const FLOOR_ID_OFFSET: u32 = 0;
|
||||
pub const FIXTURE_ID_OFFSET: u32 = 500000;
|
||||
|
||||
pub const DEFAULT_TEXTURE: &str = "default.png";
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct Textures {
|
||||
pub handles: HashMap<String, Handle<Image>>,
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct TextureIDs {
|
||||
pub refs: HashMap<u32, String>,
|
||||
}
|
||||
|
||||
const GRASS_FLOOR_PATH: &str = "grass_floor.png";
|
||||
const DIRT_FLOOR_PATH: &str = "dirt_floor.png";
|
||||
const ROCK_FLOOR_PATH: &str = "rock_floor.png";
|
||||
const BEDROCK_FLOOR_PATH: &str = "bedrock_floor.png";
|
||||
const SKY_PATH: &str = "sky.png";
|
||||
const DIRT_WALL_PATH: &str = "dirt_wall.png";
|
||||
const ROCK_WALL_PATH: &str = "rock_wall.png";
|
||||
const BEDROCK_WALL_PATH: &str = "bedrock_wall.png";
|
||||
const LOG_PATH: &str = "log.png";
|
||||
const LEAVES_PATH: &str = "leaves.png";
|
||||
|
||||
pub fn initialize_textures(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
println!("");
|
||||
println!("####################");
|
||||
let start = Instant::now();
|
||||
let mut textures: HashMap<String, Handle<Image>> = HashMap::new();
|
||||
let mut texture_ids: HashMap<u32, String> = HashMap::new();
|
||||
texture_ids.insert(u32::MAX, DEFAULT_TEXTURE.to_string());
|
||||
|
||||
texture_ids.insert(FLOOR_ID_OFFSET, SKY_PATH.to_string());
|
||||
textures.insert(SKY_PATH.to_string(), asset_server.load(SKY_PATH));
|
||||
texture_ids.insert(FLOOR_ID_OFFSET + 1, GRASS_FLOOR_PATH.to_string());
|
||||
textures.insert(
|
||||
GRASS_FLOOR_PATH.to_string(),
|
||||
asset_server.load(GRASS_FLOOR_PATH),
|
||||
);
|
||||
texture_ids.insert(FLOOR_ID_OFFSET + 2, DIRT_FLOOR_PATH.to_string());
|
||||
textures.insert(
|
||||
DIRT_FLOOR_PATH.to_string(),
|
||||
asset_server.load(DIRT_FLOOR_PATH),
|
||||
);
|
||||
texture_ids.insert(FLOOR_ID_OFFSET + 3, ROCK_FLOOR_PATH.to_string());
|
||||
textures.insert(
|
||||
ROCK_FLOOR_PATH.to_string(),
|
||||
asset_server.load(ROCK_FLOOR_PATH),
|
||||
);
|
||||
texture_ids.insert(FLOOR_ID_OFFSET + 4, BEDROCK_FLOOR_PATH.to_string());
|
||||
textures.insert(
|
||||
BEDROCK_FLOOR_PATH.to_string(),
|
||||
asset_server.load(BEDROCK_FLOOR_PATH),
|
||||
);
|
||||
|
||||
texture_ids.insert(FIXTURE_ID_OFFSET + 1, DIRT_WALL_PATH.to_string());
|
||||
textures.insert(
|
||||
DIRT_WALL_PATH.to_string(),
|
||||
asset_server.load(DIRT_WALL_PATH),
|
||||
);
|
||||
texture_ids.insert(FIXTURE_ID_OFFSET + 2, ROCK_WALL_PATH.to_string());
|
||||
textures.insert(
|
||||
ROCK_WALL_PATH.to_string(),
|
||||
asset_server.load(ROCK_WALL_PATH),
|
||||
);
|
||||
texture_ids.insert(FIXTURE_ID_OFFSET + 3, BEDROCK_WALL_PATH.to_string());
|
||||
textures.insert(
|
||||
BEDROCK_WALL_PATH.to_string(),
|
||||
asset_server.load(BEDROCK_WALL_PATH),
|
||||
);
|
||||
texture_ids.insert(FIXTURE_ID_OFFSET + 4, LOG_PATH.to_string());
|
||||
textures.insert(LOG_PATH.to_string(), asset_server.load(LOG_PATH));
|
||||
texture_ids.insert(FIXTURE_ID_OFFSET + 5, LEAVES_PATH.to_string());
|
||||
textures.insert(LEAVES_PATH.to_string(), asset_server.load(LEAVES_PATH));
|
||||
|
||||
commands.insert_resource(Textures { handles: textures });
|
||||
commands.insert_resource(TextureIDs { refs: texture_ids });
|
||||
println!("Textures initialized in {:.2?}", start.elapsed());
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod management;
|
||||
|
||||
pub use management::*;
|
||||
Reference in New Issue
Block a user