exploring...

This commit is contained in:
2019-11-02 00:16:44 +01:00
parent 4ea22c2d49
commit 1a23eb4c31
2 changed files with 243 additions and 147 deletions

206
main.js
View File

@@ -5297,10 +5297,14 @@ var $elm$core$Task$perform = F2(
A2($elm$core$Task$map, toMessage, task))); A2($elm$core$Task$map, toMessage, task)));
}); });
var $elm$browser$Browser$application = _Browser_application; var $elm$browser$Browser$application = _Browser_application;
var $author$project$Main$GroupLoot = {$: 'GroupLoot'}; var $author$project$Main$Model = F5(
var $author$project$Main$Model = F6( function (state, player, loot, groupLoot, merchantItems) {
function (key, route, player, loot, groupLoot, error) { return {groupLoot: groupLoot, loot: loot, merchantItems: merchantItems, player: player, state: state};
return {error: error, groupLoot: groupLoot, key: key, loot: loot, player: player, route: route}; });
var $author$project$Main$PlayerChest = {$: 'PlayerChest'};
var $author$project$Main$State = F4(
function (navKey, route, error, menuOpen) {
return {error: error, menuOpen: menuOpen, navKey: navKey, route: route};
}); });
var $author$project$Main$Player = F4( var $author$project$Main$Player = F4(
function (id, name, debt, wealth) { function (id, name, debt, wealth) {
@@ -5314,7 +5318,7 @@ var $author$project$Main$blankPlayer = A4(
$author$project$Main$Player, $author$project$Main$Player,
0, 0,
'Loading', 'Loading',
100, 0,
A4($author$project$Main$Wealth, 0, 0, 0, 0)); A4($author$project$Main$Wealth, 0, 0, 0, 0));
var $elm$core$Platform$Cmd$batch = _Platform_batch; var $elm$core$Platform$Cmd$batch = _Platform_batch;
var $author$project$Main$GotLoot = function (a) { var $author$project$Main$GotLoot = function (a) {
@@ -6291,9 +6295,9 @@ var $elm$url$Url$Parser$parse = F2(
url.fragment, url.fragment,
$elm$core$Basics$identity))); $elm$core$Basics$identity)));
}); });
var $author$project$Main$GroupLoot = {$: 'GroupLoot'};
var $author$project$Main$Merchant = {$: 'Merchant'}; var $author$project$Main$Merchant = {$: 'Merchant'};
var $author$project$Main$NewLoot = {$: 'NewLoot'}; var $author$project$Main$NewLoot = {$: 'NewLoot'};
var $author$project$Main$PlayerChest = {$: 'PlayerChest'};
var $elm$url$Url$Parser$Parser = function (a) { var $elm$url$Url$Parser$Parser = function (a) {
return {$: 'Parser', a: a}; return {$: 'Parser', a: a};
}; };
@@ -6391,11 +6395,11 @@ var $elm$url$Url$Parser$top = $elm$url$Url$Parser$Parser(
var $author$project$Main$routeParser = $elm$url$Url$Parser$oneOf( var $author$project$Main$routeParser = $elm$url$Url$Parser$oneOf(
_List_fromArray( _List_fromArray(
[ [
A2($elm$url$Url$Parser$map, $author$project$Main$GroupLoot, $elm$url$Url$Parser$top),
A2( A2(
$elm$url$Url$Parser$map, $elm$url$Url$Parser$map,
$author$project$Main$PlayerChest, $author$project$Main$GroupLoot,
$elm$url$Url$Parser$s('coffre')), $elm$url$Url$Parser$s('coffre')),
A2($elm$url$Url$Parser$map, $author$project$Main$PlayerChest, $elm$url$Url$Parser$top),
A2( A2(
$elm$url$Url$Parser$map, $elm$url$Url$Parser$map,
$author$project$Main$Merchant, $author$project$Main$Merchant,
@@ -6413,11 +6417,17 @@ var $author$project$Main$init = F3(
var r = _v0.a; var r = _v0.a;
return r; return r;
} else { } else {
return $author$project$Main$GroupLoot; return $author$project$Main$PlayerChest;
} }
}(); }();
return _Utils_Tuple2( return _Utils_Tuple2(
A6($author$project$Main$Model, key, route, $author$project$Main$blankPlayer, $elm$core$Maybe$Nothing, $elm$core$Maybe$Nothing, ''), A5(
$author$project$Main$Model,
A4($author$project$Main$State, key, route, '', false),
$author$project$Main$blankPlayer,
$elm$core$Maybe$Nothing,
$elm$core$Maybe$Nothing,
$elm$core$Maybe$Nothing),
$author$project$Main$initPlayer(0)); $author$project$Main$initPlayer(0));
}); });
var $elm$core$Platform$Sub$batch = _Platform_batch; var $elm$core$Platform$Sub$batch = _Platform_batch;
@@ -6434,6 +6444,17 @@ var $author$project$Main$printError = function (error) {
} }
}; };
var $elm$browser$Browser$Navigation$pushUrl = _Browser_pushUrl; var $elm$browser$Browser$Navigation$pushUrl = _Browser_pushUrl;
var $author$project$Main$setError = F2(
function (error, model) {
var state = model.state;
return _Utils_update(
model,
{
state: _Utils_update(
state,
{error: error})
});
});
var $elm$url$Url$addPort = F2( var $elm$url$Url$addPort = F2(
function (maybePort, starter) { function (maybePort, starter) {
if (maybePort.$ === 'Nothing') { if (maybePort.$ === 'Nothing') {
@@ -6489,14 +6510,12 @@ var $author$project$Main$update = F2(
model, model,
A2( A2(
$elm$browser$Browser$Navigation$pushUrl, $elm$browser$Browser$Navigation$pushUrl,
model.key, model.state.navKey,
$elm$url$Url$toString(url))); $elm$url$Url$toString(url)));
} else { } else {
var href = urlRequest.a; var href = urlRequest.a;
return _Utils_Tuple2( return _Utils_Tuple2(
_Utils_update( A2($author$project$Main$setError, 'Invalid request \'' + (href + '\''), model),
model,
{error: 'Invalid request \'' + (href + '\'')}),
$elm$core$Platform$Cmd$none); $elm$core$Platform$Cmd$none);
} }
case 'UrlChanged': case 'UrlChanged':
@@ -6505,9 +6524,16 @@ var $author$project$Main$update = F2(
if (route.$ === 'Just') { if (route.$ === 'Just') {
var page = route.a; var page = route.a;
return _Utils_Tuple2( return _Utils_Tuple2(
_Utils_update( function () {
var state = model.state;
return _Utils_update(
model, model,
{route: page}), {
state: _Utils_update(
state,
{route: page})
});
}(),
function () { function () {
if (page.$ === 'GroupLoot') { if (page.$ === 'GroupLoot') {
return $elm$core$Platform$Cmd$none; return $elm$core$Platform$Cmd$none;
@@ -6518,9 +6544,7 @@ var $author$project$Main$update = F2(
}()); }());
} else { } else {
return _Utils_Tuple2( return _Utils_Tuple2(
_Utils_update( A2($author$project$Main$setError, 'Invalid route', model),
model,
{error: 'Invalid route'}),
$elm$core$Platform$Cmd$none); $elm$core$Platform$Cmd$none);
} }
case 'PlayerChanged': case 'PlayerChanged':
@@ -6542,11 +6566,10 @@ var $author$project$Main$update = F2(
} else { } else {
var error = result.a; var error = result.a;
return _Utils_Tuple2( return _Utils_Tuple2(
_Utils_update( A2(
model, $author$project$Main$setError,
{ 'Fetching player... ' + $author$project$Main$printError(error),
error: 'Fetching player... ' + $author$project$Main$printError(error) model),
}),
$elm$core$Platform$Cmd$none); $elm$core$Platform$Cmd$none);
} }
default: default:
@@ -6563,15 +6586,15 @@ var $author$project$Main$update = F2(
} else { } else {
var error = result.a; var error = result.a;
return _Utils_Tuple2( return _Utils_Tuple2(
_Utils_update( A2(
model, $author$project$Main$setError,
{ 'Fetching loot... ' + $author$project$Main$printError(error),
error: 'Fetching loot... ' + $author$project$Main$printError(error) model),
}),
$elm$core$Platform$Cmd$none); $elm$core$Platform$Cmd$none);
} }
} }
}); });
var $elm$html$Html$article = _VirtualDom_node('article');
var $elm$json$Json$Encode$string = _Json_wrap; var $elm$json$Json$Encode$string = _Json_wrap;
var $elm$html$Html$Attributes$stringProperty = F2( var $elm$html$Html$Attributes$stringProperty = F2(
function (key, string) { function (key, string) {
@@ -6581,6 +6604,7 @@ var $elm$html$Html$Attributes$stringProperty = F2(
$elm$json$Json$Encode$string(string)); $elm$json$Json$Encode$string(string));
}); });
var $elm$html$Html$Attributes$class = $elm$html$Html$Attributes$stringProperty('className'); var $elm$html$Html$Attributes$class = $elm$html$Html$Attributes$stringProperty('className');
var $elm$html$Html$hr = _VirtualDom_node('hr');
var $elm$html$Html$p = _VirtualDom_node('p'); var $elm$html$Html$p = _VirtualDom_node('p');
var $elm$html$Html$section = _VirtualDom_node('section'); var $elm$html$Html$section = _VirtualDom_node('section');
var $elm$virtual_dom$VirtualDom$text = _VirtualDom_text; var $elm$virtual_dom$VirtualDom$text = _VirtualDom_text;
@@ -6678,7 +6702,7 @@ var $author$project$Main$viewDebugSection = function (model) {
]), ]),
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$text(model.error) $elm$html$Html$text(model.state.error)
])), ])),
A2( A2(
$elm$html$Html$p, $elm$html$Html$p,
@@ -6689,7 +6713,7 @@ var $author$project$Main$viewDebugSection = function (model) {
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$text( $elm$html$Html$text(
'Route : ' + $elm$core$Debug$toString(model.route)) 'Route : ' + $elm$core$Debug$toString(model.state.route))
])) ]))
])); ]));
}; };
@@ -6728,10 +6752,11 @@ var $author$project$Main$viewHeaderBar = function (model) {
_List_fromArray( _List_fromArray(
[ [
A2( A2(
$elm$html$Html$p, $elm$html$Html$a,
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$Attributes$class('navbar-item') $elm$html$Html$Attributes$class('navbar-item'),
$elm$html$Html$Attributes$href('/')
]), ]),
_List_fromArray( _List_fromArray(
[ [
@@ -6804,7 +6829,7 @@ var $author$project$Main$viewHeaderBar = function (model) {
]), ]),
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$text('Mon coffre') $elm$html$Html$text('Coffre de groupe')
])) ]))
])) ]))
])) ]))
@@ -6886,21 +6911,59 @@ var $author$project$Main$showWealth = function (wealth) {
A2($author$project$Main$showWealthField, 'cp', wealth.cp) A2($author$project$Main$showWealthField, 'cp', wealth.cp)
]); ]);
}; };
var $author$project$Main$viewPlayerWealth = function (player) { var $elm$html$Html$button = _VirtualDom_node('button');
var $author$project$Main$actionButton = function (t) {
return A2(
$elm$html$Html$button,
_List_fromArray(
[
$elm$html$Html$Attributes$class('button')
]),
_List_fromArray(
[
$elm$html$Html$text(t)
]));
};
var $author$project$Main$viewPlayerAction = F2(
function (player, route) {
switch (route.$) {
case 'PlayerChest':
return _List_fromArray(
[
$author$project$Main$actionButton('Vendre')
]);
case 'GroupLoot':
return _List_fromArray(
[
$author$project$Main$actionButton('Demander')
]);
case 'Merchant':
return _List_fromArray(
[
$author$project$Main$actionButton('Acheter')
]);
default:
return _List_fromArray(
[
$author$project$Main$actionButton('Valider')
]);
}
});
var $author$project$Main$viewPlayerBar = F2(
function (player, route) {
return A2( return A2(
$elm$html$Html$section, $elm$html$Html$section,
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$Attributes$class('level') $elm$html$Html$Attributes$class('level is-mobile box')
]), ]),
_Utils_ap(
_List_fromArray( _List_fromArray(
[ [
A2( A2(
$elm$html$Html$div, $elm$html$Html$div,
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$Attributes$class('level-left box') $elm$html$Html$Attributes$class('level-left')
]), ]),
_Utils_ap( _Utils_ap(
_List_fromArray( _List_fromArray(
@@ -6914,16 +6977,6 @@ var $author$project$Main$viewPlayerWealth = function (player) {
_List_fromArray( _List_fromArray(
[ [
A2( A2(
$elm$html$Html$p,
_List_fromArray(
[
$elm$html$Html$Attributes$class('is-size-3')
]),
_List_fromArray(
[
$elm$html$Html$text('Argent')
])),
A2(
$elm$html$Html$span, $elm$html$Html$span,
_List_fromArray( _List_fromArray(
[ [
@@ -6941,17 +6994,9 @@ var $author$project$Main$viewPlayerWealth = function (player) {
])) ]))
])) ]))
]), ]),
$author$project$Main$showWealth(player.wealth))) _Utils_ap(
]), $author$project$Main$showWealth(player.wealth),
(player.debt > 0) ? _List_fromArray( (player.debt > 0) ? _List_fromArray(
[
A2(
$elm$html$Html$div,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-right')
]),
_List_fromArray(
[ [
A2( A2(
$elm$html$Html$div, $elm$html$Html$div,
@@ -6973,23 +7018,39 @@ var $author$project$Main$viewPlayerWealth = function (player) {
'Dette : ' + ($elm$core$String$fromInt(player.debt) + 'po')) 'Dette : ' + ($elm$core$String$fromInt(player.debt) + 'po'))
])) ]))
])) ]))
])) ]) : _List_Nil))),
]) : _List_Nil)); A2(
}; $elm$html$Html$div,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-right')
]),
A2($author$project$Main$viewPlayerAction, player, route))
]));
});
var $elm$core$Maybe$withDefault = F2(
function (_default, maybe) {
if (maybe.$ === 'Just') {
var value = maybe.a;
return value;
} else {
return _default;
}
});
var $author$project$Main$view = function (model) { var $author$project$Main$view = function (model) {
return { return {
body: _List_fromArray( body: _List_fromArray(
[ [
$author$project$Main$viewHeaderBar(model), $author$project$Main$viewHeaderBar(model),
$author$project$Main$viewPlayerWealth(model.player), A2($author$project$Main$viewPlayerBar, model.player, model.state.route),
A2( A2(
$elm$html$Html$section, $elm$html$Html$article,
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$Attributes$class('container') $elm$html$Html$Attributes$class('section container')
]), ]),
function () { function () {
var _v0 = model.route; var _v0 = model.state.route;
switch (_v0.$) { switch (_v0.$) {
case 'PlayerChest': case 'PlayerChest':
return _List_fromArray( return _List_fromArray(
@@ -7002,15 +7063,7 @@ var $author$project$Main$view = function (model) {
$elm$html$Html$text('Mon Coffre') $elm$html$Html$text('Mon Coffre')
])), ])),
$author$project$Main$viewLoot( $author$project$Main$viewLoot(
function () { A2($elm$core$Maybe$withDefault, _List_Nil, model.loot))
var _v1 = model.loot;
if (_v1.$ === 'Just') {
var i = _v1.a;
return i;
} else {
return _List_Nil;
}
}())
]); ]);
case 'GroupLoot': case 'GroupLoot':
return _List_fromArray( return _List_fromArray(
@@ -7021,7 +7074,9 @@ var $author$project$Main$view = function (model) {
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$text('Coffre de groupe') $elm$html$Html$text('Coffre de groupe')
])) ])),
$author$project$Main$viewLoot(
A2($elm$core$Maybe$withDefault, _List_Nil, model.groupLoot))
]); ]);
case 'Merchant': case 'Merchant':
return _List_fromArray( return _List_fromArray(
@@ -7047,6 +7102,7 @@ var $author$project$Main$view = function (model) {
]); ]);
} }
}()), }()),
A2($elm$html$Html$hr, _List_Nil, _List_Nil),
A2( A2(
$elm$html$Html$section, $elm$html$Html$section,
_List_fromArray( _List_fromArray(

View File

@@ -25,13 +25,19 @@ main =
-- Model -- Model
type alias Model = type alias State =
{ key : Nav.Key { navKey : Nav.Key
, route : Route , route : Route
, error : String
, menuOpen : Bool
}
type alias Model =
{ state : State
, player: Player , player: Player
, loot: Maybe Loot , loot: Maybe Loot
, groupLoot : Maybe Loot , groupLoot : Maybe Loot
, error: String , merchantItems : Maybe Loot
} }
init : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg ) init : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
@@ -39,9 +45,9 @@ init flags url key =
let let
route = case P.parse routeParser url of route = case P.parse routeParser url of
Just r -> r Just r -> r
Nothing -> GroupLoot Nothing -> PlayerChest
in in
( Model key route blankPlayer Nothing Nothing "", initPlayer 0) ( Model (State key route "" False) blankPlayer Nothing Nothing Nothing, initPlayer 0)
-- PLAYER -- PLAYER
@@ -54,7 +60,7 @@ type alias Player =
} }
blankPlayer = blankPlayer =
Player 0 "Loading" 100 (Wealth 0 0 0 0) Player 0 "Loading" 0 (Wealth 0 0 0 0)
initPlayer id = initPlayer id =
Cmd.batch [fetchPlayer id, fetchLoot id] Cmd.batch [fetchPlayer id, fetchLoot id]
@@ -133,11 +139,12 @@ update msg model =
LinkClicked urlRequest -> LinkClicked urlRequest ->
case urlRequest of case urlRequest of
Browser.Internal url -> Browser.Internal url ->
( model, Nav.pushUrl model.key (Url.toString url) ) ( model, Nav.pushUrl model.state.navKey (Url.toString url) )
--( model, Cmd.none ) --( model, Cmd.none )
Browser.External href -> Browser.External href ->
( { model | error = "Invalid request '" ++ href ++ "'" }, Cmd.none ) ( setError ("Invalid request '" ++ href ++ "'") model
, Cmd.none )
UrlChanged url -> UrlChanged url ->
let let
@@ -145,14 +152,15 @@ update msg model =
in in
case route of case route of
Just page -> Just page ->
( { model | route = page } ( let state = model.state in
{ model | state = { state | route = page }}
, case page of , case page of
GroupLoot -> Cmd.none GroupLoot -> Cmd.none
a -> Cmd.none a -> Cmd.none
) )
Nothing -> Nothing ->
( { model | error = "Invalid route" }, Cmd.none ) ( setError "Invalid route" model, Cmd.none )
PlayerChanged newId -> PlayerChanged newId ->
( { model | player = blankPlayer }, initPlayer newId ) ( { model | player = blankPlayer }, initPlayer newId )
@@ -163,7 +171,10 @@ update msg model =
( { model | player = player } ( { model | player = player }
, Cmd.none , Cmd.none
) )
Err error -> ( { model | error = "Fetching player... " ++ (printError error) }, Cmd.none ) Err error ->
( setError ("Fetching player... " ++ printError error) model
, Cmd.none
)
GotLoot result -> GotLoot result ->
case result of case result of
@@ -171,10 +182,22 @@ update msg model =
( { model | loot = Just loot} ( { model | loot = Just loot}
, Cmd.none , Cmd.none
) )
Err error -> ( { model | error = "Fetching loot... " ++ (printError error) }, Cmd.none ) Err error ->
( setError ("Fetching loot... " ++ printError error) model
, Cmd.none
)
-- ERRORS -- ERRORS
setError : String -> Model -> Model
setError error model =
let
state = model.state
in
{ model | state =
{ state | error = error }}
printError : Http.Error -> String printError : Http.Error -> String
printError error = printError error =
case error of case error of
@@ -188,26 +211,27 @@ subscriptions _ =
Sub.none Sub.none
-- VIEW ---
-- -- VIEWS
---
view : Model -> Browser.Document Msg view : Model -> Browser.Document Msg
view model = view model =
{ title = "Loot-a-lot in ELM" { title = "Loot-a-lot in ELM"
, body = , body =
[ viewHeaderBar model [ viewHeaderBar model
, viewPlayerWealth model.player , viewPlayerBar model.player model.state.route
, section [class "container"] , article [class "section container"]
(case model.route of (case model.state.route of
PlayerChest -> PlayerChest ->
[ p [] [text "Mon Coffre"] [ p [] [text "Mon Coffre"]
, viewLoot (case model.loot of , viewLoot (Maybe.withDefault [] model.loot)
Just i -> i
Nothing -> [])
] ]
GroupLoot -> GroupLoot ->
[ p [] [text "Coffre de groupe"] ] [ p [] [text "Coffre de groupe"]
, viewLoot (Maybe.withDefault [] model.groupLoot)
]
Merchant -> Merchant ->
[ p [] [text "Acheter des objets"] ] [ p [] [text "Acheter des objets"] ]
@@ -215,27 +239,32 @@ view model =
NewLoot -> NewLoot ->
[ p [] [text "Nouveau trésor :) "] ] [ p [] [text "Nouveau trésor :) "] ]
) )
, hr [] []
, section [class "container"] [viewDebugSection model] , section [class "container"] [viewDebugSection model]
] ]
} }
-- LOOT Views
viewLoot : Loot -> Html Msg
viewLoot items =
table []
(List.map viewItemTableRow items)
viewItemTableRow item = viewItemTableRow item =
tr [class "table"] tr [class "table"]
[ td [] [p [] [text item.name]] [ td [] [p [] [text item.name]]
] ]
viewLoot : Loot -> Html Msg
viewLoot items =
table []
(List.map viewItemTableRow items)
-- DEBUG SECTION -- DEBUG SECTION
viewDebugSection : Model -> Html Msg
viewDebugSection model = viewDebugSection model =
div [class "panel is-danger"] div [class "panel is-danger"]
[ p [class "panel-heading"] [text "Debug"] [ p [class "panel-heading"] [text "Debug"]
, debugSwitchPlayers , debugSwitchPlayers
, p [class "panel-block has-text-danger"] [text model.error] , p [class "panel-block has-text-danger"] [text model.state.error]
, p [class "panel-block"] [text ("Route : " ++ Debug.toString model.route)] , p [class "panel-block"] [text ("Route : " ++ Debug.toString model.state.route)]
] ]
debugSwitchPlayers : Html Msg debugSwitchPlayers : Html Msg
@@ -245,15 +274,15 @@ debugSwitchPlayers =
, a [ onClick (PlayerChanged 1) ] [text "Lomion"] , a [ onClick (PlayerChanged 1) ] [text "Lomion"]
, a [ onClick (PlayerChanged 2) ] [text "Fefi"] , a [ onClick (PlayerChanged 2) ] [text "Fefi"]
] ]
-- HEADER SECTION -- HEADER SECTION
viewHeaderBar : Model -> Html Msg viewHeaderBar : Model -> Html Msg
viewHeaderBar model = viewHeaderBar model =
nav [ class "navbar", class "is-info" ] nav [ class "navbar", class "is-info" ]
[ div [ class "navbar-brand" ] [ div [ class "navbar-brand" ]
[ p [ class "navbar-item"] [ a [ class "navbar-item", href "/"]
[ text model.player.name ] [ text model.player.name ]
, a [class "navbar-burger is-active"] , a [class "navbar-burger is-active"]
[ span [attribute "aria-hidden" "true"] [] [ span [attribute "aria-hidden" "true"] []
, span [attribute "aria-hidden" "true"] [] , span [attribute "aria-hidden" "true"] []
@@ -263,34 +292,45 @@ viewHeaderBar model =
, div [ class "navbar-menu is-active" ] , div [ class "navbar-menu is-active" ]
[ div [class "navbar-end"] [ div [class "navbar-end"]
[ a [class "navbar-item", href "/marchand"] [text "Marchand"] [ a [class "navbar-item", href "/marchand"] [text "Marchand"]
, a [class "navbar-item", href "/coffre"] [text "Mon coffre"] , a [class "navbar-item", href "/coffre"] [text "Coffre de groupe"]
] ]
] ]
] ]
-- WEALTH -- PLAYER BAR
--
viewPlayerWealth : Player -> Html Msg viewPlayerBar : Player -> Route -> Html Msg
viewPlayerWealth player = viewPlayerBar player route =
section [ class "level" ] section [ class "level is-mobile box" ]
([div [class "level-left box"] [ div [class "level-left"]
([div [ class "level-item" ] ([div [ class "level-item" ]
[ span [ class "icon is-large" ] [ span [ class "icon is-large" ]
[ i [ class "fas fa-2x fa-piggy-bank" ] [] ]] [ i [ class "fas fa-2x fa-piggy-bank" ] [] ]]
] ++ (showWealth player.wealth)) ]
] ++ (if player.debt > 0 then ++ (showWealth player.wealth)
[ div [class "level-right"] ++ (if player.debt > 0 then
[div [class "level-item"] [div [class "level-item"]
[p [class "heading is-size-4 has-text-danger"] [p [class "heading is-size-4 has-text-danger"]
[text ("Dette : " ++ (String.fromInt player.debt) ++ "po")] [text ("Dette : " ++ (String.fromInt player.debt) ++ "po")]
] ]]
]
]
else else
[] []
)) )
)
, div [class "level-right"] (viewPlayerAction player route)
]
actionButton t = button [ class "button" ] [ text t ]
viewPlayerAction : Player -> Route -> List (Html Msg)
viewPlayerAction player route =
case route of
PlayerChest -> [actionButton "Vendre" ]
GroupLoot -> [actionButton "Demander" ]
Merchant -> [actionButton "Acheter" ]
NewLoot -> [actionButton "Valider" ]
showWealth : Wealth -> List (Html Msg) showWealth : Wealth -> List (Html Msg)
showWealth wealth = showWealth wealth =
@@ -307,9 +347,9 @@ showWealthField name value =
, p [class "heading"] [text name] , p [class "heading"] [text name]
] ]
---
-- ROUTES -- ROUTES
-- ---
type Route type Route
= PlayerChest = PlayerChest
@@ -320,8 +360,8 @@ type Route
routeParser : Parser (Route -> a) a routeParser : Parser (Route -> a) a
routeParser = routeParser =
oneOf oneOf
[ P.map GroupLoot P.top [ P.map GroupLoot (P.s "coffre")
, P.map PlayerChest (P.s "coffre") , P.map PlayerChest P.top
, P.map Merchant (P.s "marchand") , P.map Merchant (P.s "marchand")
, P.map NewLoot (P.s "nouveau-tresor") , P.map NewLoot (P.s "nouveau-tresor")
] ]