From 375a0ff2084f6309d924737e8c65eb9e4c98fc5d Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Mon, 25 Oct 2021 04:13:25 +0200 Subject: [PATCH] Options: verify starting inventory counts are positive for more than just Factorio --- Options.py | 12 +++++++++++- worlds/factorio/Options.py | 10 +++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Options.py b/Options.py index 71a6e6f3..5b25e347 100644 --- a/Options.py +++ b/Options.py @@ -262,6 +262,16 @@ class OptionDict(Option): return item in self.value +class ItemDict(OptionDict): + # implemented by Generate + verify_item_name = True + + def __init__(self, value: typing.Dict[str, int]): + if any(item_count < 1 for item_count in value.values()): + raise Exception("Cannot have non-positive item counts.") + super(ItemDict, self).__init__(value) + + class OptionList(Option): default = [] supports_weighting = False @@ -357,7 +367,7 @@ class NonLocalItems(ItemSet): displayname = "Not Local Items" -class StartInventory(OptionDict): +class StartInventory(ItemDict): """Start with these items.""" verify_item_name = True displayname = "Start Inventory" diff --git a/worlds/factorio/Options.py b/worlds/factorio/Options.py index 495669ae..b22eaf4e 100644 --- a/worlds/factorio/Options.py +++ b/worlds/factorio/Options.py @@ -1,7 +1,7 @@ from __future__ import annotations import typing -from Options import Choice, OptionDict, Option, DefaultOnToggle, Range +from Options import Choice, OptionDict, ItemDict, Option, DefaultOnToggle, Range from schema import Schema, Optional, And, Or # schema helpers @@ -120,15 +120,11 @@ class RecipeIngredients(Choice): option_science_pack = 1 -class FactorioStartItems(OptionDict): +class FactorioStartItems(ItemDict): displayname = "Starting Items" + verify_item_name = False default = {"burner-mining-drill": 19, "stone-furnace": 19} - def __init__(self, value: typing.Dict[str, typing.Any]): - if any(item_count < 1 for item_count in value.values()): - raise Exception("Cannot have non-positive item counts.") - super().__init__(value) - class TrapCount(Range): range_end = 4