init repo
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fontawesome
|
||||||
|
elm-stuff
|
||||||
10832
css/bulma.css
vendored
Normal file
10832
css/bulma.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
css/bulma.css.map
Normal file
1
css/bulma.css.map
Normal file
File diff suppressed because one or more lines are too long
1
css/bulma.min.css
vendored
Normal file
1
css/bulma.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
27
elm.json
Normal file
27
elm.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"type": "application",
|
||||||
|
"source-directories": [
|
||||||
|
"src"
|
||||||
|
],
|
||||||
|
"elm-version": "0.19.1",
|
||||||
|
"dependencies": {
|
||||||
|
"direct": {
|
||||||
|
"elm/browser": "1.0.1",
|
||||||
|
"elm/core": "1.0.2",
|
||||||
|
"elm/html": "1.0.0",
|
||||||
|
"elm/http": "2.0.0",
|
||||||
|
"elm/json": "1.1.3",
|
||||||
|
"elm/url": "1.0.0"
|
||||||
|
},
|
||||||
|
"indirect": {
|
||||||
|
"elm/bytes": "1.0.8",
|
||||||
|
"elm/file": "1.0.5",
|
||||||
|
"elm/time": "1.0.0",
|
||||||
|
"elm/virtual-dom": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test-dependencies": {
|
||||||
|
"direct": {},
|
||||||
|
"indirect": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
26
index.html
Normal file
26
index.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
|
<link rel="icon" href="/favicon.ico">
|
||||||
|
<link rel="stylesheet" href="/css/bulma.css">
|
||||||
|
<title>Loot-a-Lot !</title>
|
||||||
|
<script src="main.js"></script>
|
||||||
|
<script defer src="fontawesome/js/all.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<!-- built files will be auto injected -->
|
||||||
|
<noscript>
|
||||||
|
<strong>We're sorry but lootalot_front doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||||
|
</noscript>
|
||||||
|
<script>
|
||||||
|
var app = Elm.Main.init({
|
||||||
|
node: document.getElementById('app'),
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
219
src/Main.elm
Normal file
219
src/Main.elm
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
module Main exposing (..)
|
||||||
|
|
||||||
|
import Browser
|
||||||
|
import Browser.Navigation as Nav
|
||||||
|
import Url
|
||||||
|
import Html exposing (..)
|
||||||
|
import Html.Attributes exposing (..)
|
||||||
|
import Html.Events exposing (..)
|
||||||
|
import Http
|
||||||
|
import Json.Decode exposing (Decoder, field, string, int)
|
||||||
|
-- Main
|
||||||
|
|
||||||
|
main : Program () Model Msg
|
||||||
|
main =
|
||||||
|
Browser.application
|
||||||
|
{ init = init
|
||||||
|
, view = view
|
||||||
|
, update = update
|
||||||
|
, subscriptions = subscriptions
|
||||||
|
, onUrlChange = UrlChanged
|
||||||
|
, onUrlRequest = LinkClicked
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Model
|
||||||
|
|
||||||
|
type alias Model =
|
||||||
|
{ key : Nav.Key
|
||||||
|
, url : Url.Url
|
||||||
|
, player: Player
|
||||||
|
, error: String
|
||||||
|
}
|
||||||
|
|
||||||
|
init : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
|
||||||
|
init flags url key =
|
||||||
|
( Model key url blankPlayer "", (fetchPlayer 0))
|
||||||
|
|
||||||
|
|
||||||
|
-- PLAYER
|
||||||
|
--
|
||||||
|
type alias Player =
|
||||||
|
{ name: String
|
||||||
|
, debt: Int
|
||||||
|
, wealth: Wealth
|
||||||
|
}
|
||||||
|
|
||||||
|
blankPlayer =
|
||||||
|
Player "Loading" 100 (Wealth 0 0 0 0)
|
||||||
|
|
||||||
|
type alias Wealth =
|
||||||
|
{ cp: Int
|
||||||
|
, sp: Int
|
||||||
|
, gp: Int
|
||||||
|
, pp: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchPlayer : Int -> Cmd Msg
|
||||||
|
fetchPlayer id =
|
||||||
|
Http.get
|
||||||
|
{ url = "http://localhost:8088/api/players/" ++ (String.fromInt id) ++ "/"
|
||||||
|
, expect = Http.expectJson GotPlayer playerDecoder
|
||||||
|
}
|
||||||
|
|
||||||
|
playerDecoder : Decoder Player
|
||||||
|
playerDecoder =
|
||||||
|
Json.Decode.map3 Player
|
||||||
|
(field "value" (field "name" string))
|
||||||
|
(field "value" (field "debt" int))
|
||||||
|
(Json.Decode.map4 Wealth
|
||||||
|
(field "value" (field "cp" int))
|
||||||
|
(field "value" (field "sp" int))
|
||||||
|
(field "value" (field "gp" int))
|
||||||
|
(field "value" (field "pp" int)))
|
||||||
|
|
||||||
|
-- UPDATE
|
||||||
|
|
||||||
|
type Msg
|
||||||
|
= LinkClicked Browser.UrlRequest
|
||||||
|
| UrlChanged Url.Url
|
||||||
|
| DebugSwitchPlayer Int
|
||||||
|
| GotPlayer (Result Http.Error Player)
|
||||||
|
|
||||||
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
|
update msg model =
|
||||||
|
case msg of
|
||||||
|
LinkClicked urlRequest ->
|
||||||
|
case urlRequest of
|
||||||
|
Browser.Internal url ->
|
||||||
|
( model, Nav.pushUrl model.key (Url.toString url) )
|
||||||
|
--( model, Cmd.none )
|
||||||
|
|
||||||
|
Browser.External href ->
|
||||||
|
( { model | error = "Invalid request '" ++ href ++ "'" }, Cmd.none )
|
||||||
|
|
||||||
|
UrlChanged url ->
|
||||||
|
( { model | url = url }
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
|
||||||
|
DebugSwitchPlayer id ->
|
||||||
|
( model, fetchPlayer id)
|
||||||
|
|
||||||
|
GotPlayer result ->
|
||||||
|
case result of
|
||||||
|
Ok player ->
|
||||||
|
( { model | player = player }
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
Err error -> ( { model | error = (printError error) }, Cmd.none )
|
||||||
|
|
||||||
|
-- ERRORS
|
||||||
|
|
||||||
|
printError : Http.Error -> String
|
||||||
|
printError error =
|
||||||
|
case error of
|
||||||
|
Http.NetworkError -> "Le serveur ne répond pas"
|
||||||
|
_ -> "Erreur inconnue"
|
||||||
|
|
||||||
|
-- SUBSCRIPTIONS
|
||||||
|
--
|
||||||
|
subscriptions : Model -> Sub Msg
|
||||||
|
subscriptions _ =
|
||||||
|
Sub.none
|
||||||
|
|
||||||
|
|
||||||
|
-- VIEW
|
||||||
|
--
|
||||||
|
|
||||||
|
view : Model -> Browser.Document Msg
|
||||||
|
view model =
|
||||||
|
{ title = "Loot-a-lot in ELM"
|
||||||
|
, body =
|
||||||
|
[ viewHeaderBar model
|
||||||
|
, viewPlayerWealth model.player
|
||||||
|
, section []
|
||||||
|
[ text "Loot-a-lot" ]
|
||||||
|
, p [] [ text "Start using it !" ]
|
||||||
|
, viewDebugSection model
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
-- DEBUG SECTION
|
||||||
|
|
||||||
|
viewDebugSection model =
|
||||||
|
div [class "panel is-danger"]
|
||||||
|
[ p [class "panel-heading"] [text "Debug"]
|
||||||
|
, debugSwitchPlayers
|
||||||
|
, p [class "panel-block"] [text ("URL :" ++ Url.toString model.url)]
|
||||||
|
, p [class "panel-block has-text-danger"] [text model.error]
|
||||||
|
]
|
||||||
|
|
||||||
|
debugSwitchPlayers : Html Msg
|
||||||
|
debugSwitchPlayers =
|
||||||
|
div [ class "panel-tabs" ]
|
||||||
|
[ a [ onClick (DebugSwitchPlayer 0) ] [text "Groupe"]
|
||||||
|
, a [ onClick (DebugSwitchPlayer 1) ] [text "Lomion"]
|
||||||
|
, a [ onClick (DebugSwitchPlayer 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"]
|
||||||
|
[ text model.player.name ]
|
||||||
|
|
||||||
|
, a [class "navbar-burger is-active"]
|
||||||
|
[ span [attribute "aria-hidden" "true"] []
|
||||||
|
, span [attribute "aria-hidden" "true"] []
|
||||||
|
, span [attribute "aria-hidden" "true"] []
|
||||||
|
]
|
||||||
|
]
|
||||||
|
, 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"]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
-- WEALTH
|
||||||
|
--
|
||||||
|
|
||||||
|
viewPlayerWealth : Player -> Html Msg
|
||||||
|
viewPlayerWealth player =
|
||||||
|
section [ class "level" ]
|
||||||
|
([div [class "level-left box"]
|
||||||
|
([div [ class "level-item" ]
|
||||||
|
[ p [class "is-size-3"] [text "Argent"]
|
||||||
|
, 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"]
|
||||||
|
[div [class "level-item"]
|
||||||
|
[p [class "heading is-size-4 has-text-danger"]
|
||||||
|
[text ("Dette : " ++ (String.fromInt player.debt) ++ "po")]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
))
|
||||||
|
|
||||||
|
showWealth : Wealth -> List (Html Msg)
|
||||||
|
showWealth wealth =
|
||||||
|
[ showWealthField "pp" wealth.pp
|
||||||
|
, showWealthField "gp" wealth.gp
|
||||||
|
, showWealthField "sp" wealth.sp
|
||||||
|
, showWealthField "cp" wealth.cp
|
||||||
|
]
|
||||||
|
|
||||||
|
showWealthField : String -> Int -> Html Msg
|
||||||
|
showWealthField name value =
|
||||||
|
div [ class "level-item" ]
|
||||||
|
[ p [ class "is-size-4"] [text (String.fromInt value)]
|
||||||
|
, p [class "heading"] [text name]
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user