diff --git a/docs/api-methods/getting-the-map.md b/docs/api-methods/getting-the-map.md index 4911719..5d52cbc 100644 --- a/docs/api-methods/getting-the-map.md +++ b/docs/api-methods/getting-the-map.md @@ -2,7 +2,7 @@ ### Getting the Image -Calling `rust_socket.get_map(add_icons: bool, add_events: bool, add_vending_machines: bool, override_images: dict)` will return a `PIL.Image` with the respective additions. +Calling `rust_socket.get_map(add_icons: bool, add_events: bool, add_vending_machines: bool, add_team_positions: bool, override_images: dict, add_grid: bool)` will return a `PIL.Image` with the respective additions. ### Getting the Map Data diff --git a/docs/getting-started/getting-player-details/README.md b/docs/getting-started/getting-player-details/README.md index 9a25014..2ae2c26 100644 --- a/docs/getting-started/getting-player-details/README.md +++ b/docs/getting-started/getting-player-details/README.md @@ -54,7 +54,7 @@ In order to get your data, you need to: "name": "", "playerId": "", <- This is your steam player ID "playerToken": "", <- This is your unique token - "port": "", <- This is the token + "port": "", <- This is the port "type": "", "url": "" } @@ -65,4 +65,3 @@ You can then use these details in the Python Wrapper here: ```python rust_socket = RustSocket("IPADDRESS", "PORT", 64BITSTEAMID, PLAYERTOKEN) ``` - diff --git a/rustplus/api/rust_api.py b/rustplus/api/rust_api.py index 69521d9..a99cd01 100644 --- a/rustplus/api/rust_api.py +++ b/rustplus/api/rust_api.py @@ -37,6 +37,7 @@ translate_id_to_stack, deprecated, generate_grid, + avatar_processing, ) @@ -168,6 +169,7 @@ async def get_map( add_icons: bool = False, add_events: bool = False, add_vending_machines: bool = False, + add_team_positions: bool = False, override_images: dict = None, add_grid: bool = False, ) -> Image.Image: @@ -181,7 +183,7 @@ async def get_map( + ( 1 if [add_icons, add_events, add_vending_machines].count(True) >= 1 - else 0 + else 0 + 1 if add_team_positions else 0 ) ) @@ -271,6 +273,28 @@ async def get_map( (int(marker.x) - 50, map_size - int(marker.y) - 50), vending_machine, ) + if add_team_positions: + team = await self.get_team_info() + for member in team.members: + if member.is_alive: + avatar = ( + Image.open( + requests.get( + f"https://companion-rust.facepunch.com/api/avatar/{member.steam_id}", + stream=True, + ).raw + ) + .resize((100, 100), Image.LANCZOS) + .convert("RGBA") + ) + + player_avatar = avatar_processing(avatar, 5, member.is_online) + + game_map.paste( + player_avatar, + (format_coord(int(member.x), int(member.y), map_size)), + player_avatar, + ) return game_map.resize((2000, 2000), Image.LANCZOS) diff --git a/rustplus/utils/rust_utils.py b/rustplus/utils/rust_utils.py index c0d905c..f2520a3 100644 --- a/rustplus/utils/rust_utils.py +++ b/rustplus/utils/rust_utils.py @@ -11,6 +11,9 @@ FONT_PATH = "rustplus.utils.fonts" GRID_DIAMETER = 146.28571428571428 +PLAYER_MARKER_ONLINE_COLOR = (201, 242, 155, 255) +PLAYER_MARKER_OFFLINE_COLOR = (128, 128, 128, 255) + def format_time(protobuf: AppMessage) -> RustTime: def convert_time(time) -> str: @@ -261,3 +264,34 @@ def generate_grid( d.text(text_pos, text, fill=color, font=font) return img + + +def avatar_processing( + image: Image.Image, border_size: int, player_online: bool = False +) -> Image.Image: + size_with_border = ( + image.size[0] + 2 * border_size, + image.size[1] + 2 * border_size, + ) + + border_image = Image.new("RGBA", size_with_border, (0, 0, 0, 0)) + + mask = Image.new("L", size_with_border, 0) + draw = ImageDraw.Draw(mask) + + draw.ellipse([0, 0, size_with_border[0], size_with_border[1]], fill=255) + + border_layer = Image.new( + "RGBA", + size_with_border, + PLAYER_MARKER_ONLINE_COLOR if player_online else PLAYER_MARKER_OFFLINE_COLOR, + ) + border_image.paste(border_layer, mask=mask) + + image_mask = Image.new("L", image.size, 0) + draw = ImageDraw.Draw(image_mask) + draw.ellipse([0, 0, image.size[0], image.size[1]], fill=255) + + border_image.paste(image, (border_size, border_size), image_mask) + + return border_image