added color to prefix and suffix

This commit is contained in:
Faraphel 2022-07-20 12:19:35 +02:00
parent aa6eeb2e49
commit 5d448369ee
5 changed files with 124 additions and 101 deletions

View file

@ -5,60 +5,60 @@
"variant": "60",
"tags_prefix": {
"MSRDS": "green",
"CTR": "YOR4",
"CTTR": "YOR5",
"CNR": "YOR5",
"DKR": "YOR6",
"LCP": "green",
"LEGO-R": "red2",
"MP9": "YOR0",
"MSUSA": "green",
"FZMV": "YOR2",
"KAR": "green",
"KO": "YOR5",
"FZ": "YOR2",
"RV": "white",
"SADX": "blue2",
"SCR": "YOR2",
"SH": "red",
"SM64": "red1",
"SMB1": "red2",
"SMB2": "red3",
"SSBB": "red4",
"SMS": "YOR6",
"SMO": "YOR7",
"VVVVVV": "blue",
"WF": "green",
"WP": "yellow",
"Zelda OoT": "green",
"Zelda TP": "green",
"Zelda WW": "green",
"PMWR": "yellow",
"SHR": "green",
"SK64": "green",
"SMG": "red2",
"Spyro 1": "blue",
"Switch": "red4",
"Wii": "blue",
"3DS": "YOR3",
"DS": "white",
"GCN": "blue2",
"GBA": "blue1",
"N64": "red",
"SNES": "green",
"RMX": "YOR4",
"MKT": "YOR5",
"GP": "YOR6",
"Wii Shop": "blue1",
"UT": "red3",
"GK2": "green",
"GK3": "green",
"GK7": "green",
"FGKR": "YOR5"
"MSRDS": "{{ bmg_color_text('green', TAG) }}",
"CTR": "{{ bmg_color_text('orange', TAG) }}",
"CTTR": "{{ bmg_color_text('dark orange', TAG) }}",
"CNR": "{{ bmg_color_text('orange', TAG) }}",
"DKR": "{{ bmg_color_text('dark red', TAG) }}",
"LCP": "{{ bmg_color_text('green', TAG) }}",
"LEGO-R": "{{ bmg_color_text('light red', TAG) }}",
"MP9": "{{ bmg_color_text('neon yellow', TAG) }}",
"MSUSA": "{{ bmg_color_text('green', TAG) }}",
"FZMV": "{{ bmg_color_text('yellow', TAG) }}",
"KAR": "{{ bmg_color_text('green', TAG) }}",
"KO": "{{ bmg_color_text('dark orange', TAG) }}",
"FZ": "{{ bmg_color_text('yellow', TAG) }}",
"RV": "{{ bmg_color_text('white', TAG) }}",
"SADX": "{{ bmg_color_text('dark blue', TAG) }}",
"SCR": "{{ bmg_color_text('yellow', TAG) }}",
"SH": "{{ bmg_color_text('pink', TAG) }}",
"SM64": "{{ bmg_color_text('pink', TAG) }}",
"SMB1": "{{ bmg_color_text('light red', TAG) }}",
"SMB2": "{{ bmg_color_text('red', TAG) }}",
"SSBB": "{{ bmg_color_text('vivid red', TAG) }}",
"SMS": "{{ bmg_color_text('dark red', TAG) }}",
"SMO": "{{ bmg_color_text('apple red', TAG) }}",
"VVVVVV": "{{ bmg_color_text('azure', TAG) }}",
"WF": "{{ bmg_color_text('green', TAG) }}",
"WP": "{{ bmg_color_text('neon yellow 2', TAG) }}",
"Zelda OoT": "{{ bmg_color_text('green', TAG) }}",
"Zelda TP": "{{ bmg_color_text('green', TAG) }}",
"Zelda WW": "{{ bmg_color_text('green', TAG) }}",
"PMWR": "{{ bmg_color_text('neon yellow 2', TAG) }}",
"SHR": "{{ bmg_color_text('green', TAG) }}",
"SK64": "{{ bmg_color_text('green', TAG) }}",
"SMG": "{{ bmg_color_text('light red', TAG) }}",
"Spyro 1": "{{ bmg_color_text('azure', TAG) }}",
"Switch": "{{ bmg_color_text('vivid red', TAG) }}",
"Wii": "{{ bmg_color_text('azure', TAG) }}",
"3DS": "{{ bmg_color_text('light orange', TAG) }}",
"DS": "{{ bmg_color_text('white', TAG) }}",
"GCN": "{{ bmg_color_text('azure', TAG) }}",
"GBA": "{{ bmg_color_text('dark blue', TAG) }}",
"N64": "{{ bmg_color_text('pink', TAG) }}",
"SNES": "{{ bmg_color_text('green', TAG) }}",
"RMX": "{{ bmg_color_text('orange', TAG) }}",
"MKT": "{{ bmg_color_text('dark orange', TAG) }}",
"GP": "{{ bmg_color_text('dark red', TAG) }}",
"Wii Shop": "{{ bmg_color_text('azure', TAG) }}",
"UT": "{{ bmg_color_text('red', TAG) }}",
"GK2": "{{ bmg_color_text('green', TAG) }}",
"GK3": "{{ bmg_color_text('green', TAG) }}",
"GK7": "{{ bmg_color_text('green', TAG) }}",
"FGKR": "{{ bmg_color_text('dark orange', TAG) }}"
},
"tags_suffix": {
"Boost": "orange"
"Boost": "{{ bmg_color_text('orange', TAG) }}"
},
"tags_cups": ["Switch", "3DS", "DS", "GCN", "GBA", "N64", "SNES", "MKT", "RMX", "DX", "GP"],

