more docs generation work

This commit is contained in:
Roman Trapeznikov 2022-02-14 22:11:40 +03:00
parent 93c5edc2a5
commit b8648c5f33
No known key found for this signature in database
GPG Key ID: 89BED52F1E290F8D
36 changed files with 869 additions and 872 deletions

View File

@ -6,6 +6,7 @@
<w>outdirname</w>
<w>pagename</w>
<w>pythondir</w>
<w>templatesdir</w>
<w>unhashable</w>
</words>
</dictionary>

View File

@ -1 +1 @@
191473689765959071642564573343309028448
93799056966445196696254000169758935495

File diff suppressed because it is too large Load Diff

View File

@ -81,13 +81,14 @@ from ba._collision import Collision, getcollision
app: App
__all__: list[str] = []
# Change everything's listed module to simply 'ba' (instead of 'ba.foo.bar').
def _simplify_module_names() -> None:
for attr, obj in globals().items():
for attr, _obj in globals().items():
if not attr.startswith('_'):
if getattr(obj, '__module__', None) not in [None, 'ba']:
obj.__module__ = 'ba'
__all__.append(attr)
_simplify_module_names()

View File

@ -32,99 +32,92 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]):
Examples of Activities include games, score-screens, cutscenes, etc.
A ba.Session has one 'current' Activity at any time, though their existence
can overlap during transitions.
Attributes:
settings_raw
The settings dict passed in when the activity was made.
This attribute is deprecated and should be avoided when possible;
activities should pull all values they need from the 'settings' arg
passed to the Activity __init__ call.
teams
The list of ba.Team-s in the Activity. This gets populated just
before on_begin() is called and is updated automatically as players
join or leave the game. (at least in free-for-all mode where every
player gets their own team; in teams mode there are always 2 teams
regardless of the player count).
players
The list of ba.Player-s in the Activity. This gets populated just
before on_begin() is called and is updated automatically as players
join or leave the game.
"""
# pylint: disable=too-many-public-methods
# Annotating attr types at the class level lets us introspect at runtime.
settings_raw: dict[str, Any]
"""The settings dict passed in when the activity was made.
This attribute is deprecated and should be avoided when possible;
activities should pull all values they need from the 'settings' arg
passed to the Activity __init__ call."""
teams: list[TeamType]
"""The list of ba.Team-s in the Activity. This gets populated just
before on_begin() is called and is updated automatically as players
join or leave the game. (at least in free-for-all mode where every
player gets their own team; in teams mode there are always 2 teams
regardless of the player count)."""
players: list[PlayerType]
"""The list of ba.Player-s in the Activity. This gets populated just
before on_begin() is called and is updated automatically as players
join or leave the game."""
# Whether to print every time a player dies. This can be pertinent
# in games such as Death-Match but can be annoying in games where it
# doesn't matter.
announce_player_deaths = False
"""Whether to print every time a player dies. This can be pertinent
in games such as Death-Match but can be annoying in games where it
doesn't matter."""
# Joining activities are for waiting for initial player joins.
# They are treated slightly differently than regular activities,
# mainly in that all players are passed to the activity at once
# instead of as each joins.
is_joining_activity = False
"""Joining activities are for waiting for initial player joins.
They are treated slightly differently than regular activities,
mainly in that all players are passed to the activity at once
instead of as each joins."""
# Whether game-time should still progress when in menus/etc.
allow_pausing = False
"""Whether game-time should still progress when in menus/etc."""
# Whether idle players can potentially be kicked (should not happen in
# menus/etc).
allow_kick_idle_players = True
"""Whether idle players can potentially be kicked (should not happen in
menus/etc)."""
# In vr mode, this determines whether overlay nodes (text, images, etc)
# are created at a fixed position in space or one that moves based on
# the current map. Generally this should be on for games and off for
# transitions/score-screens/etc. that persist between maps.
use_fixed_vr_overlay = False
"""In vr mode, this determines whether overlay nodes (text, images, etc)
are created at a fixed position in space or one that moves based on
the current map. Generally this should be on for games and off for
transitions/score-screens/etc. that persist between maps."""
# If True, runs in slow motion and turns down sound pitch.
slow_motion = False
"""If True, runs in slow motion and turns down sound pitch."""
# Set this to True to inherit slow motion setting from previous
# activity (useful for transitions to avoid hitches).
inherits_slow_motion = False
"""Set this to True to inherit slow motion setting from previous
activity (useful for transitions to avoid hitches)."""
# Set this to True to keep playing the music from the previous activity
# (without even restarting it).
inherits_music = False
"""Set this to True to keep playing the music from the previous activity
(without even restarting it)."""
# Set this to true to inherit VR camera offsets from the previous
# activity (useful for preventing sporadic camera movement
# during transitions).
inherits_vr_camera_offset = False
"""Set this to true to inherit VR camera offsets from the previous
activity (useful for preventing sporadic camera movement
during transitions)."""
# Set this to true to inherit (non-fixed) VR overlay positioning from
# the previous activity (useful for prevent sporadic overlay jostling
# during transitions).
inherits_vr_overlay_center = False
"""Set this to true to inherit (non-fixed) VR overlay positioning from
the previous activity (useful for prevent sporadic overlay jostling
during transitions)."""
# Set this to true to inherit screen tint/vignette colors from the
# previous activity (useful to prevent sudden color changes during
# transitions).
inherits_tint = False
"""Set this to true to inherit screen tint/vignette colors from the
previous activity (useful to prevent sudden color changes during
transitions)."""
# Whether players should be allowed to join in the middle of this
# activity. Note that Sessions may not allow mid-activity-joins even
# if the activity says its ok.
allow_mid_activity_joins: bool = True
"""Whether players should be allowed to join in the middle of this
activity. Note that Sessions may not allow mid-activity-joins even
if the activity says its ok."""
# If the activity fades or transitions in, it should set the length of
# time here so that previous activities will be kept alive for that
# long (avoiding 'holes' in the screen)
# This value is given in real-time seconds.
transition_time = 0.0
"""If the activity fades or transitions in, it should set the length of
time here so that previous activities will be kept alive for that
long (avoiding 'holes' in the screen)
This value is given in real-time seconds."""
# Is it ok to show an ad after this activity ends before showing
# the next activity?
can_show_ad_on_death = False
"""Is it ok to show an ad after this activity ends before showing
the next activity?"""
def __init__(self, settings: dict):
"""Creates an Activity in the current ba.Session.
@ -386,11 +379,11 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]):
return UNHANDLED
def has_transitioned_in(self) -> bool:
"""Return whether ba.Activity.on_transition_in() has been called."""
"""Return whether ba.Activity.on_transition_in has been called."""
return self._has_transitioned_in
def has_begun(self) -> bool:
"""Return whether ba.Activity.on_begin() has been called."""
"""Return whether ba.Activity.on_begin has been called."""
return self._has_begun
def has_ended(self) -> bool:
@ -398,7 +391,7 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]):
return self._has_ended
def is_transitioning_out(self) -> bool:
"""Return whether ba.Activity.on_transition_out() has been called."""
"""Return whether ba.Activity.on_transition_out has been called."""
return self._transitioning_out
def transition_in(self, prev_globals: Optional[ba.Node]) -> None:

View File

@ -36,14 +36,14 @@ class Actor:
Example:
```python
>>> # Create a flag Actor in our game activity:
>>> from bastd.actor.flag import Flag
>>> self.flag = Flag(position=(0, 10, 0))
>>>
>>> # Later, destroy the flag.
>>> # (provided nothing else is holding a reference to it)
>>> # We could also just assign a new flag to this value.
>>> # Either way, the old flag disappears.
>>> self.flag = None
... from bastd.actor.flag import Flag
... self.flag = Flag(position=(0, 10, 0))
...
... # Later, destroy the flag.
... # (provided nothing else is holding a reference to it)
... # We could also just assign a new flag to this value.
... # Either way, the old flag disappears.
... self.flag = None
```
This is in contrast to the behavior of the more low level ba.Nodes,
@ -65,7 +65,9 @@ class Actor:
(though its not guaranteed to always have a meaningful effect).
In this case the Actor instance will still be around, but its exists()
and is_alive() methods will both return False.
```python
>>> self.flag.handlemessage(ba.DieMessage())
```
"""
def __init__(self) -> None:

View File

