Initial asset library impl + tile images

This commit is contained in:
Patrick Gelvin
2025-08-24 11:33:31 -07:00
parent b0ddc9236b
commit 7fb798edbe
45 changed files with 85 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 391 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 405 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 442 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 442 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 409 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 410 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B

82
src/assets.rs Normal file
View File

@@ -0,0 +1,82 @@
use bevy::prelude::*;
use std::path::Path;
pub struct TileImage {
name: &'static str,
thumbnail_handle: Handle<Image>,
tile_handle: Handle<Image>,
}
#[derive(Resource)]
pub struct AssetLibrary {
tile_images: Vec<TileImage>,
}
impl AssetLibrary {
fn new(asset_server: &AssetServer) -> Self {
let tile_names = vec![
"corner-ne-1-wall",
"corner-ne-2-walls-south",
"corner-ne-2-walls-west",
"corner-ne-3-walls",
"corner-nw-1-wall",
"corner-nw-2-walls-south",
"corner-nw-2-walls-east",
"corner-nw-3-walls",
"corner-se-1-wall",
"corner-se-2-walls-north",
"corner-se-2-walls-west",
"corner-se-3-walls",
"corner-sw-1-wall",
"corner-sw-2-walls-north",
"corner-sw-2-walls-east",
"corner-sw-3-walls",
"full-0-walls",
"full-1-wall",
"full-2-walls",
"full-3-walls",
"full-4-walls",
];
let tile_images = tile_names
.iter()
.cloned()
.map(|name| {
let thumbnail_path = Path::new("thumbnails").join(name).with_extension("png");
let tile_path = Path::new("tiles").join(name).with_extension("png");
let thumbnail_handle = asset_server.load::<Image>(thumbnail_path);
let tile_handle = asset_server.load::<Image>(tile_path);
TileImage {
name,
thumbnail_handle,
tile_handle,
}
})
.collect();
Self { tile_images }
}
pub fn get_thumbnail(&self, name: &str) -> Option<Handle<Image>> {
self
.tile_images
.iter()
.find(|&tile| tile.name == name)
.map(|tile| tile.thumbnail_handle.clone())
}
pub fn get_tile(&self, name: &str) -> Option<Handle<Image>> {
self
.tile_images
.iter()
.find(|&tile| tile.name == name)
.map(|tile| tile.tile_handle.clone())
}
}
pub fn load_assets(mut commands: Commands, asset_server: Res<AssetServer>) {
let asset_library = AssetLibrary::new(&asset_server);
commands.insert_resource(asset_library);
}

View File

@@ -1,6 +1,7 @@
use bevy::{prelude::*, window::WindowResolution};
use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin};
mod assets;
mod card;
mod constants;
mod widgets;
@@ -16,5 +17,6 @@ fn main() {
}))
.add_plugins(EguiPlugin::default())
.add_plugins(WorldInspectorPlugin::new())
.add_systems(Startup, assets::load_assets)
.run();
}