Skip to content

Commit

Permalink
Interaction plugin, pt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
David Peter committed Jul 11, 2024
1 parent 6032126 commit e734396
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 383 deletions.
53 changes: 53 additions & 0 deletions src/gui/graphics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::time::Duration;

use bevy::{
core_pipeline::bloom::BloomSettings,
prelude::*,
render::view::RenderLayers,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
Expand All @@ -24,6 +25,9 @@ pub const ANIMATION_DURATION: Duration = Duration::from_millis(300);

pub const SPACING: f32 = 90.0;

#[derive(Component)]
pub struct MainCamera;

pub fn screen_point(coord: Coord) -> Vec3 {
Vec3::new(
SPACING * (0.5 * 3_f32.sqrt() * coord.x as f32),
Expand Down Expand Up @@ -107,3 +111,52 @@ pub fn spawn_marker(
FOREGROUND_RENDER_LAYER,
));
}

fn setup_graphics(
mut commands: Commands,
mut config_store: ResMut<GizmoConfigStore>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
// Render layer 1 is for the grid
commands.spawn((
Camera2dBundle {
camera: Camera {
hdr: true,
order: 1,
..default()
},
..default()
},
BloomSettings::default(),
BACKGROUND_RENDER_LAYER,
));

// Render layer 2 is for the board elements
commands.spawn((
Camera2dBundle {
camera: Camera {
hdr: true,
order: 2,
..default()
},
..default()
},
BloomSettings::default(),
FOREGROUND_RENDER_LAYER,
MainCamera,
));

commands.insert_resource(PlayerColors {
human: materials.add(Color::srgba(1.5, 1.5, 1.5, 1.0)),
human_highlighted: materials.add(Color::srgba(4., 4., 4., 1.0)),
human_transparent: materials.add(Color::srgba(1.5, 1.5, 1.5, 0.1)),
ai: materials.add(Color::srgba(0.0, 0.0, 0.0, 1.0)),
});

let (config, _) = config_store.config_mut::<DefaultGizmoConfigGroup>();
config.render_layers = BACKGROUND_RENDER_LAYER;
}

pub fn graphics_plugin(app: &mut App) {
app.add_systems(PreStartup, setup_graphics);
}
3 changes: 1 addition & 2 deletions src/gui/information_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use bevy::prelude::*;

use yinsh::Player;

use crate::CursorCoord;

use super::{
ai::AiPlayerStrength,
graphics::BACKGROUND_RENDER_LAYER,
interaction::CursorCoord,
state::{GameState, InteractionState},
PLAYER_HUMAN,
};
Expand Down
Loading

0 comments on commit e734396

Please sign in to comment.