2019-04-29 20:37:19 +00:00
|
|
|
use serde_derive::{Deserialize, Serialize};
|
2019-01-23 20:01:58 +00:00
|
|
|
use vek::*;
|
|
|
|
|
2019-01-14 18:49:53 +00:00
|
|
|
// Crate
|
|
|
|
use crate::vol::Vox;
|
|
|
|
|
2019-05-17 17:44:30 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
2019-01-02 19:22:01 +00:00
|
|
|
pub struct Block {
|
|
|
|
kind: u8,
|
|
|
|
color: [u8; 3],
|
|
|
|
}
|
2019-01-14 18:49:53 +00:00
|
|
|
|
2019-01-23 20:01:58 +00:00
|
|
|
impl Block {
|
|
|
|
pub fn new(kind: u8, color: Rgb<u8>) -> Self {
|
|
|
|
Self {
|
|
|
|
kind,
|
|
|
|
color: color.into_array(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_color(&self) -> Option<Rgb<u8>> {
|
|
|
|
if self.is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(self.color.into())
|
|
|
|
}
|
|
|
|
}
|
2019-05-31 20:37:11 +00:00
|
|
|
|
2019-06-06 11:25:06 +00:00
|
|
|
pub fn get_opacity(&self) -> Option<f32> {
|
2019-05-31 20:37:11 +00:00
|
|
|
match self.kind {
|
2019-06-06 11:25:06 +00:00
|
|
|
0 => None,
|
|
|
|
1 => Some(0.85),
|
|
|
|
2 => Some(1.0),
|
2019-05-31 20:37:11 +00:00
|
|
|
_ => unimplemented!(),
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 20:01:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 18:49:53 +00:00
|
|
|
impl Vox for Block {
|
|
|
|
fn empty() -> Self {
|
|
|
|
Self {
|
|
|
|
kind: 0,
|
|
|
|
color: [0; 3],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_empty(&self) -> bool {
|
|
|
|
self.kind == 0
|
|
|
|
}
|
|
|
|
}
|