Skip to content

Commit

Permalink
Tests compiling (but broken), better Context naming and constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Nov 10, 2024
1 parent fc4db79 commit 94678c0
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package indigoextras.jobs
import indigo.platform.assets.DynamicText
import indigo.shared.AnimationsRegister
import indigo.shared.BoundaryLocator
import indigo.shared.Context
import indigo.shared.FontRegister
import indigo.shared.collections.Batch
import indigo.shared.datatypes.BindingKey
Expand All @@ -18,12 +19,11 @@ import indigo.shared.time.GameTime
class JobMarketTests extends munit.FunSuite {

val context =
SubSystemContext[Unit](
GameTime.zero,
Dice.loaded(6),
InputState.default,
new BoundaryLocator(new AnimationsRegister, new FontRegister, new DynamicText),
()
SubSystemContext.fromContext(
Context.initial
.modifyFrame(
_.withDice(Dice.loaded(6))
)
)

val workContext =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package indigoextras.subsystems
import indigo.platform.assets.DynamicText
import indigo.shared.AnimationsRegister
import indigo.shared.BoundaryLocator
import indigo.shared.Context
import indigo.shared.FontRegister
import indigo.shared.dice.Dice
import indigo.shared.events.InputState
Expand All @@ -13,28 +14,27 @@ import indigo.shared.time.Seconds
object FakeSubSystemFrameContext:

def context(sides: Int): SubSystemContext[Unit] =
SubSystemContext(
GameTime.zero,
Dice.loaded(sides),
InputState.default,
new BoundaryLocator(new AnimationsRegister, new FontRegister, new DynamicText),
()
SubSystemContext.fromContext(
Context.initial
.modifyFrame(
_.withDice(Dice.loaded(sides))
)
)

def context(sides: Int, time: Seconds): SubSystemContext[Unit] =
SubSystemContext(
GameTime.is(time),
Dice.loaded(sides),
InputState.default,
new BoundaryLocator(new AnimationsRegister, new FontRegister, new DynamicText),
()
SubSystemContext.fromContext(
Context.initial
.modifyFrame(
_.withDice(Dice.loaded(sides))
.withTime(GameTime.is(time))
)
)

def context(sides: Int, time: Seconds, delta: Seconds): SubSystemContext[Unit] =
SubSystemContext(
GameTime.withDelta(time, delta),
Dice.loaded(sides),
InputState.default,
new BoundaryLocator(new AnimationsRegister, new FontRegister, new DynamicText),
()
SubSystemContext.fromContext(
Context.initial
.modifyFrame(
_.withDice(Dice.loaded(sides))
.withTime(GameTime.withDelta(time, delta))
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import indigo.platform.assets.DynamicText
import indigo.platform.renderer.Renderer
import indigo.shared.AnimationsRegister
import indigo.shared.BoundaryLocator
import indigo.shared.FontRegister
import indigo.shared.Context
import indigo.shared.FontRegister
import indigo.shared.assets.AssetName
import indigo.shared.collections.Batch
import indigo.shared.constants.Key
Expand Down Expand Up @@ -45,6 +45,8 @@ class InputFieldTests extends munit.FunSuite {

val boundaryLocator: BoundaryLocator =
new BoundaryLocator(new AnimationsRegister, fontRegister, new DynamicText())
val bounds: Context.Services.Bounds =
Context.Services.Bounds(boundaryLocator)

val atCommaPosition =
InputField("Hello, world!", assets).cursorHome.cursorRight.cursorRight.cursorRight.cursorRight.cursorRight
Expand Down Expand Up @@ -153,7 +155,7 @@ class InputFieldTests extends munit.FunSuite {

test("Multi line boxes have bounds correctly caluculated") {
val actual =
InputField("ab\nc", assets).moveTo(50, 50).bounds(boundaryLocator).get
InputField("ab\nc", assets).moveTo(50, 50).bounds(bounds).get

val expected =
Rectangle(50, 50, 26, 36)
Expand All @@ -170,7 +172,7 @@ class InputFieldTests extends munit.FunSuite {

def extractCursorPosition(field: InputField): Point =
field
.draw(GameTime.zero, boundaryLocator)
.draw(GameTime.zero, bounds)
.collect { case g: Graphic[_] => g }
.head
.position
Expand Down Expand Up @@ -277,14 +279,10 @@ class InputFieldTests extends munit.FunSuite {
)

def context: Context[Unit] =
new Context[Unit](
GameTime.zero,
Dice.loaded(1),
new InputState(Mouse.default, new Keyboard(keysUp, Batch.empty, None), Gamepad.default, Pointers.default),
new BoundaryLocator(new AnimationsRegister, new FontRegister, new DynamicText),
(),
Renderer.blackHole.captureScreen
)
Context.initial
.modifyFrame(
_.withDice(Dice.loaded(1))
)

object Samples {
val material = Material.Bitmap(AssetName("font-sheet"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ final class GameEngine[StartUpData, GameModel, ViewModel](

audioPlayer.addAudioAssets(accumulatedAssetCollection.sounds)

val randomSeed = (if (firstRun) 0 else gameLoopInstance.runningTimeReference) // + gameLoopInstance.initialSeed // TODO: Bug here. Black screen of no-render death.
val randomSeed =
if (firstRun) 0
else
gameLoopInstance.runningTimeReference // + gameLoopInstance.initialSeed // TODO: Bug here. Black screen of no-render death.

if (firstRun)
platform = new Platform(parentElement, gameConfig, globalEventStream, dynamicText)
Expand Down
5 changes: 5 additions & 0 deletions indigo/indigo/src/main/scala/indigo/scenes/SceneContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ final class SceneContext[StartUpData](

def toFrameContext: Context[StartUpData] =
context

object SceneContext:

def fromFrameContext[A](sceneName: SceneName, sceneStartTime: Seconds, ctx: Context[A]): SceneContext[A] =
new SceneContext(sceneName, sceneStartTime, ctx)
Loading

0 comments on commit 94678c0

Please sign in to comment.