Better condition for moving price to options

There's no point in doing this for Ocean Garden's stuff that has a fixed
price.
This commit is contained in:
Midgard 2020-03-04 22:56:45 +01:00
parent 0f9a816eea
commit aba8301758
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -25,15 +25,16 @@ def filter_instance(cls, iterable):
class HldsSemanticActions:
def location(self, ast) -> Location:
choices = {choice.id: choice for choice in filter_instance(Choice, ast["items_"])}
dishes = filter_instance(Dish, ast["items_"])
dishes: Iterable[Dish] = filter_instance(Dish, ast["items_"])
for dish in dishes:
for i, choice in enumerate(dish.choices):
if not isinstance(choice[1], Choice):
dish.choices[i] = (dish.choices[i][0], deepcopy(choices[choice[1]]))
# Move the base price to the first single choice if there is any
# Move the base price to the first single_choice if the dish has a fixed price
first_single_choice = first(c[1] for c in dish.choices if c[0] == "single_choice")
if dish.price and first_single_choice:
price_range = dish.price_range()
if dish.price and price_range[0] != price_range[1] and first_single_choice:
for option in first_single_choice.options:
option.price += dish.price
dish.price = 0