Local Mode with
@tinybasejs: Another huge feature just shipped.
While Athena Crisis is designed as an online experience, blurring the lines between single and multiplayer, sometimes you might be offline, like on an airplane, a cabin in the woods or simply when you have a poor connection.
With Local Mode, you can play official Athena Crisis maps and campaigns on device, offline, and without syncing your save state automatically to other devices.
The implementation required changing/writing about 10,000 lines of code, and took 4 working days of 7-10 hours each.
Athena Crisis uses GraphQL and Relay, but from the beginning the game was designed to work with any data layer. That's why the game can be open source, without publishing the backend or primary frontend!
The reason it took 10k changed lines is because I tied some features like campaign mode too much to GraphQL/Relay. I had to separate some entry points into higher-order data fetching components (going back to RelayGraphQLMixin in React.createClass, for those who remember!) and move some backend logic around so it can run on the client.
As a data layer, I used
@tinybasejs because who wouldn't want to support a former favorite engineering director who turned into a sailor. It was quick to get started, even though the choice of persistence layers and browser behaviors drove me mad for about half a day. I like the reactive hooks it provides which I could wrap elegantly to slot into existing higher order components to drive gameplay.
For caching assets, and I'm honestly surprised at how well it works, I'm using vite-plugin-pwa with service workers.
Previously, local games were only available without persistence in the map editor, and the AI ran in-process. Thanks to a community contribution we moved the heavy algorithm work to a web-worker, making local mode work almost exactly like regular gameplay: Actions are dispatched to a "remote" location, either a server or worker process, and the game waits for action responses that can be applied to the game state. Maybe, as a next step, we should put the Athena Crisis AI on a smart fridge?