Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Update to bevy 0.13.0 #49

Merged
merged 5 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
958 changes: 555 additions & 403 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = {version="0.11", features = ["bevy_render", "bevy_core_pipeline", "bevy_asset", "bevy_sprite", "bevy_winit", "png", "x11", "bevy_ui", "tga", "bmp", "jpeg", "webgl2"], default-features=false }
bevy_egui = "0.21"
bevy_pancam = { git = "https://github.com/johanhelsing/bevy_pancam.git", rev="8b6263dcf634dfcc26954c5d712b88a6d7d43e29", features = ["bevy_egui"] }
bevy_prototype_lyon = "0.9.0"
bevy = {version="0.13", features = ["multi-threaded", "bevy_render", "bevy_core_pipeline", "bevy_asset", "bevy_sprite", "bevy_winit", "png", "x11", "bevy_ui", "tga", "bmp", "jpeg", "webgl2"], default-features=false }
bevy_egui = "0.25"
bevy_pancam = { version = "0.11.0", features = ["bevy_egui"] }
bevy_prototype_lyon = "0.11.0"
colorgrad = "0.6.2"
itertools = "0.10.5"
fastrand = "1.8.0"
serde = "1.0.147"
serde_json = "1.0.88"
proc-macro2 = "1.0.43"
chrono = "0.4.31"
itertools = "0.12.1"
fastrand = "2.0.1"
serde = "1.0.197"
serde_json = "1.0.114"
proc-macro2 = "1.0.76"
chrono = "0.4.35"
roarsvg = "0.4.1"
image = "0.24.6"
anyhow = "1.0.80"
image = "0.24.9"

# dependencies exclusive for wasm32
[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ distinction between color and size, it is simply that they are not independently

## How to use

Shu is distributed both through a web app (preview build at https://carrascomj.github.io/shu) and as standalone
Shu is distributed both through a web app (preview build at https://biosustain.github.io/shu) and as standalone
native application. To use the latter, download the [latest release for your operating system](https://github.com/biosustain/shu/releases/latest), unpack if necessary and run it as executable.

Documentation for the rust crate and the python API will be made available once they are published. In the meantime, a preview
of the python documentation can be found at https://carrascomj.github.io/shu/docs.
of the python documentation can be found at https://biosustain.github.io/shu/docs.

### Building from source (latest master commit)

Expand Down
31 changes: 22 additions & 9 deletions src/aesthetics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn restore_geoms<T: Tag>(
Query<&mut Stroke, (With<T>, Without<Fill>)>,
)>,
) {
for _ in restore_event.iter() {
for _ in restore_event.read() {
for (mut fill, mut path) in query.p0().iter_mut() {
// met colors
fill.color = T::default_color();
Expand Down Expand Up @@ -496,8 +496,11 @@ fn plot_side_hist(
ShapeBundle {
path: GeometryBuilder::build_as(&line),
// increment z to avoid flickering problems
transform: trans
.with_translation(trans.translation + Vec3::new(0., 0., *z_eps)),
spatial: SpatialBundle {
transform: trans
.with_translation(trans.translation + Vec3::new(0., 0., *z_eps)),
..default()
},
..default()
},
Fill::color(Color::hex(hex).unwrap()),
Expand Down Expand Up @@ -568,7 +571,10 @@ fn plot_side_box(
(
ShapeBundle {
path: GeometryBuilder::build_as(&line_box),
transform: trans.with_scale(Vec3::new(1., 1., 1.)),
spatial: SpatialBundle {
transform: trans.with_scale(Vec3::new(1., 1., 1.)),
..default()
},
..default()
},
Fill::color(color),
Expand All @@ -594,7 +600,10 @@ fn plot_side_box(
(
ShapeBundle {
path: GeometryBuilder::build_as(&shape),
transform: trans.with_scale(Vec3::new(1., 1., 1.)),
spatial: SpatialBundle {
transform: trans.with_scale(Vec3::new(1., 1., 1.)),
..default()
},
..default()
},
Fill::color(color),
Expand Down Expand Up @@ -670,8 +679,11 @@ fn plot_hover_hist(
);
let geometry = ShapeBundle {
path: GeometryBuilder::build_as(&line),
transform,
visibility: Visibility::Hidden,
spatial: SpatialBundle {
transform,
visibility: Visibility::Hidden,
..default()
},
..default()
};
let fill = Fill::color(Color::hex("ffb73388").unwrap());
Expand Down Expand Up @@ -841,8 +853,9 @@ fn follow_the_axes(
for (axis_trans, axis) in axes.iter() {
for (mut trans, hist) in hists.iter_mut() {
if (axis.node_id == hist.node_id) & (hist.side == axis.side) {
trans.translation = axis_trans.translation;
trans.rotation = axis_trans.rotation;
// z has to be maintained per element in the axis to avoid flickering
trans.translation.x = axis_trans.translation.x;
trans.translation.y = axis_trans.translation.y;
if hist.follow_scale {
trans.scale.x = axis_trans.scale.x;
}
Expand Down
52 changes: 35 additions & 17 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use crate::escher::EscherMap;
use crate::geom::{self, HistTag, Xaxis};
use crate::geom::{AesFilter, GeomHist, HistPlot};
use crate::info::Info;
use bevy::asset::{AssetLoader, LoadContext, LoadedAsset};
use bevy::asset::io::Reader;
use bevy::asset::{AssetLoader, AsyncReadExt, LoadContext};
use bevy::prelude::*;
use bevy::reflect::{TypePath, TypeUuid};
use bevy::reflect::TypePath;
use bevy::utils::thiserror;
use bevy::utils::BoxedFuture;
use itertools::Itertools;
use serde::Deserialize;
Expand All @@ -18,10 +20,10 @@ pub struct DataPlugin;

impl Plugin for DataPlugin {
fn build(&self, app: &mut App) {
app.add_asset::<EscherMap>()
.add_asset::<Data>()
.add_asset_loader(CustomAssetLoader::<EscherMap>::new(vec!["json"]))
.add_asset_loader(CustomAssetLoader::<Data>::new(vec!["metabolism.json"]))
app.init_asset::<EscherMap>()
.init_asset::<Data>()
.register_asset_loader(CustomAssetLoader::<EscherMap>::new(vec!["json"]))
.register_asset_loader(CustomAssetLoader::<Data>::new(vec!["metabolism.json"]))
.add_systems(PostUpdate, load_data);
}
}
Expand All @@ -32,19 +34,36 @@ pub struct CustomAssetLoader<A> {
_mark: std::marker::PhantomData<A>,
}

/// Possible errors that can be produced by [`CustomAssetLoader`]
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum CustomJsonLoaderError {
/// An [IO](std::io) Error
#[error("Could not load asset: {0}")]
Io(#[from] std::io::Error),
/// A [RON](ron) Error
#[error("Could not parse JSON: {0}")]
JsonSpannedError(#[from] serde_json::Error),
}

impl<A> AssetLoader for CustomAssetLoader<A>
where
for<'de> A: serde::Deserialize<'de> + bevy::asset::Asset,
{
type Asset = A;
type Settings = ();
type Error = CustomJsonLoaderError;
fn load<'a>(
&'a self,
bytes: &'a [u8],
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<(), bevy::asset::Error>> {
reader: &'a mut Reader,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let custom_asset = serde_json::from_slice::<A>(bytes)?;
load_context.set_default_asset(LoadedAsset::new(custom_asset));
Ok(())
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let custom_asset = serde_json::from_slice::<A>(&bytes)?;
Ok(custom_asset)
})
}

Expand Down Expand Up @@ -93,8 +112,7 @@ impl Number {
}

/// Metabolic data from the user that can be read from a `file.metabolism.json`.
#[derive(Deserialize, TypeUuid, Default, TypePath)]
#[uuid = "413be529-bfeb-41a3-8db0-4b8b382a2c46"]
#[derive(Deserialize, Asset, Default, TypePath)]
pub struct Data {
/// Vector of reactions' identifiers
reactions: Option<Vec<String>>,
Expand Down Expand Up @@ -188,14 +206,14 @@ fn load_data(
// remove data to be plotted, axes and histograms
to_remove: Query<Entity, Or<(With<aesthetics::Aesthetics>, With<HistTag>, With<Xaxis>)>>,
) {
let custom_asset = if let Some(reac_handle) = &mut state.reaction_data {
if asset_server.get_load_state(&*reac_handle) == bevy::asset::LoadState::Failed {
let custom_asset = if let Some(reac_handle) = &state.reaction_data {
if let Some(bevy::asset::LoadState::Failed) = asset_server.get_load_state(reac_handle) {
info_state
.notify("Failed loading data! Check if your metabolism.json is in correct format.");
state.reaction_data = None;
return;
}
custom_assets.get_mut(reac_handle)
custom_assets.get_mut(reac_handle.id())
} else {
return;
};
Expand Down
21 changes: 13 additions & 8 deletions src/escher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::funcplot::draw_arrow;
use crate::geom::{GeomHist, HistTag, Side, Xaxis};
use crate::info::Info;
use crate::scale::DefaultFontSize;
use bevy::prelude::*;
use bevy::reflect::TypePath;
use bevy::{prelude::*, reflect::TypeUuid};
use bevy_prototype_lyon::prelude::*;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -37,8 +37,7 @@ pub struct NodeToText {
pub inner: HashMap<u64, Entity>,
}

#[derive(Deserialize, TypeUuid, Default, Serialize, TypePath)]
#[uuid = "413be529-bfeb-41b3-9db0-4b8b380a2c46"]
#[derive(Deserialize, Asset, Default, Serialize, TypePath)]
pub struct EscherMap {
#[allow(dead_code)]
info: EscherInfo,
Expand Down Expand Up @@ -314,7 +313,7 @@ fn build_text_tag(
color: ARROW_COLOR,
},
)
.with_alignment(TextAlignment::Center);
.with_justify(JustifyText::Center);
(
Text2dBundle {
text,
Expand Down Expand Up @@ -374,8 +373,8 @@ pub fn load_map(
mut existing_geom_hist: Query<&mut GeomHist>,
) {
let custom_asset = custom_assets.get_mut(&state.escher_map);
if (asset_server.get_load_state(&state.escher_map) == bevy::asset::LoadState::Failed)
& !state.loaded
if let (Some(bevy::asset::LoadState::Failed), false) =
(asset_server.get_load_state(&state.escher_map), state.loaded)
{
info_state.notify("Failed loading map! Check that you JSON is correct.");
state.loaded = true;
Expand Down Expand Up @@ -432,7 +431,10 @@ pub fn load_map(
commands.spawn((
ShapeBundle {
path: GeometryBuilder::build_as(&shape),
transform: Transform::from_xyz(met.x - center_x, -met.y + center_y, 2. + z_eps),
spatial: SpatialBundle {
transform: Transform::from_xyz(met.x - center_x, -met.y + center_y, 2. + z_eps),
..default()
},
..Default::default()
},
Fill::color(MET_COLOR),
Expand Down Expand Up @@ -531,7 +533,10 @@ pub fn load_map(
commands.spawn((
ShapeBundle {
path: builder.build(),
transform: Transform::from_xyz(ori.x - center_x, ori.y + center_y, 1. + z_eps),
spatial: SpatialBundle {
transform: Transform::from_xyz(ori.x - center_x, ori.y + center_y, 1. + z_eps),
..Default::default()
},
..Default::default()
},
Stroke::new(ARROW_COLOR, 10.0),
Expand Down
9 changes: 6 additions & 3 deletions src/funcplot.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Functions for plotting data.

use bevy::prelude::{
Color, Component, Font, Handle, Text, Text2dBundle, TextStyle, Transform, Vec2,
Color, Component, Font, Handle, SpatialBundle, Text, Text2dBundle, TextStyle, Transform, Vec2,
};
use bevy_prototype_lyon::{
entity::ShapeBundle,
Expand Down Expand Up @@ -249,8 +249,11 @@ pub fn plot_line(size: f32, transform: Transform) -> (ShapeBundle, Stroke) {
(
ShapeBundle {
path: GeometryBuilder::build_as(&path_builder.build()),
visibility: bevy::prelude::Visibility::Hidden,
transform,
spatial: SpatialBundle {
visibility: bevy::prelude::Visibility::Hidden,
transform,
..Default::default()
},
..Default::default()
},
Stroke::color(Color::BLACK),
Expand Down
Loading
Loading