generated from tipragot/rust
Add the ownership system #96
|
@ -28,6 +28,7 @@ fn setup_ownership_resources(mut commands: Commands) {
|
||||||
commands.insert_resource(OwnershipColorContrast(0.4));
|
commands.insert_resource(OwnershipColorContrast(0.4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Render the ownership of the tiles by applying colors.
|
||||||
fn render_ownership(
|
fn render_ownership(
|
||||||
mut query: Query<(&mut Sprite, &Owner), Changed<Owner>>,
|
mut query: Query<(&mut Sprite, &Owner), Changed<Owner>>,
|
||||||
contrast: Res<OwnershipColorContrast>,
|
contrast: Res<OwnershipColorContrast>,
|
||||||
|
@ -40,12 +41,12 @@ fn render_ownership(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mixes two colors.
|
/// Mixes two colors.
|
||||||
fn mix_colors(color1: Color, color2: Color, alpha: f32) -> Color {
|
fn mix_colors(color1: Color, color2: Color, alpha: f32) -> Color {
|
||||||
let [r1, g1, b1, _] = color1.as_rgba_u8();
|
let [r1, g1, b1, _] = color1.as_rgba_u8();
|
||||||
let [r2, g2, b2, _] = color2.as_rgba_u8();
|
let [r2, g2, b2, _] = color2.as_rgba_u8();
|
||||||
let mixed_r = ((1.0 - alpha) * r1 as f32 + alpha * r2 as f32).round() as u8;
|
let mixed_r = (1.0 - alpha).mul_add(r1 as f32, alpha * r2 as f32).round() as u8;
|
||||||
let mixed_g = ((1.0 - alpha) * g1 as f32 + alpha * g2 as f32).round() as u8;
|
let mixed_g = (1.0 - alpha).mul_add(g1 as f32, alpha * g2 as f32).round() as u8;
|
||||||
let mixed_b = ((1.0 - alpha) * b1 as f32 + alpha * b2 as f32).round() as u8;
|
let mixed_b = (1.0 - alpha).mul_add(b1 as f32, alpha * b2 as f32).round() as u8;
|
||||||
Color::rgb_u8(mixed_r, mixed_g, mixed_b)
|
Color::rgb_u8(mixed_r, mixed_g, mixed_b)
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ fn menu_ui(
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
rank: PlayerRank::Player,
|
rank: PlayerRank::Player,
|
||||||
uuid,
|
uuid,
|
||||||
color: (0, 0, 0),
|
color: rand::random::<(u8, u8, u8)>(),
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ fn menu_ui(
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
rank: PlayerRank::Admin,
|
rank: PlayerRank::Admin,
|
||||||
uuid,
|
uuid,
|
||||||
color: (255, 255, 255),
|
color: rand::random::<(u8, u8, u8)>(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue