generated from 2ndbeam/bevy-template
feat!: Item processing
- Added try_insert_item system
- Added rotated field on Item
- Implemented UI item drawing with scale and rotation
BREAKING CHANGE: Item.swap_size renamed to Item.rotate
Item.clone_swapped renamed to Item.clone_rotated
This commit is contained in:
parent
ab993be476
commit
c46fa75e54
3 changed files with 114 additions and 15 deletions
|
|
@ -2,19 +2,20 @@ use std::mem::swap;
|
|||
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[derive(Component, Clone)]
|
||||
#[derive(Component, Clone, Debug)]
|
||||
pub struct Item {
|
||||
pub size: UVec2,
|
||||
pub position: Option<UVec2>,
|
||||
pub rotated: bool,
|
||||
}
|
||||
|
||||
impl Item {
|
||||
pub fn new(size: UVec2) -> Self {
|
||||
Self { size, position: None }
|
||||
Self { size, position: None, rotated: false }
|
||||
}
|
||||
|
||||
pub fn new_positioned(size: UVec2, position: UVec2) -> Self {
|
||||
Self { size, position: Some(position) }
|
||||
Self { size, position: Some(position), rotated: false }
|
||||
}
|
||||
|
||||
pub fn rect(&self) -> Option<URect> {
|
||||
|
|
@ -36,14 +37,15 @@ impl Item {
|
|||
}
|
||||
|
||||
/// Swap size.x with size.y
|
||||
pub fn swap_size(&mut self) {
|
||||
pub fn rotate(&mut self) {
|
||||
swap(&mut self.size.x, &mut self.size.y);
|
||||
self.rotated = !self.rotated;
|
||||
}
|
||||
|
||||
/// Get clone of item with swapped size
|
||||
pub fn clone_swapped(&self) -> Self {
|
||||
pub fn clone_rotated(&self) -> Self {
|
||||
let mut new = self.clone();
|
||||
new.swap_size();
|
||||
new.rotate();
|
||||
new
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue