diff --git a/Cargo.toml b/Cargo.toml index 262c9b7..a6becdb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,21 +19,22 @@ state = ["dep:seldom_state"] [dependencies] bevy_turborand = { version = "0.8.1", optional = true } line_drawing = { version = "1.0", optional = true } -seldom_fn_plugin = "0.6.0" -seldom_map_nav = { version = "0.6.0", optional = true } +seldom_map_nav = { git = "https://github.com/Seldom-SE/seldom_map_nav", rev = "bfa6889", optional = true } seldom_pixel_macros = { version = "0.1.0", path = "macros" } -seldom_state = { version = "0.10.0", optional = true } +seldom_state = { git = "https://github.com/Seldom-SE/seldom_state", rev = "d0abfd8", optional = true } [dependencies.bevy] -version = "0.13.0" +version = "0.14.0-rc.2" default-features = false features = ["bevy_asset", "bevy_core_pipeline", "bevy_render", "bevy_sprite"] [dev-dependencies] -bevy = { version = "0.13.0", features = ["png"] } -leafwing-input-manager = "0.13.3" +bevy = { version = "0.14.0-rc.2", features = ["png"] } +leafwing-input-manager = { git = "https://github.com/Leafwing-Studios/leafwing-input-manager", rev = "a603533" } rand = "0.8.5" -seldom_state = { version = "0.10.0", features = ["leafwing_input"] } +seldom_state = { git = "https://github.com/Seldom-SE/seldom_state", rev = "d0abfd8", features = [ + "leafwing_input", +] } [[example]] name = "line" diff --git a/src/animation.rs b/src/animation.rs index 2e50ade..5f4d3a1 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -16,7 +16,7 @@ use crate::{ text::PxTypefaceData, }; -pub(crate) fn animation_plugin(app: &mut App) { +pub(crate) fn plug(app: &mut App) { app.configure_sets( PostUpdate, PxSet::FinishAnimations diff --git a/src/asset.rs b/src/asset.rs index 657fb0c..fbd1770 100644 --- a/src/asset.rs +++ b/src/asset.rs @@ -8,8 +8,6 @@ use bevy::{ reflect::TypePath, }; -use seldom_fn_plugin::FnPluginExt; - use crate::map::PxTilesetData; use crate::{ filter::PxFilterData, @@ -22,18 +20,20 @@ use crate::{ use self::sealed::{PxAssetDataSealed, PxAssetTraitSealed}; -pub(crate) fn asset_plugin(app: &mut App) { - app.configure_sets( +pub(crate) fn plug(app: &mut App) { + app.add_plugins(( + asset_plug::, + asset_plug::, + asset_plug::, + asset_plug::, + )) + .configure_sets( PostUpdate, PxSet::LoadAssets.before(PxSet::Draw).in_set(PxSet::Loaded), - ) - .fn_plugin(px_asset_plugin::) - .fn_plugin(px_asset_plugin::) - .fn_plugin(px_asset_plugin::) - .fn_plugin(px_asset_plugin::); + ); } -fn px_asset_plugin(app: &mut App) { +fn asset_plug(app: &mut App) { app.init_asset::>() .init_resource::>() .add_systems(PostUpdate, D::load.in_set(PxSet::LoadAssets)); diff --git a/src/button.rs b/src/button.rs index 34c3579..a4d97f2 100644 --- a/src/button.rs +++ b/src/button.rs @@ -1,6 +1,6 @@ use crate::{cursor::PxCursorPosition, math::RectExt, prelude::*, set::PxSet}; -pub(crate) fn button_plugin(app: &mut App) { +pub(crate) fn plug(app: &mut App) { app.init_resource::() .add_systems( PreUpdate, @@ -191,7 +191,7 @@ fn interact_buttons( }; if IRect::pos_size_anchor(**position, bounds.size, *anchor) - .contains(cursor_pos - bounds.offset.as_ivec2()) + .contains_exclusive(cursor_pos - bounds.offset.as_ivec2()) { if hovered.is_none() { button.insert(PxHover); diff --git a/src/camera.rs b/src/camera.rs index 563d40b..a835a9e 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub(crate) fn camera_plugin(app: &mut App) { +pub(crate) fn plug(app: &mut App) { app.init_resource::(); } diff --git a/src/cursor.rs b/src/cursor.rs index dbd3dc5..bc890c5 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -12,7 +12,7 @@ use crate::{ set::PxSet, }; -pub(crate) fn cursor_plugin(app: &mut App) { +pub(crate) fn plug(app: &mut App) { app.init_resource::() .init_resource::() .add_systems( diff --git a/src/lib.rs b/src/lib.rs index dea8983..04fd3ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,19 +33,8 @@ mod ui; use std::{marker::PhantomData, path::PathBuf}; -use animation::animation_plugin; -use asset::asset_plugin; - -use button::button_plugin; -use camera::camera_plugin; -use cursor::cursor_plugin; -use palette::palette_plugin; -#[cfg(feature = "particle")] -use particle::particle_plugin; -use position::{position_plugin, PxLayer}; +use position::PxLayer; use prelude::*; -use screen::screen_plugin; -use seldom_fn_plugin::FnPluginExt; /// Add to your [`App`] to enable `seldom_pixel`. The type parameter is your custom layer type /// used for z-ordering. You can make one using [`px_layer`]. @@ -58,7 +47,18 @@ pub struct PxPlugin { impl Plugin for PxPlugin { fn build(&self, app: &mut App) { - app.fn_plugin(px_plugin::(self.screen_size, self.palette_path.clone())); + app.add_plugins(( + animation::plug, + asset::plug, + button::plug, + camera::plug, + palette::plug(self.palette_path.clone()), + position::plug, + screen::plug::(self.screen_size), + cursor::plug, + #[cfg(feature = "particle")] + (RngPlugin::default(), particle::plug::), + )); } } @@ -70,25 +70,7 @@ impl PxPlugin { Self { screen_size, palette_path, - _l: default(), + _l: PhantomData, } } } - -/// Function called by [`PxPlugin`]. You may instead call it directly or use `seldom_fn_plugin`, -/// which is another crate I maintain. -pub fn px_plugin(screen_size: UVec2, palette_path: PathBuf) -> impl FnOnce(&mut App) { - move |app| { - app.fn_plugin(animation_plugin) - .fn_plugin(asset_plugin) - .fn_plugin(button_plugin) - .fn_plugin(camera_plugin) - .fn_plugin(palette_plugin(palette_path)) - .fn_plugin(position_plugin) - .fn_plugin(screen_plugin::(screen_size)) - .fn_plugin(cursor_plugin); - #[cfg(feature = "particle")] - app.add_plugins(RngPlugin::default()) - .fn_plugin(particle_plugin::); - } -} diff --git a/src/palette.rs b/src/palette.rs index 0b9a0ad..9ef0da9 100644 --- a/src/palette.rs +++ b/src/palette.rs @@ -6,9 +6,9 @@ use bevy::{render::render_resource::TextureFormat, utils::HashMap}; use crate::{prelude::*, set::PxSet}; -pub(crate) fn palette_plugin(palette_path: PathBuf) -> impl FnOnce(&mut App) { +pub(crate) fn plug(palette_path: PathBuf) -> impl Fn(&mut App) { move |app| { - app.add_systems(Startup, load_palette(palette_path)) + app.add_systems(Startup, load_palette(palette_path.clone())) .configure_sets( PreUpdate, ( diff --git a/src/particle.rs b/src/particle.rs index b783b6d..18d5068 100644 --- a/src/particle.rs +++ b/src/particle.rs @@ -11,7 +11,7 @@ use crate::{position::PxLayer, prelude::*, set::PxSet}; // If a day isn't sufficient for your use case, file an issue! const TIME_OFFSET: Duration = Duration::from_secs(60 * 60 * 24); -pub(crate) fn particle_plugin(app: &mut App) { +pub(crate) fn plug(app: &mut App) { app.configure_sets(PostUpdate, PxSet::UpdateEmitters.before(PxSet::Draw)) .add_systems( PostUpdate, diff --git a/src/position.rs b/src/position.rs index ff3c860..43a8209 100644 --- a/src/position.rs +++ b/src/position.rs @@ -4,7 +4,7 @@ use std::fmt::Debug; use crate::{prelude::*, set::PxSet}; -pub(crate) fn position_plugin(app: &mut App) { +pub(crate) fn plug(app: &mut App) { app.configure_sets(PreUpdate, PxSet::UpdatePosToSubPos) .add_systems( PreUpdate, diff --git a/src/prelude.rs b/src/prelude.rs index edab486..516c16c 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -31,7 +31,6 @@ pub use crate::{ filter::{PxFilter, PxFilterBundle, PxFilterLayers}, map::{PxMap, PxMapBundle, PxTile, PxTileBundle, PxTileset}, position::{PxAnchor, PxLayer, PxPosition, PxSubPosition, PxVelocity}, - px_plugin, sprite::{PxSprite, PxSpriteBundle}, text::{PxCharacterConfig, PxSeparatorConfig, PxText, PxTextBundle, PxTypeface}, ui::PxRect, diff --git a/src/screen.rs b/src/screen.rs index a7d1507..af5b27f 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -29,10 +29,10 @@ use crate::{ const SCREEN_SHADER_HANDLE: Handle = Handle::weak_from_u128(0x48CE_4F2C_8B78_5954_08A8_461F_62E1_0E84); -pub(crate) fn screen_plugin(size: UVec2) -> impl FnOnce(&mut App) { +pub(crate) fn plug(size: UVec2) -> impl Fn(&mut App) { move |app| { - app.world.resource_mut::>().insert( - SCREEN_SHADER_HANDLE, + app.world_mut().resource_mut::>().insert( + SCREEN_SHADER_HANDLE.id(), Shader::from_wgsl(include_str!("screen.wgsl"), "screen.wgsl"), ); app.add_plugins(Material2dPlugin::::default()) @@ -109,11 +109,10 @@ fn init_screen( mut images, mut meshes, mut screen_materials| { - let mut screen_palette = [default(); 256]; + let mut screen_palette = [Vec3::ZERO; 256]; for (i, [r, g, b]) in palette.colors.iter().enumerate() { - let [r, g, b, _] = Color::rgb_u8(*r, *g, *b).as_linear_rgba_f32(); - screen_palette[i] = Vec3::new(r, g, b); + screen_palette[i] = Color::srgb_u8(*r, *g, *b).linear().to_vec3(); } let image = images.add(Image { @@ -762,11 +761,10 @@ fn update_screen_palette( return; } - let mut screen_palette = [default(); 256]; + let mut screen_palette = [Vec3::ZERO; 256]; for (i, [r, g, b]) in palette.colors.iter().enumerate() { - let [r, g, b, _] = Color::rgb_u8(*r, *g, *b).as_linear_rgba_f32(); - screen_palette[i] = Vec3::new(r, g, b); + screen_palette[i] = Color::srgb_u8(*r, *g, *b).linear().to_vec3(); } for screen_material in &screen_materials {