From 108bcbc715783f1583cedb607966f9fd9750831a Mon Sep 17 00:00:00 2001 From: Ollie <69084614+olijeffers0n@users.noreply.github.com> Date: Wed, 15 Mar 2023 22:07:34 +0000 Subject: [PATCH] More Lax with resubscribing --- rustplus/__init__.py | 2 +- rustplus/api/remote/camera/camera_manager.py | 5 +++- rustplus/api/remote/camera/camera_parser.py | 29 ++++++-------------- rustplus/api/remote/camera/structures.py | 5 +++- rustplus/api/remote/rust_remote_interface.py | 6 ++-- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/rustplus/__init__.py b/rustplus/__init__.py index 7c6665d..e881944 100644 --- a/rustplus/__init__.py +++ b/rustplus/__init__.py @@ -22,5 +22,5 @@ __name__ = "rustplus" __author__ = "olijeffers0n" -__version__ = "5.5.7" +__version__ = "5.5.8" __support__ = "Discord: https://discord.gg/nQqJe8qvP8" diff --git a/rustplus/api/remote/camera/camera_manager.py b/rustplus/api/remote/camera/camera_manager.py index 747d591..867743d 100644 --- a/rustplus/api/remote/camera/camera_manager.py +++ b/rustplus/api/remote/camera/camera_manager.py @@ -89,11 +89,14 @@ async def exit_camera(self) -> None: self.rust_socket.remote.ignored_responses.append(app_request.seq) self._open = False - self._last_packets = None + self._last_packets.clear() async def resubscribe(self) -> None: await self.rust_socket.remote.subscribe_to_camera(self._cam_id, True) self.time_since_last_subscribe = time.time() + self._open = True + self._last_packets.clear() + self.rust_socket.remote.camera_manager = self async def get_entities_in_frame(self) -> List[Entity]: if self._last_packets is None: diff --git a/rustplus/api/remote/camera/camera_parser.py b/rustplus/api/remote/camera/camera_parser.py index d0c601b..c1fd1ba 100644 --- a/rustplus/api/remote/camera/camera_parser.py +++ b/rustplus/api/remote/camera/camera_parser.py @@ -3,7 +3,6 @@ from PIL import Image from .camera_constants import LOOKUP_CONSTANTS -from .structures import RayPacket @dataclasses.dataclass @@ -29,7 +28,7 @@ def __init__(self, width, height) -> None: [0.7, 0.7, 0.7], [0.8, 0.6, 0.4], [1, 0.4, 0.4], - [0.5, 0.5, 0.5], + [1, 0.1, 0.1], ] self.output = [None for _ in range(self.width * self.height)] @@ -45,7 +44,7 @@ async def handle_camera_ray_data(self, data) -> None: async def step(self) -> None: if self._rays is None: - return None + return while True: if await self.process_rays_batch(): @@ -174,12 +173,7 @@ async def render(self) -> Image.Image: image.putpixel( (i % self.width, self.height - 1 - (i // self.width)), await self._convert_colour( - ( - int(colour[0] * 255), - int(colour[1] * 255), - int(colour[2] * 255), - int(alignment * 255), - ) + (colour[0], colour[1], colour[2], alignment) ), ) @@ -187,22 +181,17 @@ async def render(self) -> Image.Image: @staticmethod async def _convert_colour( - colour: Tuple[int, int, int, int], background: Tuple[int, int, int] = (0, 0, 0) + colour: Tuple[float, float, float, float], + background: Tuple[int, int, int] = (0, 0, 0), ) -> Tuple[int, int, int]: - normalised_colour = ( - colour[0] / 255, - colour[1] / 255, - colour[2] / 255, - colour[3] / 255, - ) target_colour = ( - ((1 - normalised_colour[3]) * background[0]) + (normalised_colour[3] * normalised_colour[0]), - ((1 - normalised_colour[3]) * background[1]) + (normalised_colour[3] * normalised_colour[1]), - ((1 - normalised_colour[3]) * background[2]) + (normalised_colour[3] * normalised_colour[2]) + ((1 - colour[3]) * background[0]) + (colour[3] * colour[0]), + ((1 - colour[3]) * background[1]) + (colour[3] * colour[1]), + ((1 - colour[3]) * background[2]) + (colour[3] * colour[2]), ) return ( min(255, int(target_colour[0] * 255)), min(255, int(target_colour[1] * 255)), - min(255, int(target_colour[2] * 255)) + min(255, int(target_colour[2] * 255)), ) diff --git a/rustplus/api/remote/camera/structures.py b/rustplus/api/remote/camera/structures.py index 044ed71..cbc5099 100644 --- a/rustplus/api/remote/camera/structures.py +++ b/rustplus/api/remote/camera/structures.py @@ -26,7 +26,7 @@ def __init__(self, entity_data) -> None: self.position = entity_data.position self.rotation = entity_data.rotation self.size = entity_data.size - self.name = entity_data.name + self.name: str = entity_data.name def __str__(self) -> str: return ( @@ -72,5 +72,8 @@ def get_last(self) -> Any: def pop(self) -> Any: return self._queue.pop(0) + def clear(self) -> None: + self._queue.clear() + def __len__(self) -> int: return len(self._queue) diff --git a/rustplus/api/remote/rust_remote_interface.py b/rustplus/api/remote/rust_remote_interface.py index 83441f5..275899b 100644 --- a/rustplus/api/remote/rust_remote_interface.py +++ b/rustplus/api/remote/rust_remote_interface.py @@ -226,7 +226,9 @@ def entity_event_callback(future_inner: Future) -> None: ) future.add_done_callback(entity_event_callback) - async def subscribe_to_camera(self, entity_id: int, ignore: bool = False) -> AppRequest: + async def subscribe_to_camera( + self, entity_id: int, ignore_response: bool = False + ) -> AppRequest: await self.api._handle_ratelimit() app_request = self.api._generate_protobuf() subscribe = AppCameraSubscribe() @@ -235,7 +237,7 @@ async def subscribe_to_camera(self, entity_id: int, ignore: bool = False) -> App await self.send_message(app_request) - if ignore: + if ignore_response: self.ignored_responses.append(app_request.seq) return app_request