Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Bevy Sprite Animations
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Bevy Sprite Animations
Commits
2f58dce5
Verified
Commit
2f58dce5
authored
1 year ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Simplify directionality
parent
d5074edf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/directionality.rs
+68
-22
68 additions, 22 deletions
src/directionality.rs
with
68 additions
and
22 deletions
src/directionality.rs
+
68
−
22
View file @
2f58dce5
use
std
::
fmt
::{
Display
,
Formatter
};
use
bevy
::
math
::{
Vec2
,
Vec3
};
use
bevy
::
prelude
::
Component
;
use
std
::
fmt
::{
Display
,
Formatter
};
#[derive(Clone,
Debug,
PartialEq,
Eq,
Ord,
PartialOrd,
Default)]
#[derive(
Component,
Copy,
Clone,
Debug,
PartialEq,
Eq,
Default)]
#[cfg_attr(feature
=
"serde"
,
derive(serde::Serialize,
serde::Deserialize))]
pub
enum
Horizontal
{
Left
,
...
...
@@ -11,6 +9,15 @@ pub enum Horizontal {
Right
,
}
impl
From
<
Horizontal
>
for
Directionality
{
fn
from
(
value
:
Horizontal
)
->
Self
{
match
value
{
Horizontal
::
Left
=>
Directionality
::
Left
,
Horizontal
::
Right
=>
Directionality
::
Right
,
}
}
}
impl
From
<
f32
>
for
Horizontal
{
fn
from
(
other
:
f32
)
->
Self
{
if
other
<
0.0
{
...
...
@@ -30,7 +37,7 @@ impl Display for Horizontal {
}
}
#[derive(Clone,
Debug,
PartialEq,
Eq,
Ord,
PartialOrd,
Default)]
#[derive(
Component,
Copy,
Clone,
Debug,
PartialEq,
Eq,
Default)]
#[cfg_attr(feature
=
"serde"
,
derive(serde::Serialize,
serde::Deserialize))]
pub
enum
Vertical
{
Up
,
...
...
@@ -38,6 +45,15 @@ pub enum Vertical {
Down
,
}
impl
From
<
Vertical
>
for
Directionality
{
fn
from
(
value
:
Vertical
)
->
Self
{
match
value
{
Vertical
::
Up
=>
Directionality
::
Up
,
Vertical
::
Down
=>
Directionality
::
Down
,
}
}
}
impl
From
<
f32
>
for
Vertical
{
fn
from
(
other
:
f32
)
->
Self
{
if
other
<
0.0
{
...
...
@@ -57,33 +73,63 @@ impl Display for Vertical {
}
}
#[derive(Clone,
Debug,
Component,
PartialEq,
Eq,
Ord,
PartialOrd,
Default)]
#[derive(
Component,
Copy,
Clone,
Debug,
PartialEq,
Eq,
Default)]
#[cfg_attr(feature
=
"serde"
,
derive(serde::Serialize,
serde::Deserialize))]
pub
struct
Directionality
{
pub
vertical
:
Vertical
,
pub
horizontal
:
Horizontal
,
pub
enum
Directionality
{
Up
,
Down
,
Left
,
Right
,
RightUp
,
LeftUp
,
LeftDown
,
RightDown
,
}
impl
From
<
Vec2
>
for
Directionality
{
fn
from
(
other
:
Vec2
)
->
Self
{
Self
{
horizontal
:
other
.x
.into
(),
vertical
:
other
.y
.into
(),
impl
Directionality
{
pub
fn
with_horizontal
(
&
mut
self
,
horizontal
:
Horizontal
)
{
*
self
=
match
self
{
Self
::
Up
|
Self
::
Down
|
Self
::
Left
|
Self
::
Right
=>
horizontal
.into
(),
Self
::
RightUp
|
Self
::
LeftUp
=>
match
horizontal
{
Horizontal
::
Right
=>
Self
::
RightUp
,
Horizontal
::
Left
=>
Self
::
LeftUp
,
},
Self
::
LeftDown
|
Self
::
RightDown
=>
match
horizontal
{
Horizontal
::
Right
=>
Self
::
RightDown
,
Horizontal
::
Left
=>
Self
::
LeftDown
,
},
}
}
}
impl
From
<
Vec3
>
for
Directionality
{
fn
from
(
other
:
Vec3
)
->
Self
{
Self
{
horizontal
:
other
.x
.into
(),
vertical
:
other
.y
.into
(),
pub
fn
with_vertical
(
&
mut
self
,
vertical
:
Vertical
)
{
*
self
=
match
self
{
Self
::
Up
|
Self
::
Down
|
Self
::
Left
|
Self
::
Right
=>
vertical
.into
(),
Self
::
RightUp
|
Self
::
RightDown
=>
match
vertical
{
Vertical
::
Up
=>
Self
::
RightUp
,
Vertical
::
Down
=>
Self
::
RightDown
,
},
Self
::
LeftDown
|
Self
::
LeftUp
=>
match
vertical
{
Vertical
::
Up
=>
Self
::
LeftUp
,
Vertical
::
Down
=>
Self
::
LeftDown
,
},
}
}
}
impl
Display
for
Directionality
{
fn
fmt
(
&
self
,
f
:
&
mut
Formatter
<
'_
>
)
->
std
::
fmt
::
Result
{
write!
(
f
,
"{}_{}"
,
self
.horizontal
,
self
.vertical
)
write!
(
f
,
"{}"
,
match
self
{
Self
::
Up
=>
"up"
,
Self
::
Down
=>
"down"
,
Self
::
Left
=>
"left"
,
Self
::
Right
=>
"right"
,
Self
::
RightUp
=>
"right_up"
,
Self
::
LeftUp
=>
"left_up"
,
Self
::
RightDown
=>
"right_down"
,
Self
::
LeftDown
=>
"left_down"
,
}
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment