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)));
});
var $elm$browser$Browser$application = _Browser_application;
var $author$project$Main$GroupLoot = {$: 'GroupLoot'};
var $author$project$Main$Model = F6(
function (key, route, player, loot, groupLoot, error) {
return {error: error, groupLoot: groupLoot, key: key, loot: loot, player: player, route: route};
var $author$project$Main$Model = F5(
function (state, player, loot, groupLoot, merchantItems) {
return {groupLoot: groupLoot, loot: loot, merchantItems: merchantItems, player: player, state: state};
});
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(
function (id, name, debt, wealth) {
@@ -5314,7 +5318,7 @@ var $author$project$Main$blankPlayer = A4(
$author$project$Main$Player,
0,
'Loading',
100,
0,
A4($author$project$Main$Wealth, 0, 0, 0, 0));
var $elm$core$Platform$Cmd$batch = _Platform_batch;
var $author$project$Main$GotLoot = function (a) {
@@ -6291,9 +6295,9 @@ var $elm$url$Url$Parser$parse = F2(
url.fragment,
$elm$core$Basics$identity)));
});
var $author$project$Main$GroupLoot = {$: 'GroupLoot'};
var $author$project$Main$Merchant = {$: 'Merchant'};
var $author$project$Main$NewLoot = {$: 'NewLoot'};
var $author$project$Main$PlayerChest = {$: 'PlayerChest'};
var $elm$url$Url$Parser$Parser = function (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(
_List_fromArray(
[
A2($elm$url$Url$Parser$map, $author$project$Main$GroupLoot, $elm$url$Url$Parser$top),
A2(
$elm$url$Url$Parser$map,
$author$project$Main$PlayerChest,
$author$project$Main$GroupLoot,
$elm$url$Url$Parser$s('coffre')),
A2($elm$url$Url$Parser$map, $author$project$Main$PlayerChest, $elm$url$Url$Parser$top),
A2(
$elm$url$Url$Parser$map,
$author$project$Main$Merchant,
@@ -6413,11 +6417,17 @@ var $author$project$Main$init = F3(
var r = _v0.a;
return r;
} else {
return $author$project$Main$GroupLoot;
return $author$project$Main$PlayerChest;
}
}();
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));
});
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 $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(
function (maybePort, starter) {
if (maybePort.$ === 'Nothing') {
@@ -6489,14 +6510,12 @@ var $author$project$Main$update = F2(
model,
A2(
$elm$browser$Browser$Navigation$pushUrl,
model.key,
model.state.navKey,
$elm$url$Url$toString(url)));
} else {
var href = urlRequest.a;
return _Utils_Tuple2(
_Utils_update(
model,
{error: 'Invalid request \'' + (href + '\'')}),
A2($author$project$Main$setError, 'Invalid request \'' + (href + '\''), model),
$elm$core$Platform$Cmd$none);
}
case 'UrlChanged':
@@ -6505,9 +6524,16 @@ var $author$project$Main$update = F2(
if (route.$ === 'Just') {
var page = route.a;
return _Utils_Tuple2(
_Utils_update(
function () {
var state = model.state;
return _Utils_update(
model,
{route: page}),
{
state: _Utils_update(
state,
{route: page})
});
}(),
function () {
if (page.$ === 'GroupLoot') {
return $elm$core$Platform$Cmd$none;
@@ -6518,9 +6544,7 @@ var $author$project$Main$update = F2(
}());
} else {
return _Utils_Tuple2(
_Utils_update(
model,
{error: 'Invalid route'}),
A2($author$project$Main$setError, 'Invalid route', model),
$elm$core$Platform$Cmd$none);
}
case 'PlayerChanged':
@@ -6542,11 +6566,10 @@ var $author$project$Main$update = F2(
} else {
var error = result.a;
return _Utils_Tuple2(
_Utils_update(
model,
{
error: 'Fetching player... ' + $author$project$Main$printError(error)
}),
A2(
$author$project$Main$setError,
'Fetching player... ' + $author$project$Main$printError(error),
model),
$elm$core$Platform$Cmd$none);
}
default:
@@ -6563,15 +6586,15 @@ var $author$project$Main$update = F2(
} else {
var error = result.a;
return _Utils_Tuple2(
_Utils_update(
model,
{
error: 'Fetching loot... ' + $author$project$Main$printError(error)
}),
A2(
$author$project$Main$setError,
'Fetching loot... ' + $author$project$Main$printError(error),
model),
$elm$core$Platform$Cmd$none);
}
}
});
var $elm$html$Html$article = _VirtualDom_node('article');
var $elm$json$Json$Encode$string = _Json_wrap;
var $elm$html$Html$Attributes$stringProperty = F2(
function (key, string) {
@@ -6581,6 +6604,7 @@ var $elm$html$Html$Attributes$stringProperty = F2(
$elm$json$Json$Encode$string(string));
});
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$section = _VirtualDom_node('section');
var $elm$virtual_dom$VirtualDom$text = _VirtualDom_text;
@@ -6678,7 +6702,7 @@ var $author$project$Main$viewDebugSection = function (model) {
]),
_List_fromArray(
[
$elm$html$Html$text(model.error)
$elm$html$Html$text(model.state.error)
])),
A2(
$elm$html$Html$p,
@@ -6689,7 +6713,7 @@ var $author$project$Main$viewDebugSection = function (model) {
_List_fromArray(
[
$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(
[
A2(
$elm$html$Html$p,
$elm$html$Html$a,
_List_fromArray(
[
$elm$html$Html$Attributes$class('navbar-item')
$elm$html$Html$Attributes$class('navbar-item'),
$elm$html$Html$Attributes$href('/')
]),
_List_fromArray(
[
@@ -6804,7 +6829,7 @@ var $author$project$Main$viewHeaderBar = function (model) {
]),
_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)
]);
};
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(
$elm$html$Html$section,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level')
$elm$html$Html$Attributes$class('level is-mobile box')
]),
_Utils_ap(
_List_fromArray(
[
A2(
$elm$html$Html$div,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-left box')
$elm$html$Html$Attributes$class('level-left')
]),
_Utils_ap(
_List_fromArray(
@@ -6914,16 +6977,6 @@ var $author$project$Main$viewPlayerWealth = function (player) {
_List_fromArray(
[
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,
_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(
[
A2(
$elm$html$Html$div,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-right')
]),
_List_fromArray(
[
A2(
$elm$html$Html$div,
@@ -6973,23 +7018,39 @@ var $author$project$Main$viewPlayerWealth = function (player) {
'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) {
return {
body: _List_fromArray(
[
$author$project$Main$viewHeaderBar(model),
$author$project$Main$viewPlayerWealth(model.player),
A2($author$project$Main$viewPlayerBar, model.player, model.state.route),
A2(
$elm$html$Html$section,
$elm$html$Html$article,
_List_fromArray(
[
$elm$html$Html$Attributes$class('container')
$elm$html$Html$Attributes$class('section container')
]),
function () {
var _v0 = model.route;
var _v0 = model.state.route;
switch (_v0.$) {
case 'PlayerChest':
return _List_fromArray(
@@ -7002,15 +7063,7 @@ var $author$project$Main$view = function (model) {
$elm$html$Html$text('Mon Coffre')
])),
$author$project$Main$viewLoot(
function () {
var _v1 = model.loot;
if (_v1.$ === 'Just') {
var i = _v1.a;
return i;
} else {
return _List_Nil;
}
}())
A2($elm$core$Maybe$withDefault, _List_Nil, model.loot))
]);
case 'GroupLoot':
return _List_fromArray(
@@ -7021,7 +7074,9 @@ var $author$project$Main$view = function (model) {
_List_fromArray(
[
$elm$html$Html$text('Coffre de groupe')
]))
])),
$author$project$Main$viewLoot(
A2($elm$core$Maybe$withDefault, _List_Nil, model.groupLoot))
]);
case 'Merchant':
return _List_fromArray(
@@ -7047,6 +7102,7 @@ var $author$project$Main$view = function (model) {
]);
}
}()),
A2($elm$html$Html$hr, _List_Nil, _List_Nil),
A2(
$elm$html$Html$section,
_List_fromArray(

View File

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