Interkarma / daggerfall-unity

Open source recreation of Daggerfall in the Unity engine
http://www.dfworkshop.net
MIT License
2.73k stars 331 forks source link

Transport Manager Events #2694

Closed ArshvirGoraya closed 1 week ago

ArshvirGoraya commented 2 months ago

Add Events for Transport Mode Changes

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

Why have a separate event for 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 commented 2 months ago

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 commented 2 months ago

@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 commented 1 week ago

Closing PR in favor of this instead: https://github.com/Interkarma/daggerfall-unity/pull/2701