-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29c5138
commit b6d4582
Showing
16 changed files
with
639 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# API Reference | ||
|
||
## Decks and Slides | ||
|
||
::: spiel.Deck | ||
|
||
::: spiel.Slide | ||
|
||
## Rendering Content | ||
|
||
::: spiel.Triggers | ||
|
||
## Presenting Decks | ||
|
||
::: spiel.present |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,81 @@ | ||
from __future__ import annotations | ||
|
||
from collections.abc import Sequence | ||
from dataclasses import dataclass | ||
from functools import cached_property | ||
from time import monotonic | ||
from typing import Iterator | ||
from typing import Iterator, overload | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Triggers: | ||
times: tuple[float, ...] | ||
class Triggers(Sequence[float]): | ||
""" | ||
Provides information to [`Slide.content`][spiel.Slide.content] about the current slide's "trigger state". | ||
`Triggers` is a [`Sequence`][collections.abc.Sequence] of times | ||
(produced by [`time.monotonic`][time.monotonic]) | ||
that the current slide was triggered at. | ||
Note that the slide will be triggered once when it starts being displayed, | ||
so the first trigger time will be the time when the slide started being displayed. | ||
""" | ||
|
||
now: float | ||
""" | ||
The time that the slide content is being rendered at. | ||
Use this is as a single consistent value to base relative times on. | ||
""" | ||
|
||
_times: tuple[float, ...] | ||
|
||
def __post_init__(self) -> None: | ||
if not self.times: | ||
if not self._times: | ||
raise ValueError("times must not be empty") | ||
|
||
if self.now < self.times[-1]: | ||
raise ValueError(f"now {self.now} must be later than the last time {self.times[-1]}") | ||
if self.now < self._times[-1]: | ||
raise ValueError(f"now {self.now} must be later than the last time {self._times[-1]}") | ||
|
||
@classmethod | ||
def new(self) -> Triggers: | ||
now = monotonic() | ||
return Triggers(now=now, times=(now,)) | ||
return Triggers(now=now, _times=(now,)) | ||
|
||
def __len__(self) -> int: | ||
return len(self.times) | ||
return len(self._times) | ||
|
||
def __getitem__(self, idx: int) -> float: | ||
return self.times[idx] | ||
@overload | ||
def __getitem__(self, item: int) -> float: | ||
return self._times[item] | ||
|
||
@overload | ||
def __getitem__(self, item: slice) -> Sequence[float]: | ||
return self._times[item] | ||
|
||
def __getitem__(self, item: int | slice) -> float | Sequence[float]: | ||
return self._times[item] | ||
|
||
def __iter__(self) -> Iterator[float]: | ||
return iter(self.times) | ||
return iter(self._times) | ||
|
||
def __contains__(self, item: object) -> bool: | ||
return item in self._times | ||
|
||
@cached_property | ||
def time_since_last_trigger(self) -> float: | ||
return self.now - self.times[-1] | ||
"""The elapsed time since the most recent trigger.""" | ||
return self.now - self._times[-1] | ||
|
||
@cached_property | ||
def time_since_first_trigger(self) -> float: | ||
return self.now - self.times[0] | ||
""" | ||
The elapsed time since the first trigger, | ||
which is equivalent to the time since the slide started being displayed. | ||
""" | ||
return self.now - self._times[0] | ||
|
||
@cached_property | ||
def triggered(self) -> bool: | ||
""" | ||
Returns whether the slide has been *manually* triggered | ||
(i.e., this ignores the initial trigger from when the slide starts being displayed). | ||
""" | ||
return len(self) > 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.