sc2nachos.camera

This player's camera.

1"""This player's camera."""
2
3from sc2nachos.camera._camera import Camera
4
5__all__ = ["Camera"]
@final
class Camera:
16@final
17class Camera:
18    """This player's camera: where the turn's observation has it centered, and a move sent with the turn's orders."""
19
20    __slots__ = ("_center", "_move_to")
21
22    def __init__(self, center: Point) -> None:
23        """A camera centered at `center`."""
24        self._center = center
25        self._move_to: Point | None = None
26
27    @property
28    def center(self) -> Point:
29        """Where this player's camera is centered, as the turn's observation reports it."""
30        return self._center
31
32    def move_to(self, at: PointLike) -> None:
33        """Center the camera on `at`, with the turn's orders. Only the last move of a turn is sent, and its point is
34        rounded to the protocol's 32-bit floats."""
35        self._move_to = Point._rounded_to_float32(at)
36
37    @classmethod
38    def _from_player(cls, player: raw_pb2.PlayerRaw) -> Camera:
39        """The camera as `player`, an observation's own player, reports it."""
40        return cls(Point((player.camera.x, player.camera.y)))
41
42    def _update(self, player: raw_pb2.PlayerRaw) -> None:
43        """Take in where `player`, the turn's observation's own player, has the camera."""
44        self._center = Point((player.camera.x, player.camera.y))
45
46    def _create_move_action(self) -> sc2api_pb2.Action | None:
47        """The action that sends the turn's move, which is then forgotten, or `None` if the turn moved nothing."""
48        if (at := self._move_to) is None:
49            return None
50        self._move_to = None
51        move = raw_pb2.ActionRawCameraMove(center_world_space=common_pb2.Point(x=at.x, y=at.y))
52        return sc2api_pb2.Action(action_raw=raw_pb2.ActionRaw(camera_move=move))

This player's camera: where the turn's observation has it centered, and a move sent with the turn's orders.

Camera(center: sc2nachos.Point)
22    def __init__(self, center: Point) -> None:
23        """A camera centered at `center`."""
24        self._center = center
25        self._move_to: Point | None = None

A camera centered at center.

center: sc2nachos.Point
27    @property
28    def center(self) -> Point:
29        """Where this player's camera is centered, as the turn's observation reports it."""
30        return self._center

Where this player's camera is centered, as the turn's observation reports it.

def move_to(self, at: 'PointLike') -> None:
32    def move_to(self, at: PointLike) -> None:
33        """Center the camera on `at`, with the turn's orders. Only the last move of a turn is sent, and its point is
34        rounded to the protocol's 32-bit floats."""
35        self._move_to = Point._rounded_to_float32(at)

Center the camera on at, with the turn's orders. Only the last move of a turn is sent, and its point is rounded to the protocol's 32-bit floats.