@@ 1,34 1,411 @@
-use crate::textures::{
- AssetStore,
- DirectionalTexture
-};
+use std::collections::HashMap;
+use crate::textures::DirectionalTexture;
+
+static mut CACHE: Option<HashMap<&str, DirectionalTexture>> = None;
#[derive(Eq, Hash, Clone, PartialEq)]
pub enum Block {
- Dirt,
- GrassCenter
+ Bridge,
+
+ BuildingCenter,
+ BuildingCenterBeige,
+ BuildingCorner,
+ BuildingCornerBeige,
+ BuildingDoor,
+ BuildingDoorBeige,
+ BuildingDoorWindows,
+ BuildingDoorWindowsBeige,
+ BuildingWindow,
+ BuildingWindowBeige,
+ BuildingWindows,
+ BuildingWindowsBeige,
+
+ CastleBend,
+ CastleCenter,
+ CastleCorner,
+ CastleGate,
+ CastleGateOpen,
+ CastleSlope,
+ CastleTower,
+ CastleTowerBeige,
+ CastleTowerBrown,
+ CastleTowerGreen,
+ CastleTowerPurple,
+ CastleWall,
+ CastelWindow,
+
+ DirtCenter,
+ DirtLow,
+
+ GrassCenter,
+ GrassCorner,
+ GrassPath,
+ GrassPathBend,
+ GrassPathCorner,
+ GrassPathCrossing,
+ GrassPathEnd,
+ GrassPathEndSquare,
+ GrassPathSlope,
+ GrassPathSplit,
+ GrassRiver,
+ GrassRiverBend,
+ GrassRiverBridge,
+ GrassRiverCorner,
+ GrassRiverCrossing,
+ GrassRiverEnd,
+ GrassRiverEndSquare,
+ GrassRiverSlope,
+ GrassRiverSplit,
+ GrassSlope,
+ GrassSlopeConcave,
+ GrassSlopeConvex,
+ GrassWater,
+ GrassWaterConcave,
+ GrassWaterConvex,
+ GrassWaterRiver,
+
+ RocksDirt,
+ RocksGrass,
+
+ RoofChurchBeige,
+ RoofChuchBrown,
+ RoofChurchGreen,
+ RoofChurchPurple,
+ RoofGableBeige,
+ RoofGableBrown,
+ RoofGableGreen,
+ RoofGablePurple,
+ RoofPointBeige,
+ RoofPointBrown,
+ RoofPointGreen,
+ RoofPointPurple,
+ RoofRoundBeige,
+ RoofRoundBrown,
+ RoofRoundGreen,
+ RoofRoundPurple,
+ RoofRoundedBeige,
+ RoofRoundedBrown,
+ RoofRoundedGreen,
+ RoofRoundedPurple,
+ RoofSlantBeige,
+ RoofSlantBrown,
+ RoofSlantGreen,
+ RoofSlantPurple,
+
+ StructureArch,
+ StructureHigh,
+ StructureLow,
+
+ /// tree_multiple_
+ Trees,
+ /// tree_single_
+ Tree,
+
+ WaterCenter,
+ WaterFall
}
impl Block {
/// returns the texture for the block
- /// with the direction the block is facing
- pub fn get_texture<'a>(&self, assets: &'a AssetStore) -> &'a DirectionalTexture {
- match self {
- Block::Dirt => &assets.blocks.dirt,
- Block::GrassCenter => &assets.blocks.grass_center
+ pub async fn get_texture(&self) -> DirectionalTexture {
+ let file_name = match self {
+ Block::Bridge => "bridge",
+ Block::BuildingCenter => "building_center",
+ Block::BuildingCenterBeige => "building_centerBeige",
+ Block::BuildingCorner => "building_corner",
+ Block::BuildingCornerBeige => "building_cornerBeige",
+ Block::BuildingDoor => "building_door",
+ Block::BuildingDoorBeige => "building_doorBeige",
+ Block::BuildingDoorWindows => "building_doorWindows",
+ Block::BuildingDoorWindowsBeige => "building_doorWindowsBeige",
+ Block::BuildingWindow => "building_window",
+ Block::BuildingWindowBeige => "building_windowBeige",
+ Block::BuildingWindows => "building_windows",
+ Block::BuildingWindowsBeige => "building_windowsBeige",
+
+ Block::CastleBend => "castle_bend",
+ Block::CastleCenter => "castle_center",
+ Block::CastleCorner => "castle_corner",
+ Block::CastleGate => "castle_gate",
+ Block::CastleGateOpen => "castle_gateOpen",
+ Block::CastleSlope => "castle_slope",
+ Block::CastleTower => "castle_tower",
+ Block::CastleTowerBeige => "castle_towerBeige",
+ Block::CastleTowerBrown => "castle_towerBrown",
+ Block::CastleTowerGreen => "castle_towerGreen",
+ Block::CastleTowerPurple => "castle_towerPurple",
+ Block::CastleWall => "castle_wall",
+ Block::CastelWindow => "castle_window",
+
+ Block::DirtCenter => "dirt_center",
+ Block::DirtLow => "dirt_low",
+
+ Block::GrassCenter => "grass_center",
+ Block::GrassCorner => "grass_corner",
+ Block::GrassPath => "grass_path",
+ Block::GrassPathBend => "grass_pathBend",
+ Block::GrassPathCorner => "grass_pathCorner",
+ Block::GrassPathCrossing => "grass_pathCrossing",
+ Block::GrassPathEnd => "grass_pathEnd",
+ Block::GrassPathEndSquare => "grass_pathEndSquare",
+ Block::GrassPathSlope => "grass_pathSlope",
+ Block::GrassPathSplit => "grass_pathSplit",
+ Block::GrassRiver => "grass_river",
+ Block::GrassRiverBend => "grass_riverBend",
+ Block::GrassRiverBridge => "grass_riverBridge",
+ Block::GrassRiverCorner => "grass_riverCorner",
+ Block::GrassRiverCrossing => "grass_riverCrossing",
+ Block::GrassRiverEnd => "grass_riverEnd",
+ Block::GrassRiverEndSquare => "grass_riverEndSquare",
+ Block::GrassRiverSlope => "grass_riverSlope",
+ Block::GrassRiverSplit => "grass_riverSplit",
+ Block::GrassSlope => "grass_slope",
+ Block::GrassSlopeConcave => "grass_slopeConcave",
+ Block::GrassSlopeConvex => "grass_slopeConvex",
+ Block::GrassWater => "grass_water",
+ Block::GrassWaterConcave => "grass_waterConcave",
+ Block::GrassWaterConvex => "grass_waterConvex",
+ Block::GrassWaterRiver => "grass_waterRiver",
+
+ Block::RocksDirt => "rocks_dirt",
+ Block::RocksGrass => "rocks_grass",
+
+ Block::RoofChurchBeige => "roof_churchBeige",
+ Block::RoofChuchBrown => "roof_churchBrown",
+ Block::RoofChurchGreen => "roof_churchGreen",
+ Block::RoofChurchPurple => "roof_churchPurple",
+ Block::RoofGableBeige => "roof_gableBeige",
+ Block::RoofGableBrown => "roof_gableBrown",
+ Block::RoofGableGreen => "roof_gableGreen",
+ Block::RoofGablePurple => "roof_gablePurple",
+ Block::RoofPointBeige => "roof_pointBeige",
+ Block::RoofPointBrown => "roof_pointBrown",
+ Block::RoofPointGreen => "roof_pointGreen",
+ Block::RoofPointPurple => "roof_pointPurple",
+ Block::RoofRoundBeige => "roof_roundBeige",
+ Block::RoofRoundBrown => "roof_roundBrown",
+ Block::RoofRoundGreen => "roof_roundGreen",
+ Block::RoofRoundPurple => "roof_roundPurple",
+ Block::RoofRoundedBeige => "roof_roundedBeige",
+ Block::RoofRoundedBrown => "roof_roundedBrown",
+ Block::RoofRoundedGreen => "roof_roundedGreen",
+ Block::RoofRoundedPurple => "roof_roundedPurple",
+ Block::RoofSlantBeige => "roof_slantBeige",
+ Block::RoofSlantBrown => "roof_slantBrown",
+ Block::RoofSlantGreen => "roof_slantGreen",
+ Block::RoofSlantPurple => "roof_slantPurple",
+
+ Block::StructureArch => "structure_arch",
+ Block::StructureHigh => "structure_high",
+ Block::StructureLow => "structure_low",
+
+ Block::Trees => "tree_multiple",
+ Block::Tree => "tree_single",
+
+ Block::WaterCenter => "water_center",
+ Block::WaterFall => "water_fall"
+ };
+
+
+ unsafe {
+ if CACHE.is_none() {
+ CACHE = Some(HashMap::new());
+ }
+
+ if let Some(map) = &CACHE {
+ if let Some(tx) = map.get(file_name) {
+ return tx.clone();
+ }
+ }
+ };
+
+ let texture = DirectionalTexture::from_auto_png(file_name).await;
+
+ unsafe {
+ if let Some(map) = &mut CACHE {
+ map.insert(file_name, texture.clone());
+ }
}
+
+ return texture.clone();
}
/// returns a list of all blocks
pub fn all() -> Vec<Block> {
vec![
- Block::Dirt,
- Block::GrassCenter
+ Block::Bridge,
+ Block::BuildingCenter,
+ Block::BuildingCenterBeige,
+ Block::BuildingCorner,
+ Block::BuildingCornerBeige,
+ Block::BuildingDoor,
+ Block::BuildingDoorBeige,
+ Block::BuildingDoorWindows,
+ Block::BuildingDoorWindowsBeige,
+ Block::BuildingWindow,
+ Block::BuildingWindowBeige,
+ Block::BuildingWindows,
+ Block::BuildingWindowsBeige,
+ Block::CastleBend,
+ Block::CastleCenter,
+ Block::CastleCorner,
+ Block::CastleGate,
+ Block::CastleGateOpen,
+ Block::CastleSlope,
+ Block::CastleTower,
+ Block::CastleTowerBeige,
+ Block::CastleTowerBrown,
+ Block::CastleTowerGreen,
+ Block::CastleTowerPurple,
+ Block::CastleWall,
+ Block::CastelWindow,
+ Block::DirtCenter,
+ Block::DirtLow,
+ Block::GrassCenter,
+ Block::GrassCorner,
+ Block::GrassPath,
+ Block::GrassPathBend,
+ Block::GrassPathCorner,
+ Block::GrassPathCrossing,
+ Block::GrassPathEnd,
+ Block::GrassPathEndSquare,
+ Block::GrassPathSlope,
+ Block::GrassPathSplit,
+ Block::GrassRiver,
+ Block::GrassRiverBend,
+ Block::GrassRiverBridge,
+ Block::GrassRiverCorner,
+ Block::GrassRiverCrossing,
+ Block::GrassRiverEnd,
+ Block::GrassRiverEndSquare,
+ Block::GrassRiverSlope,
+ Block::GrassRiverSplit,
+ Block::GrassSlope,
+ Block::GrassSlopeConcave,
+ Block::GrassSlopeConvex,
+ Block::GrassWater,
+ Block::GrassWaterConcave,
+ Block::GrassWaterConvex,
+ Block::GrassWaterRiver,
+ Block::RocksDirt,
+ Block::RocksGrass,
+ Block::RoofChurchBeige,
+ Block::RoofChuchBrown,
+ Block::RoofChurchGreen,
+ Block::RoofChurchPurple,
+ Block::RoofGableBeige,
+ Block::RoofGableBrown,
+ Block::RoofGableGreen,
+ Block::RoofGablePurple,
+ Block::RoofPointBeige,
+ Block::RoofPointBrown,
+ Block::RoofPointGreen,
+ Block::RoofPointPurple,
+ Block::RoofRoundBeige,
+ Block::RoofRoundBrown,
+ Block::RoofRoundGreen,
+ Block::RoofRoundPurple,
+ Block::RoofRoundedBeige,
+ Block::RoofRoundedBrown,
+ Block::RoofRoundedGreen,
+ Block::RoofRoundedPurple,
+ Block::RoofSlantBeige,
+ Block::RoofSlantBrown,
+ Block::RoofSlantGreen,
+ Block::RoofSlantPurple,
+ Block::StructureArch,
+ Block::StructureHigh,
+ Block::StructureLow,
+ Block::Trees,
+ Block::Tree,
+ Block::WaterCenter,
+ Block::WaterFall
]
}
pub fn get_name(&self) -> &str {
match self {
- Block::Dirt => "Dirt",
- Block::GrassCenter => "Grass",
+ Block::Bridge => "Bridge",
+ Block::BuildingDoor | Block::BuildingDoorBeige => "Building door",
+ Block::BuildingDoorWindows | Block::BuildingDoorWindowsBeige => "Building door",
+ Block::BuildingCenter | Block::BuildingCenterBeige => "Building",
+ Block::BuildingCorner | Block::BuildingCornerBeige => "Building corner",
+ Block::BuildingWindow | Block::BuildingWindowBeige => "Building window",
+ Block::BuildingWindows | Block::BuildingWindowsBeige => "Building windows",
+ Block::CastleBend => "Castle bend",
+ Block::CastleCenter | Block::CastleCorner => "Castle",
+ Block::CastleGate => "Castle Gate",
+ Block::CastleGateOpen => "Open castle gate",
+ Block::CastleSlope => "Castle slope",
+ Block::CastleTower
+ | Block::CastleTowerBeige
+ | Block::CastleTowerBrown
+ | Block::CastleTowerGreen
+ | Block::CastleTowerPurple => "Castle tower",
+ Block::CastleWall => "Castle wall",
+ Block::CastelWindow => "Castle window",
+
+ Block::DirtCenter | Block::DirtLow => "Dirt",
+ Block::GrassCenter | Block::GrassCorner => "Grass",
+ Block::GrassPath
+ | Block::GrassPathBend
+ | Block::GrassPathCorner
+ | Block::GrassPathCrossing
+ | Block::GrassPathEnd
+ | Block::GrassPathSplit
+ | Block::GrassPathEndSquare => "Grass path",
+ Block::GrassPathSlope => "Grass slope",
+ Block::GrassRiver
+ | Block::GrassRiverBend
+ | Block::GrassRiverBridge
+ | Block::GrassRiverCorner
+ | Block::GrassRiverCrossing
+ | Block::GrassRiverEnd
+ | Block::GrassRiverEndSquare
+ | Block::GrassRiverSplit
+ | Block::GrassRiverSlope => "River",
+ Block::GrassSlope
+ | Block::GrassSlopeConcave
+ | Block::GrassSlopeConvex => "Grass slope",
+ Block::GrassWater
+ | Block::GrassWaterConcave
+ | Block::GrassWaterConvex
+ | Block::GrassWaterRiver => "Grass water",
+ Block::RocksDirt | Block::RocksGrass => "Rocks",
+ Block::RoofChurchBeige
+ | Block::RoofChuchBrown
+ | Block::RoofChurchGreen
+ | Block::RoofChurchPurple => "Church roof",
+ Block::RoofGableBeige
+ | Block::RoofGableBrown
+ | Block::RoofGableGreen
+ | Block::RoofGablePurple => "Gable roof",
+ Block::RoofPointBeige
+ | Block::RoofPointBrown
+ | Block::RoofPointGreen
+ | Block::RoofPointPurple => "Point roof",
+ Block::RoofRoundBeige
+ | Block::RoofRoundBrown
+ | Block::RoofRoundGreen
+ | Block::RoofRoundPurple => "Round roof",
+ Block::RoofRoundedBeige
+ | Block::RoofRoundedBrown
+ | Block::RoofRoundedGreen
+ | Block::RoofRoundedPurple => "Rounded roof",
+ Block::RoofSlantBeige
+ | Block::RoofSlantBrown
+ | Block::RoofSlantGreen
+ | Block::RoofSlantPurple => "Slant roof",
+ Block::StructureArch
+ | Block::StructureHigh
+ | Block::StructureLow => "Scaffold",
+ Block::Trees => "Trees",
+ Block::Tree => "Tree",
+ Block::WaterCenter => "Water",
+ Block::WaterFall => "Waterfall"
}
}
}
+impl Default for Block {
+ fn default() -> Self {
+ Block::StructureHigh
+ }
+}