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

Transport Manager Events #2694

Closed

Conversation

ArshvirGoraya
Copy link

Add Events for Transport Mode Changes

Adds events inside of "TransportManager.cs" and triggers them inside the UpdateMode method.

  • OnTransportModeChanged
    • Usage: TransportManager.OnTransportModeChanged += TransportManager_OnTransportModeChanged;
    • A simple event that is raised when the TransportMode changes. Has the new TransportMode value as a parameter.
  • OnTransportModeShipChanged
    • Usage: TransportManager.OnTransportModeShipChanged += TransportManager_OnTransportModeShipChanged;
    • An event that is raised when the transport mode is changed to or from ship. Has a ToShip or FromShip parameter to indicate if we are warping to the ship or out of it.

Why have a separate event for the ship?

  • The code doesn't handle the ship mode like the others. It sets it to foot immediately after the ship is warped into or out of. This can be problematic if a developer makes some mod that sets the TransportMode to something right after warping to the ship. Whatever they set it to will be overwritten by the automatic "foot" transport mode set by the code. So an event specifically for the ship is better for those cases as those will only be raised when the ship has been warped to/from and after the foot transport mode has been automatically set. It ends up being much cleaner for any code that needs to run right after the TransportMode is set to the ship.

It may also be useful to have an event like "ChangingFromTransportMode," to let developers know when the TransportMode is changing away from something. I haven't added this however, since a nice alternative is just creating an accessible variable called PreviousTransportMode, which they can check whenever the above OnTransportModeChanged is fired. This isn't needed for my mod specifically, but I thought it was worth mentioning as it may be useful for others.

@ajrb
Copy link
Collaborator

ajrb commented Sep 3, 2024

I think the ship event is redundant. The change mode event could specify the from and to mode easily. What exactly is the use case you're trying to achieve?

@ArshvirGoraya
Copy link
Author

@ajrb

The use case is to optimize one of my mods in the next release: https://github.com/ArshvirGoraya/Remember-Transport-Mode.

One of the things the mod does is saves the TransportMode whenever the player changes it in exteriors. In order to do this, I currently just have some logic in my Update() function that checks when the TransportMode changes by comparing it to what it was last time the Update() function ran. However, it would be more optimal if I could just listen to TransportMode change events.

For the Ship event: you're right. I changed the code to remove the ship event and modified the ModeChange event to include ship warp information.

@ArshvirGoraya
Copy link
Author

Closing PR in favor of this instead: #2701

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants