mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2025-12-27 22:59:48 +01:00
28 lines
780 B
Python
28 lines
780 B
Python
import pytiled_parser.objects as objects
|
|
|
|
|
|
def parse_color(color: str) -> objects.Color:
|
|
"""
|
|
Converts the color formats that Tiled uses into ones that Arcade accepts.
|
|
|
|
Returns:
|
|
:Color: Color object in the format that Arcade understands.
|
|
"""
|
|
# strip initial '#' character
|
|
if not len(color) % 2 == 0: # pylint: disable=C2001
|
|
color = color[1:]
|
|
|
|
if len(color) == 6:
|
|
# full opacity if no alpha specified
|
|
alpha = 0xFF
|
|
red = int(color[0:2], 16)
|
|
green = int(color[2:4], 16)
|
|
blue = int(color[4:6], 16)
|
|
else:
|
|
alpha = int(color[0:2], 16)
|
|
red = int(color[2:4], 16)
|
|
green = int(color[4:6], 16)
|
|
blue = int(color[6:8], 16)
|
|
|
|
return objects.Color(red, green, blue, alpha)
|