Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rogue UI #39

Merged
merged 9 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import scala.sys.process._
import scala.language.postfixOps

import sbtwelcome._
import indigoplugin.IndigoOptions
import indigoplugin._

val scala3Version = "3.3.1"
val indigoVersion = "0.15.1"
val indigoVersion = "0.15.2"
val roguelikeStarterKitVersion = "0.3.3-SNAPSHOT"

Global / onChangedBuildSource := ReloadOnSourceChanges
Expand Down Expand Up @@ -75,6 +75,7 @@ lazy val demoOptions: IndigoOptions =
.withTitle("Indigo Roguelike!")
.withBackgroundColor("black")
.withAssetDirectory("demo/assets")
.withWindowSize(800, 600)

lazy val demo =
(project in file("demo"))
Expand All @@ -94,6 +95,14 @@ lazy val demo =
publish / skip := true,
publishLocal / skip := true
)
.settings(
Compile / sourceGenerators += Def.task {
IndigoGenerators("demo")
.listAssets("Assets", demoOptions.assets)
.generateConfig("Config", demoOptions)
.toSourceFiles((Compile / sourceManaged).value)
}
)
.dependsOn(roguelike)

lazy val benchmarks =
Expand Down
14 changes: 0 additions & 14 deletions demo/src/main/scala/demo/Assets.scala

This file was deleted.

91 changes: 60 additions & 31 deletions demo/src/main/scala/demo/RogueLikeGame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,88 @@ import roguelikestarterkit.*
import scala.scalajs.js.annotation.JSExportTopLevel

@JSExportTopLevel("IndigoGame")
object RogueLikeGame extends IndigoGame[Unit, Unit, Unit, Unit]:
object RogueLikeGame extends IndigoGame[Size, Size, Model, ViewModel]:

val maxTileCount: Int = 4000
val magnification: Int = 2

def initialScene(bootData: Unit): Option[SceneName] =
Option(RogueTerminalEmulatorScene.name)
def initialScene(bootData: Size): Option[SceneName] =
None

def scenes(bootData: Unit): NonEmptyList[Scene[Unit, Unit, Unit]] =
NonEmptyList(TerminalTextScene, TerminalEmulatorScene, RogueTerminalEmulatorScene)
def scenes(bootData: Size): NonEmptyList[Scene[Size, Model, ViewModel]] =
NonEmptyList(UIScene, RogueTerminalEmulatorScene, TerminalTextScene, TerminalEmulatorScene)

val eventFilters: EventFilters =
EventFilters.Permissive

def boot(flags: Map[String, String]): Outcome[BootResult[Unit]] =
def boot(flags: Map[String, String]): Outcome[BootResult[Size]] =
Outcome(
BootResult
.noData(
GameConfig.default
.withMagnification(2)
.withFrameRateLimit(FPS.`60`)
)
BootResult(
Config.config.withMagnification(magnification),
Config.config.viewport.size / 2
)
.withFonts(RoguelikeTiles.Size10x10.Fonts.fontInfo)
.withAssets(Assets.assets)
.withAssets(Assets.assets.assetSet)
.withShaders(
TerminalText.standardShader,
TerminalMaterial.standardShader,
TerminalTextScene.customShader(ShaderId("my shader"))
uiShaders ++ Set(
TerminalText.standardShader,
TerminalMaterial.standardShader,
TerminalTextScene.customShader(ShaderId("my shader"))
)
)
.withSubSystems(FPSCounter(Point(10, 350)))
)

def initialModel(startupData: Unit): Outcome[Unit] =
Outcome(())
def initialModel(startupData: Size): Outcome[Model] =
Outcome(Model.initial)

def initialViewModel(startupData: Unit, model: Unit): Outcome[Unit] =
Outcome(())
def initialViewModel(startupData: Size, model: Model): Outcome[ViewModel] =
Outcome(ViewModel.initial(startupData))

def setup(bootData: Unit, assetCollection: AssetCollection, dice: Dice): Outcome[Startup[Unit]] =
Outcome(Startup.Success(()))
def setup(bootData: Size, assetCollection: AssetCollection, dice: Dice): Outcome[Startup[Size]] =
Outcome(Startup.Success(bootData))

def updateModel(context: FrameContext[Unit], model: Unit): GlobalEvent => Outcome[Unit] =
def updateModel(context: FrameContext[Size], model: Model): GlobalEvent => Outcome[Model] =
_ => Outcome(model)

def updateViewModel(
context: FrameContext[Unit],
model: Unit,
viewModel: Unit
): GlobalEvent => Outcome[Unit] =
context: FrameContext[Size],
model: Model,
viewModel: ViewModel
): GlobalEvent => Outcome[ViewModel] =
_ => Outcome(viewModel)

