Skip to content

Commit

Permalink
Merge branch '0.14'
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldom-SE committed Jul 10, 2024
2 parents 9f247e6 + 7493b03 commit c54d8b9
Show file tree
Hide file tree
Showing 17 changed files with 261 additions and 300 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 0.7 (2024-07-09)

### Changed

- Updated `bevy` to 0.14

### Removed

- `seldom_fn_plugin` integration

## 0.6.1 (2024-05-30)

### Fixed
Expand Down
19 changes: 9 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "seldom_pixel"
version = "0.6.1"
version = "0.7.0"
edition = "2021"
categories = ["game-development"]
description = "Bevy plugin for limited color palette pixel art games"
Expand All @@ -22,23 +22,22 @@ event-listener = "5.3"
serde = "1.0"
line_drawing = { version = "1.0", optional = true }
kiddo = { version = "4.2" }
seldom_fn_plugin = "0.6.0"
seldom_singleton = "0.1.0"
bevy_turborand = { version = "0.8.1", optional = true }
seldom_state = { version = "0.10.0", optional = true }
seldom_map_nav = { version = "0.6.0", optional = true }
seldom_singleton = "0.2.0"
bevy_turborand = { version = "0.9.0", optional = true }
seldom_map_nav = { version = "0.7.0", optional = true }
seldom_pixel_macros = { version = "0.1.0", path = "macros" }
seldom_state = { version = "0.11.0", optional = true }

[dependencies.bevy]
version = "0.13.0"
version = "0.14.0"
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", features = ["png"] }
leafwing-input-manager = "0.14.0"
rand = "0.8.5"
seldom_state = { version = "0.10.0", features = ["leafwing_input"] }
seldom_state = { version = "0.11.0", features = ["leafwing_input"] }

[[example]]
name = "line"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Then add `PxPlugin` to your app. Check out the examples for further usage.

| Bevy | `seldom_state` | `seldom_map_nav` | `seldom_interop` | `bevy_ecs_tilemap` | `seldom_pixel` |
| ---- | -------------- | ---------------- | ---------------- | ------------------ | -------------- |
| 0.14 | 0.11 | 0.7 | | | 0.7 |
| 0.13 | 0.10 | 0.6 | | | 0.6 |
| 0.12 | 0.9 | | 0.5 | 0.12 | 0.5 |
| 0.11 | 0.7 | | 0.4 | 0.11 | 0.4 |
Expand Down
2 changes: 1 addition & 1 deletion src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
set::PxSet,
};

