use bevy::prelude::*; use crate::level::Level; #[derive(States, Debug, Clone, PartialEq, Eq, Hash, Default)] pub enum GameState { #[default] Loading, Main, LoadingSceneData(Level), LoadingLevel(Level), Level(Level) } #[derive(Debug, Clone, PartialEq, Eq, Hash)] struct LoadingLevelState; impl ComputedStates for LoadingLevelState { type SourceStates = GameState; fn compute(sources: Self::SourceStates) -> Option { match sources { GameState::LoadingLevel(_) => Some(LoadingLevelState), _ => None } } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] struct LevelState; impl ComputedStates for LevelState { type SourceStates = GameState; fn compute(sources: Self::SourceStates) -> Option { match sources { GameState::Level(_) => Some(LevelState), _ => None } } } #[derive(Resource)] pub struct GameAssets { pub terminal_primitive0: Handle, pub terminal_primitive1: Handle, pub terminal_chassis_mat: Handle } pub fn plugin(app: &mut App) { app.add_computed_state::() .add_computed_state::() .add_systems(OnEnter(LoadingLevelState), load_terminal); } fn load_terminal(mut commands: Commands, asset_server: Res) { let assets = GameAssets{ terminal_primitive0: asset_server.load("models/terminal.glb#Mesh0/Primitive0"), terminal_primitive1: asset_server.load("models/terminal.glb#Mesh0/Primitive1"), terminal_chassis_mat: asset_server.load("models/terminal.glb#Material0") }; commands.insert_resource(assets); }