def present(
context: FrameContext[Unit],
model: Unit,
viewModel: Unit
context: FrameContext[Size],
model: Model,
viewModel: ViewModel
): Outcome[SceneUpdateFragment] =
Outcome(SceneUpdateFragment.empty)

final case class CustomContext() // Placeholder, not used.

final case class Model(windowManager: WindowManagerModel[Size, CustomContext])

object Model:

val defaultCharSheet: CharSheet =
CharSheet(
Assets.assets.AnikkiSquare10x10,
Size(10),
RoguelikeTiles.Size10x10.charCrops
)

val initial: Model =
Model(
WindowManagerModel
.initial[Size, CustomContext]
.add(
ColourWindow.window(
defaultCharSheet
)
)
)

final case class ViewModel(windowManager: WindowManagerViewModel[Size, CustomContext])
object ViewModel:
def initial(viewportSize: Size): ViewModel =
ViewModel(WindowManagerViewModel.initial)
28 changes: 14 additions & 14 deletions demo/src/main/scala/demo/RogueTerminalEmulatorScene.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import indigo.*
import indigo.scenes.*
import roguelikestarterkit.*

object RogueTerminalEmulatorScene extends Scene[Unit, Unit, Unit]:
object RogueTerminalEmulatorScene extends Scene[Size, Model, ViewModel]:

type SceneModel = Unit
type SceneViewModel = Unit
type SceneModel = Model
type SceneViewModel = ViewModel

val name: SceneName =
SceneName("RogueTerminalEmulatorScene")

val modelLens: Lens[Unit, Unit] =
val modelLens: Lens[Model, Model] =
Lens.keepLatest

val viewModelLens: Lens[Unit, Unit] =
val viewModelLens: Lens[ViewModel, ViewModel] =
Lens.keepLatest

val eventFilters: EventFilters =
Expand All @@ -24,18 +24,18 @@ object RogueTerminalEmulatorScene extends Scene[Unit, Unit, Unit]:
val subSystems: Set[SubSystem] =
Set()

def updateModel(context: SceneContext[Unit], model: Unit): GlobalEvent => Outcome[Unit] =
def updateModel(context: SceneContext[Size], model: Model): GlobalEvent => Outcome[Model] =
case KeyboardEvent.KeyUp(Key.SPACE) =>
Outcome(model).addGlobalEvents(SceneEvent.JumpTo(TerminalTextScene.name))

case _ =>
Outcome(model)

def updateViewModel(
context: SceneContext[Unit],
model: Unit,
viewModel: Unit
): GlobalEvent => Outcome[Unit] =
context: SceneContext[Size],
model: Model,
viewModel: ViewModel
): GlobalEvent => Outcome[ViewModel] =
_ => Outcome(viewModel)

// This shouldn't live here really, just keeping it simple for demo purposes.
Expand All @@ -50,17 +50,17 @@ object RogueTerminalEmulatorScene extends Scene[Unit, Unit, Unit]:
.put(Point(5, 5), MapTile(Tile.`@`, RGBA.Cyan))

def present(
context: SceneContext[Unit],
model: Unit,
viewModel: Unit
context: SceneContext[Size],
model: Model,
viewModel: ViewModel
): Outcome[SceneUpdateFragment] =
val tiles =
terminal.toCloneTiles(
CloneId("demo"),
Point.zero,
RoguelikeTiles.Size10x10.charCrops
) { (fg, bg) =>
Graphic(10, 10, TerminalMaterial(Assets.tileMap, fg, bg))
Graphic(10, 10, TerminalMaterial(Assets.assets.AnikkiSquare10x10, fg, bg))
}

Outcome(tiles.toSceneUpdateFragment)
30 changes: 15 additions & 15 deletions demo/src/main/scala/demo/TerminalEmulatorScene.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import indigo.*
import indigo.scenes.*
import roguelikestarterkit.*

object TerminalEmulatorScene extends Scene[Unit, Unit, Unit]:
object TerminalEmulatorScene extends Scene[Size, Model, ViewModel]:

type SceneModel = Unit
type SceneViewModel = Unit
type SceneModel = Model
type SceneViewModel = ViewModel

val name: SceneName =
SceneName("TerminalEmulatorScene")

val modelLens: Lens[Unit, Unit] =
val modelLens: Lens[Model, Model] =
Lens.keepLatest

val viewModelLens: Lens[Unit, Unit] =
val viewModelLens: Lens[ViewModel, ViewModel] =
Lens.keepLatest

val eventFilters: EventFilters =
Expand All @@ -24,18 +24,18 @@ object TerminalEmulatorScene extends Scene[Unit, Unit, Unit]:
val subSystems: Set[SubSystem] =
Set()

