forked from ArchipelagoMW/Archipelago
-
Notifications
You must be signed in to change notification settings - Fork 2
All changes needed for UT compatibility #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FarisTheAncient
wants to merge
14
commits into
qwint:hk_rework
Choose a base branch
from
FarisTheAncient:add_ut_to_hk
base: hk_rework
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
285c575
All changes needed for UT compatibility
FarisTheAncient aa80461
Trying to fix shop costs... we have not done it
FarisTheAncient bf650b5
finish fixing shops
FarisTheAncient 06e1959
Merge remote-tracking branch 'qwint/hk_rework' into add_ut_to_hk
FarisTheAncient f30491a
Fixing decoupled tracking
FarisTheAncient 20b55ad
Merge remote-tracking branch 'qwint/hk_rework' into add_ut_to_hk
FarisTheAncient 83be91d
Adding explain and get_logical_path overrides
FarisTheAncient 8126719
Adding explain_spot
FarisTheAncient c9658c0
First round of fixes from review comments
FarisTheAncient 99b64df
switching these to cheaper type asserting
FarisTheAncient 3a4be1a
fix formatting for targets that match both region and entrance/location
FarisTheAncient 67976e0
because you're a bitch about it
FarisTheAncient af33e9a
Your blackmail from the space bar union has cleared, give me back my …
FarisTheAncient 48f4bf6
i hate linters
FarisTheAncient File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from BaseClasses import CollectionState, Entrance, Location, Region | ||
| from NetUtils import JSONMessagePart | ||
|
|
||
| from .classes import HKClause | ||
|
|
||
| if TYPE_CHECKING: | ||
| from . import HKWorld | ||
|
|
||
|
|
||
| def parse_clause( | ||
| self: "HKWorld", clause: HKClause, parent_region: Region, state: CollectionState | ||
| ) -> list[JSONMessagePart]: | ||
| l_return: list[JSONMessagePart] = [] | ||
| for item, count in clause.hk_item_requirements.items(): | ||
| valid = state.has(item, self.player, count) | ||
| l_return.append({ | ||
| "type": "color", | ||
| "color": "green" if valid else "red", | ||
| "text": item if count == 1 else f"{item}:{count}" | ||
| }) | ||
| l_return.append({"type": "text", "text": ", "}) | ||
| for region in clause.hk_region_requirements: | ||
| valid = state.can_reach_region(region, self.player) | ||
| l_return.append({"type": "color", "color": "green" if valid else "red", "text": region}) | ||
| l_return.append({"type": "text", "text": ", "}) | ||
| if clause.hk_state_requirements and parent_region: | ||
| valid = ( | ||
| state.can_reach_region(parent_region.name, self.player) and | ||
| state._hk_test_fake_state(clause, parent_region) | ||
| ) | ||
| l_return.append({ | ||
| "type": "color", | ||
| "color": "green" if valid else "red", | ||
| "text": str(clause.hk_state_requirements) | ||
| }) | ||
| l_return.append({"type": "text", "text": ", "}) | ||
| l_return.pop() # Remove the last comma | ||
| return l_return | ||
|
|
||
|
|
||
| def explain_path(self: "HKWorld", entrance: Entrance, state: CollectionState) -> list[JSONMessagePart]: | ||
| hk_rule = getattr(entrance, "hk_rule", None) | ||
| if hk_rule is None: | ||
| return [] # Empty list to tell UT to use normal entrance handeling | ||
| assert isinstance(hk_rule, list) | ||
| l_return: list[JSONMessagePart] = [{"type": "color", "color": "blue", "text": entrance.name}] | ||
| for index, clause in enumerate(hk_rule): | ||
| assert isinstance(clause, HKClause) | ||
| l_return.append({"type": "text", "text": f"\nClause {index+1} - "}) | ||
| l_return.extend(parse_clause(self, clause, entrance.parent_region, state)) | ||
| return l_return | ||
|
|
||
|
|
||
| def explain_spot(self: "HKWorld", location: Location, state: CollectionState) -> list[JSONMessagePart]: | ||
| hk_rule = getattr(location, "hk_rule", None) | ||
| if hk_rule is None: | ||
| return [] # Empty list to tell UT to use normal entrance handeling | ||
| assert isinstance(hk_rule, list) | ||
| l_return: list[JSONMessagePart] = [{"type": "color", "color": "green", "text": f" -> {location.name}"}] | ||
| for index, clause in enumerate(hk_rule): | ||
| assert isinstance(clause, HKClause) | ||
| l_return.append({"type": "text", "text": f"\nClause {index+1} - "}) | ||
| l_return.extend(parse_clause(self, clause, location.parent_region, state)) | ||
| return l_return | ||
|
|
||
|
|
||
| def explain_rule(self: "HKWorld", target_name: str, state: CollectionState) -> list[JSONMessagePart]: | ||
| l_return: list[JSONMessagePart] = [] | ||
|
|
||
| target = None | ||
| parent_region = None | ||
| if target_name in self.multiworld.regions.region_cache[self.player]: | ||
| target = self.get_region(target_name) | ||
| l_return.extend([ | ||
| {"type": "text", "text": "Region "}, | ||
| {"type": "color", "color": "magenta", "text": target_name}, | ||
| {"type": "text", "text": "'s Entrances:\n"} | ||
| ]) | ||
| # Leave parent_region None so if location/entrances don't match we return normally | ||
| # Regions have to be dealt with differently, but they don't directly have rules or costs so it's fine | ||
| for ent in target.entrances: | ||
| ent_path = self.explain_path(ent, state) | ||
| if ent_path: | ||
| l_return.extend(ent_path) | ||
| l_return.append({"type": "text", "text": "\n"}) | ||
| else: # Default entrance rule | ||
| l_return.append({"type": "color", "color": "blue", "text": ent.name}) | ||
| l_return.append({"type": "text", "text": "\nDefault rule - "}) | ||
| passable = ent.access_rule(state) | ||
| l_return.append({ | ||
| "type": "color", | ||
| "text": "Passable" if passable else "Impassable", | ||
| "color": "green" if passable else "red" | ||
| }) | ||
| l_return.append({"type": "text", "text": "\n"}) | ||
| if target_name in self.multiworld.regions.entrance_cache[self.player]: | ||
| l_return.extend([ | ||
| {"type": "text", "text": "Entrance "}, | ||
| {"type": "color", "color": "magenta", "text": target_name}, | ||
| {"type": "text", "text": "'s Rules:"} | ||
| ]) | ||
| target = self.get_entrance(target_name) | ||
| parent_region = target.parent_region | ||
| elif target_name in self.multiworld.regions.location_cache[self.player]: | ||
| l_return.extend([ | ||
| {"type": "text", "text": "Location "}, | ||
| {"type": "color", "color": "magenta", "text": target_name}, | ||
| {"type": "text", "text": "'s Rules:"} | ||
| ]) | ||
| target = self.get_location(target_name) | ||
| parent_region = target.parent_region | ||
|
|
||
| if target is None or parent_region is None: | ||
| if l_return: # If there's content to return, we have a trailing newline we need to remove | ||
| l_return.pop() | ||
| return l_return | ||
| hk_rule = getattr(target, "hk_rule", None) | ||
| if hk_rule is None: | ||
| l_return.append({"type": "text", "text": "Default Access"}) | ||
| else: | ||
| assert isinstance(hk_rule, list) | ||
| for index, clause in enumerate(hk_rule): | ||
| assert isinstance(clause, HKClause) | ||
| l_return.append({"type": "text", "text": f"\nClause {index+1} - "}) | ||
| l_return.extend(parse_clause(self, clause, parent_region, state)) | ||
| costs = getattr(target, "costs", None) | ||
| if costs is not None: | ||
| assert isinstance(costs, dict) | ||
| l_return.append({"type": "text", "text": "\nCosts - ["}) | ||
| for cost, count in costs.items(): | ||
| if cost == "GEO": | ||
| valid = state.has("Can_Replenish_Geo", self.player) | ||
| else: | ||
| valid = state.has(cost, self.player, count) | ||
| l_return.append({"type": "color", "color": "green" if valid else "red", "text": f"{cost}:{count}"}) | ||
| l_return.append({"type": "text", "text": ", "}) | ||
| l_return.pop() # Remove the last comma | ||
| l_return.append({"type": "text", "text": "]"}) # And replace with a close bracket | ||
| return l_return |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.