Dev Log Week 2024-15: Code Duplication

Code duplication is my nemesis. Whenever I see it, I can’t help but try to eliminate it. And there’s a lot of it in various places around simulogics and our games. So you can see the issue :smiley:

Last week I encountered it in two places:

The first one is our account management frontend, also dubbed “hub”. It’s where you register and log in, buy credits or change your email address. We’re currently giving it a fresh coat of paint to make it work better with the upcoming Steam integration. So naturally, we take a lot of ideas and code from Prosperous Universe (which already has a Steam integration and is generally younger) and apply them to AirlineSim. And then you immediately get copied&pasted code aka code duplication. So I spent a little bit of time to de-duplicate a few things. I especially don’t want to have checks a la “are we currently in an AS or a PU context?” littered all over the codebase :slight_smile:

The second encounter was within AirlineSim itself and the offending code dates back (far) more than a decade. Back then I was an even less experienced programmer than I am today, so when we partially switched from an ancient action-based framework to a (then) more up-to-date component-based framework, I introduced a whole bunch of code duplication for anything that’s visible on all pages of the game. Think things like navigation menus etc. Because I have to touch a lot of the latter for Steam, I constantly had to change the same things twice. Which is merely annoying for simple matters of styling, but can be a likely source of bugs for any actual logic. So I tried my best to rewrite some of the respective code in a way that the important bits are defined in a single location, for example whether a link to the payment page should go to the regular hub page or the Steam equivalent.

Speaking of which: Originally, we wanted to do all account-related things in an overlay “above” the game when in Steam since in Steam you don’t have the usual browser navigation as you do in…well…a browser. So if someone navigated to the hub, how would they find their way back to where they were? The overlay would help with that: Just close it whenever you’re done buying credits or whatever. But sadly, the Steam payment integration doesn’t allow for that for security reasons, so for better or worse, we had to go with a slightly less transparent method. We “remember” the game world a user game from and give them the option to navigate back to it. Not ideal, but should get the job done.

Within the game, we just add our own navigation whenever we’re in Steam:

Finally, the aforementioned work on the hub is almost finished and will very likely roll out later this week.

1 Like