@ -155,18 +155,23 @@ class _WeakCall:
bar() method 5 seconds later; it will be kept alive even though
we overwrite its variable with None because the bound method
we pass as a timer callback (foo.bar) strong-references it
```python
>>> foo = FooClass()
... ba.timer(5.0, foo.bar)
... foo = None
```
EXAMPLE B: this code will *not* keep our object alive; it will die
when we overwrite it with None and the timer will be a no-op when it
fires
```python
>>> foo = FooClass()
... ba.timer(5.0, ba.WeakCall(foo.bar))
... foo = None
```
EXAMPLE C: Wrap a method call with some positional and keyword args:
```python
>>> myweakcall = ba.WeakCall(self.dostuff, argval1,
... namedarg=argval2)
... # Now we have a single callable to run that whole mess.
@ -174,6 +179,7 @@ class _WeakCall:
... # (provided my_obj still exists; this will do nothing
... # otherwise).
... myweakcall()
```
Note: additional args and keywords you provide to the WeakCall()
constructor are stored as regular strong-references; you'll need
@ -232,10 +238,12 @@ class _Call:
Example:
Wrap a method call with 1 positional and 1 keyword arg:
```python
>>> mycall = ba.Call(myobj.dostuff, argval, namedarg=argval2)
... # Now we have a single callable to run that whole mess.
... # ..the same as calling myobj.dostuff(argval, namedarg=argval2)
... mycall()
```
"""
self._call = args[0]
self._args = args[1:]

View File

@ -18,18 +18,16 @@ class Keyboard:
Keyboards are discoverable by the meta-tag system
and the user can select which one they want to use.
On-screen keyboard uses chars from active ba.Keyboard.
Attributes:
name
Displays when user selecting this keyboard.
chars
Used for row/column lengths.
pages
Extra chars like emojis.
nums
The 'num' page.
"""
name: str
"""Displays when user selecting this keyboard."""
chars: list[tuple[str, ...]]
"""Used for row/column lengths."""
pages: dict[str, tuple[str, ...]]
"""Extra chars like emojis."""
nums: tuple[str, ...]
"""The 'num' page."""

View File

@ -378,19 +378,25 @@ class Lstr:
Examples:
EXAMPLE 1: specify a string from a resource path
```python
>>> mynode.text = ba.Lstr(resource='audioSettingsWindow.titleText')
```
EXAMPLE 2: specify a translated string via a category and english
value; if a translated value is available, it will be used; otherwise
the english value will be. To see available translation categories,
look under the 'translations' resource section.
```python
>>> mynode.text = ba.Lstr(translate=('gameDescriptions',
... 'Defeat all enemies'))
```
EXAMPLE 3: specify a raw value and some substitutions. Substitutions
can be used with resource and translate modes as well.
```python
>>> mynode.text = ba.Lstr(value='${A} / ${B}',
... subs=[('${A}', str(score)), ('${B}', str(total))])
```
EXAMPLE 4: ba.Lstr's can be nested. This example would display the
resource at res_a but replace ${NAME} with the value of the

View File

@ -48,18 +48,15 @@ class Player(Generic[TeamType]):
These correspond to ba.SessionPlayer objects, but are associated with a
single ba.Activity instance. This allows activities to specify their
own custom ba.Player types.
Attributes:
actor
The ba.Actor associated with the player.
"""
# These are instance attrs but we define them at the type level so
# their type annotations are introspectable (for docs generation).
character: str
actor: Optional[ba.Actor]
"""The ba.Actor associated with the player."""
color: Sequence[float]
highlight: Sequence[float]

View File

@ -28,29 +28,21 @@ class ScoreConfig:
"""Settings for how a game handles scores.
Category: Gameplay Classes
Attributes:
label
A label show to the user for scores; 'Score', 'Time Survived', etc.
scoretype
How the score value should be displayed.
lower_is_better
Whether lower scores are preferable. Higher scores are by default.
none_is_winner
Whether a value of None is considered better than other scores.
By default it is not.
version
To change high-score lists used by a game without renaming the game,
change this. Defaults to an empty string.
"""
label: str = 'Score'
"""A label show to the user for scores; 'Score', 'Time Survived', etc."""
scoretype: ba.ScoreType = ScoreType.POINTS
"""How the score value should be displayed."""
lower_is_better: bool = False
"""Whether lower scores are preferable. Higher scores are by default."""
none_is_winner: bool = False
"""Whether a value of None is considered better than other scores.
By default it is not."""
version: str = ''
"""To change high-score lists used by a game without renaming the game,
change this. Defaults to an empty string."""

View File

@ -19,7 +19,7 @@ if TYPE_CHECKING:
class Session:
"""Defines a high level series of ba.Activity-es with a common purpose.
category: Gameplay Classes
Category: Gameplay Classes
Examples of sessions are ba.FreeForAllSession, ba.DualTeamSession, and
ba.CoopSession.
@ -27,58 +27,48 @@ class Session:
A Session is responsible for wrangling and transitioning between various
ba.Activity instances such as mini-games and score-screens, and for
maintaining state between them (players, teams, score tallies, etc).
Attributes:
sessionteams
All the ba.SessionTeams in the Session. Most things should use the
list of ba.Team-s in ba.Activity; not this.
sessionplayers
All ba.SessionPlayers in the Session. Most things should use the
list of ba.Player-s in ba.Activity; not this. Some players, such as
those who have not yet selected a character, will only be
found on this list.
min_players
The minimum number of players who must be present for the Session
to proceed past the initial joining screen.
max_players
The maximum number of players allowed in the Session.
lobby
The ba.Lobby instance where new ba.Player-s go to select a
Profile/Team/etc. before being added to games.
Be aware this value may be None if a Session does not allow
any such selection.
use_teams
Whether this session groups players into an explicit set of
teams. If this is off, a unique team is generated for each
player that joins.
use_team_colors
Whether players on a team should all adopt the colors of that
team instead of their own profile colors. This only applies if
use_teams is enabled.
customdata
A shared dictionary for objects to use as storage on this session.
Ensure that keys here are unique to avoid collisions.
"""
use_teams: bool = False
use_team_colors: bool = True
# Note: even though these are instance vars, we annotate them at the
# class level so that docs generation can access their types.
use_teams: bool = False
"""Whether this session groups players into an explicit set of
teams. If this is off, a unique team is generated for each
player that joins."""
use_team_colors: bool = True
"""Whether players on a team should all adopt the colors of that
team instead of their own profile colors. This only applies if
use_teams is enabled."""
# Note: even though these are instance vars, we annotate and document them
# at the class level so that looks better and nobody get lost while
# reading large __init__
lobby: ba.Lobby
"""The ba.Lobby instance where new ba.Player-s go to select a
Profile/Team/etc. before being added to games.
Be aware this value may be None if a Session does not allow
any such selection."""
max_players: int
"""The maximum number of players allowed in the Session."""
min_players: int
"""The minimum number of players who must be present for the Session
to proceed past the initial joining screen"""
sessionplayers: list[ba.SessionPlayer]
"""All ba.SessionPlayers in the Session. Most things should use the
list of ba.Player-s in ba.Activity; not this. Some players, such as
those who have not yet selected a character, will only be
found on this list."""
customdata: dict
"""A shared dictionary for objects to use as storage on this session.
Ensure that keys here are unique to avoid collisions."""
sessionteams: list[ba.SessionTeam]
"""All the ba.SessionTeams in the Session. Most things should use the
list of ba.Team-s in ba.Activity; not this."""
def __init__(self,
depsets: Sequence[ba.DependencySet],

View File

@ -22,13 +22,10 @@ class PlayerScoredMessage:
"""Informs something that a ba.Player scored.
Category: Message Classes
Attributes:
score
The score value.
"""
score: int
"""The score value."""
class PlayerRecord:
@ -232,7 +229,7 @@ class PlayerRecord:
class Stats:
"""Manages scores and statistics for a ba.Session.
category: Gameplay Classes
Category: Gameplay Classes
"""
def __init__(self) -> None:

View File

@ -0,0 +1,20 @@
{% extends "default/module.html.jinja2" %}
{% block style_content %}
{{ super() }}
/* Docstrings */
<style>
.pdoc .docstring {
margin-bottom: 1.5rem;
margin-left: 2rem;
}
</style>
{% endblock %}
{% macro is_public(doc) %}
{% if "(internal)" in doc.docstring %}
{# Returning no text is interpreted as false #}
{% else %}
{{ default_is_public(doc) }}
{% endif %}
{% endmacro %}

View File

@ -25,9 +25,9 @@ void PythonClassCollideModel::SetupType(PyTypeObject* obj) {
obj->tp_doc =
"A reference to a collide-model.\n"
"\n"
"Category: Asset Classes\n"
"Category: **Asset Classes**\n"
"\n"
"Use ba.getcollidemodel() to instantiate one.";
"Use ba.getcollidemodel to instantiate one.";
obj->tp_repr = (reprfunc)tp_repr;
obj->tp_new = tp_new;
obj->tp_dealloc = (destructor)tp_dealloc;

View File

@ -19,7 +19,7 @@ void PythonClassContext::SetupType(PyTypeObject* obj) {
"\n"
"A game context state.\n"
"\n"
"Category: General Utility Classes\n"
"Category: **General Utility Classes**\n"
"\n"
"Many operations such as ba.newnode or ba.gettexture operate\n"
"implicitly on the current context. Each ba.Activity has its own\n"
@ -30,46 +30,43 @@ void PythonClassContext::SetupType(PyTypeObject* obj) {
"since timers and other callbacks will take care of saving and\n"
"restoring the context automatically, but there may be rare cases where\n"
"you need to deal with them, such as when loading media in for use in\n"
"the UI (there is a special 'ui' context for all user-interface-related\n"
"functionality)\n"
"the UI (there is a special `'ui'` context for all\n"
"user-interface-related functionality).\n"
"\n"
"When instantiating a ba.Context instance, a single ``'source'`` "
"When instantiating a ba.Context instance, a single `'source'` "
"argument\n"
"is passed, which can be one of the following strings/objects:\n\n"
"``'empty'``:\n"
" Gives an empty context; it can be handy to run code here to ensure\n"
" it does no loading of media, creation of nodes, etc.\n"
"`'empty'`:\n"
"> Gives an empty context; it can be handy to run code here to ensure\n"
"it does no loading of media, creation of nodes, etc.\n"
"\n"
"``'current'``:\n"
" Sets the context object to the current context.\n"
"###### `'current'`\n"
"> Sets the context object to the current context.\n"
"\n"
"``'ui'``:\n"
" Sets to the UI context. UI functions as well as loading of media to\n"
" be used in said functions must happen in the UI context.\n"
"###### `'ui'`\n"
"> Sets to the UI context. UI functions as well as loading of media to\n"
"be used in said functions must happen in the UI context.\n"
"\n"
"A ba.Activity instance:\n"
" Gives the context for the provided ba.Activity.\n"
"###### A ba.Activity instance\n"
"> Gives the context for the provided ba.Activity.\n"
" Most all code run during a game happens in an Activity's Context.\n"
"\n"
"A ba.Session instance:\n"
" Gives the context for the provided ba.Session.\n"
" Generally a user should not need to run anything here.\n"
"###### A ba.Session instance\n"
"> Gives the context for the provided ba.Session.\n"
"Generally a user should not need to run anything here.\n"
"\n"
"\n"
"Usage:\n"
" Contexts are generally used with the python 'with' statement, "
"which\n"
" sets the context as current on entry and resets it to the previous\n"
" value on exit.\n"
"##### Usage\n"
"Contexts are generally used with the python 'with' statement, which\n"
"sets the context as current on entry and resets it to the previous\n"
"value on exit.\n"
"\n"
"Example:\n"
" Load a few textures into the UI context\n"
" (for use in widgets, etc):\n"
" ```python\n"
" >>> with ba.Context('ui'):\n"
" ... tex1 = ba.gettexture('foo_tex_1')\n"
" ... tex2 = ba.gettexture('foo_tex_2')\n"
" ```\n";
"##### Example\n"
"Load a few textures into the UI context\n"
"(for use in widgets, etc):\n"
">>> with ba.Context('ui'):\n"
"... tex1 = ba.gettexture('foo_tex_1')\n"
"... tex2 = ba.gettexture('foo_tex_2')\n";
obj->tp_new = tp_new;
obj->tp_dealloc = (destructor)tp_dealloc;

View File

@ -16,7 +16,7 @@ void PythonClassContextCall::SetupType(PyTypeObject* obj) {
"\n"
"A context-preserving callable.\n"
"\n"
"Category: General Utility Classes\n"
"Category: **General Utility Classes**\n"
"\n"
"A ContextCall wraps a callable object along with a reference\n"
"to the current context (see ba.Context); it handles restoring the\n"
@ -38,23 +38,20 @@ void PythonClassContextCall::SetupType(PyTypeObject* obj) {
"shutdown, whereas ba.WeakCall simply looks at whether the target\n"
"object still exists.\n"
"\n"
"Examples:\n"
" Example A: code like this can inadvertently prevent our activity\n"
" (self) from ending until the operation completes, since the bound\n"
" method we're passing (self.dosomething) contains a "
"strong-reference\n"
" to self).\n"
" >>> start_some_long_action(callback_when_done=self.dosomething)\n"
"##### Examples\n"
"**Example A:** code like this can inadvertently prevent our activity\n"
"(self) from ending until the operation completes, since the bound\n"
"method we're passing (self.dosomething) contains a strong-reference\n"
"to self).\n"
">>> start_some_long_action(callback_when_done=self.dosomething)\n"
"\n"
" Example B: in this case our activity (self) can still die\n"
" properly; the callback will clear itself when the activity starts\n"
" shutting down, becoming a harmless no-op and releasing the "
"reference\n"
" to our activity.\n"
" ```python\n"
" >>> start_long_action(\n"
" ... callback_when_done=ba.ContextCall(self.mycallback))\n"
" ```\n";
"**Example B:** in this case our activity (self) can still die\n"
"properly; the callback will clear itself when the activity starts\n"
"shutting down, becoming a harmless no-op and releasing the reference\n"
"to our activity.\n"
"\n"
">>> start_long_action(\n"
"... callback_when_done=ba.ContextCall(self.mycallback))\n";
obj->tp_new = tp_new;
obj->tp_dealloc = (destructor)tp_dealloc;

View File

@ -24,9 +24,9 @@ void PythonClassData::SetupType(PyTypeObject* obj) {
obj->tp_doc =
"A reference to a data object.\n"
"\n"
"Category: Asset Classes\n"
"Category: **Asset Classes**\n"
"\n"
"Use ba.getdata() to instantiate one.";
"Use ba.getdata to instantiate one.";
obj->tp_repr = (reprfunc)tp_repr;
obj->tp_new = tp_new;
obj->tp_dealloc = (destructor)tp_dealloc;

View File

@ -19,7 +19,7 @@ void PythonClassInputDevice::SetupType(PyTypeObject* obj) {
obj->tp_doc =
"An input-device such as a gamepad, touchscreen, or keyboard.\n"
"\n"
"Category: Gameplay Classes\n"
"Category: **Gameplay Classes**\n"
"\n"
"Attributes:\n"
"\n"

View File

@ -280,147 +280,151 @@ PyMethodDef PythonClassMaterial::tp_methods[] = {
"\n"
"Add one or more actions to the material, optionally with conditions.\n"
"\n"
"Conditions:\n"
" Conditions are provided as tuples which can be combined\n"
" to form boolean logic. A single condition might look like\n"
" ``('condition_name', cond_arg)``, or a more complex nested one\n"
" might look like ``(('some_condition', cond_arg), 'or',\n"
" ('another_condition', cond2_arg))``.\n"
"##### Conditions\n"
"Conditions are provided as tuples which can be combined\n"
"to form boolean logic. A single condition might look like\n"
"`('condition_name', cond_arg)`, or a more complex nested one\n"
"might look like `(('some_condition', cond_arg), 'or',\n"
"('another_condition', cond2_arg))`.\n"
"\n"
" ``'and'``, ``'or'``, and ``'xor'`` are available to chain\n"
" together 2 conditions, as seen above.\n"
"`'and'`, `'or'`, and `'xor'` are available to chain\n"
"together 2 conditions, as seen above.\n"
"\n"
"Available Conditions:\n"
" ``('they_have_material', material)`` - does the part we\'re\n"
" hitting have a given ba.Material?\n"
"##### Available Conditions\n"
"###### `('they_have_material', material)`\n"
"> Does the part we\'re hitting have a given ba.Material?\n"
"\n"
" ``('they_dont_have_material', material)`` - does the part we\'re\n"
" hitting not have a given ba.Material?\n"
"###### `('they_dont_have_material', material)`\n"
"> Does the part we\'re hitting not have a given ba.Material?\n"
"\n"
" ``('eval_colliding')`` - is ``'collide'`` true at this point\n"
" in material evaluation? (see the modify_part_collision action)\n"
"###### `('eval_colliding')`\n"
"> Is `'collide'` true at this point\n"
"in material evaluation? (see the `modify_part_collision` action)\n"
"\n"
" ``('eval_not_colliding')`` - is 'collide' false at this point\n"
" in material evaluation? (see the modify_part_collision action)\n"
"###### `('eval_not_colliding')`\n"
"> Is 'collide' false at this point\n"
"in material evaluation? (see the `modify_part_collision` action)\n"
"\n"
" ``('we_are_younger_than', age)`` - is our part younger than\n"
" ``'age'`` (in milliseconds)?\n"
"###### `('we_are_younger_than', age)`\n"
"> Is our part younger than `age` (in milliseconds)?\n"
"\n"
" ``('we_are_older_than', age)`` - is our part older than ``'age'``\n"
" (in milliseconds)?\n"
"###### `('we_are_older_than', age)`\n"
"> Is our part older than `age` (in milliseconds)?\n"
"\n"
" ``('they_are_younger_than', age)`` - is the part we're hitting\n"
" younger than ``'age'`` (in milliseconds)?\n"
"###### `('they_are_younger_than', age)`\n"
"> Is the part we're hitting younger than `age` (in milliseconds)?\n"
"\n"
" ``('they_are_older_than', age)`` - is the part we're hitting\n"
" older than ``'age'`` (in milliseconds)?\n"
"###### `('they_are_older_than', age)`\n"
"> Is the part we're hitting older than `age` (in milliseconds)?\n"
"\n"
" ``('they_are_same_node_as_us')`` - does the part we're hitting\n"
" belong to the same ba.Node as us?\n"
"###### `('they_are_same_node_as_us')`\n"
"> Does the part we're hitting belong to the same ba.Node as us?\n"
"\n"
" ``('they_are_different_node_than_us')`` - does the part we're\n"
" hitting belong to a different ba.Node than us?\n"
"###### `('they_are_different_node_than_us')`\n"
"> Does the part we're hitting belong to a different ba.Node than us?\n"
"\n"
"Actions:\n"
" In a similar manner, actions are specified as tuples.\n"
" Multiple actions can be specified by providing a tuple\n"
" of tuples.\n"
"##### Actions\n"
"In a similar manner, actions are specified as tuples.\n"
"Multiple actions can be specified by providing a tuple\n"
"of tuples.\n"
"\n"
"Available Actions:\n"
" ``('call', when, callable)`` - calls the provided callable;\n"
" ``'when'`` can be either ``'at_connect'`` or ``'at_disconnect'``.\n"
" ``'at_connect'`` means to fire\n"
" when the two parts first come in contact; ``'at_disconnect'``\n"
" means to fire once they cease being in contact.\n"
"##### Available Actions\n"
"###### `('call', when, callable)`\n"
"> Calls the provided callable;\n"
"`when` can be either `'at_connect'` or `'at_disconnect'`.\n"
"`'at_connect'` means to fire\n"
"when the two parts first come in contact; `'at_disconnect'`\n"
"means to fire once they cease being in contact.\n"
"\n"
" ``('message', who, when, message_obj)`` - sends a message object;\n"
" ``'who'`` can\n"
" be either ``'our_node'`` or ``'their_node'``, ``'when'`` can be\n"
" ``'at_connect'`` or\n"
" ``'at_disconnect'``, and message_obj is the message object to send.\n"
" This has the same effect as calling the node's\n"
" ba.Node.handlemessage method.\n"
"###### `('message', who, when, message_obj)`\n"
"> Sends a message object;\n"
"`who` can be either `'our_node'` or `'their_node'`, `when` can be\n"
"`'at_connect'` or `'at_disconnect'`, and `message_obj` is the message\n"
"object to send.\n"
"This has the same effect as calling the node's\n"
"ba.Node.handlemessage method.\n"
"\n"
" ``('modify_part_collision', attr, value)`` - changes some\n"
" characteristic of the physical collision that will occur between\n"
" our part and their part. This change will remain in effect as\n"
" long as the two parts remain overlapping. This means if you have a\n"
" part with a material that turns ``'collide'`` off against parts\n"
" younger than 100ms, and it touches another part that is 50ms old,\n"
" it will continue to not collide with that part until they separate,\n"
" even if the 100ms threshold is passed. Options for attr/value are:\n"
" ``'physical'`` (boolean value; whether a *physical* response will\n"
" occur at all), ``'friction'`` (float value; how friction-y the\n"
" physical response will be), ``'collide'`` (boolean value;\n"
" whether *any* collision will occur at all, including non-physical\n"
" stuff like callbacks), ``'use_node_collide'``\n"
" (boolean value; whether to honor modify_node_collision\n"
" overrides for this collision), ``'stiffness'`` (float value,\n"
" how springy the physical response is), ``'damping'`` (float\n"
" value, how damped the physical response is), ``'bounce'`` (float\n"
" value; how bouncy the physical response is)."
"###### `('modify_part_collision', attr, value)`\n"
"> Changes some\n"
"characteristic of the physical collision that will occur between\n"
"our part and their part. This change will remain in effect as\n"
"long as the two parts remain overlapping. This means if you have a\n"
"part with a material that turns `'collide'` off against parts\n"
"younger than 100ms, and it touches another part that is 50ms old,\n"
"it will continue to not collide with that part until they separate,\n"
"even if the 100ms threshold is passed. Options for attr/value are:\n"
"`'physical'` (boolean value; whether a *physical* response will\n"
"occur at all), `'friction'` (float value; how friction-y the\n"
"physical response will be), `'collide'` (boolean value;\n"
"whether *any* collision will occur at all, including non-physical\n"
"stuff like callbacks), `'use_node_collide'`\n"
"(boolean value; whether to honor modify_node_collision\n"
"overrides for this collision), `'stiffness'` (float value,\n"
"how springy the physical response is), `'damping'` (float\n"
"value, how damped the physical response is), `'bounce'` (float\n"
"value; how bouncy the physical response is)."
"\n"
" ``('modify_node_collision', attr, value)`` - similar to\n"
" ``modify_part_collision``, but operates at a node-level.\n"
" collision attributes set here will remain in effect as long as\n"
" *anything* from our part's node and their part's node overlap.\n"
" A key use of this functionality is to prevent new nodes from\n"
" colliding with each other if they appear overlapped;\n"
" if ``modify_part_collision`` is used, only the individual\n"
" parts that were overlapping would avoid contact, but other parts\n"
" could still contact leaving the two nodes 'tangled up'. Using\n"
" ``modify_node_collision ensures`` that the nodes must completely\n"
" separate before they can start colliding. Currently the only attr\n"
" available here is ``'collide'`` (a boolean value).\n"
"###### `('modify_node_collision', attr, value)`\n"
"> Similar to\n"
"`modify_part_collision`, but operates at a node-level.\n"
"collision attributes set here will remain in effect as long as\n"
"*anything* from our part's node and their part's node overlap.\n"
"A key use of this functionality is to prevent new nodes from\n"
"colliding with each other if they appear overlapped;\n"
"if `modify_part_collision` is used, only the individual\n"
"parts that were overlapping would avoid contact, but other parts\n"
"could still contact leaving the two nodes 'tangled up'. Using\n"
"`modify_node_collision` ensures that the nodes must completely\n"
"separate before they can start colliding. Currently the only attr\n"
"available here is `'collide'` (a boolean value).\n"
"\n"
" ``('sound', sound, volume)`` - plays a ba.Sound when a collision\n"
" occurs, at a given volume, regardless of the collision speed/etc.\n"
"###### `('sound', sound, volume)`\n"
"> Plays a ba.Sound when a collision\n"
"occurs, at a given volume, regardless of the collision speed/etc.\n"
"\n"
" ``('impact_sound', sound, targetImpulse, volume)`` - plays a sound\n"
" when a collision occurs, based on the speed of impact.\n"
" Provide a ba.Sound, a target-impulse, and a volume.\n"
"###### `('impact_sound', sound, targetImpulse, volume)`\n"
"> Plays a sound\n"
"when a collision occurs, based on the speed of impact.\n"
"Provide a ba.Sound, a target-impulse, and a volume.\n"
"\n"
" ``('skid_sound', sound, targetImpulse, volume)`` - plays a sound\n"
" during a collision when parts are 'scraping' against each other.\n"
" Provide a ba.Sound, a target-impulse, and a volume.\n"
"###### `('skid_sound', sound, targetImpulse, volume)`\n"
"> Plays a sound\n"
"during a collision when parts are 'scraping' against each other.\n"
"Provide a ba.Sound, a target-impulse, and a volume.\n"
"\n"
" ``('roll_sound', sound, targetImpulse, volume)`` - plays a sound\n"
" during a collision when parts are 'rolling' against each other.\n"
" Provide a ba.Sound, a target-impulse, and a volume.\n"
"###### `('roll_sound', sound, targetImpulse, volume)`\n"
"> Plays a sound\n"
"during a collision when parts are 'rolling' against each other.\n"
"Provide a ba.Sound, a target-impulse, and a volume.\n"
"\n"
"Examples:\n"
" example 1: create a material that lets us ignore\n"
" collisions against any nodes we touch in the first\n"
" 100 ms of our existence; handy for preventing us from\n"
" exploding outward if we spawn on top of another object:\n"
" ```python\n"
" >>> m = ba.Material()\n"
" ... m.add_actions(\n"
" ... conditions=(('we_are_younger_than', 100),\n"
" ... 'or', ('they_are_younger_than', 100)),\n"
" ... actions=('modify_node_collision', 'collide', False))\n"
" ```\n"
"##### Examples\n"
"**Example 1:** create a material that lets us ignore\n"
"collisions against any nodes we touch in the first\n"
"100 ms of our existence; handy for preventing us from\n"
"exploding outward if we spawn on top of another object:\n"
">>> m = ba.Material()\n"
"... m.add_actions(\n"
"... conditions=(('we_are_younger_than', 100),\n"
"... 'or', ('they_are_younger_than', 100)),\n"
"... actions=('modify_node_collision', 'collide', False))\n"
"\n"
" example 2: send a ba.DieMessage to anything we touch, but cause\n"
" no physical response. This should cause any ba.Actor to drop dead:\n"
" ```python\n"
" >>> m = ba.Material()\n"
" ... m.add_actions(\n"
" ... actions=(('modify_part_collision', 'physical', False),\n"
" ... ('message', 'their_node', 'at_connect',\n"
" ... ba.DieMessage())))\n"
" ```\n"
"**Example 2:** send a ba.DieMessage to anything we touch, but cause\n"
"no physical response. This should cause any ba.Actor to drop dead:\n"
"```python\n"
">>> m = ba.Material()\n"
"... m.add_actions(\n"
"... actions=(('modify_part_collision', 'physical', False),\n"
"... ('message', 'their_node', 'at_connect',\n"
"... ba.DieMessage())))\n"
"\n"
" example 3: play some sounds when we're contacting the ground:\n"
" ```python\n"
" >>> m = ba.Material()\n"
" ... m.add_actions(\n"
" ... conditions=('they_have_material',\n"
" shared.footing_material),\n"
" ... actions=(('impact_sound', ba.getsound('metalHit'), 2, 5),\n"
" ... ('skid_sound', ba.getsound('metalSkid'), 2, 5)))\n"
" ```\n"
"\n"},
"**Example 3:** play some sounds when we're contacting the ground:\n"
"```python\n"
">>> m = ba.Material()\n"
"... m.add_actions(\n"
"... conditions=('they_have_material',\n"
"... shared.footing_material),\n"
"... actions=(('impact_sound', ba.getsound('metalHit'), 2, 5),\n"
"... ('skid_sound', ba.getsound('metalSkid'), 2, 5)))\n"},
{"__dir__", (PyCFunction)Dir, METH_NOARGS,
"allows inclusion of our custom attrs in standard python dir()"},

View File

@ -24,7 +24,7 @@ void PythonClassModel::SetupType(PyTypeObject* obj) {
obj->tp_doc =
"A reference to a model.\n"
"\n"
"Category: Asset Classes\n"
"Category: **Asset Classes**\n"
"\n"
"Models are used for drawing.\n"
"Use ba.getmodel() to instantiate one.";

View File

@ -34,8 +34,8 @@ void PythonClassNode::SetupType(PyTypeObject* obj) {
"to a game node; *not* the node itself. This means a Node's\n"
"lifecycle is completely independent of how many Python references\n"
"to it exist. To explicitly add a new node to the game, use\n"
"ba.newnode(), and to explicitly delete one, use ba.Node.delete().\n"
"ba.Node.exists() can be used to determine if a Node still points to\n"
"ba.newnode, and to explicitly delete one, use ba.Node.delete.\n"
"ba.Node.exists can be used to determine if a Node still points to\n"
"a live node in the game.\n"
"\n"
"You can use ba.Node(None) to instantiate an invalid\n"
@ -413,7 +413,7 @@ PyMethodDef PythonClassNode::tp_methods[] = {
{"delete", (PyCFunction)Delete, METH_VARARGS | METH_KEYWORDS,
"delete(ignore_missing: bool = True) -> None\n"
"\n"
"Delete the node. Ignores already-deleted nodes if ignore_missing\n"
"Delete the node. Ignores already-deleted nodes if `ignore_missing`\n"
"is True; otherwise a ba.NodeNotFoundError is thrown."},
{"handlemessage", (PyCFunction)HandleMessage, METH_VARARGS,
"handlemessage(*args: Any) -> None\n"
@ -423,7 +423,7 @@ PyMethodDef PythonClassNode::tp_methods[] = {
"All standard message objects are forwarded along to the ba.Node's\n"
"delegate for handling (generally the ba.Actor that made the node).\n"
"\n"
"ba.Nodes are unique, however, in that they can be passed a second\n"
"ba.Node-s are unique, however, in that they can be passed a second\n"
"form of message; 'node-messages'. These consist of a string type-name\n"
"as a first argument along with the args specific to that type name\n"
"as additional arguments.\n"
@ -445,13 +445,11 @@ PyMethodDef PythonClassNode::tp_methods[] = {
"setting the target attribute to any value or connecting another\n"
"node attribute to it.\n"
"\n"
"Example:\n"
" Create a locator and attach a light to it:\n"
" ```python\n"
" >>> light = ba.newnode('light')\n"
" ... loc = ba.newnode('locator', attrs={'position': (0, 10, 0)})\n"
" ... loc.connectattr('position', light, 'position')\n"
" ```\n"},
"##### Example\n"
"Create a locator and attach a light to it:\n"
">>> light = ba.newnode('light')\n"
"... loc = ba.newnode('locator', attrs={'position': (0, 10, 0)})\n"
"... loc.connectattr('position', light, 'position')\n"},
{"__dir__", (PyCFunction)Dir, METH_NOARGS,
"allows inclusion of our custom attrs in standard python dir()"},
{nullptr}};

View File

@ -46,14 +46,14 @@ void PythonClassSessionPlayer::SetupType(PyTypeObject* obj) {
obj->tp_doc =
"A reference to a player in the ba.Session.\n"
"\n"
"Category: Gameplay Classes\n"
"Category: **Gameplay Classes**\n"
"\n"
"These are created and managed internally and\n"
"provided to your Session/Activity instances.\n"
"provided to your ba.Session/ba.Activity instances.\n"
"Be aware that, like ba.Nodes, ba.SessionPlayer objects are 'weak'\n"
"references under-the-hood; a player can leave the game at\n"
" any point. For this reason, you should make judicious use of the\n"
"ba.SessionPlayer.exists() method (or boolean operator) to ensure\n"
"ba.SessionPlayer.exists method (or boolean operator) to ensure\n"
"that a SessionPlayer is still present if retaining references to one\n"
"for any length of time.\n"
"\n"

View File

@ -24,9 +24,9 @@ void PythonClassSound::SetupType(PyTypeObject* obj) {
obj->tp_doc =
"A reference to a sound.\n"
"\n"
"Category: Asset Classes\n"
"Category: **Asset Classes**\n"
"\n"
"Use ba.getsound() to instantiate one.";
"Use ba.getsound to instantiate one.";
obj->tp_repr = (reprfunc)tp_repr;
obj->tp_new = tp_new;
obj->tp_dealloc = (destructor)tp_dealloc;

View File

@ -24,7 +24,7 @@ void PythonClassTexture::SetupType(PyTypeObject* obj) {
obj->tp_doc =
"A reference to a texture.\n"
"\n"
"Category: Asset Classes\n"
"Category: **Asset Classes**\n"
"\n"
"Use ba.gettexture() to instantiate one.";
obj->tp_repr = (reprfunc)tp_repr;

View File

@ -19,7 +19,7 @@ void PythonClassTimer::SetupType(PyTypeObject* obj) {
"\n"
"Timers are used to run code at later points in time.\n"
"\n"
"Category: General Utility Classes\n"
"Category: **General Utility Classes**\n"
"\n"
"This class encapsulates a timer in the current ba.Context.\n"
"The underlying timer will be destroyed when either this object is\n"
@ -27,38 +27,41 @@ void PythonClassTimer::SetupType(PyTypeObject* obj) {
"do not want to worry about keeping a reference to your timer around,\n"
"you should use the ba.timer() function instead.\n"
"\n"
"time: length of time (in seconds by default) that the timer will wait\n"
"###### time\n"
"> Length of time (in seconds by default) that the timer will wait\n"
"before firing. Note that the actual delay experienced may vary\n"
"depending on the timetype. (see below)\n"
"\n"
"call: A callable Python object. Note that the timer will retain a\n"
"###### call\n"
"> A callable Python object. Note that the timer will retain a\n"
"strong reference to the callable for as long as it exists, so you\n"
"may want to look into concepts such as ba.WeakCall if that is not\n"
"desired.\n"
"\n"
"repeat: if True, the timer will fire repeatedly, with each successive\n"
"###### repeat\n"
"> If True, the timer will fire repeatedly, with each successive\n"
"firing having the same delay as the first.\n"
"\n"
"timetype: A ba.TimeType value determining which timeline the timer is\n"
"###### timetype\n"
"> A ba.TimeType value determining which timeline the timer is\n"
"placed onto.\n"
"\n"
"timeformat: A ba.TimeFormat value determining how the passed time is\n"
"###### timeformat\n"
"> A ba.TimeFormat value determining how the passed time is\n"
"interpreted.\n"
"\n"
"Example:\n"
" Use a Timer object to print repeatedly for a few seconds:\n"
" ```python\n"
" >>> def say_it():\n"
" ... ba.screenmessage('BADGER!')\n"
" ... def stop_saying_it():\n"
" ... self.t = None\n"
" ... ba.screenmessage('MUSHROOM MUSHROOM!')\n"
" ... # Create our timer; it will run as long as we have the self.t "
"ref.\n"
" ... self.t = ba.Timer(0.3, say_it, repeat=True)\n"
" ... # Now fire off a one-shot timer to kill it.\n"
" ... ba.timer(3.89, stop_saying_it)\n"
" ```\n";
"##### Example\n"
"\n"
"Use a Timer object to print repeatedly for a few seconds:\n"
">>> def say_it():\n"
"... ba.screenmessage('BADGER!')\n"
"... def stop_saying_it():\n"
"... self.t = None\n"
"... ba.screenmessage('MUSHROOM MUSHROOM!')\n"
"... # Create our timer; it will run as long as we have the self.t ref.\n"
"... self.t = ba.Timer(0.3, say_it, repeat=True)\n"
"... # Now fire off a one-shot timer to kill it.\n"
"... ba.timer(3.89, stop_saying_it)\n";
obj->tp_new = tp_new;
obj->tp_dealloc = (destructor)tp_dealloc;
}

View File

@ -29,7 +29,7 @@ void PythonClassVec3::SetupType(PyTypeObject* obj) {
obj->tp_doc =
"A vector of 3 floats.\n"
"\n"
"Category: General Utility Classes\n"
"Category: **General Utility Classes**\n"
"\n"
"These can be created the following ways (checked in this order):\n"
"- with no args, all values are set to 0\n"

View File

@ -22,11 +22,11 @@ void PythonClassWidget::SetupType(PyTypeObject* obj) {
obj->tp_doc =
"Internal type for low level UI elements; buttons, windows, etc.\n"
"\n"
"Category: User Interface Classes\n"
"Category: **User Interface Classes**\n"
"\n"
"This class represents a weak reference to a widget object\n"
"in the internal c++ layer. Currently, functions such as\n"
"ba.buttonwidget() must be used to instantiate or edit these.";
"in the internal C++ layer. Currently, functions such as\n"
"ba.buttonwidget must be used to instantiate or edit these.";
obj->tp_new = tp_new;
obj->tp_dealloc = (destructor)tp_dealloc;
obj->tp_repr = (reprfunc)tp_repr;

View File

@ -926,7 +926,7 @@ auto PythonMethodsApp::GetMethods() -> std::vector<PyMethodDef> {
"log(message: str, to_stdout: bool = True,\n"
" to_server: bool = True) -> None\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"Log a message. This goes to the default logging mechanism depending\n"
"on the platform (stdout on mac, android log on android, etc).\n"
@ -989,7 +989,7 @@ auto PythonMethodsApp::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Quit the game.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"On systems like android, 'soft' will end the activity but keep the\n"
"app running."},
@ -1003,7 +1003,7 @@ auto PythonMethodsApp::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Print a message to the local client's screen, in a given color.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"If 'top' is True, the message will go to the top message area.\n"
"For 'top' messages, 'image' can be a texture to display alongside "
@ -1027,41 +1027,34 @@ auto PythonMethodsApp::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Schedule a call to run at a later point in time.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"This function adds a timer to the current ba.Context.\n"
"This timer cannot be canceled or modified once created. If you\n"
" require the ability to do so, use the ba.Timer class instead.\n"
"\n"
"Arguments:\n"
" time (float):\n"
" Length of time (in seconds by default) that the timer will "
"wait\n"
" before firing. Note that the actual delay experienced may "
"vary\n "
" depending on the timetype. (see below)\n"
"##### Arguments\n"
"###### time (float):\n"
"> Length of time (in seconds by default) that the timer will wait\n"
"before firing. Note that the actual delay experienced may vary\n "
"depending on the timetype. (see below)\n"
"\n"
" call (Callable[[], Any]):\n"
" A callable Python object. Note that the timer will retain a\n"
" strong reference to the callable for as long as it exists, "
"so you\n"
" may want to look into concepts such as ba.WeakCall if that "
"is not\n"
" desired.\n"
"###### call (Callable[[], Any])\n"
"> A callable Python object. Note that the timer will retain a\n"
"strong reference to the callable for as long as it exists, so you\n"
"may want to look into concepts such as ba.WeakCall if that is not\n"
"desired.\n"
"\n"
" repeat (bool):\n"
" If True, the timer will fire repeatedly, with each "
"successive\n"
" firing having the same delay as the first.\n"
"###### repeat (bool)\n"
"> If True, the timer will fire repeatedly, with each successive\n"
"firing having the same delay as the first.\n"
"\n"
"###### timetype (ba.TimeType)\n"
"> Can be either `SIM`, `BASE`, or `REAL`. It defaults to\n"
"`SIM`.\n"
"\n"
" timetype (ba.TimeType):\n"
" Can be either ``SIM``, ``BASE``, or ``REAL``. It defaults "
"to\n"
" ``SIM``.\n"
"\n"
" timeformat (ba.TimeFormat):\n"
" Defaults to seconds but can also be milliseconds.\n"
"###### timeformat (ba.TimeFormat)\n"
"> Defaults to seconds but can also be milliseconds.\n"
"\n"
"- SIM time maps to local simulation time in ba.Activity or "
"ba.Session\n"
@ -1081,15 +1074,13 @@ auto PythonMethodsApp::GetMethods() -> std::vector<PyMethodDef> {
"backgrounded, system time changing, etc.)\n"
"Real time timers are currently only available in the UI context.\n"
"\n"
"Examples:\n"
" Print some stuff through time:\n"
" ```python\n"
" >>> ba.screenmessage('hello from now!')\n"
" >>> ba.timer(1.0, ba.Call(ba.screenmessage, 'hello from the "
"##### Examples\n"
"Print some stuff through time:\n"
">>> ba.screenmessage('hello from now!')\n"
">>> ba.timer(1.0, ba.Call(ba.screenmessage, 'hello from the "
"future!'))\n"
" >>> ba.timer(2.0, ba.Call(ba.screenmessage,\n"
" ... 'hello from the future 2!'))\n"
" ```\n"},
">>> ba.timer(2.0, ba.Call(ba.screenmessage,\n"
"... 'hello from the future 2!'))\n"},
{"time", (PyCFunction)PyTime, METH_VARARGS | METH_KEYWORDS,
"time(timetype: ba.TimeType = TimeType.SIM,\n"
@ -1098,32 +1089,32 @@ auto PythonMethodsApp::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Return the current time.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"The time returned depends on the current ba.Context and timetype.\n"
"\n"
"timetype can be either SIM, BASE, or REAL. It defaults to\n"
"SIM. Types are explained below:\n"
"\n"
"SIM time maps to local simulation time in ba.Activity or ba.Session\n"
"- SIM time maps to local simulation time in ba.Activity or "
"ba.Session\n"
"Contexts. This means that it may progress slower in slow-motion "
"play\n"
"modes, stop when the game is paused, etc. This time type is not\n"
"available in UI contexts.\n"
"\n"
"BASE time is also linked to gameplay in ba.Activity or ba.Session\n"
"- BASE time is also linked to gameplay in ba.Activity or ba.Session\n"
"Contexts, but it progresses at a constant rate regardless of\n "
"slow-motion states or pausing. It can, however, slow down or stop\n"
"in certain cases such as network outages or game slowdowns due to\n"
"cpu load. Like 'sim' time, this is unavailable in UI contexts.\n"
"\n"
"REAL time always maps to actual clock time with a bit of filtering\n"
"added, regardless of Context. (the filtering prevents it from "
"going\n"
"- REAL time always maps to actual clock time with a bit of "
"filtering\n"
"added, regardless of Context. (The filtering prevents it from going\n"
"backwards or jumping forward by large amounts due to the app being\n"
"backgrounded, system time changing, etc.)\n"
"Real time timers are currently only available in the UI context.\n"
"\n"
"the 'timeformat' arg defaults to SECONDS which returns float "
"The 'timeformat' arg defaults to SECONDS which returns float "
"seconds,\n"
"but it can also be MILLISECONDS to return integer milliseconds.\n"
"\n"
@ -1136,7 +1127,7 @@ auto PythonMethodsApp::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Pushes a call onto the event loop to be run during the next cycle.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"This can be handy for calls that are disallowed from within other\n"
"callbacks, etc.\n"
@ -1155,7 +1146,7 @@ auto PythonMethodsApp::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Return the current ba.Activity instance.\n"
"\n"
"Category: Gameplay Functions\n"
"Category: **Gameplay Functions**\n"
"\n"
"Note that this is based on context; thus code run in a timer "
"generated\n"
@ -1171,7 +1162,7 @@ auto PythonMethodsApp::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Instantiates a ba.Activity given a type object.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"Activities require special setup and thus cannot be directly\n"
"instantiated; you must go through this function."},
@ -1220,7 +1211,7 @@ auto PythonMethodsApp::GetMethods() -> std::vector<PyMethodDef> {
{"getsession", (PyCFunction)PyGetSession, METH_VARARGS | METH_KEYWORDS,
"getsession(doraise: bool = True) -> <varies>\n"
"\n"
"Category: Gameplay Functions\n"
"Category: **Gameplay Functions**\n"
"\n"
"Returns the current ba.Session instance.\n"
"Note that this is based on context; thus code being run in the UI\n"

View File

@ -685,7 +685,7 @@ auto PythonMethodsGameplay::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Emit particles, smoke, etc. into the fx sim layer.\n"
"\n"
"Category: Gameplay Functions\n"
"Category: **Gameplay Functions**\n"
"\n"
"The fx sim layer is a secondary dynamics simulation that runs in\n"
"the background and just looks pretty; it does not affect gameplay.\n"
@ -698,17 +698,17 @@ auto PythonMethodsGameplay::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Play a ba.Sound a single time.\n"
"\n"
"Category: Gameplay Functions\n"
"Category: **Gameplay Functions**\n"
"\n"
"If position is not provided, the sound will be at a constant volume\n"
"everywhere. Position should be a float tuple of size 3."},
"everywhere. Position should be a float tuple of size 3."},
{"camerashake", (PyCFunction)PyCameraShake, METH_VARARGS | METH_KEYWORDS,
"camerashake(intensity: float = 1.0) -> None\n"
"\n"
"Shake the camera.\n"
"\n"
"Category: Gameplay Functions\n"
"Category: **Gameplay Functions**\n"
"\n"
"Note that some cameras and/or platforms (such as VR) may not display\n"
"camera-shake, so do not rely on this always being visible to the\n"
@ -719,7 +719,7 @@ auto PythonMethodsGameplay::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Return collision related values\n"
"\n"
"Category: Gameplay Functions\n"
"Category: **Gameplay Functions**\n"
"\n"
"Returns a single collision value or tuple of values such as location,\n"
"depth, nodes involved, etc. Only call this in the handler of a\n"
@ -730,14 +730,14 @@ auto PythonMethodsGameplay::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Return all nodes in the current ba.Context."
"\n"
"Category: Gameplay Functions"},
"Category: **Gameplay Functions**"},
{"printnodes", PyPrintNodes, METH_VARARGS,
"printnodes() -> None\n"
"\n"
"Print various info about existing nodes; useful for debugging.\n"
"\n"
"Category: Gameplay Functions"},
"Category: **Gameplay Functions**"},
{"newnode", (PyCFunction)PyNewNode, METH_VARARGS | METH_KEYWORDS,
"newnode(type: str, owner: ba.Node = None,\n"
@ -746,7 +746,7 @@ auto PythonMethodsGameplay::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Add a node of the given type to the game.\n"
"\n"
"Category: Gameplay Functions\n"
"Category: **Gameplay Functions**\n"
"\n"
"If a dict is provided for 'attributes', the node's initial attributes\n"
"will be set based on them.\n"

View File

@ -423,7 +423,7 @@ auto PythonMethodsGraphics::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Given a color tuple, return a color safe to display as text.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"Accepts tuples of length 3 or 4. This will slightly brighten very\n"
"dark colors, etc."},
@ -433,7 +433,7 @@ auto PythonMethodsGraphics::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Get a unicode string representing a special character.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"Note that these utilize the private-use block of unicode characters\n"
"(U+E000-U+F8FF) and are specific to the game; exporting or rendering\n"

View File

@ -468,7 +468,7 @@ auto PythonMethodsMedia::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Return a collide-model, loading it if necessary.\n"
"\n"
"Category: Asset Functions\n"
"Category: **Asset Functions**\n"
"\n"
"Collide-models are used in physics calculations for such things as\n"
"terrain.\n"
@ -491,7 +491,7 @@ auto PythonMethodsMedia::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Return a model, loading it if necessary.\n"
"\n"
"Category: Asset Functions\n"
"Category: **Asset Functions**\n"
"\n"
"Note that this function returns immediately even if the media has yet\n"
"to be loaded. To avoid hitches, instantiate your media objects in\n"
@ -510,7 +510,7 @@ auto PythonMethodsMedia::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Return a sound, loading it if necessary.\n"
"\n"
"Category: Asset Functions\n"
"Category: **Asset Functions**\n"
"\n"
"Note that this function returns immediately even if the media has yet\n"
"to be loaded. To avoid hitches, instantiate your media objects in\n"
@ -529,7 +529,7 @@ auto PythonMethodsMedia::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Return a data, loading it if necessary.\n"
"\n"
"Category: Asset Functions\n"
"Category: **Asset Functions**\n"
"\n"
"Note that this function returns immediately even if the media has yet\n"
"to be loaded. To avoid hitches, instantiate your media objects in\n"
@ -548,7 +548,7 @@ auto PythonMethodsMedia::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Return a texture, loading it if necessary.\n"
"\n"
"Category: Asset Functions\n"
"Category: **Asset Functions**\n"
"\n"
"Note that this function returns immediately even if the media has yet\n"
"to be loaded. To avoid hitches, instantiate your media objects in\n"

View File

@ -791,7 +791,7 @@ auto PythonMethodsSystem::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Return whether this platform supports clipboard operations at all.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"If this returns False, UIs should not show 'copy to clipboard'\n"
"buttons, etc."},
@ -800,7 +800,7 @@ auto PythonMethodsSystem::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Return whether there is currently text on the clipboard.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"This will return False if no system clipboard is available; no need\n"
" to call ba.clipboard_available() separately."},
@ -810,18 +810,18 @@ auto PythonMethodsSystem::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Copy a string to the system clipboard.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"Ensure that ba.clipboard_available() returns True before adding\n"
"Ensure that ba.clipboard_available returns True before adding\n"
" buttons/etc. that make use of this functionality."},
{"clipboard_get_text", (PyCFunction)PyClipboardGetText, METH_NOARGS,
"clipboard_get_text() -> str\n"
"\n"
"Return text currently on the system clipboard.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"Ensure that ba.clipboard_has_text() returns True before calling\n"
"Ensure that ba.clipboard_has_text returns True before calling\n"
" this function."},
{"printobjects", (PyCFunction)PyPrintObjects,
METH_VARARGS | METH_KEYWORDS,
@ -829,7 +829,7 @@ auto PythonMethodsSystem::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Print debugging info about game objects.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"This call only functions in debug builds of the game.\n"
"It prints various info about the current object count, etc."},
@ -839,20 +839,18 @@ auto PythonMethodsSystem::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Return whether this is the first time running a line of code.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"This is used by 'print_once()' type calls to keep from overflowing\n"
"logs. The call functions by registering the filename and line where\n"
"The call is made from. Returns True if this location has not been\n"
"registered already, and False if it has.\n"
"\n"
"Example:\n"
" This print will only fire for the first loop iteration:\n"
" ```python\n"
" >>> for i in range(10):\n"
" ... if ba.do_once():\n"
" ... print('Hello once from loop!')\n"
" ```\n"},
"##### Example\n"
"This print will only fire for the first loop iteration:\n"
">>> for i in range(10):\n"
"... if ba.do_once():\n"
"... print('Hello once from loop!')\n"},
{"_app", (PyCFunction)PyApp, METH_VARARGS | METH_KEYWORDS,
"_app() -> ba.App\n"
@ -904,7 +902,7 @@ auto PythonMethodsSystem::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Used for analytics to see where in the app players spend their time.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"Generally called when opening a new window or entering some UI.\n"
"'screen' should be a string description of an app location\n"
@ -1006,7 +1004,7 @@ auto PythonMethodsSystem::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"(internal)\n"
"\n"
"Category: General Utility Functions"},
"Category: **General Utility Functions**"},
{"print_context", (PyCFunction)PyPrintContext,
METH_VARARGS | METH_KEYWORDS,

View File

@ -2331,7 +2331,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Open a provided URL.\n"
"\n"
"Category: General Utility Functions\n"
"Category: **General Utility Functions**\n"
"\n"
"Open the provided url in a web-browser, or display the URL\n"
"string in a window if that isn't possible.\n"},
@ -2395,7 +2395,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"(internal)\n"
"\n"
"Category: General Utility Functions"},
"Category: **General Utility Functions**"},
{"show_progress_bar", (PyCFunction)PyShowProgressBar,
METH_VARARGS | METH_KEYWORDS,
@ -2403,7 +2403,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"(internal)\n"
"\n"
"Category: General Utility Functions"},
"Category: **General Utility Functions**"},
{"show_app_invite", (PyCFunction)PyShowAppInvite,
METH_VARARGS | METH_KEYWORDS,
@ -2413,7 +2413,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"(internal)\n"
"\n"
"Category: General Utility Functions"},
"Category: **General Utility Functions**"},
{"show_ad", (PyCFunction)PyShowAd, METH_VARARGS | METH_KEYWORDS,
"show_ad(purpose: str, on_completion_call: Callable[[], None] = None)\n"
@ -2508,7 +2508,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Create or edit a button widget.\n"
"\n"
"Category: User Interface Functions\n"
"Category: **User Interface Functions**\n"
"\n"
"Pass a valid existing ba.Widget as 'edit' to modify it; otherwise\n"
"a new one is created and returned. Arguments that are not set to None\n"
@ -2534,7 +2534,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Create or edit a check-box widget.\n"
"\n"
"Category: User Interface Functions\n"
"Category: **User Interface Functions**\n"
"\n"
"Pass a valid existing ba.Widget as 'edit' to modify it; otherwise\n"
"a new one is created and returned. Arguments that are not set to None\n"
@ -2555,7 +2555,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Create or edit an image widget.\n"
"\n"
"Category: User Interface Functions\n"
"Category: **User Interface Functions**\n"
"\n"
"Pass a valid existing ba.Widget as 'edit' to modify it; otherwise\n"
"a new one is created and returned. Arguments that are not set to None\n"
@ -2583,7 +2583,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Create or edit a column widget.\n"
"\n"
"Category: User Interface Functions\n"
"Category: **User Interface Functions**\n"
"\n"
"Pass a valid existing ba.Widget as 'edit' to modify it; otherwise\n"
"a new one is created and returned. Arguments that are not set to None\n"
@ -2625,7 +2625,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Create or edit a container widget.\n"
"\n"
"Category: User Interface Functions\n"
"Category: **User Interface Functions**\n"
"\n"
"Pass a valid existing ba.Widget as 'edit' to modify it; otherwise\n"
"a new one is created and returned. Arguments that are not set to None\n"
@ -2643,7 +2643,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Create or edit a row widget.\n"
"\n"
"Category: User Interface Functions\n"
"Category: **User Interface Functions**\n"
"\n"
"Pass a valid existing ba.Widget as 'edit' to modify it; otherwise\n"
"a new one is created and returned. Arguments that are not set to None\n"
@ -2666,7 +2666,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Create or edit a scroll widget.\n"
"\n"
"Category: User Interface Functions\n"
"Category: **User Interface Functions**\n"
"\n"
"Pass a valid existing ba.Widget as 'edit' to modify it; otherwise\n"
"a new one is created and returned. Arguments that are not set to None\n"
@ -2688,7 +2688,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Create or edit a horizontal scroll widget.\n"
"\n"
"Category: User Interface Functions\n"
"Category: **User Interface Functions**\n"
"\n"
"Pass a valid existing ba.Widget as 'edit' to modify it; otherwise\n"
"a new one is created and returned. Arguments that are not set to None\n"
@ -2719,7 +2719,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Create or edit a text widget.\n"
"\n"
"Category: User Interface Functions\n"
"Category: **User Interface Functions**\n"
"\n"
"Pass a valid existing ba.Widget as 'edit' to modify it; otherwise\n"
"a new one is created and returned. Arguments that are not set to None\n"
@ -2734,7 +2734,7 @@ auto PythonMethodsUI::GetMethods() -> std::vector<PyMethodDef> {
"\n"
"Edit common attributes of any widget.\n"
"\n"
"Category: User Interface Functions\n"
"Category: **User Interface Functions**\n"
"\n"
"Unlike other UI calls, this can only be used to edit, not to "
"create.\n"},

View File

@ -80,15 +80,17 @@ def generate(projroot: str) -> None:
# Make sure we're running from the dir above this script.
os.chdir(projroot)
pythondir = str(
Path(projroot, 'assets', 'src', 'ba_data', 'python').absolute())
sys.path.append(pythondir)
outdirname = Path('build', 'docs_html').absolute()
templatesdir = (Path(projroot) / 'assets' / 'src' / 'pdoc' /
'templates').absolute()
pythondir = (Path(projroot) / 'assets' / 'src' / 'ba_data' /
'python').absolute()
outdirname = (Path(projroot) / 'build' / 'docs_html').absolute()
sys.path.append(str(pythondir))
try:
pdoc.render.configure(docformat='google',
search=True,
show_source=True)
pdoc.render.configure(search=True,
show_source=True,
template_directory=templatesdir)
pdoc.pdoc('ba', 'bastd', output_directory=outdirname)
except Exception as exc:
import traceback

View File

@ -252,7 +252,8 @@ def _writefuncs(parent: Any, funcnames: Sequence[str], indent: int,
f'unknown returns value: {returns} for {funcname}')
returnspc = indstr + ' '
returnstr = ('\n' + returnspc).join(returnstr.strip().splitlines())
docstr_out = _formatdoc(docstr, indent + 4, funcname=funcname)
docstr_out = _formatdoc(_filterdoc(docstr, funcname=funcname),
indent + 4)
out += spcstr + defsline + docstr_out + f'{returnspc}{returnstr}\n'
return out
@ -470,11 +471,7 @@ def _special_class_cases(classname: str) -> str:
return out
def _formatdoc(docstr: str,
indent: int,
funcname: Optional[str] = None) -> str:
out = ''
indentstr = indent * ' '
def _filterdoc(docstr: str, funcname: Optional[str] = None) -> str:
docslines = docstr.splitlines()
if (funcname and docslines and docslines[0]
@ -484,14 +481,48 @@ def _formatdoc(docstr: str,
_, docstr = docstr.split('\n\n', maxsplit=1)
docslines = docstr.splitlines()
# Assuming that each line between 'Attributes:' and '\n\n' belongs to
# attrs descriptions.
empty_lines_count = 0
attributes_line: Optional[int] = None
attrs_definitions_last_line: Optional[int] = None
for i, line in enumerate(docslines):
if line.strip() in ['Attrs:', 'Attributes:']:
if attributes_line is not None:
raise Exception("Multiple 'Attributes:' lines found")
attributes_line = i
if not line.strip():
empty_lines_count += 1
else:
empty_lines_count = 0
if empty_lines_count >= 2 and attributes_line is not None:
# It seems attribute definitions ended.
attrs_definitions_last_line = i
break
if attrs_definitions_last_line is None:
attrs_definitions_last_line = len(docslines) - 1
return '\n'.join(docslines[:attributes_line] +
docslines[attrs_definitions_last_line + 1:])
def _formatdoc(docstr: str,
indent: int,
no_end_newline: bool = False,
inner_indent: int = 0) -> str:
out = ''
indentstr = indent * ' '
inner_indent_str = inner_indent * ' '
docslines = docstr.splitlines()
if len(docslines) == 1:
out += '\n' + indentstr + '"""' + docslines[0] + '"""\n'
else:
for i, line in enumerate(docslines):
if i != 0 and line != '':
docslines[i] = indentstr + line
out += ('\n' + indentstr + '"""' + '\n'.join(docslines) + '\n' +
indentstr + '"""\n')
docslines[i] = indentstr + inner_indent_str + line
out += ('\n' + indentstr + '"""' + '\n'.join(docslines) +
('' if no_end_newline else '\n' + indentstr) + '"""\n')
return out
@ -514,7 +545,7 @@ def _writeclasses(module: ModuleType, classnames: Sequence[str]) -> str:
docstr = cls.__doc__
# classname is constructor name
out += _formatdoc(docstr, 4, funcname=classname)
out += _formatdoc(_filterdoc(docstr, funcname=classname), 4)
# Create a public constructor if it has one.
# If the first docs line appears to be a function signature
@ -548,6 +579,12 @@ def _writeclasses(module: ModuleType, classnames: Sequence[str]) -> str:
for attr in attrs:
if attr.attr_type is not None:
out += f' {attr.name}: {attr.attr_type}\n'
if attr.docs:
out += _formatdoc(_filterdoc(attr.docs),
indent=4,
inner_indent=3,
no_end_newline=True)
out += '\n'
else:
raise Exception(f'Found untyped attr in'
f' {classname} docs: {attr.name}')