use bevy::prelude::*; use bevy_lospec::{Palette, PalettePlugin}; #[derive(Resource, Deref)] struct RusticPalette(Handle); // see https://github.com/NiklasEi/bevy_asset_loader for a better way to load impl FromWorld for RusticPalette { fn from_world(world: &mut World) -> Self { let asset_server = world .get_resource::() .expect("no asset server"); Self(asset_server.load("rustic-gb.json")) } } fn main() { App::new() .add_plugins((DefaultPlugins, PalettePlugin)) .init_resource::() .add_systems(Startup, setup) .add_systems(Update, spawn_sprites) .run(); } fn setup(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); } fn spawn_sprites( mut spawned: Local, mut commands: Commands, palettes: Res>, rustic_palette: Res, ) { if *spawned { return; } if let Some(palette) = palettes.get(rustic_palette.id()) { let tile_size = 40.; let num_colors = palette.iter().count(); let left_side = -((num_colors - 1) as f32 / 2.) * tile_size; for (i, &color) in palette.iter().enumerate() { info!("{color:?}"); // todo: spawn sprites here commands.spawn(SpriteBundle { transform: Transform::from_xyz(left_side + i as f32 * tile_size, 0., 0.), sprite: Sprite { color, custom_size: Some(Vec2::splat(tile_size)), ..default() }, ..default() }); } *spawned = true; } }