Skip to content
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

Core: move PlandoConnections and PlandoTexts to the options system #2904

Merged
merged 59 commits into from
Jun 1, 2024

Conversation

Silvris
Copy link
Collaborator

@Silvris Silvris commented Mar 5, 2024

What is this fixing or adding?

Moves plando connections and texts to the options system. In order to use plando connections and texts, worlds will need to define the option in their options dataclass/definitions, and supported games will have plando connections and texts appear within the template yaml. Additionally, rolled plando connections/texts will appear in the spoiler log.

This includes changes to LttP, OoT, Minecraft, and TUNIC as they use plando connections currently (or plan to in the near future).

How was this tested?

Manually, by generating games using plando connections and confirming that the resulting connection was proper.

Texts was tested by generating a game using the mercenary mode trigger block, and confirming that the text was correctly placed.

No automated testing has been added.

If this makes graphical changes, please attach screenshots.

Excerpt from LttP template:

  plando_connections:
    # Generic connections plando. Format is:
    # - entrance: "Entrance Name"
    #   exit: "Exit Name"
    #   direction: "Direction"
    #   percentage: 100
    # Direction must be one of 'entrance', 'exit', or 'both', and defaults to 'both' if omitted.
    # Percentage is an integer from 1 to 100, and defaults to 100 when omitted.
    []

  plando_texts:
    # Text plando. Format is:
    # - text: 'This is your text'
    #   at: text_key
    #   percentage: 100
    # Percentage is an integer from 1 to 100, and defaults to 100 when omitted.
    []

Excerpt from spoiler log:

Plando Connections:              Eastern Palace => Tower of Hera (Bottom)
Plando Texts:                    {'kakariko_tavern_fisherman': 'hey @\nYour mark schemes within a den of evil.', 'sign_ganon': "A hit has been put out on one of Ganon's generals."}

@github-actions github-actions bot added waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. affects: core Issues/PRs that touch core and may need additional validation. and removed waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. labels Mar 5, 2024
@Silvris
Copy link
Collaborator Author

Silvris commented Mar 5, 2024

@ScipioWright ScipioWright added the waiting-on: world-maintainer Issue/PR is waiting for feedback or approval by the maintainer of a world. label Mar 5, 2024
@ScipioWright
Copy link
Collaborator

ScipioWright commented Mar 5, 2024

I'm the one doing the ER and connection plando stuff for Tunic, so I'm approving this in Silent's stead.
I currently have this PR up for implementing connection plando: #2864
If the PR I have up gets merged first, I'll PR to your branch to fix any merge conflicts/errors. And if your PR gets merged first, I'll update mine accordingly.

Well, approving the Tunic change anyway. I'll try to remember to actually review this tonight -- it looked fine already just skimming the code, but I want to do test gens and such for an actual review.

@ScipioWright ScipioWright added the waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. label Mar 5, 2024
@beauxq

This comment was marked as resolved.

Options.py Outdated Show resolved Hide resolved
@Silvris
Copy link
Collaborator Author

Silvris commented Mar 6, 2024

Updated for KDL3.

Co-authored-by: Doug Hoskisson <[email protected]>
Copy link
Collaborator

@alwaysintreble alwaysintreble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks fine other than some style gripes. i'm not really sure some of these typing hints are useful since they have Any in them and it might be better to force/assert them as the correct type at some point instead? and then i think two implementation detail questions i had.

Options.py Show resolved Hide resolved
Options.py Show resolved Hide resolved
Options.py Show resolved Hide resolved
Options.py Show resolved Hide resolved
Options.py Show resolved Hide resolved
Copy link
Collaborator

@alwaysintreble alwaysintreble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resubmitting review from earlier because my comment lines got fucked up for some reason

def can_connect(cls, entrance: str, exit: str) -> bool:
"""Checks that a given entrance can connect to a given exit.
By default, this will always return true unless overridden."""
return True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure this should be the default behavior? it seems like enough of the worlds that use this would be fine with it (and my world is too) but it almost feels backwards.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It primarily does two things.

As you've said, it's sufficient for worlds that don't have wild constraints on possible connections. It also simplifies backward compatibility with the currently implemented games, as they already have to check for whether or not the plando is a valid connection, so we can skip the option-based check (the exception being Minecraft, as it's can_connect was simple enough to implement on the option itself).

