Skip to content

Commit

Permalink
Fixed asset loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac8668 committed Jan 27, 2025
1 parent b727871 commit 7ba73bb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ rotsprite = "0.1"

puffin = "0.19"

thiserror = "2.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
bevy_dylib = "0.15"

Expand Down
10 changes: 4 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ fn main() {

let mut app = App::new();

app.init_state::<GameState>()
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
app.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
//local plugins
.add_plugins((
ChunkManagerPlugin,
Expand All @@ -76,7 +75,8 @@ fn main() {
RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(1.),
MenuPlugin,
))
.add_systems(Startup, setup);
.add_systems(Startup, setup)
.init_state::<GameState>();

if args.contains(&"-d".to_string()) || args.contains(&"--debug".to_string()) {
app.add_plugins((DebugPlugin,));
Expand All @@ -91,9 +91,7 @@ fn main() {

fn setup(mut commands: Commands, mut time: ResMut<Time<Fixed>>) {
time.set_timestep_hz(58.);

let camera = Camera2d::default();
commands.spawn((camera, Transform::from_scale(Vec3::new(0.23, 0.23, 1.))));
commands.spawn((Camera2d, Transform::from_scale(Vec3::new(0.23, 0.23, 1.))));
}

#[derive(Clone, Copy, Eq, PartialEq, Debug, Hash, States)]
Expand Down
26 changes: 11 additions & 15 deletions src/materials.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::prelude::*;

use bevy::utils::thiserror;
use bevy::{
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
asset::{io::Reader, AssetLoader, LoadContext},
prelude::*,
reflect::TypePath,
utils::BoxedFuture,
};
use serde::Deserialize;
use thiserror::Error;
Expand Down Expand Up @@ -99,18 +97,16 @@ impl AssetLoader for MaterialsLoader {
type Asset = Materials;
type Settings = ();
type Error = MaterialsLoaderError;
fn load<'a>(
&'a self,
reader: &'a mut Reader,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let custom_asset = ron::de::from_bytes::<Materials>(&bytes)?;
Ok(custom_asset)
})
async fn load(
&self,
reader: &mut dyn Reader,
_settings: &(),
_load_context: &mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let custom_asset = ron::de::from_bytes::<Materials>(&bytes)?;
Ok(custom_asset)
}

fn extensions(&self) -> &[&str] {
Expand Down

0 comments on commit 7ba73bb

Please sign in to comment.