|
|
|
@ -5,7 +5,7 @@ use bevy::asset::io::Reader; |
|
|
|
use bevy::asset::{AssetLoader, LoadContext}; |
|
|
|
use bevy::asset::{AssetLoader, LoadContext}; |
|
|
|
use serde::Deserialize; |
|
|
|
use serde::Deserialize; |
|
|
|
|
|
|
|
|
|
|
|
pub fn plugin(app: &mut App) { |
|
|
|
pub(super) fn plugin(app: &mut App) { |
|
|
|
let mesh = Mesh::from(Cuboid::new(1.0, 1.0, 1.0)); |
|
|
|
let mesh = Mesh::from(Cuboid::new(1.0, 1.0, 1.0)); |
|
|
|
let cube = app.world_mut().add_asset(mesh); |
|
|
|
let cube = app.world_mut().add_asset(mesh); |
|
|
|
app.insert_resource(BuiltinBlockMeshes { cube }); |
|
|
|
app.insert_resource(BuiltinBlockMeshes { cube }); |
|
|
|
@ -22,10 +22,25 @@ struct BuiltinBlockMeshes { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Asset, TypePath)] |
|
|
|
#[derive(Asset, TypePath)] |
|
|
|
struct BlockVisuals { |
|
|
|
pub struct BlockVisuals { |
|
|
|
_id: Identifier<Block>, |
|
|
|
_id: Identifier<Block>, |
|
|
|
// mesh: Handle<Mesh>,
|
|
|
|
color: Color, |
|
|
|
material: Handle<StandardMaterial>, |
|
|
|
material: Handle<StandardMaterial>, |
|
|
|
|
|
|
|
// mesh: Handle<Mesh>,
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl BlockVisuals { |
|
|
|
|
|
|
|
// pub fn id(&self) -> &Identifier<Block> {
|
|
|
|
|
|
|
|
// &self.id
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn color(&self) -> Color { |
|
|
|
|
|
|
|
self.color |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// pub fn material(&self) -> &Handle<StandardMaterial> {
|
|
|
|
|
|
|
|
// &self.material
|
|
|
|
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl ManifestEntry for BlockVisuals { |
|
|
|
impl ManifestEntry for BlockVisuals { |
|
|
|
@ -57,14 +72,19 @@ impl AssetLoader for BlockVisualsLoader { |
|
|
|
let raw = ron::de::from_bytes::<BlockTypeVisualsRaw>(&bytes)?; |
|
|
|
let raw = ron::de::from_bytes::<BlockTypeVisualsRaw>(&bytes)?; |
|
|
|
|
|
|
|
|
|
|
|
let (r, g, b) = raw.color; |
|
|
|
let (r, g, b) = raw.color; |
|
|
|
let material = StandardMaterial::from(Color::srgb_u8(r, g, b)); |
|
|
|
let color = Color::srgb_u8(r, g, b); |
|
|
|
|
|
|
|
let material = StandardMaterial::from(color); |
|
|
|
let material = load_context.add_labeled_asset("material".to_string(), material); |
|
|
|
let material = load_context.add_labeled_asset("material".to_string(), material); |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Figure out how to reference a procedural mesh from here.
|
|
|
|
// TODO: Figure out how to reference a procedural mesh from here.
|
|
|
|
// let mesh = load_context.load(???);
|
|
|
|
// let mesh = load_context.load(???);
|
|
|
|
|
|
|
|
|
|
|
|
let id = load_context.path().try_into()?; |
|
|
|
let id = load_context.path().try_into()?; |
|
|
|
Ok(BlockVisuals { _id: id, material }) |
|
|
|
Ok(BlockVisuals { |
|
|
|
|
|
|
|
_id: id, |
|
|
|
|
|
|
|
color, |
|
|
|
|
|
|
|
material, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn extensions(&self) -> &[&str] { |
|
|
|
fn extensions(&self) -> &[&str] { |
|
|
|
|