Add support for colorless searches

This commit is contained in:
Correl Roush 2021-07-17 00:56:15 -04:00
parent b0fff226ea
commit eb61663888
2 changed files with 9 additions and 5 deletions

View file

@ -7,6 +7,7 @@ import uuid
class Color(enum.IntEnum): class Color(enum.IntEnum):
Colorless = 0
White = 1 White = 1
Blue = 2 Blue = 2
Black = 3 Black = 3
@ -14,7 +15,7 @@ class Color(enum.IntEnum):
Red = 5 Red = 5
def __str__(self) -> str: def __str__(self) -> str:
return dict(zip(Color, "WUBGR")).get(self.value) return dict(zip(Color, "CWUBGR")).get(self.value).replace("C", "")
@staticmethod @staticmethod
def to_string(colors: typing.List["Color"]) -> str: def to_string(colors: typing.List["Color"]) -> str:
@ -24,7 +25,7 @@ class Color(enum.IntEnum):
def from_string(colors: str) -> typing.List["Color"]: def from_string(colors: str) -> typing.List["Color"]:
return [ return [
color 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 if color is not None
] ]

View file

@ -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()) lstring_from = functools.partial(parsy.string_from, transform=lambda s: s.lower())
ustring_from = functools.partial(parsy.string_from, transform=lambda s: s.upper()) 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.White,
tutor.models.Color.Blue, tutor.models.Color.Blue,
tutor.models.Color.Black, tutor.models.Color.Black,
@ -73,7 +74,8 @@ gte = parsy.string(">=").map(Operator)
lte = parsy.string("<=").map(Operator) lte = parsy.string("<=").map(Operator)
color = ( color = (
ustring("w").result(W) ustring("c").result(C)
| ustring("w").result(W)
| ustring("u").result(U) | ustring("u").result(U)
| ustring("b").result(B) | ustring("b").result(B)
| ustring("g").result(G) | ustring("g").result(G)
@ -83,7 +85,8 @@ color = (
multicolor = color.many() multicolor = color.many()
single_color = ( single_color = (
lstring("white").result({W}) lstring("colorless").result({C})
| lstring("white").result({W})
| lstring("blue").result({U}) | lstring("blue").result({U})
| lstring("black").result({B}) | lstring("black").result({B})
| lstring("green").result({G}) | lstring("green").result({G})