Skip to content

Commit

Permalink
correctly support spots without rule in explain
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouramie committed Dec 15, 2024
1 parent 6b8d576 commit 8bdeeac
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions worlds/stardew_valley/stardew_rule/rule_explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
from functools import cached_property, singledispatch
from typing import Iterable, Set, Tuple, List, Optional

from BaseClasses import CollectionState
from BaseClasses import CollectionState, Location, Entrance
from worlds.generic.Rules import CollectionRule
from . import StardewRule, AggregatingStardewRule, Count, Has, TotalReceived, Received, Reach, true_


@dataclass
class RuleExplanation:
rule: StardewRule
state: CollectionState
state: CollectionState = field(repr=False, hash=False)
expected: bool
sub_rules: Iterable[StardewRule] = field(default_factory=list)
explored_rules_key: Set[Tuple[str, str]] = field(default_factory=set)
explored_rules_key: Set[Tuple[str, str]] = field(default_factory=set, repr=False, hash=False)
current_rule_explored: bool = False

def __post_init__(self):
Expand All @@ -38,13 +38,6 @@ def __str__(self, depth=0):
if i.result is not self.expected else i.summary(depth + 1)
for i in sorted(self.explained_sub_rules, key=lambda x: x.result))

def __repr__(self, depth=0):
if not self.sub_rules:
return self.summary(depth)

return self.summary(depth) + "\n" + "\n".join(i.__repr__(depth + 1)
for i in sorted(self.explained_sub_rules, key=lambda x: x.result))

@cached_property
def result(self) -> bool:
try:
Expand Down Expand Up @@ -134,6 +127,10 @@ def _(rule: Reach, state: CollectionState, expected: bool, explored_spots: Set[T
access_rules = [Reach(spot.parent_region.name, "Region", rule.player)]
else:
access_rules = [spot.access_rule, Reach(spot.parent_region.name, "Region", rule.player)]
elif spot.access_rule == Location.access_rule:
# Sometime locations just don't have an access rule and all the relevant logic is in the parent region.
access_rules = [Reach(spot.parent_region.name, "Region", rule.player)]


elif rule.resolution_hint == 'Entrance':
spot = state.multiworld.get_entrance(rule.spot, rule.player)
Expand All @@ -143,6 +140,9 @@ def _(rule: Reach, state: CollectionState, expected: bool, explored_spots: Set[T
access_rules = [Reach(spot.parent_region.name, "Region", rule.player)]
else:
access_rules = [spot.access_rule, Reach(spot.parent_region.name, "Region", rule.player)]
elif spot.access_rule == Entrance.access_rule:
# Sometime entrances just don't have an access rule and all the relevant logic is in the parent region.
access_rules = [Reach(spot.parent_region.name, "Region", rule.player)]

else:
spot = state.multiworld.get_region(rule.spot, rule.player)
Expand Down

0 comments on commit 8bdeeac

Please sign in to comment.