Orasund / elm-card-game / Game.Entity

module for working with entities.

Entity


type alias Entity a =
{ position : ( Basics.Float
, Basics.Float )
, rotation : Basics.Float
, customTransformations : List Transformation
, zIndex : Basics.Int
, content : a 
}

A entity allows for different relative transformations like rotating or moving by a relative amount.

new : a -> Entity a

construct a entity

toAttributes : Entity a -> ( a, List (Html.Attribute msg) )

Attributes of a Entity

toHtml : List (Html.Attribute msg) -> Entity (List (Html.Attribute msg) -> Html msg) -> Html msg

turn the entity into html

pileAbove : Html msg -> List (Entity (List (Html.Attribute msg) -> Html msg)) -> Entity (List (Html.Attribute msg) -> Html msg)

Group Entities into a pile

move : ( Basics.Float, Basics.Float ) -> Entity a -> Entity a

move a entity

rotate : Basics.Float -> Entity a -> Entity a

rotate a entity

map : (a -> b) -> Entity a -> Entity b

map the content of a entity

mapCustomTransformations : (List Transformation -> List Transformation) -> Entity a -> Entity a

map custom transformations

mapPosition : (( Basics.Float, Basics.Float ) -> ( Basics.Float, Basics.Float )) -> Entity a -> Entity a

map position

mapRotation : (Basics.Float -> Basics.Float) -> Entity a -> Entity a

map rotation

mapZIndex : (Basics.Int -> Basics.Int) -> Entity a -> Entity a

map z-index

flippable : List (Html.Attribute msg) -> { front : Entity (List (Html.Attribute msg) -> Html msg), back : Entity (List (Html.Attribute msg) -> Html msg), faceUp : Basics.Bool } -> Entity (List (Html.Attribute msg) -> Html msg)

Create an entity that can be flipped

For technical reasons we needed to provide a width. Default is a ratio of 2/3

You can overrule the default by providing a width:

height = 200

ratio = 2/3

flippable [Html.Attributes.style "width" (String.fromFloat (height * ratio) ++ "px")]

perspective : Html.Attribute msg

Activates a 3d-effect for the child notes. Should be used in combination with flip

Transformation


type alias Transformation =
String

A transformation string

transform : List Transformation -> Html.Attribute msg

Add transformations to a card

scale : Basics.Float -> Transformation

Scale the card

moveTransformation : ( Basics.Float, Basics.Float ) -> Transformation

Move the card

rotateTransformation : Basics.Float -> Transformation

Rotate the card by a radial.

flipTransformation : Basics.Float -> Transformation

Flip the card. Only works if the outer div has a perspective Attribute