Last active
February 14, 2022 23:17
-
-
Save hobnob/436318b3ae5eed5891ba2b18bb8c264b to your computer and use it in GitHub Desktop.
Initial HelloTyrian example for Indigo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tyrian.* | |
import tyrian.Html.* | |
import org.scalajs.dom.document | |
import scala.scalajs.js.annotation.* | |
enum Msg: | |
case StartIndigo extends Msg | |
@JSExportTopLevel("TyrianApp") | |
object Main extends TyrianApp[Msg, TyrianModel]: | |
val gameDivId = "game-container" | |
def init(flags: Map[String, String]): (TyrianModel, Cmd[Msg]) = | |
(TyrianModel.init, Cmd.Emit(Msg.StartIndigo)) | |
def update(msg: Msg, model: TyrianModel): (TyrianModel, Cmd[Msg]) = | |
msg match | |
case Msg.StartIndigo => | |
( | |
model, | |
Cmd.SideEffect { () => | |
HelloIndigo(model.bridge.subSystem(IndigoGameId(gameDivId))) | |
.launch( | |
gameDivId, | |
"width" -> "550", | |
"height" -> "400" | |
) | |
} | |
) | |
def view(model: TyrianModel): Html[Msg] = | |
div(`class` := "main")( | |
div(`class` := "game", id := gameDivId)(), | |
div(`class`:= "counter")(), | |
div(`class`:= "btn")( | |
button()("Click me") | |
) | |
) | |
def subscriptions(model: TyrianModel): Sub[Msg] = | |
Sub.Empty | |
def main(args: Array[String]): Unit = | |
Tyrian.start(document.getElementById("main"), init, update, view, subscriptions) | |
final case class TyrianModel(bridge: TyrianIndigoBridge[Int]) | |
object TyrianModel: | |
val init: TyrianModel(TyrianIndigoBridge()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment