Skip to content

Instantly share code, notes, and snippets.

@arturaz
Created September 17, 2014 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturaz/3312f974eaa36843fff7 to your computer and use it in GitHub Desktop.
Save arturaz/3312f974eaa36843fff7 to your computer and use it in GitHub Desktop.
package app.models.world
import java.util.UUID
import shapeless._
import shapeless.ops.record.Selector
import shapeless.record._
case class Vect2(x: Int, y: Int)
case class Bounds(position: Vect2, size: Vect2)
object WObject {
type Id = UUID
def newId: Id = UUID.randomUUID()
object Fields {
object id extends FieldOf[Id]
object position extends FieldOf[Vect2]
case class all[L <: HList](implicit
_id: Selector[L, id.type], _position: Selector[L, position.type]
)
object all {
implicit def make[L <: HList](implicit
_id: Selector[L, id.type],
_position: Selector[L, position.type]
) = all[L]
}
}
}
import WObject._
/* World object */
abstract class WObject[L <: HList](val props: L)(implicit sel: Fields.all[L]) {
def this(id: WObject.Id, position: Vect2) =
this(Fields.id ->> id :: Fields.position ->> position :: HNil)
def id = props(Fields.id)
def position = props(Fields.position)
lazy val bounds = Bounds(position, Vect2(1, 1))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment