pub mod player; pub mod layout; pub mod input; pub mod inventory; #[cfg(test)] mod tests; use bevy::prelude::*; use leafwing_input_manager::prelude::*; use serde::{Deserialize, Serialize}; pub struct ExpeditionPlugin; #[derive(Actionlike, PartialEq, Eq, Hash, Debug, Clone, Reflect, Serialize, Deserialize)] pub enum InputAction { #[actionlike(Axis)] Move, ToggleInventory, Interact, } impl InputAction { pub fn default_input_map() -> InputMap { let input_map = InputMap::default() .with_axis(Self::Move, VirtualAxis::ad()) .with_axis(Self::Move, GamepadAxis::LeftStickX) .with(Self::ToggleInventory, KeyCode::KeyI) .with(Self::ToggleInventory, GamepadButton::Select) .with(Self::Interact, KeyCode::KeyE) .with(Self::Interact, GamepadButton::East); input_map } } fn camera_bundle() -> impl Bundle { ( Camera2d, Camera { clear_color: ClearColorConfig::Custom(Color::hsl(0.02, 0.67, 0.65)), ..default() }, Projection::Orthographic(OrthographicProjection { scaling_mode: bevy::camera::ScalingMode::FixedVertical { viewport_height: 384., }, scale: 1., ..OrthographicProjection::default_2d() }), ) } fn setup_global(mut commands: Commands) { commands.spawn(camera_bundle()); } impl Plugin for ExpeditionPlugin { fn build(&self, app: &mut App) { app.add_plugins(input::InputAssetPlugin::::default()) .add_systems(Startup, (player::setup_player, setup_global)) .add_systems(Update, player::handle_input); } }