Add support for colorless searches
This commit is contained in:
parent
b0fff226ea
commit
eb61663888
2 changed files with 9 additions and 5 deletions
|
@ -7,6 +7,7 @@ import uuid
|
|||
|
||||
|
||||
class Color(enum.IntEnum):
|
||||
Colorless = 0
|
||||
White = 1
|
||||
Blue = 2
|
||||
Black = 3
|
||||
|
@ -14,7 +15,7 @@ class Color(enum.IntEnum):
|
|||
Red = 5
|
||||
|
||||
def __str__(self) -> str:
|
||||
return dict(zip(Color, "WUBGR")).get(self.value)
|
||||
return dict(zip(Color, "CWUBGR")).get(self.value).replace("C", "")
|
||||
|
||||
@staticmethod
|
||||
def to_string(colors: typing.List["Color"]) -> str:
|
||||
|
@ -24,7 +25,7 @@ class Color(enum.IntEnum):
|
|||
def from_string(colors: str) -> typing.List["Color"]:
|
||||
return [
|
||||
color
|
||||
for color in [dict(zip("WUBGR", Color)).get(c) for c in colors.upper()]
|
||||
for color in [dict(zip("CWUBGR", Color)).get(c) for c in colors.upper()]
|
||||
if color is not None
|
||||
]
|
||||
|
||||
|
|
|
@ -60,7 +60,8 @@ ustring = functools.partial(parsy.string, transform=lambda s: s.upper())
|
|||
lstring_from = functools.partial(parsy.string_from, transform=lambda s: s.lower())
|
||||
ustring_from = functools.partial(parsy.string_from, transform=lambda s: s.upper())
|
||||
|
||||
W, U, B, G, R = (
|
||||
C, W, U, B, G, R = (
|
||||
tutor.models.Color.Colorless,
|
||||
tutor.models.Color.White,
|
||||
tutor.models.Color.Blue,
|
||||
tutor.models.Color.Black,
|
||||
|
@ -73,7 +74,8 @@ gte = parsy.string(">=").map(Operator)
|
|||
lte = parsy.string("<=").map(Operator)
|
||||
|
||||
color = (
|
||||
ustring("w").result(W)
|
||||
ustring("c").result(C)
|
||||
| ustring("w").result(W)
|
||||
| ustring("u").result(U)
|
||||
| ustring("b").result(B)
|
||||
| ustring("g").result(G)
|
||||
|
@ -83,7 +85,8 @@ color = (
|
|||
multicolor = color.many()
|
||||
|
||||
single_color = (
|
||||
lstring("white").result({W})
|
||||
lstring("colorless").result({C})
|
||||
| lstring("white").result({W})
|
||||
| lstring("blue").result({U})
|
||||
| lstring("black").result({B})
|
||||
| lstring("green").result({G})
|
||||
|
|
Loading…
Reference in a new issue