[IDEA] a way to test a web game in the Browser from the Editor

Started by eri0o, Sat 30/11/2024 12:53:13

Previous topic - Next topic

eri0o

[shadow=black,right]Open in browser button[/shadow]

motivation

The web builds from the engine produce an index.html file that has to request the necessary files for running the ags game, including the web build of the engine that is the ags.wasm file. All of these files have to be requested in a way that requires the files to be served from a server, including also safety requirements in modern web browsers. In this way, it's not possible to double-click the index.html file produced by the engine to load it in the browser.

idea

Come up with some way to serve the web files built files from the Editor. My idea is to add an entry in the build menu, right after Run without debugger entry that is Run in Web Browser. It may optionally also have an icon for this in the toolbar.

I imagine the menu entry and toolbar icon would only be enable if both: building for web is enabled in general settings and the last successful build included the web build.

problems

  • Need to come up with a good icon that fits the existing ones and conveys the idea of running in a web browser.
  • I don't know how to properly enable disable the button in the mentioned conditions - looking at AGS Editor code I don't see if such events already exist or not
  • Should it have an entry in the status bar showing the web server as active or not? And possibly a way to turn it off from there?
  • Clicking the button could load a browser pointing to localhost:8000 too, but closing it wouldn't stop the server unless we modify the index.html to throw some call to the server on close

limitations

These are not exactly problems, but constraints from implementing this in the editor. If put in an external tool like my AGS Toolbox, it could be easier to support these stuff.

  • The .NET only supports serving to localhost without requiring complex netsh calls, so this means one can only open a browser in the PC that has AGS Editor in this test - the python implementation could serve to 0.0.0.0 which serves public across the local network, so it's easy to test on a phone. It will never be possible to support this in the Editor afaict
  • Serving games that are not the project itself being built will not be supported

additional context

I have actually implemented this idea in a previous Game Engine Editor I made:

https://github.com/ericoporto/fgmk/blob/master/fgmk/game_server.py
The game server is linked above

The close of the tab in the browser stopping the server was implemented like this
https://github.com/ericoporto/fgmkJsEngine/blob/b40a1a173d2b4d3b8a0f25caeebe322e3b8703bc/src/bootstrap.js#L24

When the tab closed, it requested an invalid file called exit.json, and then the server would filter for this specifically and then stop it's thread when this was requested.

implementation

To make this easier to iterate on in C#, Winforms and .NET without going through building the entire AGS Editor I made a minimal prototype

MinimalWebServer.zip

This proposal was motivated by the thread in the forums here, I really would like to tackle but I need helping imagining the design of this, even if it's through drawings in paint and comments from other game developers.

SMF spam blocked by CleanTalk