diff --git a/src/map.rs b/src/map.rs index daeec26..fd44c50 100644 --- a/src/map.rs +++ b/src/map.rs @@ -1,6 +1,6 @@ use bevy::{ app::{Plugin, Update}, - asset::{AssetServer, Assets, Handle, LoadedFolder}, + asset::{AssetServer, Assets, Handle}, color::Color, hierarchy::{BuildChildren, DespawnRecursiveExt}, math::{UVec2, Vec2, Vec3}, @@ -20,38 +20,16 @@ const MAX_OFFSET: f32 = ((CHUNKS_TO_LOAD * CHUNK_WIDTH * BLOCK_SIZE) / 2) as f32 pub struct MapPlugin; -#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, States)] -enum AppState { - #[default] - Setup, - Finished, -} - impl Plugin for MapPlugin { fn build(&self, app: &mut bevy::prelude::App) { - app.init_state::() - .add_systems(OnEnter(AppState::Setup), initialize) - .add_systems( - Update, - ( - check_textures.run_if(in_state(AppState::Setup)), - map_movement.run_if(in_state(AppState::Finished)), - ) - .chain(), - ) - .add_systems( - OnEnter(AppState::Finished), - (load_textures, startup).chain(), - ); + app.add_systems(Startup, (initialize, load_textures, startup).chain()) + .add_systems(Update, map_movement); } } #[derive(Resource)] pub struct CurrentChunkOffset(usize); -#[derive(Resource)] -struct TilesFolder(Handle); - #[derive(Resource)] struct Tiles { standard: Handle, @@ -81,10 +59,8 @@ enum SolidBlock { Earth, } -fn initialize(mut commands: Commands, asset_server: Res) { +fn initialize(mut commands: Commands) { commands.insert_resource(CurrentChunkOffset(CHUNK_INITIAL_OFFSET)); - let tiles_folder = TilesFolder(asset_server.load_folder("bgp_catdev/Tillesets")); - commands.insert_resource(tiles_folder); } fn load_textures( @@ -100,19 +76,6 @@ fn load_textures( }); } -fn check_textures( - mut next_state: ResMut>, - tiles_folder: Res, - mut events: EventReader>, -) { - // Advance the `AppState` once all sprite handles have been loaded by the `AssetServer` - for event in events.read() { - if event.is_loaded_with_dependencies(&tiles_folder.0) { - next_state.set(AppState::Finished); - } - } -} - fn startup( mut commands: Commands, game_world: Res,