Skip to content

Commit

Permalink
Remove type bounds from GameViewport
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Nov 8, 2024
1 parent 52e21d5 commit 16f82df
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions indigo/indigo/src/main/scala/indigo/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ object syntax:
extension [A](l: List[Option[A]]) def sequence: Option[List[A]] = NonEmptyList.sequenceListOption(l)
extension [A](l: NonEmptyList[Option[A]]) def sequence: Option[NonEmptyList[A]] = NonEmptyList.sequenceOption(l)

extension (s: Size)
def toGameViewport: GameViewport = GameViewport(s)

// Timeline animations
object animations:
import indigo.shared.animation.timeline.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ final case class GameConfig(

def withViewport(width: Int, height: Int): GameConfig =
this.copy(viewport = GameViewport(width, height))
def withViewport(size: Size): GameConfig =
this.copy(viewport = GameViewport(size.width, size.height))
def withViewport(newViewport: GameViewport): GameConfig =
this.copy(viewport = newViewport)

def withFrameRateLimit(limit: FPS): GameConfig =
this.copy(frameRateLimit = Option(limit))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import indigo.shared.datatypes.Point
import indigo.shared.datatypes.Rectangle
import indigo.shared.datatypes.Size

opaque type GameViewport <: Size = Size
opaque type GameViewport = Size
object GameViewport:
def apply(size: Size): GameViewport = size
def apply(width: Int, height: Int): GameViewport = Size(width, height)
Expand All @@ -19,12 +19,13 @@ object GameViewport:
val at720pBy2: GameViewport = GameViewport(640, 360)

extension (a: GameViewport)
def width: Int = a.width
def height: Int = a.height

def horizontalMiddle: Int = a.width / 2
def verticalMiddle: Int = a.height / 2
def center: Point = Point(horizontalMiddle, verticalMiddle)

@deprecated("use 'toRectangle' instead")
def asRectangle: Rectangle = toRectangle
def toRectangle: Rectangle = Rectangle(Point.zero, a)
def size: Size = a
def toSize: Size = a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package example.game

import cats.effect.IO
import indigo._
import indigo.scenes._
import indigo.*
import indigo.scenes.*
import tyrian.TyrianSubSystem

final case class MyAwesomeGame(tyrianSubSystem: TyrianSubSystem[IO, String, Unit], clockwise: Boolean)
Expand Down

0 comments on commit 16f82df

Please sign in to comment.