feat: Paint mode done
This commit is contained in:
parent
fb0e374f17
commit
346d4ed290
2 changed files with 12 additions and 6 deletions
|
|
@ -7,7 +7,9 @@ pub struct EditorPlugin;
|
|||
|
||||
impl Plugin for EditorPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<EditorTools>().add_observer(apply_tool).add_systems(Update, calculate_tools);
|
||||
app.init_resource::<EditorTools>()
|
||||
.add_observer(apply_tool)
|
||||
.add_systems(Update, calculate_tools);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,7 +33,8 @@ pub fn calculate_tools(
|
|||
ray_map: Res<RayMap>,
|
||||
mut raycast: MeshRayCast,
|
||||
mut tool: ResMut<EditorTools>,
|
||||
mut gizmos: Gizmos
|
||||
mut gizmos: Gizmos,
|
||||
grid: Res<Grid>
|
||||
) {
|
||||
let new_tool: Option<EditorTools> = match tool.clone() {
|
||||
EditorTools::None => None,
|
||||
|
|
@ -39,8 +42,9 @@ pub fn calculate_tools(
|
|||
let mut new_position: Option<UVec3> = None;
|
||||
for (_, ray) in ray_map.iter() {
|
||||
let Some((_, hit)) = raycast.cast_ray(*ray, &MeshRayCastSettings::default()).first() else {continue;};
|
||||
gizmos.sphere(hit.point.round(), 0.5, Color::BLACK);
|
||||
new_position = Some(hit.point.floor().as_uvec3());
|
||||
let converted_position = (hit.point + 0.51 * hit.normal.normalize()).round();
|
||||
gizmos.sphere(converted_position, 0.5, Color::BLACK);
|
||||
new_position = Some(converted_position.as_ivec3().max(IVec3::ZERO).as_uvec3().min(grid.size-UVec3::ONE));
|
||||
}
|
||||
|
||||
new_position.map(|pos|{
|
||||
|
|
@ -65,7 +69,9 @@ pub fn apply_tool(params: On<ApplyTool>, mut grid: ResMut<Grid>) {
|
|||
match params.0 {
|
||||
EditorTools::None => {},
|
||||
EditorTools::Paint { position, block } => {
|
||||
let index = grid.indexify(position).unwrap();
|
||||
let Some(index) = grid.indexify(position) else {
|
||||
error!("Grid position {position} is incorrect");
|
||||
return;};
|
||||
grid.data[index] = block;
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ fn editor_column() -> impl Scene {
|
|||
@caption: bsn!{label("Paint")}
|
||||
}
|
||||
on(|_activate: On<Activate>, mut tool: ResMut<EditorTools>, mut label: Single<&mut Text, With<ToolLabel>>| {
|
||||
*tool = EditorTools::Paint { position: UVec3::default(), block: GridElement::Solid };
|
||||
*tool = EditorTools::Paint { position: UVec3::default(), block: GridElement::Water { amount: 1000 } };
|
||||
label.0 = "Current tool: Paint".to_string();
|
||||
}),
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue