Skip to content

Instantly share code, notes, and snippets.

@arturaz
Created September 17, 2014 09:50
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/52be25fa21d32ad1c4c1 to your computer and use it in GitHub Desktop.
Save arturaz/52be25fa21d32ad1c4c1 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._
import shapeless.syntax.singleton._
trait WObjectStats
object WObject {
type Id = UUID
def newId: Id = UUID.randomUUID()
private object Witnesses {
val id = Witness("id")
val position = Witness("position")
}
private object Selectors {
type Id = Selector[Witnesses.id.T, UUID]
type Position = Selector[Witnesses.position.T, Vect2]
}
}
/* World object */
abstract class WObject[A <: HList](val props: A)(implicit
idSel: WObject.Selectors.Id, positionSel: WObject.Selectors.Position
) {
def this(id: WObject.Id, position: Vect2) =
this("id" ->> id :: "position" ->> position :: HNil)
def id = props("id")
def position = props("position")
def withId(id: WObject.Id) = props
def stats: Stats
lazy val bounds = Bounds(position, Vect2.one)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment