Skip to content

Guidelines

Guidelines

Bases: Dict[float, GuidelineColor], RobTop

Represents guidelines.

Binary
struct Guideline {
    timestamp: f32,
    color: f32,
}

struct Guidelines {
    guidelines_length: u32,
    guidelines: [Guideline; guidelines_length],
}
Source code in gd/api/guidelines.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Guidelines(Dict[float, GuidelineColor], RobTop):
    """Represents guidelines.

    Binary:
        ```rust
        struct Guideline {
            timestamp: f32,
            color: f32,
        }

        struct Guidelines {
            guidelines_length: u32,
            guidelines: [Guideline; guidelines_length],
        }
        ```
    """

    def add(self, timestamp: float, color: GuidelineColor = GuidelineColor.DEFAULT) -> None:
        """Adds the guideline described by `timestamp` and `color`.

        Arguments:
            timestamp: The timestamp of the guideline.
            color: The color of the guideline.

        Example:
            ```python
            >>> guidelines = Guidelines()
            >>> guidelines.add(1.0, GuidelineColor.GREEN)
            >>> guidelines
            {1.0: <GuidelineColor.GREEN: 1.0>}
            ```
        """
        self[timestamp] = color

    @classmethod
    def from_robtop(cls, string: str) -> Self:
        color = GuidelineColor

        return cls(
            {timestamp: color(value) for timestamp, value in split_guidelines(string).items()}
        )

    def to_robtop(self) -> str:
        return concat_guidelines({timestamp: color.value for timestamp, color in self.items()})

    @classmethod
    def can_be_in(cls, string: str) -> bool:
        return GUIDELINES_SEPARATOR in string

add(timestamp: float, color: GuidelineColor = GuidelineColor.DEFAULT) -> None

Adds the guideline described by timestamp and color.

Parameters:

Name Type Description Default
timestamp float

The timestamp of the guideline.

required
color GuidelineColor

The color of the guideline.

DEFAULT
Example
>>> guidelines = Guidelines()
>>> guidelines.add(1.0, GuidelineColor.GREEN)
>>> guidelines
{1.0: <GuidelineColor.GREEN: 1.0>}
Source code in gd/api/guidelines.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def add(self, timestamp: float, color: GuidelineColor = GuidelineColor.DEFAULT) -> None:
    """Adds the guideline described by `timestamp` and `color`.

    Arguments:
        timestamp: The timestamp of the guideline.
        color: The color of the guideline.

    Example:
        ```python
        >>> guidelines = Guidelines()
        >>> guidelines.add(1.0, GuidelineColor.GREEN)
        >>> guidelines
        {1.0: <GuidelineColor.GREEN: 1.0>}
        ```
    """
    self[timestamp] = color