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
2eaa8ae9
Verified
Commit
2eaa8ae9
authored
3 months ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Add more doctests for layout types & CI config
parent
b845870c
Branches
feature/larger-grids
trunk
Tags
v0.2.0
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci.yaml
+22
-0
22 additions, 0 deletions
.gitlab-ci.yaml
src/layout.rs
+56
-5
56 additions, 5 deletions
src/layout.rs
with
78 additions
and
5 deletions
.gitlab-ci.yaml
0 → 100644
+
22
−
0
View file @
2eaa8ae9
image
:
rust:1.82-alpine
stages
:
-
test
lint
:
stage
:
test
script
:
-
cargo fmt --all --check
-
cargo clippy --offline --frozen --locked -- -D warnings
test
:
stage
:
test
script
:
-
cargo test
package
:
stage
:
test
script
:
-
cargo package --release
dependencies
:
-
test
-
lint
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/layout.rs
+
56
−
5
View file @
2eaa8ae9
...
...
@@ -82,13 +82,13 @@ impl TileLayout {
}
/// Construct a filled grid of tile data
pub
fn
filled
(
values
:
[
i
32
;
TILE_GRID_SIZE
])
->
Self
{
TileLayout
(
values
.map
(
Some
))
pub
fn
filled
(
values
:
[
i
mpl
IntoTile
;
TILE_GRID_SIZE
])
->
Self
{
TileLayout
(
values
.map
(
|
val
|
Some
(
val
.into_tile
())
))
}
/// Construct a filled grid of identical tile data
pub
fn
spread
(
value
:
i
32
)
->
Self
{
TileLayout
([
Some
(
value
);
TILE_GRID_SIZE
])
pub
fn
spread
(
value
:
i
mpl
IntoTile
)
->
Self
{
TileLayout
([
Some
(
value
.into_tile
()
);
TILE_GRID_SIZE
])
}
/// Filter the layout data so that it only contains the tiles surrounding the target tile. This
...
...
@@ -190,13 +190,33 @@ impl Default for TileMatcher {
}
impl
TileMatcher
{
/// Create a matcher that only evaluates one rule against the central target tile
///
/// ## Examples
///
/// ```
/// # use micro_autotile::{TileLayout, TileMatcher, TileStatus};
/// let rule = TileStatus::IsNot(123);
/// let matcher = TileMatcher::single(rule);
///
/// assert!(matcher.matches(&TileLayout::single(456)));
/// assert!(matcher.matches(&TileLayout::spread(1)));
/// ```
pub
const
fn
single
(
value
:
TileStatus
)
->
Self
{
let
mut
rules
=
[
TileStatus
::
Ignore
;
TILE_GRID_SIZE
];
rules
[
GRID_CENTER
]
=
value
;
TileMatcher
(
rules
)
}
/// Create a 1x1 matcher, with any rule for the target tile
/// Create a matcher that only checks if the target tile matches the given value
///
/// ## Examples
///
/// ```
/// # use micro_autotile::{TileLayout, TileMatcher};
/// let matcher = TileMatcher::single_match(123);
/// assert!(matcher.matches(&TileLayout::single(123)));
/// ```
pub
const
fn
single_match
(
value
:
i32
)
->
Self
{
Self
::
single
(
TileStatus
::
Is
(
value
))
}
...
...
@@ -211,6 +231,37 @@ 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`
///
/// ## Examples
///
/// A simple 1x1 LDTK Array
///
/// ```
/// # use micro_autotile::{TileMatcher, TileLayout};
/// let matcher = TileMatcher::from_ldtk_array(vec![1]).expect("Invalid input");
/// assert!(matcher.matches(&TileLayout::single(1)));
/// ```
///
/// A 3x3 matcher with more complex rules
///
/// ```
/// # use micro_autotile::{TileMatcher, TileLayout};
/// let rule_input: Vec<i64> = vec![
/// 100, -100, 100,
/// 0, 5, 0,
/// 0, 0, 0
/// ];
///
/// let tile_section: [i32; 9] = [
/// 100, 5, 100,
/// 24, 5, 293,
/// 34, 21, 22
/// ];
///
/// let matcher = TileMatcher::from_ldtk_array(rule_input).expect("Invalid input");
/// let map_layout = TileLayout::try_from(tile_section.as_slice()).expect("Invalid input");
/// assert!(matcher.matches(&map_layout));
/// ```
pub
fn
from_ldtk_array
(
value
:
Vec
<
i64
>
)
->
Option
<
Self
>
{
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