Skip to content

Commit

Permalink
Fixed PurpleKingdomGames#633: SceneUpdateFragment added withLayers
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Nov 18, 2023
1 parent b06ed12 commit 17b80be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ final case class SceneUpdateFragment(
def addLayers(newLayers: Batch[Layer]): SceneUpdateFragment =
this.copy(layers = newLayers.foldLeft(layers)((acc, l) => SceneUpdateFragment.addLayer(acc, l)))

def withLayers(layers: Batch[Layer]): SceneUpdateFragment =
this.copy(layers = layers)
def withLayers(layers: Layer*): SceneUpdateFragment =
withLayers(layers.toBatch)

def noLights: SceneUpdateFragment =
this.copy(lights = Batch.empty)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SceneUpdateFragmentTests extends munit.FunSuite {
SceneUpdateFragment(Option(Layer(BindingKey("key A"))))

val expected =
SceneUpdateFragment.empty.addLayers(Batch(Layer(BindingKey("key A"))))
SceneUpdateFragment.empty.addLayers(Batch(Layer(BindingKey("key "))))

assertEquals(actual, expected)

Expand Down Expand Up @@ -95,6 +95,19 @@ class SceneUpdateFragmentTests extends munit.FunSuite {

}

test("Replace layers using withLayers") {

val scene =
SceneUpdateFragment.empty.addLayer(Layer(BindingKey("key A")))

val actual =
scene.withLayers(Layer(BindingKey("key B")))

assert(actual.layers.length == 1)
assertEquals(actual.layers.head.key, Some(BindingKey("key B")))

}

test("SUF append preseves layer keys") {

val sceneA: SceneUpdateFragment =
Expand Down

0 comments on commit 17b80be

Please sign in to comment.