Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of biddable and hidden fields #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions pokecat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def populate_pokeset(pokeset, skip_ev_check=False):
# special cases. I couldn't come up with a structure that wouldn't
# just feel forced. It could be better, but it could also be worse,
# and to be honest it's easy enough to maintain (for me at least).

# make deepcopy to not modify original data
pokeset = deepcopy(pokeset)

# check if there are wrongly capitalized keys
for key, value in list(pokeset.items()):
key_lower = key.lower()
Expand Down Expand Up @@ -345,24 +345,34 @@ def populate_pokeset(pokeset, skip_ev_check=False):
warn("rarity is %d, which is surprisingly high. Note that 1.0 is the default "
"and high values mean the Pokémon gets chosen more often." % rarity)

# fix default biddable value
if pokeset["biddable"] is None:
pokeset["biddable"] = not pokeset["shiny"]
if not isinstance(pokeset["biddable"], bool):
raise ValueError("biddable must be a boolean (true or false), not %s" % type(pokeset["biddable"]))

# fix default hidden value
if pokeset["hidden"] is None:
pokeset["hidden"] = pokeset["shiny"]
if not isinstance(pokeset["hidden"], bool):
raise ValueError("hidden must be a boolean (true or false), not %s" % type(pokeset["hidden"]))

if pokeset["biddable"] and pokeset["hidden"]:
warn("Set is biddable, but also hidden, which doesn't make sense.")
if pokeset["shiny"] and pokeset["biddable"] and Suppressions.PUBLIC_SHINY not in suppressions:
warn("Set is shiny, but also biddable, which means it can be used in token matches. Is this intended?")
if pokeset["shiny"] and not pokeset["hidden"] and Suppressions.PUBLIC_SHINY not in suppressions:
warn("Set is shiny, but not hidden, which means it is publicly visible. Is this intended?")
if pokeset["shiny"] and Suppressions.PUBLIC_SHINY not in suppressions:
if pokeset["biddable"] is True:
warn("Set is shiny, but also biddable, which means it can be used in token "
"matches. Is this intended?")
if pokeset["hidden"] is False:
warn("Set is shiny, but not hidden, which means it is publicly visible. Is "
"this intended?")

if pokeset["biddable"] is pokeset["hidden"] is True:
warn("Set is explicitly biddable, but also explicitly hidden, which doesn't make sense.")
else:
# fix default biddable value
if pokeset["biddable"] is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the above warnings emits, this codepath isn't executed, meaning biddable and hidden may still be None after population. Is this expected behaviour?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also the fields aren't being validated either. The above should be an error, or cause sensible defaults I guess

if pokeset["hidden"] is True:
pokeset["biddable"] = False
else:
pokeset["biddable"] = not pokeset["shiny"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The paragraph on biddable in pokesetspec.md needs updating

if not isinstance(pokeset["biddable"], bool):
raise ValueError("biddable must be a boolean (true or false), not %s" % type(pokeset["biddable"]))
# fix default hidden value
if pokeset["hidden"] is None:
if pokeset["biddable"]:
# User set as biddable, OR user didn't specify and pokeset is not shiny
pokeset["hidden"] = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose hidden in pokesetspec.md needs updating too

else:
pokeset["hidden"] = pokeset["shiny"]
if not isinstance(pokeset["hidden"], bool):
raise ValueError("hidden must be a boolean (true or false), not %s" % type(pokeset["hidden"]))

# fix displayname
if pokeset["displayname"] is None:
Expand Down Expand Up @@ -584,7 +594,7 @@ def fix_moves(instance):
for move in instance["moves"]:
# extra displayname, might differ due to special cases
move["displayname"] = move["name"]

# special case: Hidden Power. Fix type, power and displayname
if move["name"] == "Hidden Power":
a, b, c, d, e, f = [ivs[stat] % 2 for stat in ("hp", "atk", "def", "spe", "spA", "spD")]
Expand Down