riichi/priv/src/Riichi.elm

92 lines
1.9 KiB
Elm
Raw Normal View History

2017-07-19 02:13:27 +00:00
module Riichi exposing (..)
import Hand
2017-07-19 02:13:27 +00:00
import Html exposing (..)
2017-08-18 03:31:24 +00:00
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Html.CssHelpers
import Stylesheets as S
{ id, class, classList } =
Html.CssHelpers.withNamespace "riichi"
2017-07-19 02:13:27 +00:00
type alias Model =
2017-08-18 03:31:24 +00:00
{ tileset : S.Tileset
, hand : Hand.Model
}
2017-07-19 02:13:27 +00:00
type Msg
2017-08-18 03:31:24 +00:00
= SetTileset S.Tileset
2017-07-19 02:13:27 +00:00
init : ( Model, Cmd Msg )
init =
2017-08-18 03:31:24 +00:00
( { tileset = S.White
, hand =
Hand.fromJSON
{ tiles =
[ "4 pin"
, "5 pin"
, "6 pin"
, "4 sou"
, "5 sou"
, "6 sou"
, "4 man"
, "5 man"
, "6 man"
, "red dragon"
]
}
}
, Cmd.none
)
2017-07-19 02:13:27 +00:00
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
2017-08-18 03:31:24 +00:00
case msg of
SetTileset tileset ->
( { model | tileset = tileset }
, Cmd.none
)
2017-07-19 02:13:27 +00:00
main : Program Never Model Msg
main =
program
{ init = init
, update = update
, view = view
, subscriptions = \_ -> Sub.none
}
view : Model -> Html Msg
view model =
2017-08-18 03:31:24 +00:00
div [ class [ S.Tileset model.tileset ] ]
[ h1 [] [ text "Riichi Mahjong" ]
2017-08-18 03:31:24 +00:00
, fieldset []
[ legend [] [ text "Tile Set" ]
, radio "tileset" "White" (SetTileset S.White) (model.tileset == S.White)
, radio "tileset" "Black" (SetTileset S.Black) (model.tileset == S.Black)
]
, Hand.view model.hand
]
2017-08-18 03:31:24 +00:00
radio : String -> String -> Msg -> Bool -> Html Msg
radio name_ value msg checked_ =
label []
[ input
[ type_ "radio"
, name name_
, onClick msg
, checked checked_
]
[]
, text value
]