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

Fix onSquadSelectionPage dispatching for weapons #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Lemonymous
Copy link
Contributor

@Lemonymous Lemonymous commented Jul 15, 2023

Addresses #216

The event onSquadSelectionPage could be incorrectly dispatched when changing the weapon inventory page during a run. It will now only be dispatched while the squad selection window is visible.

The game remembers the squad selection pages for the squad selection page in the hangar and the statistics separately, so sdlext.squadSelectionPage and the local lastSquadPage has been been re-specified, so that both can be known at all times.

  • sdlext.squadSelectionPage -> sdlext.squadSelectionPageInHangar | sdlext.squadSelectionPageInStatistics
  • lastSquadPage -> lastSquadPageInHangar | lastSquadPageInStatistics

The existing code has also been refactored.

  • Moved detection of squad selection page out of GetText, into its own function.
  • Moved page update code out of GetText, and into its own onFrameDrawStart event.
  • Removed custom windows.Hangar_Select.show function, and moved the logic to an onSquadSelectionWindowShown event.

Removed behavior that caused onSquadSelectionPageChanged to be dispatched, potentially several times over several frames, when opening the squad selection window. Replaced with logic that sets the correct page immediately as the window has been detected.

The 3rd argument dispatched with onSquadSelectionPageChanged has been removed. I could not find the documentation for this argument, but it appears to have been there to distinguish false from true page changes. As the new code does not dispatch false page changes, this is no longer needed.

Testing PR:

The following functions can be copy-pasted into the console to add debug logs, to test whether the events are dispatched correctly.

modApi.events.onSquadSelectionWindowShown:subscribe(function() 
	LOG("onSquadSelectionWindowShown on page", sdlext.getSquadSelectionPage()) 
end) 
modApi.events.onSquadSelectionPageChanged:subscribe(function(to, from) 
	LOG("onSquadSelectionPageChanged from", from, "to", to) 
end) 
modApi.events.onSquadSelectionWindowHidden:subscribe(function() 
	local page = sdlext.isHangar() and sdlext.squadSelectionPageInHangar or sdlext.squadSelectionPageInStatistics 
	LOG("onSquadSelectionWindowHidden on page", page) 
end) 

The event `onSquadSelectionPage` could be incorrectly dispatched when changing the weapon inventory page during a run. It will now only be dispatched while the squad selection window is visible.

The game remembers the squad selection pages for the squad selection page in the hangar and the statistics separately, so `sdlext.squadSelectionPage` and the local `lastSquadPage` has been been re-specified, so that both can be known at all times.
`sdlext.squadSelectionPage` -> `sdlext.squadSelectionPageInHangar` | `sdlext.squadSelectionPageInStatistics`
`lastSquadPage` -> `lastSquadPageInHangar` | `lastSquadPageInStatistics`

The existing code has also been refactored.
- Moved detection of squad selection page out of `GetText`, into its own function.
- Moved page update code out of `GetText`, and into its own `onFrameDrawStart` event.
- Removed custom `windows.Hangar_Select.show` function, and moved the logic to an `onSquadSelectionWindowShown` event.

Removed behavior that caused `onSquadSelectionPageChanged` to be dispatched, potentially several times over several frames, when opening the squad selection window. Replaced with logic that sets the correct page immediately as the window has been detected.

The 3rd argument dispatched with `onSquadSelectionPageChanged` has been removed. I could not find the documentation for this argument, but it appears to have been there to distinguish false from true page changes. As the new code does not dispatch false page changes, this is no longer needed.
@Lemonymous Lemonymous added bug Something isn't working enhancement New feature or request labels Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant