Skip to content
Snippets Groups Projects
Verified Commit d747cba9 authored by Louis's avatar Louis :fire:
Browse files

Fix readme formatting

parent 078ba9e0
No related branches found
No related tags found
No related merge requests found
......@@ -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
chance for that rule to be chosen.
* ```rust
use micro_autotile::AutoTileRule;
const GROUND: usize = 0;
const WALL: usize = 1;
let alt_ground_rule = AutoTileRule::single_any_chance(GROUND, vec![123, 124, 125], 0.2);
let fallback_ground_rule = AutoTileRule::exact(GROUND, 126);
```rust
use micro_autotile::AutoTileRule;
const GROUND: usize = 0;
const WALL: usize = 1;
let alt_ground_rule = AutoTileRule::single_any_chance(GROUND, vec![123, 124, 125], 0.2);
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
* ```rust
use micro_autotile::{AutoRuleSet, AutoTileRule};
let ground_rules = AutoRuleSet::new(vec![alt_ground_rule, fallback_ground_rule]);
let wall_rules = AutoTileRule::exact(WALL, 35).into();
let combined_rules = wall_rules + ground_rules;
```
```rust
use micro_autotile::{AutoRuleSet, AutoTileRule};
let ground_rules = AutoRuleSet::new(vec![alt_ground_rule, fallback_ground_rule]);
let wall_rules = AutoTileRule::exact(WALL, 35).into();
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
(the central element) and its surrounding neighbors. The order of the neighbors is important, and is laid
out as though in a flattened grid.
* ```rust
use micro_autotile::TileLayout;
let layout = TileLayout::filled([
GROUND, GROUND, GROUND,
GROUND, WALL, GROUND,
GROUND, GROUND, GROUND,
]);
```rust
use micro_autotile::TileLayout;
let layout = TileLayout::filled([
GROUND, GROUND, GROUND,
GROUND, WALL, GROUND,
GROUND, GROUND, GROUND,
]);
```
4. Produce an output using either the rule set or the rule directly (the same methods exist for both)
* ```rust
let output = combined_rules.resolve_match(&layout);
assert_eq!(output, Some(35));
```rust
let output = combined_rules.resolve_match(&layout);
assert_eq!(output, Some(35));
```
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment