Skip to content

Commit

Permalink
Drop Python 3.6 Support
Browse files Browse the repository at this point in the history
Main features of Python 3.7 being utilized is `from __future__ import annotations` and dataclasses.
  • Loading branch information
Cuphat committed May 19, 2023
1 parent 3c6d1f1 commit c167a69
Show file tree
Hide file tree
Showing 54 changed files with 1,049 additions and 985 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.6"]
python-version: ["3.7"]

steps:
- uses: actions/checkout@v3
Expand Down
92 changes: 46 additions & 46 deletions Colors.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations
import random
import re
from collections import namedtuple
from typing import Dict, Tuple, List

Color = namedtuple('Color', ' R G B')

tunic_colors: Dict[str, Color] = {
tunic_colors: dict[str, Color] = {
"Kokiri Green": Color(0x1E, 0x69, 0x1B),
"Goron Red": Color(0x64, 0x14, 0x00),
"Zora Blue": Color(0x00, 0x3C, 0x64),
Expand Down Expand Up @@ -40,7 +40,7 @@
}

# Inner Core Color Outer Glow Color
NaviColors: Dict[str, Tuple[Color, Color]] = {
NaviColors: dict[str, tuple[Color, Color]] = {
"Rainbow": (Color(0x00, 0x00, 0x00), Color(0x00, 0x00, 0x00)),
"Gold": (Color(0xFE, 0xCC, 0x3C), Color(0xFE, 0xC0, 0x07)),
"White": (Color(0xFF, 0xFF, 0xFF), Color(0x00, 0x00, 0xFF)),
Expand All @@ -63,7 +63,7 @@
"Phantom Zelda": (Color(0x97, 0x7A, 0x6C), Color(0x6F, 0x46, 0x67)),
}

sword_trail_colors: Dict[str, Color] = {
sword_trail_colors: dict[str, Color] = {
"Rainbow": Color(0x00, 0x00, 0x00),
"White": Color(0xFF, 0xFF, 0xFF),
"Red": Color(0xFF, 0x00, 0x00),
Expand All @@ -77,7 +77,7 @@
"Pink": Color(0xFF, 0x69, 0xB4),
}

bombchu_trail_colors: Dict[str, Color] = {
bombchu_trail_colors: dict[str, Color] = {
"Rainbow": Color(0x00, 0x00, 0x00),
"Red": Color(0xFA, 0x00, 0x00),
"Green": Color(0x00, 0xFF, 0x00),
Expand All @@ -90,7 +90,7 @@
"Pink": Color(0xFF, 0x69, 0xB4),
}

boomerang_trail_colors: Dict[str, Color] = {
boomerang_trail_colors: dict[str, Color] = {
"Rainbow": Color(0x00, 0x00, 0x00),
"Yellow": Color(0xFF, 0xFF, 0x64),
"Red": Color(0xFF, 0x00, 0x00),
Expand All @@ -104,7 +104,7 @@
"Pink": Color(0xFF, 0x69, 0xB4),
}

gauntlet_colors: Dict[str, Color] = {
gauntlet_colors: dict[str, Color] = {
"Silver": Color(0xFF, 0xFF, 0xFF),
"Gold": Color(0xFE, 0xCF, 0x0F),
"Black": Color(0x00, 0x00, 0x06),
Expand All @@ -120,7 +120,7 @@
"Purple": Color(0x80, 0x00, 0x80),
}

shield_frame_colors: Dict[str, Color] = {
shield_frame_colors: dict[str, Color] = {
"Red": Color(0xD7, 0x00, 0x00),
"Green": Color(0x00, 0xFF, 0x00),
"Blue": Color(0x00, 0x40, 0xD8),
Expand All @@ -133,14 +133,14 @@
"Pink": Color(0xFF, 0x69, 0xB4),
}

heart_colors: Dict[str, Color] = {
heart_colors: dict[str, Color] = {
"Red": Color(0xFF, 0x46, 0x32),
"Green": Color(0x46, 0xC8, 0x32),
"Blue": Color(0x32, 0x46, 0xFF),
"Yellow": Color(0xFF, 0xE0, 0x00),
}

magic_colors: Dict[str, Color] = {
magic_colors: dict[str, Color] = {
"Green": Color(0x00, 0xC8, 0x00),
"Red": Color(0xC8, 0x00, 0x00),
"Blue": Color(0x00, 0x30, 0xFF),
Expand All @@ -152,7 +152,7 @@

# A Button Text Cursor Shop Cursor Save/Death Cursor
# Pause Menu A Cursor Pause Menu A Icon A Note
a_button_colors: Dict[str, Tuple[Color, Color, Color, Color, Color, Color, Color]] = {
a_button_colors: dict[str, tuple[Color, Color, Color, Color, Color, Color, Color]] = {
"N64 Blue": (Color(0x5A, 0x5A, 0xFF), Color(0x00, 0x50, 0xC8), Color(0x00, 0x50, 0xFF), Color(0x64, 0x64, 0xFF),
Color(0x00, 0x32, 0xFF), Color(0x00, 0x64, 0xFF), Color(0x50, 0x96, 0xFF)),
"N64 Green": (Color(0x00, 0x96, 0x00), Color(0x00, 0x96, 0x00), Color(0x00, 0x96, 0x00), Color(0x64, 0x96, 0x64),
Expand Down Expand Up @@ -188,7 +188,7 @@
}

# B Button
b_button_colors: Dict[str, Color] = {
b_button_colors: dict[str, Color] = {
"N64 Blue": Color(0x5A, 0x5A, 0xFF),
"N64 Green": Color(0x00, 0x96, 0x00),
"N64 Red": Color(0xC8, 0x00, 0x00),
Expand All @@ -208,7 +208,7 @@
}

# C Button Pause Menu C Cursor Pause Menu C Icon C Note
c_button_colors: Dict[str, Tuple[Color, Color, Color, Color]] = {
c_button_colors: dict[str, tuple[Color, Color, Color, Color]] = {
"N64 Blue": (Color(0x5A, 0x5A, 0xFF), Color(0x00, 0x32, 0xFF), Color(0x00, 0x64, 0xFF), Color(0x50, 0x96, 0xFF)),
"N64 Green": (Color(0x00, 0x96, 0x00), Color(0x00, 0x96, 0x00), Color(0x00, 0x96, 0x00), Color(0x00, 0x96, 0x00)),
"N64 Red": (Color(0xC8, 0x00, 0x00), Color(0xC8, 0x00, 0x00), Color(0xC8, 0x00, 0x00), Color(0xC8, 0x00, 0x00)),
Expand All @@ -228,7 +228,7 @@
}

# Start Button
start_button_colors: Dict[str, Color] = {
start_button_colors: dict[str, Color] = {
"N64 Blue": Color(0x5A, 0x5A, 0xFF),
"N64 Green": Color(0x00, 0x96, 0x00),
"N64 Red": Color(0xC8, 0x00, 0x00),
Expand All @@ -247,133 +247,133 @@
"Orange": Color(0xFF, 0x80, 0x00),
}

meta_color_choices: List[str] = ["Random Choice", "Completely Random", "Custom Color"]
meta_color_choices: list[str] = ["Random Choice", "Completely Random", "Custom Color"]


def get_tunic_colors() -> List[str]:
def get_tunic_colors() -> list[str]:
return list(tunic_colors.keys())


def get_tunic_color_options() -> List[str]:
def get_tunic_color_options() -> list[str]:
return meta_color_choices + ["Rainbow"] + get_tunic_colors()


def get_navi_colors() -> List[str]:
def get_navi_colors() -> list[str]:
return list(NaviColors.keys())


def get_navi_color_options(outer: bool = False) -> List[str]:
def get_navi_color_options(outer: bool = False) -> list[str]:
if outer:
return ["[Same as Inner]"] + meta_color_choices + get_navi_colors()
else:
return meta_color_choices + get_navi_colors()


def get_sword_trail_colors() -> List[str]:
def get_sword_trail_colors() -> list[str]:
return list(sword_trail_colors.keys())


def get_sword_trail_color_options(outer: bool = False) -> List[str]:
def get_sword_trail_color_options(outer: bool = False) -> list[str]:
if outer:
return ["[Same as Inner]"] + meta_color_choices + get_sword_trail_colors()
else:
return meta_color_choices + get_sword_trail_colors()


def get_bombchu_trail_colors() -> List[str]:
def get_bombchu_trail_colors() -> list[str]:
return list(bombchu_trail_colors.keys())


def get_bombchu_trail_color_options(outer: bool = False) -> List[str]:
def get_bombchu_trail_color_options(outer: bool = False) -> list[str]:
if outer:
return ["[Same as Inner]"] + meta_color_choices + get_bombchu_trail_colors()
else:
return meta_color_choices + get_bombchu_trail_colors()


def get_boomerang_trail_colors() -> List[str]:
def get_boomerang_trail_colors() -> list[str]:
return list(boomerang_trail_colors.keys())


def get_boomerang_trail_color_options(outer: bool = False) -> List[str]:
def get_boomerang_trail_color_options(outer: bool = False) -> list[str]:
if outer:
return ["[Same as Inner]"] + meta_color_choices + get_boomerang_trail_colors()
else:
return meta_color_choices + get_boomerang_trail_colors()


def get_gauntlet_colors() -> List[str]:
def get_gauntlet_colors() -> list[str]:
return list(gauntlet_colors.keys())


def get_gauntlet_color_options() -> List[str]:
def get_gauntlet_color_options() -> list[str]:
return meta_color_choices + get_gauntlet_colors()


def get_shield_frame_colors() -> List[str]:
def get_shield_frame_colors() -> list[str]:
return list(shield_frame_colors.keys())


def get_shield_frame_color_options() -> List[str]:
def get_shield_frame_color_options() -> list[str]:
return meta_color_choices + get_shield_frame_colors()


def get_heart_colors() -> List[str]:
def get_heart_colors() -> list[str]:
return list(heart_colors.keys())


def get_heart_color_options() -> List[str]:
def get_heart_color_options() -> list[str]:
return meta_color_choices + get_heart_colors()


def get_magic_colors() -> List[str]:
def get_magic_colors() -> list[str]:
return list(magic_colors.keys())


def get_magic_color_options() -> List[str]:
def get_magic_color_options() -> list[str]:
return meta_color_choices + get_magic_colors()


def get_a_button_colors() -> List[str]:
def get_a_button_colors() -> list[str]:
return list(a_button_colors.keys())


def get_a_button_color_options() -> List[str]:
def get_a_button_color_options() -> list[str]:
return meta_color_choices + get_a_button_colors()


def get_b_button_colors() -> List[str]:
def get_b_button_colors() -> list[str]:
return list(b_button_colors.keys())


def get_b_button_color_options() -> List[str]:
def get_b_button_color_options() -> list[str]:
return meta_color_choices + get_b_button_colors()


def get_c_button_colors() -> List[str]:
def get_c_button_colors() -> list[str]:
return list(c_button_colors.keys())


def get_c_button_color_options() -> List[str]:
def get_c_button_color_options() -> list[str]:
return meta_color_choices + get_c_button_colors()


def get_start_button_colors() -> List[str]:
def get_start_button_colors() -> list[str]:
return list(start_button_colors.keys())


def get_start_button_color_options() -> List[str]:
def get_start_button_color_options() -> list[str]:
return meta_color_choices + get_start_button_colors()


def contrast_ratio(color1: List[int], color2: List[int]) -> float:
def contrast_ratio(color1: list[int], color2: list[int]) -> float:
# Based on accessibility standards (WCAG 2.0)
lum1 = relative_luminance(color1)
lum2 = relative_luminance(color2)
return (max(lum1, lum2) + 0.05) / (min(lum1, lum2) + 0.05)


def relative_luminance(color: List[int]) -> float:
def relative_luminance(color: list[int]) -> float:
color_ratios = list(map(lum_color_ratio, color))
return color_ratios[0] * 0.299 + color_ratios[1] * 0.587 + color_ratios[2] * 0.114

Expand All @@ -386,11 +386,11 @@ def lum_color_ratio(val: float) -> float:
return pow((val + 0.055) / 1.055, 2.4)


def generate_random_color() -> List[int]:
def generate_random_color() -> list[int]:
return [random.getrandbits(8), random.getrandbits(8), random.getrandbits(8)]


def hex_to_color(option: str) -> List[int]:
def hex_to_color(option: str) -> list[int]:
if not hasattr(hex_to_color, "regex"):
hex_to_color.regex = re.compile(r'^(?:[0-9a-fA-F]{3}){1,2}$')

Expand All @@ -404,5 +404,5 @@ def hex_to_color(option: str) -> List[int]:
return list(int(f'{option[i]}{option[i]}', 16) for i in (0, 1, 2))


def color_to_hex(color: List[int]) -> str:
def color_to_hex(color: list[int]) -> str:
return '#' + ''.join(['{:02X}'.format(c) for c in color])
Loading

0 comments on commit c167a69

Please sign in to comment.