Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,265 changes: 1,124 additions & 1,141 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ license = "MIT OR Apache-2.0"
default = []

[workspace.dependencies]
bevy = "0.16"
bevy = "0.18.1"
noise = "0.9"
priority-queue = "2.3.1"
leafwing-input-manager = "0.17.0"
bevy-inspector-egui = "0.31"
priority-queue = "2.7.0"
leafwing-input-manager = "0.20.0"
bevy-inspector-egui = "0.36"

[dependencies]
animation = { path = "crates/animation"}
Expand Down
4 changes: 2 additions & 2 deletions crates/assets/src/icon_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ impl IconAsset {

pub fn sprite(&self, index: usize) -> Sprite {
Sprite {
image: self.image.clone_weak(),
image: self.image.clone(),
color: Color::default().with_alpha(0.8),
texture_atlas: Some(TextureAtlas {
layout: self.layout_handle.clone_weak(),
layout: self.layout_handle.clone(),
index,
}),
..default()
Expand Down
2 changes: 1 addition & 1 deletion crates/camera/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn setup(mut commands: Commands) {
input_map,
Camera2d,
CameraLayer(0),
StateScoped(AppState::MainGame),
DespawnOnExit(AppState::MainGame),
));
}

Expand Down
1 change: 0 additions & 1 deletion crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use states::AppState;

pub fn plugin(app: &mut App) {
app.init_state::<AppState>()
.enable_state_scoped_entities::<AppState>()
.add_systems(PostUpdate, systems::apply_world_coordinates)
.register_type::<ImageNodeFade>();
}
4 changes: 2 additions & 2 deletions crates/common/src/traits/ui_root.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use bevy::prelude::*;

pub trait UiRoot {
fn ui_root(&mut self) -> EntityCommands;
fn ui_root(&mut self) -> EntityCommands<'_>;
}

impl UiRoot for Commands<'_, '_> {
fn ui_root(&mut self) -> EntityCommands {
fn ui_root(&mut self) -> EntityCommands<'_> {
self.spawn((
Name::new("Ui Root"),
Node {
Expand Down
37 changes: 19 additions & 18 deletions crates/designations/src/designations.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::{prelude::*, window::PrimaryWindow};
use bevy_inspector_egui::bevy_egui::EguiContexts;
use bevy_inspector_egui::bevy_egui::{EguiContexts, EguiPrimaryContextPass};
use camera::CameraLayer;
use common::{
functions::world_position_to_world_coordinates, states::AppState, types::BlockCoordinates,
Expand All @@ -21,7 +21,7 @@ pub(crate) enum MouseActions {
Dig,
}

#[derive(Event)]
#[derive(Message)]
enum BrushInputEvent {
Designated(BlockCoordinates),
}
Expand All @@ -35,16 +35,16 @@ pub(crate) struct BrushSettings {
pub fn plugin(app: &mut App) {
app.insert_resource(BrushSettings::default())
.add_plugins(InputManagerPlugin::<MouseControls>::default())
.add_event::<BrushInputEvent>()
.add_message::<BrushInputEvent>()
.add_systems(OnEnter(AppState::MainGame), setup_brush)
.add_systems(
Update,
(
handle_brush_input,
handle_brush.after(handle_brush_input),
ui::brushes,
)
(handle_brush_input, handle_brush.after(handle_brush_input))
.run_if(in_state(AppState::MainGame)),
)
.add_systems(
EguiPrimaryContextPass,
ui::brushes.run_if(in_state(AppState::MainGame)),
);
}

Expand All @@ -66,36 +66,37 @@ fn handle_brush_input(
query: Single<&ActionState<MouseControls>>,
window: Single<&Window, With<PrimaryWindow>>,
camera: Single<(&Camera, &GlobalTransform, &CameraLayer), With<Camera>>,
mut brush_event_writer: EventWriter<BrushInputEvent>,
mut brush_event_writer: MessageWriter<BrushInputEvent>,
mut contexts: EguiContexts,
) {
// Skip pointer events that are captured by egui
let ctx = contexts.ctx_mut();
let Ok(ctx) = contexts.ctx_mut() else {
return;
};
if ctx.wants_pointer_input() {
return;
}

let window = window.into_inner();
let action_state = query.into_inner();
let (camera, camera_transform, layer) = camera.into_inner();
if action_state.pressed(&MouseControls::PrimaryAction) {
if let Some(world_position) = window
if action_state.pressed(&MouseControls::PrimaryAction)
&& let Some(world_position) = window
.cursor_position()
.and_then(|cursor| camera.viewport_to_world(camera_transform, cursor).ok())
.map(|ray| ray.origin.truncate())
{
let world_coordinates =
world_position_to_world_coordinates(world_position.extend(layer.0 as f32));
brush_event_writer.write(BrushInputEvent::Designated(world_coordinates));
}
{
let world_coordinates =
world_position_to_world_coordinates(world_position.extend(layer.0 as f32));
brush_event_writer.write(BrushInputEvent::Designated(world_coordinates));
}
}

fn handle_brush(
brush_settings: Res<BrushSettings>,
world_map: Res<WorldMap>,
work_order_queue: Res<WorkOrderQueue>,
mut brush_event_reader: EventReader<BrushInputEvent>,
mut brush_event_reader: MessageReader<BrushInputEvent>,
mut commands: Commands,
) {
for brush_input_event in brush_event_reader.read() {
Expand Down
9 changes: 6 additions & 3 deletions crates/designations/src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use bevy::{prelude::*, window::PrimaryWindow};
use bevy_inspector_egui::{bevy_egui::EguiContext, egui};
use bevy::prelude::*;
use bevy_inspector_egui::{
bevy_egui::{EguiContext, PrimaryEguiContext},
egui,
};

use crate::{BrushSettings, MouseActions};

pub(crate) fn brushes(
mut brush_settings: ResMut<BrushSettings>,
context: Single<&mut EguiContext, With<PrimaryWindow>>,
context: Single<&mut EguiContext, With<PrimaryEguiContext>>,
) {
let mut egui_context = context.into_inner().clone();
egui::TopBottomPanel::bottom("brushes")
Expand Down
10 changes: 3 additions & 7 deletions crates/dwarf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ pub fn plugin(app: &mut App) {
#[require(AnimationConfig, WorldCoordinates)]
pub struct Dwarf;

fn on_add_dwarf(
trigger: Trigger<OnAdd, Dwarf>,
dwarf: Res<DwarfSpriteAsset>,
mut commands: Commands,
) {
commands.entity(trigger.target()).insert((
fn on_add_dwarf(trigger: On<Add, Dwarf>, dwarf: Res<DwarfSpriteAsset>, mut commands: Commands) {
commands.entity(trigger.entity).insert((
Name::new("Dwarf"),
Sprite {
image: dwarf.sprite.clone_weak(),
image: dwarf.sprite.clone(),
texture_atlas: Some(dwarf.texture_atlas.clone()),
..default()
},
Expand Down
9 changes: 3 additions & 6 deletions crates/loading_screen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ pub fn plugin(app: &mut App) {
.add_systems(
Update,
continue_to_title_screen.run_if(all_assets_loaded.and(in_state(AppState::Loading))),
)
.add_systems(OnExit(AppState::Loading), teardown);
);
}

fn setup(mut commands: Commands) {
commands.ui_root().insert((
Name::new("Loading Screen"),
StateScoped(AppState::Loading),
DespawnOnExit(AppState::Loading),
children![(
Node {
justify_content: JustifyContent::Center,
Expand All @@ -26,7 +25,7 @@ fn setup(mut commands: Commands) {
)],
));

commands.spawn((Camera2d, StateScoped(AppState::Loading)));
commands.spawn((Camera2d, DespawnOnExit(AppState::Loading)));
}

fn continue_to_title_screen(mut next_state: ResMut<NextState<AppState>>) {
Expand All @@ -36,5 +35,3 @@ fn continue_to_title_screen(mut next_state: ResMut<NextState<AppState>>) {
fn all_assets_loaded(resource_handles: Res<ResourceHandles>) -> bool {
resource_handles.is_all_done()
}

fn teardown() {}
4 changes: 2 additions & 2 deletions crates/main_game/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ fn setup(mut commands: Commands) {
}

fn add_vis_to_work_order(
trigger: Trigger<OnAdd, WorkOrder>,
trigger: On<Add, WorkOrder>,
icon_asset: Res<IconAsset>,
mut commands: Commands,
) {
commands
.entity(trigger.target())
.entity(trigger.entity)
.insert(icon_asset.sprite(IconAsset::SHOVEL));
}
2 changes: 1 addition & 1 deletion crates/map_generation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024"

[dependencies]
bevy = { workspace = true }
bevy_ecs_tilemap = "0.16.0"
bevy_ecs_tilemap = "0.18.1"
noise = { workspace = true }
assets = { path = "../assets" }
camera = { path = "../camera" }
Expand Down
10 changes: 5 additions & 5 deletions crates/map_generation/src/chunk_visualisation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ use crate::{
///
/// Is called when a [`ChunkVisualisation`]` is inserted into an entity
pub(crate) fn on_insert(
trigger: Trigger<OnInsert, ChunkVisualisation>,
trigger: On<Insert, ChunkVisualisation>,
mut world_map: ResMut<WorldMap>,
tileset: Res<TilesetAsset>,
camera_layer: Single<&CameraLayer>,
chunks: Query<&ChunkVisualisation>,
mut commands: Commands,
) {
let target = trigger.target();
let target = trigger.entity;
let chunk_visualisation = chunks.get(target).unwrap();
world_map.ensure_surrounding_exist(chunk_visualisation.0);

Expand Down Expand Up @@ -123,7 +123,7 @@ pub(crate) fn on_insert(
map_type: TilemapType::Square,
size: map_size,
storage: tile_storage,
texture: TilemapTexture::Single(tileset.soil_tileset.clone_weak()),
texture: TilemapTexture::Single(tileset.soil_tileset.clone()),
tile_size,
anchor: TilemapAnchor::BottomLeft,
..default()
Expand Down Expand Up @@ -236,7 +236,7 @@ fn spawn_tile_map(
map_type: TilemapType::Square,
size,
storage,
texture: TilemapTexture::Single(tileset.clone_weak()),
texture: TilemapTexture::Single(tileset.clone()),
tile_size,
anchor: TilemapAnchor::BottomLeft,
transform: Transform::from_xyz(0.0, 0.0, z_offset),
Expand All @@ -246,7 +246,7 @@ fn spawn_tile_map(
}

pub(crate) fn on_chunk_visualisation_event(
trigger: Trigger<ChunkVisualisationEvent>,
trigger: On<ChunkVisualisationEvent>,
query: Query<(Entity, &ChunkVisualisation)>,
mut commands: Commands,
) {
Expand Down
8 changes: 4 additions & 4 deletions crates/menu_screen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ fn setup(background: Res<MenuBackgroundAsset>, mut commands: Commands) {
commands
.ui_root()
.insert((
StateScoped(AppState::MainMenu),
DespawnOnExit(AppState::MainMenu),
ImageNode {
image: background.sprite.clone_weak(),
image: background.sprite.clone(),
..default()
},
))
Expand All @@ -24,9 +24,9 @@ fn setup(background: Res<MenuBackgroundAsset>, mut commands: Commands) {
root.spawn_named_observer(target, on_press_start, "on_press_start");
});

commands.spawn((Camera2d, StateScoped(AppState::MainMenu)));
commands.spawn((Camera2d, DespawnOnExit(AppState::MainMenu)));
}

fn on_press_start(_trigger: Trigger<Pointer<Click>>, mut next_state: ResMut<NextState<AppState>>) {
fn on_press_start(_trigger: On<Pointer<Click>>, mut next_state: ResMut<NextState<AppState>>) {
next_state.set(AppState::WorldGeneration);
}
Loading