|
|
|
|
@ -24,34 +24,30 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
.run_if(in_state(GameState::Loading))
|
|
|
|
|
.run_if(on_event::<AssetEvent<Tweaks>>()),
|
|
|
|
|
hydrate_camera.run_if(any_component_added::<Camera3d>()),
|
|
|
|
|
set_piece_model.run_if(any_component_added::<Piece>()),
|
|
|
|
|
set_piece_model.run_if(any_component_changed::<Piece>()),
|
|
|
|
|
set_board_model.run_if(any_component_added::<game::BoardComponent>()),
|
|
|
|
|
set_board_model.run_if(any_component_added::<TilesComponent>()),
|
|
|
|
|
set_valid_move_model.run_if(any_component_added::<game::ValidMove>()),
|
|
|
|
|
set_tile_hitbox.run_if(any_component_added::<game::Tile>()),
|
|
|
|
|
set_piece_position.run_if(any_component_changed::<BoardIndex>()),
|
|
|
|
|
update_tweaks
|
|
|
|
|
.run_if(on_event::<AssetEvent<Tweaks>>())
|
|
|
|
|
.run_if(resource_exists::<tweak::GameTweaks>),
|
|
|
|
|
switch_sides
|
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
|
.run_if(state_changed::<game::TurnState>),
|
|
|
|
|
set_piece_model
|
|
|
|
|
.run_if(any_component_added::<Piece>().or_else(any_component_changed::<Piece>())),
|
|
|
|
|
set_piece_texture
|
|
|
|
|
.run_if(any_component_changed::<Side>())
|
|
|
|
|
.run_if(any_component_changed::<Side>().or_else(any_component_added::<Side>()))
|
|
|
|
|
.run_if(resource_exists::<tweak::GameTweaks>),
|
|
|
|
|
set_piece_position.run_if(any_component_changed::<BoardIndex>()),
|
|
|
|
|
set_board_model.run_if(
|
|
|
|
|
any_component_added::<game::BoardComponent>()
|
|
|
|
|
.or_else(any_component_added::<TilesComponent>())
|
|
|
|
|
),
|
|
|
|
|
set_valid_move_model.run_if(any_component_added::<game::ValidMove>()),
|
|
|
|
|
set_tile_hitbox.run_if(any_component_added::<game::Tile>()),
|
|
|
|
|
select
|
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
|
.run_if(in_state(DisplayState::Display3d))
|
|
|
|
|
.run_if(on_event::<MouseButtonInput>()),
|
|
|
|
|
pick_up.run_if(any_component_added::<game::Selected>()),
|
|
|
|
|
put_down.run_if(any_component_removed::<game::Selected>()),
|
|
|
|
|
switch_sides
|
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
|
.run_if(state_changed::<game::TurnState>),
|
|
|
|
|
update_tweaks
|
|
|
|
|
.run_if(on_event::<AssetEvent<Tweaks>>())
|
|
|
|
|
.run_if(resource_exists::<tweak::GameTweaks>),
|
|
|
|
|
scale_lighting.run_if(
|
|
|
|
|
any_component_added::<DirectionalLight>()
|
|
|
|
|
.or_else(any_component_added::<SpotLight>())
|
|
|
|
|
.or_else(any_component_added::<PointLight>())
|
|
|
|
|
.or_else(on_event::<AssetEvent<Tweaks>>()),
|
|
|
|
|
),
|
|
|
|
|
setup_capture_piece.run_if(any_component_changed::<Handle<StandardMaterial>>()),
|
|
|
|
|
capture_piece.run_if(any_with_component::<game::Captured>),
|
|
|
|
|
skip_animation
|
|
|
|
|
@ -560,12 +556,11 @@ fn mouse_zoom(
|
|
|
|
|
/// PERF: We are saving what to work on in a Vector which is bad.
|
|
|
|
|
/// CAVEAT: We are only exeucting this when a piece changes or state is changed.
|
|
|
|
|
fn set_piece_texture(
|
|
|
|
|
events: Query<
|
|
|
|
|
query: Query<
|
|
|
|
|
(Entity, &Piece, &Side),
|
|
|
|
|
(
|
|
|
|
|
With<game::Piece>,
|
|
|
|
|
With<Display3d>,
|
|
|
|
|
Or<(Changed<Side>, Added<Side>)>,
|
|
|
|
|
),
|
|
|
|
|
>,
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
@ -574,7 +569,7 @@ fn set_piece_texture(
|
|
|
|
|
tweaks: Res<Assets<Tweaks>>,
|
|
|
|
|
tweaks_file: Res<tweak::GameTweaks>,
|
|
|
|
|
) {
|
|
|
|
|
events.iter().for_each(|(entity, piece, side)| {
|
|
|
|
|
query.iter().for_each(|(entity, piece, side)| {
|
|
|
|
|
debug!("Checking piece texture for {:?}", entity);
|
|
|
|
|
let tweak = tweaks.get(tweaks_file.handle.clone()).unwrap();
|
|
|
|
|
let assets_handle = tweak
|
|
|
|
|
@ -757,14 +752,17 @@ fn select(
|
|
|
|
|
.filter(|ev| ev.state == ButtonState::Pressed)
|
|
|
|
|
.for_each(|_| {
|
|
|
|
|
windows.iter().for_each(|window| {
|
|
|
|
|
if let Some(pos) = window.cursor_position() { cameras.iter().for_each(|(camera, gt)| {
|
|
|
|
|
if let Some(ray) = camera.viewport_to_world(gt, pos) { query
|
|
|
|
|
if let Some(pos) = window.cursor_position() {
|
|
|
|
|
cameras.iter().for_each(|(camera, gt)| {
|
|
|
|
|
if let Some(ray) = camera.viewport_to_world(gt, pos) {
|
|
|
|
|
query
|
|
|
|
|
.iter()
|
|
|
|
|
.filter_map(|(entity, handle, gt)| {
|
|
|
|
|
meshes.get(handle).map(|mesh| (entity, mesh, gt))
|
|
|
|
|
})
|
|
|
|
|
.for_each(|(entity, mesh, gt)| {
|
|
|
|
|
if let Some(_hit) = hit::intersects3d(&ray, mesh, gt) { selectable
|
|
|
|
|
if let Some(_hit) = hit::intersects3d(&ray, mesh, gt) {
|
|
|
|
|
selectable
|
|
|
|
|
.iter()
|
|
|
|
|
.find_map(|(e, &board_index, &side)| {
|
|
|
|
|
// Check the side of the selection if no piece is selected
|
|
|
|
|
@ -789,11 +787,13 @@ fn select(
|
|
|
|
|
.iter()
|
|
|
|
|
.for_each(|&board_index| {
|
|
|
|
|
info!("Board index selected: {:?}", board_index);
|
|
|
|
|
selections
|
|
|
|
|
.send(game::Selection(board_index));
|
|
|
|
|
}); }
|
|
|
|
|
}); }
|
|
|
|
|
}); }
|
|
|
|
|
selections.send(game::Selection(board_index));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
@ -1042,64 +1042,6 @@ fn switch_sides(
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn scale_lighting(
|
|
|
|
|
mut directional: Query<(
|
|
|
|
|
Entity,
|
|
|
|
|
&mut DirectionalLight,
|
|
|
|
|
Option<&Original<DirectionalLight>>,
|
|
|
|
|
)>,
|
|
|
|
|
mut spot: Query<(Entity, &mut SpotLight, Option<&Original<SpotLight>>)>,
|
|
|
|
|
mut point: Query<(Entity, &mut PointLight, Option<&Original<PointLight>>)>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
tweaks: Res<Assets<Tweaks>>,
|
|
|
|
|
tweaks_file: Res<tweak::GameTweaks>,
|
|
|
|
|
) {
|
|
|
|
|
let tweak = tweaks
|
|
|
|
|
.get(tweaks_file.handle.clone())
|
|
|
|
|
.expect("Load tweakfile");
|
|
|
|
|
|
|
|
|
|
let directional_tweak = tweak
|
|
|
|
|
.get::<f32>("display3d_lights_scaling_directional")
|
|
|
|
|
.expect("Directional lighting scalar");
|
|
|
|
|
directional
|
|
|
|
|
.iter_mut()
|
|
|
|
|
.for_each(|(entity, mut val, original)| {
|
|
|
|
|
debug!("Scaling directional light {:?}", entity);
|
|
|
|
|
if let Some(Original(v)) = original {
|
|
|
|
|
val.illuminance = v.illuminance * directional_tweak;
|
|
|
|
|
} else {
|
|
|
|
|
commands.entity(entity).insert(Original(val.clone()));
|
|
|
|
|
val.illuminance *= directional_tweak;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let spot_tweak = tweak
|
|
|
|
|
.get::<f32>("display3d_lights_scaling_spot")
|
|
|
|
|
.expect("Spot lighting scalar");
|
|
|
|
|
spot.iter_mut().for_each(|(entity, mut val, original)| {
|
|
|
|
|
debug!("Scaling spot light {:?}", entity);
|
|
|
|
|
if let Some(Original(v)) = original {
|
|
|
|
|
val.intensity = v.intensity * spot_tweak;
|
|
|
|
|
} else {
|
|
|
|
|
commands.entity(entity).insert(Original(*val));
|
|
|
|
|
val.intensity *= spot_tweak;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let point_tweak = tweak
|
|
|
|
|
.get::<f32>("display3d_lights_scaling_point")
|
|
|
|
|
.expect("Point lighting scalar");
|
|
|
|
|
point.iter_mut().for_each(|(entity, mut val, original)| {
|
|
|
|
|
debug!("Scaling point light {:?}", entity);
|
|
|
|
|
if let Some(Original(v)) = original {
|
|
|
|
|
val.intensity = v.intensity * point_tweak;
|
|
|
|
|
} else {
|
|
|
|
|
commands.entity(entity).insert(Original(*val));
|
|
|
|
|
val.intensity *= point_tweak;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(super) mod tweaks {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
|