Skip to content

Commit 3797027

Browse files
committed
Update doc roles, add inline code highlighting.
1 parent a7a037b commit 3797027

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@
378378
napoleon_use_param = True
379379
napoleon_use_rtype = True
380380

381-
rst_epilog = ".. include:: /epilog.rst"
381+
rst_prolog = ".. include:: /prolog.rst" # Added to the beginning of every source file.
382+
rst_epilog = ".. include:: /epilog.rst" # Added to the end of every source file.
382383

383384
# Example configuration for intersphinx: refer to the Python standard library.
384385
intersphinx_mapping = {

docs/prolog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. Add inline code roles to all sources
2+
.. role:: python(code)
3+
:language: python
4+
5+
.. role:: shell(code)
6+
:language: shell

docs/tutorial/part-00.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _part-0:
2+
13
Part 0 - Setting up a project
24
##############################################################################
35

@@ -18,7 +20,7 @@ First script
1820
==============================================================================
1921

2022
First start with a modern top-level script.
21-
Create a script in the project root folder called ``main.py`` which checks ``if __name__ == "__main__":`` and calls a ``main`` function.
23+
Create a script in the project root folder called ``main.py`` which checks :python:`if __name__ == "__main__":` and calls a ``main`` function.
2224

2325
.. code-block:: python
2426
@@ -33,6 +35,6 @@ In VSCode on the left sidebar is a **Run and Debug** tab.
3335
On this tab select **create a launch.json** file.
3436
This will prompt about what kind of program to launch.
3537
Pick ``Python``, then ``Module``, then when asked for the module name type ``main``.
36-
From now on the ``F5`` key will launch ``main.py`` in debug mode.
38+
From now on the :kbd:`F5` key will launch ``main.py`` in debug mode.
3739

38-
Run the script now and ``"Hello World!"`` should be visible in the terminal output.
40+
Run the script now and ``Hello World!`` should be visible in the terminal output.

docs/tutorial/part-01.rst

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _part-1:
2+
13
Part 1 - Moving a player around the screen
24
##############################################################################
35

@@ -23,7 +25,7 @@ Loading a tileset and opening a window
2325
From here it is time to setup a ``tcod`` program.
2426
Download `Alloy_curses_12x12.png <https://raw.githubusercontent.com/HexDecimal/python-tcod-tutorial-2023/6b69bf9b5531963a0e5f09f9d8fe72a4001d4881/data/Alloy_curses_12x12.png>`_ and place this file in your projects ``data/`` directory.
2527
This tileset is from the `Dwarf Fortress tileset repository <https://dwarffortresswiki.org/index.php/DF2014:Tileset_repository>`_.
26-
These kinds of tilesets are always loaded with ``columns=16, rows=16, charmap=tcod.tileset.CHARMAP_CP437``.
28+
These kinds of tilesets are always loaded with :python:`columns=16, rows=16, charmap=tcod.tileset.CHARMAP_CP437`.
2729

2830
Load the tileset with :any:`tcod.tileset.load_tilesheet` and then pass it to :any:`tcod.context.new`.
2931
These functions are part of modules which have not been imported yet, so new imports need to be added.
@@ -47,7 +49,7 @@ These functions are part of modules which have not been imported yet, so new imp
4749
...
4850
4951
If an import fails that means you do not have ``tcod`` installed on the Python environment you just used to run the script.
50-
If you use an IDE then make sure the Python environment it is using is correct and then run ``pip install tcod`` from the shell terminal within that IDE.
52+
If you use an IDE then make sure the Python environment it is using is correct and then run :shell:`pip install tcod` from the shell terminal within that IDE.
5153

5254
If you run this script now then a window will open and then immediately close.
5355
If that happens without seeing a traceback in your terminal then the script is correct.
@@ -57,18 +59,18 @@ Configuring an event loop
5759

5860
The next step is to keep the window open until the user closes it.
5961

60-
Since nothing is displayed yet a :any:`Console` should be created with ``"Hello World"`` printed to it.
62+
Since nothing is displayed yet a :any:`Console` should be created with :python:`"Hello World"` printed to it.
6163
The size of the console can be used as a reference to create the context by adding the console to :any:`tcod.context.new`.
6264

63-
Begin the main game loop with a ``while True:`` statement.
65+
Begin the main game loop with a :python:`while True:` statement.
6466

6567
To actually display the console to the window the :any:`Context.present` method must be called with the console as a parameter.
6668
Do this first in the game loop before handing events.
6769

6870
Events are checked by iterating over all pending events with :any:`tcod.event.wait`.
69-
Use the code ``for event in tcod.event.wait():`` to begin handing events.
70-
Test if an event is for closing the window with ``if isinstance(event, tcod.event.Quit):``.
71-
If this is True then you should exit the function with ``raise SystemExit``.
71+
Use the code :python:`for event in tcod.event.wait():` to begin handing events.
72+
Test if an event is for closing the window with :python:`if isinstance(event, tcod.event.Quit):`.
73+
If this is True then you should exit the function with :python:`raise SystemExit`.
7274

7375
.. code-block:: python
7476
:emphasize-lines: 2,3,11-18
@@ -93,7 +95,7 @@ If this is True then you should exit the function with ``raise SystemExit``.
9395
raise SystemExit()
9496
...
9597
96-
If you run this then you get a window saying ``"Hello World"``.
98+
If you run this then you get a window saying :python:`"Hello World"`.
9799
The window can be resized and the console will be stretched to fit the new resolution.
98100

99101
An example game state
@@ -102,18 +104,18 @@ An example game state
102104
What exists now is not very interactive.
103105
The next step is to change state based on user input.
104106

105-
Like ``tcod`` you'll need to install ``attrs`` with Pip, such as with ``pip install attrs``.
107+
Like ``tcod`` you'll need to install ``attrs`` with Pip, such as with :shell:`pip install attrs`.
106108

107109
Start by adding an ``attrs`` class called ``ExampleState``.
108-
This a normal class with the ``@attrs.define(eq=False)`` decorator added.
110+
This a normal class with the :python:`@attrs.define(eq=False)` decorator added.
109111

110112
This class should hold coordinates for the player.
111113
It should also have a ``on_draw`` method which takes :any:`tcod.console.Console` as a parameter and marks the player position on it.
112-
The parameters for ``on_draw`` are ``self`` because this is an instance method and ``console: tcod.console.Console``.
113-
``on_draw`` returns nothing, so be sure to add ``-> None``.
114+
The parameters for ``on_draw`` are ``self`` because this is an instance method and :python:`console: tcod.console.Console`.
115+
``on_draw`` returns nothing, so be sure to add :python:`-> None`.
114116

115117
:any:`Console.print` is the simplest way to draw the player because other options would require bounds-checking.
116-
Call this method using the players current coordinates and the ``"@"`` character.
118+
Call this method using the players current coordinates and the :python:`"@"` character.
117119

118120
.. code-block:: python
119121
@@ -135,13 +137,13 @@ Call this method using the players current coordinates and the ``"@"`` character
135137
console.print(self.player_x, self.player_y, "@")
136138
...
137139
138-
Now remove the ``console.print(0, 0, "Hello World")`` line from ``main``.
140+
Now remove the :python:`console.print(0, 0, "Hello World")` line from ``main``.
139141

140142
Before the context is made create a new ``ExampleState`` with player coordinates on the screen.
141-
Each :any:`Console` has ``.width`` and ``.height`` attributes which you can divide by 2 to get a centered coordinate for the player.
142-
Use Python's floor division operator ``//`` so that the resulting type is ``int``.
143+
Each :any:`Console` has :python:`.width` and :python:`.height` attributes which you can divide by 2 to get a centered coordinate for the player.
144+
Use Python's floor division operator :python:`//` so that the resulting type is :python:`int`.
143145

144-
Modify the drawing routine so that the console is cleared, then passed to ``ExampleState.on_draw``, then passed to :any:`Context.present`.
146+
Modify the drawing routine so that the console is cleared, then passed to :python:`ExampleState.on_draw`, then passed to :any:`Context.present`.
145147

146148
.. code-block:: python
147149
:emphasize-lines: 9,12-14
@@ -174,9 +176,9 @@ A new method will be added to the ``ExampleState`` for this called ``on_event``.
174176
Events are best handled using Python's `Structural Pattern Matching <https://peps.python.org/pep-0622/>`_.
175177
Consider reading `Python's Structural Pattern Matching Tutorial <https://peps.python.org/pep-0636/>`_.
176178

177-
Begin matching with ``match event:``.
178-
The equivalent to ``if isinstance(event, tcod.event.Quit):`` is ``case tcod.event.Quit():``.
179-
Keyboard keys can be checked with ``case tcod.event.KeyDown(sym=tcod.event.KeySym.LEFT):``.
179+
Begin matching with :python:`match event:`.
180+
The equivalent to :python:`if isinstance(event, tcod.event.Quit):` is :python:`case tcod.event.Quit():`.
181+
Keyboard keys can be checked with :python:`case tcod.event.KeyDown(sym=tcod.event.KeySym.LEFT):`.
180182
Make a case for each arrow key: ``LEFT`` ``RIGHT`` ``UP`` ``DOWN`` and move the player in the direction of that key.
181183
See :any:`KeySym` for a list of all keys.
182184

0 commit comments

Comments
 (0)