Closed cyberang3l closed 9 months ago
I understand the issue, but I'm not sure if I like the solution:
init
parameter in the first reading without thinking about your additional commentsI'll think about this some more.
from my understanding, there is no way to reload the JSON config at runtime
There is - every time one make changes to the mapconfig.json, closes the menu and goes back to the menu that selects an online map, the mapconfig.json is reloaded. So you don't need to exit X-Plane (or restart AviTab) every time. Just alt-tab to move between X-Plane and the notepad, and reload the menu.
Removing the OpenTopo button was a bit more challenging that we thought, as when the map config is broken AviTab will fail to load any map. I came up with a solution that uses a hardcoded fallback map (OpenTopoMap) to get around this issue. The hardcoded fallback map will only be used when the config is broken. When the config is correct, the first enabled map that is found in the config is used as the default map. As a bonus, we now also support letting users choose their favorite default map by modifying the config. The feature in this commit commit work as follow:
MapApp::setMapSource
function. The init flag is false by default, and the only time I set it to true is when calling thesetMapSource
function from theMapApp
constructor.MapApp::selectOnlineMaps
function was also extended with two additional variables: One to hint if the function is called for interactive usage or not, and the second one passes a hardcoded fallback OnlineSlippySource (OpenTopoMap) that is used whenever we fail to read themapconfig.json
properly.setMapSource
function is called withinit == true
, and the map source isMapSource::ONLINE_TILES
, theselectOnlineMaps
method is called in non-interactive mode.selectOnlineMaps
in non-interactive mode will first try to parse themapconfig.json
. If that fails, it will show an error to the user (so now when the user messes up with themapconfig.json
, they will be notified to fix it right when they start AviTab), and set the default map to the hardcoded fallback map (OpenTopoMap
). If themapconfig.json
can be parsed correctly, the first enabled map that is found in the config will be used as the default map. By default, with the config we ship in AviTab, the default map isOpenTopoMap
. But if user wants to use a different default they can now do that by moving to the top of themapconfig.json
the map definition of their choosing.selectOnlineMaps
in interactive mode will work as it used to: show up the menu if themapconfig.json
can be parsed correctly, and let the user pick their map. In the unlikely event that the map can't be parsed correctly after they started AviTab, the fallback is also used as described above. Note the latter failure in interactive mode can only happen when the user is explicitly messing up with the config without closing the program. In this case, it means that the user knows what they are doing. In any other case where the config was edited before opening the program, an error message will be shown to the user when starting AviTab (see screenshots in this PR).This is what the user now will see when they start AviTab with a broken
mapconfig.json
config:Once they explicitly acknowledge the error by clicking on the
X
button of the error window, they can still use AviTab and when they go to the MapApp the default hardcoded fallback (OpenTopoMap) is used: