Skip to content

Commit

Permalink
Improve guide by example punctuation
Browse files Browse the repository at this point in the history
  • Loading branch information
leudz committed Jul 12, 2024
1 parent a4ccafb commit ed3f864
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion guide/0.7/src/learn-by-example/breather.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn collision(mut player: UniqueViewMut<Player>, v_friend: View<Friend>) -> Resul
Systems can return any type, [`World::run`](https://docs.rs/shipyard/latest/shipyard/struct.World.html#method.run) then returns when the function returns.\
Moving the panic to `main` isn't a big change but it allows a better control of what happens which will be useful later on.

To finish this chapter we can better show the duplicity of the "`Friend`s".
To conclude this chapter we can better show the duplicity of the "`Friends`".

```rust,noplaypen
fn render(player: UniqueView<Player>, v_friend: View<Friend>) {
Expand Down
12 changes: 6 additions & 6 deletions guide/0.7/src/learn-by-example/friends.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Instead we'll store them in a [`World`](https://docs.rs/shipyard/latest/shipyard
[`World`](https://docs.rs/shipyard/latest/shipyard/struct.World.html) is shipyard's main type.\
It's where everything is stored, from components to entities to systems.

In this guide I'll be explicit about `shipyard` imports but you could `use shipyard::*;` if you wanted.
In this guide, I'll be explicit about `shipyard` imports but you could `use shipyard::*;` if you prefer.

```rust,noplaypen
use macroquad::rand::gen_range;
Expand Down Expand Up @@ -63,10 +63,10 @@ impl Friend {
}
```

This won't compile just yet, `Friend` is not a [`Component`](https://docs.rs/shipyard/latest/shipyard/trait.Component.html).\
Some ECS require you to explicitly specify which types are components and some don't.\
This won't compile just yet, as `Friend` is not a [`Component`](https://docs.rs/shipyard/latest/shipyard/trait.Component.html).\
Some ECS require you to explicitly specify which types are components, and some don't.\
One of the reasons shipyard requires it is to easily identify components in codebases.\
With small projects this isn't a big issue but as the number of lines grow, you'll have to find a way to identify components. This could be moving types to a `component.rs` but I'd rather have modules split based on what they do.
With small projects, this isn't a big issue, but as the number of lines grow, you'll have to find a way to identify components. This could be moving types to a `component.rs`, but I'd rather have modules split based on what they do.

Let's add the missing piece.

Expand All @@ -81,7 +81,7 @@ And [`iter`](https://docs.rs/shipyard/latest/shipyard/struct.World.html#method.i

We can move `Player` into the [`World`](https://docs.rs/shipyard/latest/shipyard/struct.World.html) to simplify our code a little.\
We only have a single `Player` and it will only ever have a single component.\
For this kind of entities shipyard has [`Unique`](https://docs.rs/shipyard/latest/shipyard/trait.Unique.html) components.
For this kind of entities, shipyard has [`Unique`](https://docs.rs/shipyard/latest/shipyard/trait.Unique.html) components.

```rust,noplaypen
use shipyard::{Component, Unique, World};
Expand Down Expand Up @@ -169,7 +169,7 @@ fn move_player(mut player: UniqueViewMut<Player>) {
```

You've just written your first systems.\
With shipyard all functions that have only views as arguments are systems.\
With shipyard, all functions that have only views as arguments are systems.\
The [`World`](https://docs.rs/shipyard/latest/shipyard/struct.World.html) understands these functions and provides the desired components automatically.

The `v_`/`vm_` prefix for views is a convention that some `shipyard` users use. I'll follow it throughout the guide.
14 changes: 7 additions & 7 deletions guide/0.7/src/learn-by-example/reign.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Reign

We've had plenty of time to think of a way for our `Player` to get back at those pesky `Friend`s.\
Sometimes the simplest solution is the best.\
If the `Friend`s can overpower the `Player` when they are fully grown, we shouldn't let them reach that size.\
We've had plenty of time to think of a way for our `Player` to get back at those pesky `Friends`.\
Sometimes, the simplest solution is the best.\
If the `Friends` can overpower the `Player` when they are fully grown, we shouldn't let them reach that size.\
I'm sure the `Player` can overcome `Friend` that are smaller than them.

```rust,noplaypen
Expand Down Expand Up @@ -33,13 +33,13 @@ fn collision(
}
```

It appears our `Player` can even overcome `Friend`s that are their size.\
It appears our `Player` can even overcome `Friends` of equal size.\
By... eating them!?

Remember when we added `Friend`s to the [`World`](https://docs.rs/shipyard/latest/shipyard/struct.World.html), each one was assigned an [`EntityId`](https://docs.rs/shipyard/latest/shipyard/struct.EntityId.html).\
Remember when we added `Friends` to the [`World`](https://docs.rs/shipyard/latest/shipyard/struct.World.html), each one was assigned an [`EntityId`](https://docs.rs/shipyard/latest/shipyard/struct.EntityId.html).\
We can iterate over both components and the [`EntityId`](https://docs.rs/shipyard/latest/shipyard/struct.EntityId.html) of the entity that owns them by using `with_id`.

Then we can use this [`EntityId`](https://docs.rs/shipyard/latest/shipyard/struct.EntityId.html) to add another component to the vanquished `Friend`s.\
Then we can use this [`EntityId`](https://docs.rs/shipyard/latest/shipyard/struct.EntityId.html) to add another component to the vanquished `Friends`.\
As you may have noticed we are not modifying `entities`. We only need it to check that the `eid` is alive.

`ToDelete` is not a special component, we still have to make it do its job.
Expand Down Expand Up @@ -80,7 +80,7 @@ We are using it to [`delete_any`](https://docs.rs/shipyard/latest/shipyard/struc

## It's over

Defeating smaller `Friend`s is nice but most of the time they've grown by the time the `Player` reaches them.\
Defeating smaller `Friends` is nice but most of the time they've grown by the time the `Player` reaches them.\
The `Player` needs more power.

```rust,noplaypen
Expand Down
10 changes: 5 additions & 5 deletions guide/0.7/src/learn-by-example/spark.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ fn grow(mut vm_friend: ViewMut<Friend>) {
}
```

`grow`'s code could be simpler but this version makes `Friend`s grow from their center which feels a lot more natural.
`grow`'s code could be simpler but this version makes `Friends` grow from their center, which feels a lot more natural.

It appears our `Friend`s want to come close to the `Player`, likely to give them a hug.
It appears our `Friends` want to come close to the `Player`, likely to give them a hug.

```rust,noplaypen
const SPEED: f32 = 1.5;
Expand Down Expand Up @@ -97,8 +97,8 @@ fn move_friends(player: UniqueView<Player>, mut vm_friend: ViewMut<Friend>) {
}
```

As you can see you can iterate views multiple times in the same system.\
We also make sure the `Friend`s don't simply all overlap by stirring them away from their neighbors.
As you can see, you can iterate views multiple times in the same system.\
We also prevent the `Friends` from overlapping by stirring them away from their neighbors.

But something doesn't feel right...

Expand Down Expand Up @@ -139,4 +139,4 @@ fn collision(mut player: UniqueViewMut<Player>, v_friend: View<Friend>) {
}
```

Oh my god! The "`Friend`s" killed the `Player`!?
Oh my god! The "`Friends`" killed the `Player`!?
20 changes: 10 additions & 10 deletions guide/0.7/src/learn-by-example/true-victory.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# True victory

It seems the `Friend`s are able to copy the power pellets' spawning mechanic!
It seems the `Friends` are able to copy the power pellets' spawning mechanic!
And they've learned to avoid the `Player` whenever they are powered up.

```rust,noplaypen
Expand Down Expand Up @@ -44,7 +44,7 @@ fn spawn(
```

Let's give the `Player` a little bit of help and a way to win again.
In many games whenever the player is hit they'll turn invincible for a few frames.
In many games, whenever the player is hit, they'll turn invincible for a few frames.

```rust,noplaypen
async fn main() {
Expand Down Expand Up @@ -102,7 +102,7 @@ fn counters(mut player: UniqueViewMut<Player>) {
}
```

We'll finish this guide by allowing the `Player` to win.
We'll conclude this guide by allowing the `Player` to win.

```rust,noplaypen
use shipyard::{
Expand Down Expand Up @@ -189,10 +189,10 @@ fn check_game_over(player: UniqueView<Player>, v_friends: View<Friend>) -> Resul
[`Workload`](https://docs.rs/shipyard/latest/shipyard/struct.Workload.html)s are a collection of systems.\
We only have a single [`Workload`](https://docs.rs/shipyard/latest/shipyard/struct.Workload.html) in our game since it's quite small.\
You would usually have smaller [`Workload`](https://docs.rs/shipyard/latest/shipyard/struct.Workload.html)s that make up larger ones.\
Apart from organization, [`Workload`](https://docs.rs/shipyard/latest/shipyard/struct.Workload.html)s are automatically run across multiple threads which can usually boost performance.
Apart from organization, [`Workload`](https://docs.rs/shipyard/latest/shipyard/struct.Workload.html)s are automatically run across multiple threads, which can usually boost performance.

The last touch is to handle `check_game_over`'s return value.\
We use [`into_workload_try_system`](https://docs.rs/shipyard/latest/shipyard/trait.IntoWorkloadTrySystem.html#tymethod.into_workload_try_system) to explicitly tell the [`Workload`](https://docs.rs/shipyard/latest/shipyard/struct.Workload.html) that this system might return something but we don't handle it anywhere.
We use [`into_workload_try_system`](https://docs.rs/shipyard/latest/shipyard/trait.IntoWorkloadTrySystem.html#tymethod.into_workload_try_system) to explicitly inform the [`Workload`](https://docs.rs/shipyard/latest/shipyard/struct.Workload.html) that this system might return something, but we don't handle it anywhere.

```rust,noplaypen
async fn main() {
Expand All @@ -216,20 +216,20 @@ async fn main() {
}
```

After some type juggling we can get our result back.
After some type juggling, we can get our result back.

## Conclusion

This concludes the example guide.\
You've encountered the main ways you can interact with entities, components and systems.\
The following reference guide goes deeper into details and is a good place to come back to once you start your own project.
The following reference guide delves deeper into details and is a good place to come back to once you start your own project.

---

You may be wondering where are the floors, the shop,...\
Your mission, should you choose to accept it is to build the rest of the game.

Each new floor reached the `Friend`s gain one of these bonus:
Each new floor reached, the `Friends` gain one of these bonuses:
- start size +0.5
- growth rate +0.05
- speed +0.1
Expand All @@ -244,6 +244,6 @@ Each floor, new or not, the `Player` chooses between:
- defense +0.4 (capped at 5)

The game alternates between floor and shop.\
Each floor a total of `(floor_number + 1) * 2` `Friend`s spawn.\
If the `Player` is able to eat all `Friend`s they move to the next floor.\
Each floor a total of `(floor_number + 1) * 2` `Friends` spawn.\
If the `Player` is able to eat all `Friends`, they move to the next floor.\
If not, they stay on the same floor but with a visit to the shop.
2 changes: 1 addition & 1 deletion guide/master/src/learn-by-example/breather.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn collision(mut player: UniqueViewMut<Player>, v_friend: View<Friend>) -> Resul
Systems can return any type, [`World::run`](https://docs.rs/shipyard/latest/shipyard/struct.World.html#method.run) then returns when the function returns.\
Moving the panic to `main` isn't a big change but it allows a better control of what happens which will be useful later on.

To finish this chapter we can better show the duplicity of the "`Friend`s".
To conclude this chapter we can better show the duplicity of the "`Friends`".

```rust,noplaypen
fn render(player: UniqueView<Player>, v_friend: View<Friend>) {
Expand Down
10 changes: 5 additions & 5 deletions guide/master/src/learn-by-example/friends.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Instead we'll store them in a [`World`](https://docs.rs/shipyard/latest/shipyard
[`World`](https://docs.rs/shipyard/latest/shipyard/struct.World.html) is shipyard's main type.\
It's where everything is stored, from components to entities to systems.

In this guide I'll be explicit about `shipyard` imports but you could `use shipyard::*;` if you wanted.
In this guide, I'll be explicit about `shipyard` imports but you could `use shipyard::*;` if you prefer.

```rust,noplaypen
use macroquad::rand::gen_range;
Expand Down Expand Up @@ -63,10 +63,10 @@ impl Friend {
}
```

This won't compile just yet, `Friend` is not a [`Component`](https://docs.rs/shipyard/latest/shipyard/trait.Component.html).\
This won't compile just yet, as `Friend` is not a [`Component`](https://docs.rs/shipyard/latest/shipyard/trait.Component.html).\
Some ECS require you to explicitly specify which types are components and some don't.\
One of the reasons shipyard requires it is to easily identify components in codebases.\
With small projects this isn't a big issue but as the number of lines grow, you'll have to find a way to identify components. This could be moving types to a `component.rs` but I'd rather have modules split based on what they do.
With small projects, this isn't a big issue but as the number of lines grow, you'll have to find a way to identify components. This could be moving types to a `component.rs`, but I'd rather have modules split based on what they do.

Let's add the missing piece.

Expand All @@ -81,7 +81,7 @@ And [`iter`](https://docs.rs/shipyard/latest/shipyard/struct.World.html#method.i

We can move `Player` into the [`World`](https://docs.rs/shipyard/latest/shipyard/struct.World.html) to simplify our code a little.\
We only have a single `Player` and it will only ever have a single component.\
For this kind of entities shipyard has [`Unique`](https://docs.rs/shipyard/latest/shipyard/trait.Unique.html) components.
For this kind of entities, shipyard has [`Unique`](https://docs.rs/shipyard/latest/shipyard/trait.Unique.html) components.

```rust,noplaypen
use shipyard::{Component, Unique, World};
Expand Down Expand Up @@ -169,7 +169,7 @@ fn move_player(mut player: UniqueViewMut<Player>) {
```

You've just written your first systems.\
With shipyard all functions that have only views as arguments are systems.\
With shipyard, all functions that have only views as arguments are systems.\
The [`World`](https://docs.rs/shipyard/latest/shipyard/struct.World.html) understands these functions and provides the desired components automatically.

The `v_`/`vm_` prefix for views is a convention that some `shipyard` users use. I'll follow it throughout the guide.
14 changes: 7 additions & 7 deletions guide/master/src/learn-by-example/reign.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Reign

We've had plenty of time to think of a way for our `Player` to get back at those pesky `Friend`s.\
Sometimes the simplest solution is the best.\
If the `Friend`s can overpower the `Player` when they are fully grown, we shouldn't let them reach that size.\
We've had plenty of time to think of a way for our `Player` to get back at those pesky `Friends`.\
Sometimes, the simplest solution is the best.\
If the `Friends` can overpower the `Player` when they are fully grown, we shouldn't let them reach that size.\
I'm sure the `Player` can overcome `Friend` that are smaller than them.

```rust,noplaypen
Expand Down Expand Up @@ -33,13 +33,13 @@ fn collision(
}
```

It appears our `Player` can even overcome `Friend`s that are their size.\
It appears our `Player` can even overcome `Friends` of equal size.\
By... eating them!?

Remember when we added `Friend`s to the [`World`](https://docs.rs/shipyard/latest/shipyard/struct.World.html), each one was assigned an [`EntityId`](https://docs.rs/shipyard/latest/shipyard/struct.EntityId.html).\
Remember when we added `Friends` to the [`World`](https://docs.rs/shipyard/latest/shipyard/struct.World.html), each one was assigned an [`EntityId`](https://docs.rs/shipyard/latest/shipyard/struct.EntityId.html).\
We can iterate over both components and the [`EntityId`](https://docs.rs/shipyard/latest/shipyard/struct.EntityId.html) of the entity that owns them by using `with_id`.

Then we can use this [`EntityId`](https://docs.rs/shipyard/latest/shipyard/struct.EntityId.html) to add another component to the vanquished `Friend`s.\
Then we can use this [`EntityId`](https://docs.rs/shipyard/latest/shipyard/struct.EntityId.html) to add another component to the vanquished `Friends`.\
As you may have noticed we are not modifying `entities`. We only need it to check that the `eid` is alive.

`ToDelete` is not a special component, we still have to make it do its job.
Expand Down Expand Up @@ -80,7 +80,7 @@ We are using it to [`delete_any`](https://docs.rs/shipyard/latest/shipyard/struc

## It's over

Defeating smaller `Friend`s is nice but most of the time they've grown by the time the `Player` reaches them.\
Defeating smaller `Friends` is nice but most of the time they've grown by the time the `Player` reaches them.\
The `Player` needs more power.

```rust,noplaypen
Expand Down
10 changes: 5 additions & 5 deletions guide/master/src/learn-by-example/spark.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ fn grow(mut vm_friend: ViewMut<Friend>) {
}
```

`grow`'s code could be simpler but this version makes `Friend`s grow from their center which feels a lot more natural.
`grow`'s code could be simpler but this version makes `Friends` grow from their center, which feels a lot more natural.

It appears our `Friend`s want to come close to the `Player`, likely to give them a hug.
It appears our `Friends` want to come close to the `Player`, likely to give them a hug.

```rust,noplaypen
const SPEED: f32 = 1.5;
Expand Down Expand Up @@ -97,8 +97,8 @@ fn move_friends(player: UniqueView<Player>, mut vm_friend: ViewMut<Friend>) {
}
```

As you can see you can iterate views multiple times in the same system.\
We also make sure the `Friend`s don't simply all overlap by stirring them away from their neighbors.
As you can see, you can iterate views multiple times in the same system.\
We also prevent the `Friends` from overlapping by stirring them away from their neighbors.

But something doesn't feel right...

Expand Down Expand Up @@ -139,4 +139,4 @@ fn collision(mut player: UniqueViewMut<Player>, v_friend: View<Friend>) {
}
```

Oh my god! The "`Friend`s" killed the `Player`!?
Oh my god! The "`Friends`" killed the `Player`!?
Loading

0 comments on commit ed3f864

Please sign in to comment.