Skip to content

Commit

Permalink
Formatting ready for merge to master
Browse files Browse the repository at this point in the history
  • Loading branch information
olijeffers0n committed Apr 21, 2023
1 parent 336b10c commit 77a05ef
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 15 deletions.
34 changes: 28 additions & 6 deletions rustplus/api/remote/camera/camera_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@

from .camera_parser import Parser
from ..events import EventLoopManager, EventHandler
from ..rustplus_proto import AppCameraInput, Vector2, AppEmpty, AppRequest, AppCameraInfo
from ..rustplus_proto import (
AppCameraInput,
Vector2,
AppEmpty,
AppRequest,
AppCameraInfo,
)
from ...structures import Vector
from .structures import CameraInfo, Entity, LimitedQueue

RS = TypeVar("RS", bound="RustSocket")


class CameraManager:
def __init__(self, rust_socket: RS, cam_id: str, cam_info_message: AppCameraInfo) -> None:
def __init__(
self, rust_socket: RS, cam_id: str, cam_info_message: AppCameraInfo
) -> None:
self.rust_socket: RS = rust_socket
self._cam_id: str = cam_id
self._last_packets: LimitedQueue = LimitedQueue(6)
Expand Down Expand Up @@ -47,7 +55,12 @@ def on_frame_received(self, coro: Coroutine) -> Coroutine:
def has_frame_data(self) -> bool:
return self._last_packets is not None and len(self._last_packets) > 0

def _create_frame(self, render_entities: bool = True, entity_render_distance: float = float("inf"), max_entity_amount: int = float("inf")) -> Union[Image.Image, None]:
def _create_frame(
self,
render_entities: bool = True,
entity_render_distance: float = float("inf"),
max_entity_amount: int = float("inf"),
) -> Union[Image.Image, None]:
if self._last_packets is None:
return None

Expand All @@ -72,11 +85,20 @@ def _create_frame(self, render_entities: bool = True, entity_render_distance: fl
last_packet.vertical_fov,
self._cam_info_message.far_plane,
entity_render_distance,
max_entity_amount if max_entity_amount is not None else len(self._last_packets.get_last().entities),
max_entity_amount
if max_entity_amount is not None
else len(self._last_packets.get_last().entities),
)

async def get_frame(self, render_entities: bool = True, entity_render_distance: float = float("inf"), max_entity_amount: int = float("inf")) -> Union[Image.Image, None]:
return self._create_frame(render_entities, entity_render_distance, max_entity_amount)
async def get_frame(
self,
render_entities: bool = True,
entity_render_distance: float = float("inf"),
max_entity_amount: int = float("inf"),
) -> Union[Image.Image, None]:
return self._create_frame(
render_entities, entity_render_distance, max_entity_amount
)

def can_move(self, control_type: int) -> bool:
return self._cam_info_message.is_move_option_permissible(control_type)
Expand Down
8 changes: 6 additions & 2 deletions rustplus/api/remote/events/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@

class EventHandler:
@staticmethod
def schedule_event(loop: asyncio.AbstractEventLoop, coro: Coroutine, arg: Any) -> None:
def schedule_event(
loop: asyncio.AbstractEventLoop, coro: Coroutine, arg: Any
) -> None:
def callback(inner_future: Future):
if inner_future.exception() is not None:
logging.getLogger("rustplus.py").exception(inner_future.exception())

future: Future = asyncio.run_coroutine_threadsafe(coro(arg), loop)
future.add_done_callback(callback)

def run_entity_event(self, name: str, app_message: AppMessage, server_id: ServerID) -> None:
def run_entity_event(
self, name: str, app_message: AppMessage, server_id: ServerID
) -> None:

handlers: Set[RegisteredListener] = EntityEvent.handlers.get_handlers(
server_id
Expand Down
3 changes: 0 additions & 3 deletions rustplus/api/remote/rust_remote_interface.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import asyncio
import logging

from asyncio import Future
from typing import Dict

from .camera.camera_manager import CameraManager
from .events import EventLoopManager, EntityEvent, RegisteredListener
from .events.event_handler import EventHandler
Expand Down
2 changes: 1 addition & 1 deletion rustplus/api/remote/rustplus_proto/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .rustplus import *
from .rustplus import *
4 changes: 3 additions & 1 deletion rustplus/api/remote/rustws.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ def get_prefix(self, message: str) -> Optional[str]:

@staticmethod
def is_message(app_message: AppMessage) -> bool:
return betterproto.serialized_on_wire(app_message.broadcast.team_message.message)
return betterproto.serialized_on_wire(
app_message.broadcast.team_message.message
)

@staticmethod
def is_camera_broadcast(app_message: AppMessage) -> bool:
Expand Down
3 changes: 2 additions & 1 deletion rustplus/api/remote/server_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ def _check_server(self) -> None:
for msg in req.json()["messages"]:
if "does not match your outgoing IP address" not in msg:
self.logger.warning(f"Error from server Checker: {msg}")
except Exception:
except Exception as e:
self.logger.warning(f"An error occurred in the server checker request: {e}")

This comment has been minimized.

Copy link
@psykzz

psykzz Apr 21, 2023

Contributor
self.logger.exception(f"Unable to test connection to server - {self.ip}:{self.port}")

Note that logger.exception will already include the exception, so you just need to describe the issue.

This comment has been minimized.

Copy link
@olijeffers0n

olijeffers0n Apr 21, 2023

Author Owner

That’s a handy utility method. I’m out of town for the next few days - if you wanna PR it, i’ll just instamerge it.

pass
7 changes: 6 additions & 1 deletion rustplus/api/rust_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
RustContents,
RustItem,
)
from .remote.rustplus_proto import AppEmpty, AppSendMessage, AppSetEntityValue, AppPromoteToLeader
from .remote.rustplus_proto import (
AppEmpty,
AppSendMessage,
AppSetEntityValue,
AppPromoteToLeader,
)
from .remote import HeartBeat, RateLimiter
from ..commands import CommandOptions
from ..exceptions import *
Expand Down

0 comments on commit 77a05ef

Please sign in to comment.