238 lines
5.7 KiB
Elm
238 lines
5.7 KiB
Elm
module Page exposing (Page(..), PageMsg, gotoHome, gotoShop, update, view)
|
|
|
|
import Html exposing (..)
|
|
import Html.Attributes exposing (..)
|
|
import Html.Events exposing (..)
|
|
import Page.Admin as Admin
|
|
import Page.Chest as Chest
|
|
import Page.Chest.Wealth as Wealth
|
|
import Page.Shop as Shop
|
|
import Session exposing (Session)
|
|
import Utils exposing (renderIcon)
|
|
|
|
|
|
type Page
|
|
= Chest Chest.Model
|
|
| Admin Admin.Model
|
|
| Shop Shop.Model
|
|
| About
|
|
| Loading
|
|
|
|
|
|
|
|
{-
|
|
|
|
type Page
|
|
= Dashboard Session
|
|
| GroupChest Session
|
|
| Shop Shop.Model
|
|
| NewLoot Session
|
|
| About
|
|
| Loading
|
|
|
|
|
|
-}
|
|
|
|
|
|
init =
|
|
Loading
|
|
|
|
|
|
mapMsg toMsg =
|
|
List.map (Html.map toMsg)
|
|
|
|
|
|
view page =
|
|
let
|
|
maybeSession =
|
|
case page of
|
|
Chest model ->
|
|
Just <| Session.getSession model
|
|
|
|
Admin model ->
|
|
Just <| Admin.getSession model
|
|
|
|
Shop model ->
|
|
Just <| Session.getSession model
|
|
|
|
_ ->
|
|
Nothing
|
|
|
|
( title, ( controls, content ) ) =
|
|
case page of
|
|
Chest chest ->
|
|
( "Lootalot", ( text "", mapMsg GotChestMsg <| Chest.view chest ) )
|
|
|
|
Admin admin ->
|
|
( "Administration", ( text "", mapMsg GotAdminMsg <| Admin.view admin ) )
|
|
|
|
Shop shop ->
|
|
( "Marchand"
|
|
, Shop.view shop
|
|
|> Tuple.mapBoth
|
|
(Html.map GotShopMsg)
|
|
(mapMsg GotShopMsg)
|
|
)
|
|
|
|
About ->
|
|
( "Loot-a-lot", ( text "", [ p [] [ text "A propos" ] ] ) )
|
|
|
|
Loading ->
|
|
( "Loot-a-lot", ( text "", [ p [] [ text "Chargement" ] ] ) )
|
|
|
|
navbarTitle =
|
|
case maybeSession of
|
|
Just session ->
|
|
case Session.user session of
|
|
Session.Player player _ ->
|
|
player.name
|
|
|
|
Session.Admin ->
|
|
"Administration"
|
|
|
|
Nothing ->
|
|
"Loot-a-lot"
|
|
|
|
navbarLinks =
|
|
case maybeSession of
|
|
Just session ->
|
|
case Session.user session of
|
|
Session.Player player _ ->
|
|
let
|
|
linkWithGem =
|
|
navLink "fas fa-gem"
|
|
in
|
|
[ navLink "fas fa-store-alt" "Marchand" "/marchand"
|
|
, if player.id == 0 then
|
|
linkWithGem "Nouveau loot" "/nouveau-tresor"
|
|
|
|
else
|
|
linkWithGem "Coffre de groupe" "/coffre"
|
|
]
|
|
|
|
Session.Admin ->
|
|
[ navLink "fas fa-store-alt" "Marchand" "/marchand" ]
|
|
|
|
Nothing ->
|
|
[]
|
|
in
|
|
( title
|
|
, { title = navbarTitle, links = navbarLinks }
|
|
, [ div [ class "container" ] <|
|
|
viewSessionBar maybeSession [ controls ]
|
|
:: content
|
|
]
|
|
)
|
|
|
|
|
|
viewSessionBar maybeSession controls =
|
|
let
|
|
user =
|
|
case Maybe.map Session.user maybeSession of
|
|
Nothing ->
|
|
[ text "" ]
|
|
|
|
Just (Session.Player player wealth) ->
|
|
Wealth.view player.wealth wealth
|
|
++ (if player.debt > 0 then
|
|
[ div [ class "level-item" ]
|
|
[ p [ class "heading is-size-4 has-text-danger" ]
|
|
[ text ("Dette : " ++ String.fromInt player.debt ++ "po") ]
|
|
]
|
|
]
|
|
|
|
else
|
|
[]
|
|
)
|
|
|> List.map (Html.map Wealth)
|
|
|
|
Just Session.Admin ->
|
|
[ text "Admin" ]
|
|
in
|
|
section [ class "hero is-dark is-bold" ]
|
|
[ div [ class "hero-body" ]
|
|
[ renderLevel user controls ]
|
|
]
|
|
|
|
|
|
renderLevel left right =
|
|
div [ class "level container is-mobile" ]
|
|
[ div [ class "level-left" ] left
|
|
, div [ class "level-right" ] right
|
|
]
|
|
|
|
|
|
|
|
-- PLAYER BAR
|
|
|
|
|
|
navLink icon linkText url =
|
|
a [ class "navbar-item", href url ]
|
|
[ renderIcon { icon = icon, ratio = "1x", size = "medium" }
|
|
, span [] [ text linkText ]
|
|
]
|
|
|
|
|
|
|
|
-- UPDATE
|
|
--
|
|
|
|
|
|
type PageMsg
|
|
= GotChestMsg Chest.Msg
|
|
| GotAdminMsg Admin.Msg
|
|
| GotShopMsg Shop.Msg
|
|
| Wealth Wealth.Msg
|
|
|
|
|
|
update msg page =
|
|
case ( msg, page ) of
|
|
( GotChestMsg subMsg, Chest chest ) ->
|
|
Chest.update subMsg chest
|
|
|> updatePage Chest GotChestMsg
|
|
|
|
( GotAdminMsg subMsg, Admin admin ) ->
|
|
Admin.update subMsg admin
|
|
|> updatePage Admin GotAdminMsg
|
|
|
|
( GotShopMsg subMsg, Shop shop ) ->
|
|
Shop.update subMsg shop
|
|
|> updatePage Shop GotShopMsg
|
|
|
|
_ ->
|
|
( page, Cmd.none )
|
|
|
|
|
|
updatePage toPage toMsg ( subModel, subMsg ) =
|
|
( toPage subModel
|
|
, Cmd.map toMsg subMsg
|
|
)
|
|
|
|
|
|
|
|
-- CHANGE ROUTE
|
|
|
|
|
|
gotoHome session =
|
|
case Session.user session of
|
|
Session.Player _ _ ->
|
|
Chest.init session
|
|
|> updatePage Chest GotChestMsg
|
|
|
|
Session.Admin ->
|
|
Admin.init session
|
|
|> updatePage Admin GotAdminMsg
|
|
|
|
|
|
gotoShop session =
|
|
Shop.init session
|
|
|> updatePage Shop GotShopMsg
|
|
|
|
|
|
gotoGroupChest session =
|
|
()
|
|
|
|
|
|
gotoInventory session =
|
|
()
|