You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you `cargo run` your project now, you can run around the (otherwise deserted) demo map:
299
+
300
+
.
301
+
302
+
## Populating the test map with prefabbed entities
303
+
304
+
Let's pretend that our test map is some sort of super-duper end-game map. We'll take a copy and call it `wfc-populated.xp`. Then we'll splat a bunch of monster and item glyphs around it:
305
+
306
+
.
307
+
308
+
The color coding is completely optional, but I put it in for clarity. You'll see we have an `@` to indicate the player start, a `>` to indicate the exit, and a bunch of `g` goblins, `o` orcs, `!` potions, `%` rations and `^` traps. Not too bad a map, really.
309
+
310
+
We'll add `wfc-populated.xp` to our `resources` folder, and extend `rex_assets.rs` to load it:
We also want to be able to list out spawns that are required by the map. Looking in `spawner.rs`, we have an established `tuple` format for how we pass spawns - so we'll use it in the struct:
338
+
339
+
```rust
340
+
#[allow(dead_code)]
341
+
pubstructPrefabBuilder {
342
+
map:Map,
343
+
starting_position:Position,
344
+
depth:i32,
345
+
history:Vec<Map>,
346
+
mode:PrefabMode,
347
+
spawns:Vec<(usize, String)>
348
+
}
349
+
```
350
+
351
+
Now we'll modify our constructor to *use* the new map, and initialize `spawns`:
To make use of the function in `spawner.rs` that accepts this type of data, we need to make it *public*. So we open up the file, and add the word `pub` to the function signature:
370
+
371
+
```rust
372
+
/// Spawns a named entity (name in tuple.1) at the location in (tuple.0)
We do a bit of a dance with references just to work with the previous function signature (and not have to change it, which would change lots of other code). So far, so good - it reads the `spawn` list, and requests that everything in the list be placed onto the map. Now would be a good time to add something to the list! We'll want to modify our `load_rex_map` to handle the new data:
This recognizes the extra glyphs, and prints a warning to the console if we've loaded one we forgot to handle. Note that for entities, we're setting the tile to `Floor` and *then* adding the entity type. That's because we can't overlay two glyphs on the same tile - but it stands to reason that the entity is *standing* on a floor.
441
+
442
+
Lastly, we need to modify our `build` function to not move the exit and the player. We simply wrap the fallback code in an `if` statement to detect if we've set a `starting_position` (we're going to require that if you set a start, you also set an exit):
0 commit comments