51
source/mkw/MKWColor.py Normal file
View file

@ -0,0 +1,51 @@
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)
def bmg_color_text(color_name: str, text: str) -> str:
"""
Useful shortcut to color a text
:param color_name: name of the color
:param text: text to color
:return: return the formatted text with the color
"""
return r"\c{" + MKWColor(color_name).bmg + "}" + text + r"\c{" + MKWColor('off').bmg + "}"

View file

@ -4,7 +4,7 @@ from typing import Generator
from PIL import Image
from source import threaded
from source.mkw import Tag, Color
from source.mkw import Tag, MKWColor
from source.mkw.Cup import Cup
from source.mkw.Track import Track
import json
@ -26,7 +26,7 @@ class ModConfig:
"keep_original_track", "enable_random_cup", "tags_cups", "track_file_template")
def __init__(self, path: Path | str, name: str, nickname: str = None, version: str = None, variant: str = None,
tags_prefix: dict[Tag, Color] = None, tags_suffix: dict[Tag, Color] = None,
tags_prefix: dict[Tag, str] = None, tags_suffix: dict[Tag, str] = None,
tags_cups: list[Tag] = None,
default_track: "Track | TrackGroup" = None, tracks: list["Track | TrackGroup"] = None,
original_track_prefix: bool = None, swap_original_order: bool = None,

View file

@ -1,6 +1,7 @@
from typing import Generator
from source.mkw import Tag, Slot
from source.mkw.MKWColor import bmg_color_text
from source.safe_eval import multiple_safe_eval
@ -60,6 +61,22 @@ class Track:
return multiple_safe_eval(template, extra_token_map, {"track": self})
def get_tag_template(self, templates: dict[str, str], default: any = None) -> any:
"""
Return the tag template found in templates. If not found, return default
:param templates: template with all the tags and its replacement
:param default: default value if no tag template is found
:return: formatted representation of the tag
"""
for tag in filter(lambda tag: tag in templates, self.tags):
template: str = templates[tag]
return multiple_safe_eval(
template,
extra_token_map={"TAG": "TAG", "bmg_color_text": "bmg_color_text"},
env={"TAG": tag, "bmg_color_text": bmg_color_text}
)
return default
def get_prefix(self, mod_config: "ModConfig", default: any = None) -> any:
"""
return the prefix of the track
@ -67,8 +84,7 @@ class Track:
:param mod_config: mod configuration
:return: formatted representation of the track prefix
"""
for tag in filter(lambda tag: tag in mod_config.tags_prefix, self.tags): return tag
return default
return self.get_tag_template(mod_config.tags_prefix, default)
def get_suffix(self, mod_config: "ModConfig", default: any = None) -> any:
"""
@ -77,8 +93,7 @@ class Track:
:param mod_config: mod configuration
:return: formatted representation of the track suffix
"""
for tag in filter(lambda tag: tag in mod_config.tags_suffix, self.tags): return tag
return default
return self.get_tag_template(mod_config.tags_suffix, default)
def is_highlight(self, mod_config: "ModConfig", default: any = None) -> bool:
...

View file

@ -1,45 +1,2 @@
Tag = str
Slot = str
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)