PurpleKingdomGames / indigo

An FP game engine for Scala.
https://indigoengine.io/
MIT License
643 stars 60 forks source link

Add support for interacting with the Electron API from a game. #289

Open Sintrastes opened 2 years ago

Sintrastes commented 2 years ago

This should be possible, but currently as far as I can tell, Indigo doesn't expose any APIs for it.

I'm not entirely sure what the best way to expose such an API would be, as access to such an API is dependent on the version of the game (i.e. is this built for the web, or electron?). Maybe the electron-specific APIs could be exposed as an Option somewhere?

davesmith00000 commented 2 years ago

You're the first person to wonder about this, and that includes me! So welcome to the pointy end of Indigo where the path has not been trodden! But I'm excited about discovering and resolving all the things that need sorting out.

No, the electron APIs are not exposed anywhere, two reasons:

  1. The electron support provided out of the box was really just a bare bones minimal reference to help you start building your game. The assumption was always that someone would want to do something custom if they got beyond these meagre needs.
  2. Indigo - apart from a bit of dev support in the plugin - makes no real assumptions about where you're going to deploy to currently. We certainly could add specific and fuller support for obvious platforms like electron though. Maybe in a new module?

Some options:

  1. You roll your own subsystem - if you need to talk to JS, the assumption is that you'll encapsulate that work in a subsystem. This forces your code to play nicely with Indigo, while allowing you to do whatever mutable, scary thing you need to do to make this work via scalajs-dom.
  2. We build in official support and a new module - which will start by us doing point (1) as a PoC and end with an officially published implementation.
  3. You use Tyrian (after the next release? Coming soon) - The next version of Tyrian has built in support for Indigo, including communicating with it. Tyrian's whole purpose in life is talking to JS and the DOM, so maybe what we could do is set up a Tyrian project that acts as a wrapper for Indigo games that need to talk to Electron? We could even have electron publishing as a Tyrian option eventually? Keeps the nasty stuff out of your game / Indigo but has the overhead of people needing to learn about Tyrian. Maybe it's too much?
Sintrastes commented 2 years ago

I think I like the Tyrian idea the best. That seems like the cleanest option to me, and avoids the issue of how to expose specific platform APIs to Indigo -- you just communicate with events (I'm assuming).

I'll have to mess around with creating a wrapper for Electron (or an Electron alternative like Tauri -- I'm hoping that such alternatives still have good enough webGL support and so on to work well with Indigo) that interacts with Indigo when that is released.

With a good enough wrapper distributed as a project template and docs, I don't think there's even a lot someone would have to learn about Tyrian unless they have needs that go beyond what is exposed by the wrapper.