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
d747cba9
Verified
Commit
d747cba9
authored
1 year ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Fix readme formatting
parent
078ba9e0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+25
-23
25 additions, 23 deletions
README.md
with
25 additions
and
23 deletions
README.md
+
25
−
23
View file @
d747cba9
...
@@ -40,34 +40,36 @@ index in some theoretical sprite sheet.
...
@@ -40,34 +40,36 @@ index in some theoretical sprite sheet.
1.
Create one or more rules that define a pattern to match, a value to output, and optionally a percentage
1.
Create one or more rules that define a pattern to match, a value to output, and optionally a percentage
chance for that rule to be chosen.
chance for that rule to be chosen.
*
```rust
```
rust
use micro_autotile::AutoTileRule;
use
micro_autotile
::
AutoTileRule
;
const GROUND: usize = 0;
const
GROUND
:
usize
=
0
;
const WALL: usize = 1;
const
WALL
:
usize
=
1
;
let alt_ground_rule = AutoTileRule::single_any_chance(GROUND, vec![123, 124, 125], 0.2);
let
alt_ground_rule
=
AutoTileRule
::
single_any_chance
(
GROUND
,
vec!
[
123
,
124
,
125
],
0.2
);
let fallback_ground_rule = AutoTileRule::exact(GROUND, 126);
let
fallback_ground_rule
=
AutoTileRule
::
exact
(
GROUND
,
126
);
```
```
2.
(Optional) Put together your rules in a rule set. This can be skipped and the rule structs used directly
2.
(Optional) Put together your rules in a rule set. This can be skipped and the rule structs used directly
*
```rust
```
rust
use micro_autotile::{AutoRuleSet, AutoTileRule};
use
micro_autotile
::{
AutoRuleSet
,
AutoTileRule
};
let ground_rules = AutoRuleSet::new(vec![alt_ground_rule, fallback_ground_rule]);
let
ground_rules
=
AutoRuleSet
::
new
(
vec!
[
alt_ground_rule
,
fallback_ground_rule
]);
let wall_rules = AutoTileRule::exact(WALL, 35).into();
let
wall_rules
=
AutoTileRule
::
exact
(
WALL
,
35
)
.into
();
let combined_rules = wall_rules + ground_rules;
let
combined_rules
=
wall_rules
+
ground_rules
;
```
```
3.
Elsewhere, generate a slice of level data wrapped in a
`TileLayout`
struct. This represents a single tile
3.
Elsewhere, generate a slice of level data wrapped in a
`TileLayout`
struct. This represents a single tile
(the central element) and its surrounding neighbors. The order of the neighbors is important, and is laid
(the central element) and its surrounding neighbors. The order of the neighbors is important, and is laid
out as though in a flattened grid.
out as though in a flattened grid.
*
```rust
```
rust
use micro_autotile::TileLayout;
use
micro_autotile
::
TileLayout
;
let layout = TileLayout::filled([
let
layout
=
TileLayout
::
filled
([
GROUND, GROUND, GROUND,
GROUND
,
GROUND
,
GROUND
,
GROUND, WALL, GROUND,
GROUND
,
WALL
,
GROUND
,
GROUND, GROUND, GROUND,
GROUND
,
GROUND
,
GROUND
,
]);
]);
```
```
4.
Produce
an
output
using
either
the
rule
set
or
the
rule
directly
(
the
same
methods
exist
for
both
)
4.
Produce
an
output
using
either
the
rule
set
or
the
rule
directly
(
the
same
methods
exist
for
both
)
*
```rust
```
rust
let output = combined_rules.resolve_match(&layout);
let output = combined_rules.resolve_match(
&layout);
assert_eq!(output, Some(35));
assert_eq!(output, Some(35));
```
```
\ No newline at end of file
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