refactor!: Split everything into submodules

- Bump version to 0.2.0
- Split every module to systems, observers, plugins, etc
- Renamed Crate to Container
- Removed Wall component
- Removed try_insert_item system
- Removed inventory::ui module
This commit is contained in:
Alexey 2026-03-19 14:23:26 +03:00
commit 7c386d4128
20 changed files with 830 additions and 772 deletions

View file

@ -1,3 +1,12 @@
use bevy::{
prelude::*,
ui_widgets::ScrollbarPlugin
};
use bevy_rapier2d::{
prelude::*,
rapier::prelude::IntegrationParameters
};
pub mod player;
pub mod layout;
pub mod input;
@ -6,28 +15,10 @@ pub mod ui;
#[cfg(test)]
mod tests;
use bevy::{prelude::*, ui_widgets::ScrollbarPlugin};
use bevy_rapier2d::{prelude::*, rapier::prelude::IntegrationParameters};
use leafwing_input_manager::prelude::*;
use serde::{Deserialize, Serialize};
pub const PIXELS_PER_METER: f32 = 16.0;
pub struct ExpeditionPlugin;
#[derive(Actionlike, PartialEq, Eq, Hash, Debug, Clone, Reflect, Serialize, Deserialize)]
pub enum InputAction {
#[actionlike(Axis)]
Move,
ToggleInventory,
Interact,
}
#[derive(Actionlike, PartialEq, Eq, Hash, Debug, Clone, Reflect, Serialize, Deserialize)]
pub enum UiAction {
Rotate,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default, States)]
pub enum GameState {
#[default]
@ -35,26 +26,6 @@ pub enum GameState {
Inventory,
}
impl InputAction {
pub fn default_input_map() -> InputMap<Self> {
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)
}
}
impl UiAction {
pub fn default_input_map() -> InputMap<Self> {
InputMap::default()
.with(Self::Rotate, KeyCode::KeyR)
.with(Self::Rotate, GamepadButton::West)
}
}
pub fn insert_entity_name(names: Query<(Entity, &mut Name), Added<Name>>) {
for (entity, mut name) in names {
name.mutate(|name| name.insert_str(0, format!("{entity}: ").as_str()));
@ -87,8 +58,8 @@ fn setup_global(mut commands: Commands) {
impl Plugin for ExpeditionPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((
input::InputAssetPlugin::<InputAction>::default(),
input::InputAssetPlugin::<UiAction>::default(),
input::plugin::InputAssetPlugin::<input::InputAction>::default(),
input::plugin::InputAssetPlugin::<input::UiAction>::default(),
ScrollbarPlugin,
RapierPhysicsPlugin::<()>::default()
.with_custom_initialization(RapierContextInitialization::InitializeDefaultRapierContext {
@ -107,22 +78,16 @@ impl Plugin for ExpeditionPlugin {
))
.init_state::<GameState>()
.insert_resource(ui::WindowSize::default())
.add_systems(Startup, (player::setup_player, setup_global, layout::setup_world))
.add_systems(Startup, (player::systems::setup_player, setup_global, layout::systems::setup_world))
.add_systems(Update, (
player::handle_input,
player::systems::handle_input,
ui::update_window_size,
ui::handle_input,
insert_entity_name,
layout::detect_interact_collisions,
layout::systems::detect_interact_collisions,
))
.add_systems(OnEnter(GameState::Inventory), inventory::ui::setup_ui_inventory)
.add_systems(OnExit(GameState::Inventory), inventory::ui::clear_ui_inventory)
.register_type::<inventory::Inventory>()
.register_type::<inventory::ActiveInventory>()
.register_type::<inventory::item::Item>()
.register_type::<inventory::ui::UiItem>()
.register_type::<inventory::ui::UiInventorySlot>()
.register_type::<inventory::ui::UiInventory>()
.add_observer(inventory::ui::on_ui_rotate);
.add_systems(OnEnter(GameState::Inventory), ui::inventory::systems::setup_ui_inventory)
.add_systems(OnExit(GameState::Inventory), ui::inventory::systems::clear_ui_inventory)
.add_observer(ui::inventory::observers::on_ui_rotate);
}
}