Skip to content

Commit 5e64593

Browse files
committed
let dev change world.item_values values instead of reseting them in validation
1 parent 63605b3 commit 5e64593

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/DataValidation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def preFillCheckIfEnoughItemsForValue(world: World, multiworld: MultiWorld):
285285
existing_items = [item for item in get_items_for_player(multiworld, player, True) if item.code is not None and
286286
item.classification == ItemClassification.progression or item.classification == ItemClassification.progression_skip_balancing]
287287
for value, val_count in values_requested.items():
288-
items_value = get_items_with_value(world, multiworld, value, player, True)
288+
items_value = get_items_with_value(world, multiworld, value, player)
289289
found_count = 0
290290
if items_value:
291291
for item in existing_items:

src/Helpers.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ def get_items_for_player(multiworld: MultiWorld, player: int, includePrecollecte
128128
items.extend(multiworld.precollected_items.get(player, []))
129129
return items
130130

131-
def get_items_with_value(world: World, multiworld: MultiWorld, value: str, player: Optional[int] = None, force: bool = False) -> dict[str, int]:
131+
def get_items_with_value(world: World, multiworld: MultiWorld, value: str, player: Optional[int] = None, skipCache: bool = False) -> dict[str, int]:
132132
"""Return a dict of every items with a specific value type present in their respective 'value' dict\n
133133
Output in the format 'Item Name': 'value count'\n
134-
Keep a cache of the result and wont redo unless 'force == True'
134+
Keep a cache of the result, it can be skipped with 'skipCache == True'\n
135+
To force a Reset of the player's cache of a value do world.item_values[player].pop(value) and then run get_items_with_value(..., value)
135136
"""
136137
if player is None:
137138
player = world.player
@@ -143,15 +144,18 @@ def get_items_with_value(world: World, multiworld: MultiWorld, value: str, playe
143144

144145
value = value.lower().strip()
145146

146-
if not hasattr(world, 'item_values'): #Cache of just the item values
147-
world.item_values = {}
147+
if not skipCache:
148+
if not hasattr(world, 'item_values'): #Cache of just the item values
149+
world.item_values = {}
148150

149-
if not world.item_values.get(player):
150-
world.item_values[player] = {}
151+
if not world.item_values.get(player):
152+
world.item_values[player] = {}
151153

152-
if value not in world.item_values.get(player, {}).keys() or force:
154+
if value not in world.item_values.get(player, {}).keys() or skipCache:
153155
item_with_values = {i.name: world.item_name_to_item[i.name]['value'].get(value, 0)
154156
for i in player_items if i.code is not None
155157
and i.name in world.item_name_groups.get(f'has_{value}_value', [])}
158+
if skipCache:
159+
return item_with_values
156160
world.item_values[player][value] = item_with_values
157161
return world.item_values[player].get(value)

0 commit comments

Comments
 (0)