pub(crate) fn animation_plugin(app: &mut App) {
pub(crate) fn plug(app: &mut App) {
app.configure_sets(
PostUpdate,
PxSet::FinishAnimations
Expand Down
4 changes: 2 additions & 2 deletions src/button.rs
Original file line number Diff line number Diff line change
@@ -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::<PxEnableButtons>()
.add_systems(
PreUpdate,
Expand Down Expand Up @@ -189,7 +189,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);
Expand Down
2 changes: 1 addition & 1 deletion src/camera.rs
Original file line number Diff line number Diff line change
@@ -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::<PxCamera>();
}

Expand Down
2 changes: 1 addition & 1 deletion src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
set::PxSet,
};

pub(crate) fn cursor_plugin(app: &mut App) {
pub(crate) fn plug(app: &mut App) {
app.init_resource::<PxCursor>()
.init_resource::<PxCursorPosition>()
.add_systems(
Expand Down
95 changes: 46 additions & 49 deletions src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use anyhow::{Error, Result};
use bevy::{
asset::{io::Reader, AssetLoader, LoadContext},
render::texture::{ImageLoader, ImageLoaderSettings},
utils::BoxedFuture,
};

use crate::{
Expand All @@ -18,7 +17,7 @@ use crate::{
prelude::*,
};

pub(crate) fn filter_plugin(app: &mut App) {
pub(crate) fn plug(app: &mut App) {
app.init_asset::<PxFilter>()
.init_asset_loader::<PxFilterLoader>();
}
Expand All @@ -36,60 +35,58 @@ impl AssetLoader for PxFilterLoader {
type Settings = ImageLoaderSettings;
type Error = Error;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
settings: &'a ImageLoaderSettings,
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<PxFilter>> {
Box::pin(async move {
let Self(image_loader) = self;
let image = image_loader.load(reader, settings, load_context).await?;
let palette = asset_palette().await;
let indices = PxImage::palette_indices(palette, &image)?;

let mut filter = Vec::with_capacity(indices.area());
let frame_size = palette.size;
let frame_area = frame_size.x * frame_size.y;
let filter_width = image.texture_descriptor.size.width;
let frame_filter_width = filter_width / palette.size.x;

let mut frame_visible = true;

for i in 0..indices.area() {
let frame_index = i as u32 / frame_area;
let frame_pos = i as u32 % frame_area;

if frame_pos == 0 {
if !frame_visible {
for _ in 0..frame_area {
filter.pop();
}
break;
load_context: &'a mut LoadContext<'_>,
) -> Result<PxFilter> {
let Self(image_loader) = self;
let image = image_loader.load(reader, settings, load_context).await?;
let palette = asset_palette().await;
let indices = PxImage::palette_indices(palette, &image)?;

let mut filter = Vec::with_capacity(indices.area());
let frame_size = palette.size;
let frame_area = frame_size.x * frame_size.y;
let filter_width = image.texture_descriptor.size.width;
let frame_filter_width = filter_width / palette.size.x;

let mut frame_visible = true;

for i in 0..indices.area() {
let frame_index = i as u32 / frame_area;
let frame_pos = i as u32 % frame_area;

if frame_pos == 0 {
if !frame_visible {
for _ in 0..frame_area {
filter.pop();
}

frame_visible = false;
break;
}

filter.push(
if let Some(index) = indices.pixel(
(UVec2::new(
frame_index % frame_filter_width,
frame_index / frame_filter_width,
) * frame_size
+ UVec2::new(frame_pos % frame_size.x, frame_pos / frame_size.x))
.as_ivec2(),
) {
frame_visible = true;
index
} else {
0
},
);
frame_visible = false;
}

Ok(PxFilter(PxImage::new(filter, frame_area as usize)))
})
filter.push(
if let Some(index) = indices.pixel(
(UVec2::new(
frame_index % frame_filter_width,
frame_index / frame_filter_width,
) * frame_size
+ UVec2::new(frame_pos % frame_size.x, frame_pos / frame_size.x))
.as_ivec2(),
) {
frame_visible = true;
index
} else {
0
},
);
}

Ok(PxFilter(PxImage::new(filter, frame_area as usize)))
}

fn extensions(&self) -> &[&str] {
Expand Down
60 changes: 16 additions & 44 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,9 @@ mod ui;

use std::{marker::PhantomData, path::PathBuf};

use animation::animation_plugin;
use bevy::render::view::RenderLayers;
use button::button_plugin;
use camera::camera_plugin;
use cursor::cursor_plugin;
use filter::filter_plugin;
use map::map_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;
use sprite::sprite_plugin;
use text::text_plugin;

/// 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`].
Expand All @@ -68,7 +55,7 @@ impl<L: PxLayer> PxPlugin<L> {
screen_size: screen_size.into(),
palette_path: palette_path.into(),
layers: RenderLayers::default(),
_l: default(),
_l: PhantomData,
}
}

Expand All @@ -81,35 +68,20 @@ impl<L: PxLayer> PxPlugin<L> {

impl<L: PxLayer> Plugin for PxPlugin<L> {
fn build(&self, app: &mut App) {
app.fn_plugin(px_plugin::<L>(
self.screen_size,
self.palette_path.clone(),
self.layers,
app.add_plugins((
animation::plug,
button::plug,
camera::plug,
cursor::plug,
filter::plug,
map::plug,
palette::plug(self.palette_path.clone()),
position::plug,
screen::plug::<L>(self.screen_size, self.layers.clone()),
sprite::plug,
text::plug,
#[cfg(feature = "particle")]
(RngPlugin::default(), particle::plug::<L>),
));
}
}

/// 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<L: PxLayer>(
screen_size: ScreenSize,
palette_path: PathBuf,
layers: RenderLayers,
) -> impl FnOnce(&mut App) {
move |app| {
app.fn_plugin(animation_plugin)
.fn_plugin(button_plugin)
.fn_plugin(camera_plugin)
.fn_plugin(cursor_plugin)
.fn_plugin(filter_plugin)
.fn_plugin(map_plugin)
.fn_plugin(palette_plugin(palette_path))
.fn_plugin(position_plugin)
.fn_plugin(screen_plugin::<L>(screen_size, layers))
.fn_plugin(sprite_plugin)
.fn_plugin(text_plugin);
#[cfg(feature = "particle")]
app.add_plugins(RngPlugin::default())
.fn_plugin(particle_plugin::<L>);
}
}
Loading

0 comments on commit c54d8b9

Please sign in to comment.