map color update

This commit is contained in:
Arkitu 2024-12-22 22:19:07 +01:00
parent 2d793f5f6c
commit e5b2e51a29

View File

@ -65,7 +65,7 @@ fn setup(
} else if z <= 0.52 {
CellKind::Beach
} else if z < 0.8 {
CellKind::Dirt
CellKind::Grass
} else {
CellKind::Stone
};
@ -77,7 +77,7 @@ fn setup(
let mut colors = Vec::new();
let mut indices = Vec::new();
for (c, cd) in voronoi.iter_cells().zip(cells_data.iter_mut()).filter(|(_,cd)| cd.kind != CellKind::Forest) {
for (c, mut cd) in voronoi.iter_cells().zip(cells_data).filter(|(_,cd)| cd.kind != CellKind::Forest) {
let mut color = cd.color();
// if c.site() == selected_tile {
// color[0] = (color[0]+0.4).clamp(0., 1.);
@ -95,6 +95,7 @@ fn setup(
indices.extend_from_slice(&[i as u32, (i+v) as u32, (i+v+1) as u32]);
cd.vertices.extend_from_slice(&[i, i+v, i+v+1]);
}
cmds.spawn(cd);
}
let mesh = Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::default())
@ -121,16 +122,19 @@ fn setup(
}
fn update(
cells: Query<&CellData>,
mut cells: Query<&mut CellData>,
mut map: Query<(&Mesh2d, &mut MapColors), With<MapMarker>>,
mut meshes: ResMut<Assets<Mesh>>
) {
let (mesh, mut cols) = map.single_mut();
if let Some(mesh) = meshes.get_mut(mesh) {
// let cols = mesh.attribute_mut(Mesh::ATTRIBUTE_COLOR).unwrap();
for cd in cells.iter() {
for mut cd in cells.iter_mut() {
// info!(cd.resource);
cd.update();
// dbg!(cd.resource);
let col = cd.color();
for id in cd.vertices.iter() {
for id in cd.vertices.iter() {
cols.0[*id] = col.clone();
}
}