-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_utils.py
More file actions
103 lines (66 loc) · 2.75 KB
/
_utils.py
File metadata and controls
103 lines (66 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
''' Helpful methods for card shuffling '''
from PIL import ImageGrab
from _constants import (
boundingBoxType as boundingBox,
card_suites,
card_names,
card_utf8_codes
)
def _setup_52() -> tuple[list[int], list[int]]:
'''Get a deck of cards and positions to fill for the new deck
This facilitates the default of taking 52 cards then shuffling them into a new arrangement
Previously, the deck of cards was modeled as list of tuples to represent suite and card value
but now is a list of integers which represent the cards original position in new deck order:
before = [('spade', 1), ('diamond', 1), ('club', 1), ('heart', 1)]
now = [0,13,38,51]
'''
return list(range(52)), list(range(52))
def get_card_title(card_index: int) -> str:
'''The full name of a card
The card suite and number in english: "jack of club"
'''
if card_index < 13:
name_idx = card_index
else:
name_idx = card_index % 13
suite_idx = card_index // 13
if card_index < 26:
name_lookup = card_names
else:
name_lookup = list(reversed(card_names))
return "{} of {}".format(name_lookup[name_idx], card_suites[suite_idx])
def get_card_symbol(card_index: int) -> chr:
''' The glyph/pictograph/icon of the card '''
return chr(int(card_utf8_codes[card_index], 16))
def get_card_color(card_index: int, four_color: bool = False) -> int:
'''Determine what color for each card suite
With the options for card colors as a list like below, pick which option the card suit
should use so that different color names can be used for different targets:
['red', 'blue', 'green', 'purple]
'''
color_option = None
in_spade_range = card_index <= 12
in_diamond_range = 13 <= card_index <= 25
in_club_range = 26 <= card_index <= 38
in_heart_range = 39 <= card_index <= 51
if in_spade_range or in_club_range:
color_option = 0
if four_color and in_club_range:
color_option = 2
if in_diamond_range or in_heart_range:
color_option = 1
if four_color and in_heart_range:
color_option = 3
return color_option
def _capture_tkinter(capture_bounds: boundingBox, capture_prefix: str) -> None:
'''Save an image of the display cards
Grab the current screen using pillow and crop the area outside of the gui
'''
capture_filename = "{}.decklist.png".format(capture_prefix)
# https://pillow.readthedocs.io/en/stable/reference/ImageGrab.html
#
capture_image = ImageGrab.grab(
bbox=(capture_bounds[0], capture_bounds[1], capture_bounds[2], capture_bounds[3])
)
capture_image.save(capture_filename)
print("Decklist saved to '{}'".format(capture_filename))