implemented MKWColor for easier naming of BMG color

This commit is contained in:
Faraphel 2022-07-20 10:30:37 +02:00
parent 9a97453a20
commit aa6eeb2e49

View file

@ -2,25 +2,44 @@ Tag = str
Slot = str
Color = {
"yor7": 0xF5090B, # apple red
"yor6": 0xE82C09, # dark red
"yor5": 0xE65118, # dark orange (flame)
"yor4": 0xFF760E, # orange (pumpkin)
"yor3": 0xFFA61F, # light orange (bright yellow)
"yor2": 0xFEBC1F, # yellow (ripe mango)
"yor1": 0xFFE71F, # light yellow
"yor0": 0xFFFF22, # neon yellow
"blue2": 0x1170EC, # dark blue
"blue1": 0x75B5F6, # azure
"green": 0x0EB00A, # green
"yellow": 0xFFFD1E, # neon yellow 2
"red4": 0xEE0C10, # vivid red
"red3": 0xFF0308, # red
"red2": 0xF14A4E, # light red
"red1": 0xE46C74, # pink
"white": 0xFFFFFF, # white
"clear": 0x000000, # clear
"off": 0x998C86 # off
}
class ColorNotFound(Exception):
def __init__(self, color_data: any):
super().__init__(f'Can\'t find color "{color_data}"')
class MKWColor:
"""
Represent a color that can be used inside MKW files
"""
all_colors: list[dict] = [
{"bmg": "yor7", "hex": 0xF5090B, "name": "apple red"},
{"bmg": "yor6", "hex": 0xE82C09, "name": "dark red"},
{"bmg": "yor5", "hex": 0xE65118, "name": "dark orange"}, # flame
{"bmg": "yor4", "hex": 0xFF760E, "name": "orange"}, # pumpkin
{"bmg": "yor3", "hex": 0xFFA61F, "name": "light orange"}, # bright yellow
{"bmg": "yor2", "hex": 0xFEBC1F, "name": "yellow"}, # ripe mango
{"bmg": "yor1", "hex": 0xFFE71F, "name": "light yellow"},
{"bmg": "yor0", "hex": 0xFFFF22, "name": "neon yellow"},
{"bmg": "blue2", "hex": 0x1170EC, "name": "dark blue"},
{"bmg": "blue1", "hex": 0x75B5F6, "name": "azure"},
{"bmg": "green", "hex": 0x0EB00A, "name": "green"},
{"bmg": "yellow", "hex": 0xFFFD1E, "name": "neon yellow 2"},
{"bmg": "red4", "hex": 0xEE0C10, "name": "vivid red"},
{"bmg": "red3", "hex": 0xFF0308, "name": "red"},
{"bmg": "red2", "hex": 0xF14A4E, "name": "light red"},
{"bmg": "red1", "hex": 0xE46C74, "name": "pink"},
{"bmg": "white", "hex": 0xFFFFFF, "name": "white"},
{"bmg": "clear", "hex": 0x000000, "name": "clear"},
{"bmg": "off", "hex": 0x998C86, "name": "off"},
]
__slots__ = ("bmg", "hex", "name")
def __init__(self, color_data: any, color_key: str = "name"):
colors = list(filter(lambda color: color[color_key] == color_data, self.all_colors))
if len(colors) == 0: raise ColorNotFound(color_data)
for key, value in colors[0].items():
setattr(self, key, value)