def from_json(cls, value: dict, game: RandovaniaGame) -> "MajorItemsConfiguration": item_database = default_database.item_database_for_game(game) items_state = {} for name, item in item_database.major_items.items(): if name in value["items_state"]: state = MajorItemState.from_json(value["items_state"][name]) else: state = MajorItemState() items_state[item] = state default_items = {} for category, options in item_database.default_items.items(): default_items[category] = item_database.major_items[ value["default_items"][category.value]] if default_items[category] not in options: raise ValueError( f"Category {category} has {default_items[category]} as default item, " f"but that's not a valid option.") return cls( items_state=items_state, default_items=default_items, minimum_random_starting_items=value[ "minimum_random_starting_items"], maximum_random_starting_items=value[ "maximum_random_starting_items"], )
def _state_with_data(request): item = MajorItem( name="Item Name", item_category=ItemCategory(request.param.get("category", "visor")), model_index=0, progression=(), ammo_index=request.param.get("ammo_index", ()), required=True, original_index=None, probability_offset=0, ) return item, request.param["encoded"], MajorItemState.from_json(request.param["json"])
def get_default_major_items_configurations() -> MajorItemsConfiguration: item_database = default_prime2_item_database() with get_data_path().joinpath("item_database", "default_state", "major-items.json").open() as open_file: data = json.load(open_file) return MajorItemsConfiguration( items_state={ item_database.major_items[name]: MajorItemState.from_json(state_data) for name, state_data in data["items_state"].items() } )
def from_json(cls, value: dict, item_database: ItemDatabase) -> "MajorItemsConfiguration": items_state = {} for name, item in item_database.major_items.items(): if name in value["items_state"]: state = MajorItemState.from_json(value["items_state"][name]) else: state = MajorItemState() items_state[item] = state return cls( items_state=items_state, minimum_random_starting_items=value[ "minimum_random_starting_items"], maximum_random_starting_items=value[ "maximum_random_starting_items"], )
def from_json(cls, value: dict, item_database: ItemDatabase) -> "MajorItemsConfiguration": default = cls.default() items_state = copy.copy(default.items_state) for name, state_data in value["items_state"].items(): items_state[item_database.major_items[ name]] = MajorItemState.from_json(state_data) return cls( items_state=items_state, progressive_suit=value["progressive_suit"], progressive_grapple=value["progressive_grapple"], minimum_random_starting_items=value[ "minimum_random_starting_items"], maximum_random_starting_items=value[ "maximum_random_starting_items"], )
def test_blank_from_json(): assert MajorItemState.from_json({}) == MajorItemState()