Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Autotile
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Autotile
Commits
5f1bdebe
Verified
Commit
5f1bdebe
authored
3 months ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Switch from_ldtk_array to use new try_from impl
parent
d4f55411
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/layout.rs
+4
-8
4 additions, 8 deletions
src/layout.rs
with
4 additions
and
8 deletions
src/layout.rs
+
4
−
8
View file @
5f1bdebe
use
std
::
fmt
::{
write
,
Debug
,
Formatter
};
use
std
::
fmt
::{
Debug
,
Formatter
};
use
crate
::
utils
::
IntoTile
;
/// The size of the grid that can be matched; equal to the length of one side of the square grid
...
...
@@ -11,7 +11,7 @@ const GRID_CENTER: usize = (TILE_GRID_SIZE - 1) / 2;
#[derive(Debug,
Clone,
Copy,
Eq,
PartialEq)]
pub
struct
NotSquareError
;
impl
std
::
fmt
::
Display
for
NotSquareError
{
fn
fmt
(
&
self
,
f
:
&
mut
std
::
fmt
::
Formatter
<
'_
>
)
->
std
::
fmt
::
Result
{
fn
fmt
(
&
self
,
f
:
&
mut
Formatter
<
'_
>
)
->
std
::
fmt
::
Result
{
write!
(
f
,
"Input is not a square grid"
)
}
}
...
...
@@ -149,7 +149,7 @@ impl Debug for TileLayout {
}
}
impl
<
T
>
TryFrom
<&
[
T
]
>
for
TileLayout
where
T
:
IntoTile
+
Copy
+
Default
+
Debug
{
impl
<
T
>
TryFrom
<&
[
T
]
>
for
TileLayout
where
T
:
IntoTile
+
Copy
+
Default
{
type
Error
=
NotSquareError
;
fn
try_from
(
value
:
&
[
T
])
->
Result
<
Self
,
Self
::
Error
>
{
if
is_square
(
value
.len
())
{
...
...
@@ -213,11 +213,7 @@ impl TileMatcher {
/// Load data from an LDTK JSON file. Supports arbitrary sized matchers for any square grid.
/// Other sizes of matcher will result in `None`
pub
fn
from_ldtk_array
(
value
:
Vec
<
i64
>
)
->
Option
<
Self
>
{
if
is_square
(
value
.len
())
{
Some
(
Self
(
transpose
(
value
.as_slice
())
.map
(
TileStatus
::
from
)))
}
else
{
None
}
Self
::
try_from
(
value
.as_slice
())
.ok
()
}
}
...
...
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