Files
pytiled_parser/pytiled_parser/utilities.py
Benjamin Kirkbride 5eaa03e9c3 oof
2019-04-30 21:10:18 -04:00

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)