I am working on a game engine in Scala which I want to support both a web implementation and a jvm implementation, so game creators can deploy their same game to different platforms through a single command. Note that I am not talking about “publishing” my modules as libraries on the internet to Maven etc., I want this command to produce executables locally.
I would like to do this using mill but as I am very new to the tool I have a faint idea how to do it. I have read this Scala Web Project Examples :: The Mill Build Tool
And I roughly understand how to share code between folders that use different platforms.
What I don’t understand, is how I can make a deploy js/jvm
command that will take the source code of my game and then compile it to whatever platform was specified. My game code might say import physics.*
, but which physics will that import as? the js
implementation or the jvm
implementation?
My current understanding for what to do is to make submodules for each major part of my engine gui
physics
assetloading
, which my actual game modules will consume. Supposing I am making the game mario
build.sc
gui/
src/
src-js/
src-jvm/
physics/
src/
src-js/
src-jvm/
assetloading/
src/
src-js/
src-jvm/
mario/
src/
main.scala // <-- imports gui, physics, assetloading etc. is the real game
And I want to be able to say something like
mario deploy js
mario deploy jvm
and have it take the contents of mario
(which should be totally platform agnostic and contain no mentions of jvm/js) and then do a sort of “dependency injection” to give the appropriate providers? Similar analogy to dynamic dispatch in OOP? All references to renderer
in the mario game code would be replaced with JSRenderer
or JVMRenderre
respectively.
Is my thinking correct? How difficult is this, and how should I approach it? Is it mill’s “Tasks” system?