Making it easier to clean up changed LuaPlayer::zoom_limits
Posted: Sun May 18, 2025 11:45 am
I have been experimenting with the new zoom_limits API and feel like it is hard for a mod to clean up after itself after having made changes. The issue especially noticeable when uninstalling a mod.
The mod I'm maintaining "unlimits" the zoom function and this works really well with the new API, the settings are flexible and the experience is seamless as there is no need to hack about manually with the zoom value.
The only thing that detracts from the UX is that the settings persist even after the mod is uninstalled.
As it is only possible to adjust the zoom_limits of the active controller for a player the results can become unpredictable, especially in multiplayer games where some players may be limited depending on whether they played when the mod was active or not (the difference may even be on a per controller basis).
The only reliable way I've been able to figure out so far to handle removal is either:
-Having a "disable" mode in the mod that resets zoom_limits instead of the regular processing. With some additional bookkeeping of which player/controller combinations have been changed it could likely emit a message once the mod is safe to remove without leaving altered zoom_limits.
-Creating a dedicated "reset" mod to be installed instead that would actively reset zoom_limits, there is no way for this mod to know when it is done though.
It might be possible to iterate through all controllers for all players using LuaPlayer::set_controller{} and reset the zoom_limits but some of the controllers have side effects on permissions etc. that would need to be compensated for.
I'm not really sure how to solve this in a good way.
-Being able to access the zoom_limits for other controllers than the active one could help with the cleanup and would also make subscribing to defines.events.on_player_controller_changed less mandatory. Even if it wouldn't solve the entire issue it would reliably be able to reset even offline players in a save.
-zoom_limits not being persistent to save/load would be clunky as they cannot be modified during on_load().
Thoughts and suggestions for how to tackle this are very welcome!
The mod I'm maintaining "unlimits" the zoom function and this works really well with the new API, the settings are flexible and the experience is seamless as there is no need to hack about manually with the zoom value.
The only thing that detracts from the UX is that the settings persist even after the mod is uninstalled.
As it is only possible to adjust the zoom_limits of the active controller for a player the results can become unpredictable, especially in multiplayer games where some players may be limited depending on whether they played when the mod was active or not (the difference may even be on a per controller basis).
The only reliable way I've been able to figure out so far to handle removal is either:
-Having a "disable" mode in the mod that resets zoom_limits instead of the regular processing. With some additional bookkeeping of which player/controller combinations have been changed it could likely emit a message once the mod is safe to remove without leaving altered zoom_limits.
-Creating a dedicated "reset" mod to be installed instead that would actively reset zoom_limits, there is no way for this mod to know when it is done though.
It might be possible to iterate through all controllers for all players using LuaPlayer::set_controller{} and reset the zoom_limits but some of the controllers have side effects on permissions etc. that would need to be compensated for.
I'm not really sure how to solve this in a good way.
-Being able to access the zoom_limits for other controllers than the active one could help with the cleanup and would also make subscribing to defines.events.on_player_controller_changed less mandatory. Even if it wouldn't solve the entire issue it would reliably be able to reset even offline players in a save.
-zoom_limits not being persistent to save/load would be clunky as they cannot be modified during on_load().
Thoughts and suggestions for how to tackle this are very welcome!