Skip to content

Commit

Permalink
Clean up minor formatting issues with the tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
HexDecimal committed Jul 16, 2024
1 parent 98093c1 commit 3bc0ce0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions docs/tutorial/part-01.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Use the code :python:`for event in tcod.event.wait():` to begin handing events.

In the event loop start with the line :python:`print(event)` so that all events can be viewed from the program output.
Then test if an event is for closing the window with :python:`if isinstance(event, tcod.event.Quit):`.
If this is True then you should exit the function with :python:`raise SystemExit()`. [#why_raise]_
If this is True then you should exit the function with :python:`raise SystemExit`. [#why_raise]_

.. code-block:: python
:emphasize-lines: 3,5,15-23
Expand All @@ -121,7 +121,7 @@ If this is True then you should exit the function with :python:`raise SystemExit
for event in tcod.event.wait(): # Event loop, blocks until pending events exist
print(event)
if isinstance(event, tcod.event.Quit):
raise SystemExit()
raise SystemExit
if __name__ == "__main__":
Expand Down Expand Up @@ -205,7 +205,7 @@ Modify the drawing routine so that the console is cleared, then passed to :pytho
for event in tcod.event.wait():
print(event)
if isinstance(event, tcod.event.Quit):
raise SystemExit()
raise SystemExit
if __name__ == "__main__":
Expand Down Expand Up @@ -259,7 +259,7 @@ The full script so far is:
"""Move the player on events and handle exiting. Movement is hard-coded."""
match event:
case tcod.event.Quit():
raise SystemExit()
raise SystemExit
case tcod.event.KeyDown(sym=tcod.event.KeySym.LEFT):
self.player_x -= 1
case tcod.event.KeyDown(sym=tcod.event.KeySym.RIGHT):
Expand Down Expand Up @@ -308,5 +308,5 @@ You can review the part-1 source code `here <https://github.com/HexDecimal/pytho
.. [#init_context] This tutorial follows the setup for a fixed-size console.
The alternatives shown in :ref:`getting-started` are outside the scope of this tutorial.
.. [#why_raise] You could use :python:`return` here to exit the ``main`` function and end the program, but :python:`raise SystemExit()` is used because it will close the program from anywhere.
:python:`raise SystemExit()` is also more useful to teach than :any:`sys.exit`.
.. [#why_raise] You could use :python:`return` here to exit the ``main`` function and end the program, but :python:`raise SystemExit` is used because it will close the program from anywhere.
:python:`raise SystemExit` is also more useful to teach than :any:`sys.exit`.
8 changes: 5 additions & 3 deletions docs/tutorial/part-02.rst
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ Use :python:`from tcod.event import KeySym` to make ``KeySym`` enums easier to w
"""Global constants are stored here."""
from __future__ import annotations
from typing import Final
from tcod.event import KeySym
Expand Down Expand Up @@ -386,7 +388,7 @@ The query to fetch player entities is :python:`g.world.Q.all_of(tags=[IsPlayer])
We expect only one player so the result will be unpacked into a single name: :python:`(player,) = g.world.Q.all_of(tags=[IsPlayer])`.

Next is to handle the event.
Handling :python:`case tcod.event.Quit():` is the same as before: :python:`raise SystemExit()`.
Handling :python:`case tcod.event.Quit():` is the same as before: :python:`raise SystemExit`.

The case for direction keys will now be done in a single case: :python:`case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS:`.
``sym=sym`` assigns from the event attribute to a local name.
Expand Down Expand Up @@ -419,7 +421,7 @@ Then use :python:`gold.clear()` at the end to remove all components and tags fro
(player,) = g.world.Q.all_of(tags=[IsPlayer])
match event:
case tcod.event.Quit():
raise SystemExit()
raise SystemExit
case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS:
player.components[Position] += DIRECTION_KEYS[sym]
# Auto pickup gold
Expand Down Expand Up @@ -499,7 +501,7 @@ It should be at the same level as the ``for`` loop and not inside of it.
(player,) = g.world.Q.all_of(tags=[IsPlayer])
match event:
case tcod.event.Quit():
raise SystemExit()
raise SystemExit
case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS:
player.components[Position] += DIRECTION_KEYS[sym]
# Auto pickup gold
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorial/part-03.rst
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ Menus
"""Handle events for menus."""
match event:
case tcod.event.Quit():
raise SystemExit()
raise SystemExit
case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS:
dx, dy = DIRECTION_KEYS[sym]
if dx != 0 or dy == 0:
Expand Down Expand Up @@ -379,7 +379,7 @@ Update states
@staticmethod
def quit() -> StateResult:
"""Close the program."""
raise SystemExit()
raise SystemExit
.. code-block:: python
:emphasize-lines: 2,5,19-23
Expand All @@ -393,7 +393,7 @@ Update states
(player,) = g.world.Q.all_of(tags=[IsPlayer])
match event:
case tcod.event.Quit():
raise SystemExit()
raise SystemExit
case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS:
player.components[Position] += DIRECTION_KEYS[sym]
# Auto pickup gold
Expand Down

0 comments on commit 3bc0ce0

Please sign in to comment.