Created
September 17, 2014 10:28
-
-
Save arturaz/3312f974eaa36843fff7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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