def updateModel(context: SceneContext[Unit], model: Unit): GlobalEvent => Outcome[Unit] =
def updateModel(context: SceneContext[Size], model: Model): GlobalEvent => Outcome[Model] =
case KeyboardEvent.KeyUp(Key.SPACE) =>
Outcome(model).addGlobalEvents(SceneEvent.JumpTo(RogueTerminalEmulatorScene.name))
Outcome(model).addGlobalEvents(SceneEvent.JumpTo(UIScene.name))

case _ =>
Outcome(model)

def updateViewModel(
context: SceneContext[Unit],
model: Unit,
viewModel: Unit
): GlobalEvent => Outcome[Unit] =
context: SceneContext[Size],
model: Model,
viewModel: ViewModel
): GlobalEvent => Outcome[ViewModel] =
_ => Outcome(viewModel)

// This shouldn't live here really, just keeping it simple for demo purposes.
Expand All @@ -54,17 +54,17 @@ object TerminalEmulatorScene extends Scene[Unit, Unit, Unit]:
)

def present(
context: SceneContext[Unit],
model: Unit,
viewModel: Unit
context: SceneContext[Size],
model: Model,
viewModel: ViewModel
): Outcome[SceneUpdateFragment] =
val tiles =
terminal.toCloneTiles(
CloneId("demo"),
Point.zero,
RoguelikeTiles.Size10x10.charCrops
) { (fg, bg) =>
Graphic(10, 10, TerminalMaterial(Assets.tileMap, fg, bg))
Graphic(10, 10, TerminalMaterial(Assets.assets.AnikkiSquare10x10, fg, bg))
}

Outcome(
Expand Down
38 changes: 22 additions & 16 deletions demo/src/main/scala/demo/TerminalTextScene.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import indigo.*
import indigo.scenes.*
import roguelikestarterkit.*

object TerminalTextScene extends Scene[Unit, Unit, Unit]:
object TerminalTextScene extends Scene[Size, Model, ViewModel]:

type SceneModel = Unit
type SceneViewModel = Unit
type SceneModel = Model
type SceneViewModel = ViewModel

val name: SceneName =
SceneName("TerminalText scene")

val modelLens: Lens[Unit, Unit] =
val modelLens: Lens[Model, Model] =
Lens.keepLatest

val viewModelLens: Lens[Unit, Unit] =
val viewModelLens: Lens[ViewModel, ViewModel] =
Lens.keepLatest

val eventFilters: EventFilters =
Expand All @@ -24,18 +24,18 @@ object TerminalTextScene extends Scene[Unit, Unit, Unit]:
val subSystems: Set[SubSystem] =
Set()

def updateModel(context: SceneContext[Unit], model: Unit): GlobalEvent => Outcome[Unit] =
def updateModel(context: SceneContext[Size], model: Model): GlobalEvent => Outcome[Model] =
case KeyboardEvent.KeyUp(Key.SPACE) =>
Outcome(model).addGlobalEvents(SceneEvent.JumpTo(TerminalEmulatorScene.name))

case _ =>
Outcome(model)

def updateViewModel(
context: SceneContext[Unit],
model: Unit,
viewModel: Unit
): GlobalEvent => Outcome[Unit] =
context: SceneContext[Size],
model: Model,
viewModel: ViewModel
): GlobalEvent => Outcome[ViewModel] =
_ => Outcome(viewModel)

val size = Size(30)
Expand All @@ -48,26 +48,32 @@ object TerminalTextScene extends Scene[Unit, Unit, Unit]:
|""".stripMargin

def present(
context: SceneContext[Unit],
model: Unit,
viewModel: Unit
context: SceneContext[Size],
model: Model,
viewModel: ViewModel
): Outcome[SceneUpdateFragment] =
Outcome(
SceneUpdateFragment(
Text(
message,
RoguelikeTiles.Size10x10.Fonts.fontKey,
TerminalText(Assets.tileMap, RGBA.Cyan, RGBA.Blue)
TerminalText(Assets.assets.AnikkiSquare10x10, RGBA.Cyan, RGBA.Blue)
),
Text(
message,
RoguelikeTiles.Size10x10.Fonts.fontKey,
TerminalText(Assets.tileMap, RGBA.Yellow, RGBA.Red).withShaderId(ShaderId("my shader"))
TerminalText(Assets.assets.AnikkiSquare10x10, RGBA.Yellow, RGBA.Red)
.withShaderId(ShaderId("my shader"))
).moveBy(0, 40),
Text(
message,
RoguelikeTiles.Size10x10.Fonts.fontKey,
TerminalText(Assets.tileMap, RGBA.White, RGBA.Zero, RGBA.Magenta.withAlpha(0.75))
TerminalText(
Assets.assets.AnikkiSquare10x10,
RGBA.White,
RGBA.Zero,
RGBA.Magenta.withAlpha(0.75)
)
).moveBy(0, 80)
)
)
Expand Down
Loading
Loading