Options.py Outdated
percentage: 100
Direction must be one of 'entrance', 'exit', or 'both', and defaults to 'both' if omitted.
Percentage is an integer from 1 to 100, and defaults to 100 when omitted."""
class Direction:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is going to be a scoped class like this it should probably be in the PlandoConnection one instead of here so that the direction can be correctly typed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this.

But also, maybe an Enum?

(The downside to making it an Enum is the long definition... PlandoConnection.Direction.both compared to "both")

So another alternative is no class, just a type alias:

PlandoConnectionDirection = typing.Literal["entrance", "exit", "both"]


class PlandoConnection(typing.NamedTuple):
    entrance: str
    exit: str
    direction: PlandoConnectionDirection
    percentage: int = 100

(I think a type alias has to be gloabal scope.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once 3.8 is dropped, StrEnum would probably be a good option. Not sure what the best option is for right now.

Copy link
Collaborator

@beauxq beauxq Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see what value StrEnum would have over Enum for this.
The values in a normal Enum can be str.
StrEnum is for when you want to pass it to a function that only takes str, or use str methods like lower, but I don't see you doing any of that here.

Copy link
Collaborator

@beauxq beauxq Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It almost seems better to make the values:

class Direction(Enum):
    ENTRANCE = "=>"
    EXIT = "<="
    BOTH = "<=>"

so that you could use those values in get_option_name (and simplify the code there)

Copy link
Collaborator

@alwaysintreble alwaysintreble Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the issue with that is that the existing implementations specifically compare the string when resolving the connections, so it'd need to be an alias of some sort.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I didn't realize this was connecting with past implementations.

Options.py Outdated Show resolved Hide resolved
Options.py Show resolved Hide resolved
Options.py Show resolved Hide resolved
ScipioWright

This comment was marked as resolved.

Options.py Outdated Show resolved Hide resolved
Copy link
Member

@Berserker66 Berserker66 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scrolled over it, looks fine. Didn't test anything.

ScipioWright

This comment was marked as resolved.

@Silvris
Copy link
Collaborator Author

Silvris commented May 31, 2024

With this current system, I can't do self.options.plando_connections.remove(connection), nor can I do self.options.plando_connections.exit = "Shop Portal", nor can I do self.options.plando_connections[index] = replacement, so as far as I can tell there's no way for me to modify the player's plando connections like I used to.

self.options.plando_connections.value.remove(cxn). That being said, you will need to explicitly define "Shop" as a valid entrance/exit.

@alwaysintreble
Copy link
Collaborator

With this current system, I can't do self.options.plando_connections.remove(connection), nor can I do self.options.plando_connections.exit = "Shop Portal", nor can I do self.options.plando_connections[index] = replacement, so as far as I can tell there's no way for me to modify the player's plando connections like I used to.

self.options.plando_connections.value.remove(cxn). That being said, you will need to explicitly define "Shop" as a valid entrance/exit.

is there a reason they don't just inherit from OptionList? it has the necessary overrides to do exactly as requested here

@Silvris
Copy link
Collaborator Author

Silvris commented May 31, 2024

is there a reason they don't just inherit from OptionList? it has the necessary overrides to do exactly as requested here

This code would also fail on an OptionList, as it does not override explicit "insert" and "remove", nor does it inherit it from Option or VerifyKeys.

@ThePhar ThePhar merged commit 4e5b6bb into ArchipelagoMW:main Jun 1, 2024
16 checks passed
wu4 pushed a commit to wu4/Archipelago that referenced this pull request Jun 6, 2024
…rchipelagoMW#2904)

Co-authored-by: Doug Hoskisson <[email protected]>
Co-authored-by: Scipio Wright <[email protected]>
Co-authored-by: beauxq <[email protected]>
Co-authored-by: alwaysintreble <[email protected]>
jnschurig pushed a commit to Tranquilite0/Archipelago-SoulBlazer that referenced this pull request Jun 13, 2024
…rchipelagoMW#2904)

Co-authored-by: Doug Hoskisson <[email protected]>
Co-authored-by: Scipio Wright <[email protected]>
Co-authored-by: beauxq <[email protected]>
Co-authored-by: alwaysintreble <[email protected]>
sflavelle pushed a commit to sflavelle/Archipelago-tgc that referenced this pull request Jun 20, 2024
…rchipelagoMW#2904)

Co-authored-by: Doug Hoskisson <[email protected]>
Co-authored-by: Scipio Wright <[email protected]>
Co-authored-by: beauxq <[email protected]>
Co-authored-by: alwaysintreble <[email protected]>
qwint pushed a commit to qwint/Archipelago that referenced this pull request Jun 24, 2024
…rchipelagoMW#2904)

Co-authored-by: Doug Hoskisson <[email protected]>
Co-authored-by: Scipio Wright <[email protected]>
Co-authored-by: beauxq <[email protected]>
Co-authored-by: alwaysintreble <[email protected]>
Berserker66 pushed a commit that referenced this pull request Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: core Issues/PRs that touch core and may need additional validation. is: refactor/cleanup Improvements to code/output readability or organizization. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. waiting-on: world-maintainer Issue/PR is waiting for feedback or approval by the maintainer of a world.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants