|
|
@@ -1,5 +1,6 @@
|
|
|
module Main exposing (..)
|
|
|
|
|
|
+import API
|
|
|
import Browser exposing (Document)
|
|
|
import Card exposing (CardData, CardPerformanceDistributions, calculatePerformanceDistributions, manaCostToSymbol)
|
|
|
import Chart as C
|
|
|
@@ -7,7 +8,7 @@ import Chart.Attributes as CA
|
|
|
import Database
|
|
|
import Deck
|
|
|
import Draft exposing (Draft)
|
|
|
-import Html exposing (Html, a, button, div, img, li, span, text, ul)
|
|
|
+import Html exposing (Html, a, button, div, img, li, p, span, text, ul)
|
|
|
import Html.Attributes exposing (alt, class, classList, disabled, src)
|
|
|
import Html.Events as Events exposing (onClick, onMouseEnter)
|
|
|
import Html.Keyed as Keyed
|
|
|
@@ -30,7 +31,8 @@ main =
|
|
|
|
|
|
|
|
|
type Model
|
|
|
- = Ready ReadyModel
|
|
|
+ = ChooseSet ChooseSetModel
|
|
|
+ | Ready ReadyModel
|
|
|
| Error ErrorModel
|
|
|
|
|
|
|
|
|
@@ -51,6 +53,14 @@ type alias ToolboxAccordion =
|
|
|
{ cmc : Bool, signals : Bool, signalsDelta : Bool, deckList : Bool }
|
|
|
|
|
|
|
|
|
+type alias ChooseSetModel =
|
|
|
+ { draftData : String
|
|
|
+ , cardRatings : String
|
|
|
+ , setData : String
|
|
|
+ , sets : Maybe (List String)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
type alias ReadyModel =
|
|
|
{ draft : Draft
|
|
|
, database : Database.Database
|
|
|
@@ -71,7 +81,34 @@ type alias ErrorModel =
|
|
|
|
|
|
init : { setData : String, draftData : String, cardRatings : String } -> ( Model, Cmd Msg )
|
|
|
init flags =
|
|
|
- case ( Draft.decode flags.draftData, Database.decode flags.setData flags.cardRatings ) of
|
|
|
+ ( ChooseSet
|
|
|
+ { setData = flags.setData
|
|
|
+ , draftData = flags.draftData
|
|
|
+ , cardRatings = flags.cardRatings
|
|
|
+ , sets = Nothing
|
|
|
+ }
|
|
|
+ , API.getSets IOGotSets
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+type Msg
|
|
|
+ = Increment
|
|
|
+ | Decrement
|
|
|
+ | Highlight String
|
|
|
+ | FlipHighlightedCard
|
|
|
+ | SetFocusStat FocusStat
|
|
|
+ | SetDeckProgress DeckProgress
|
|
|
+ | ToggleCMCChart
|
|
|
+ | ToggleSignalsChart
|
|
|
+ | ToggleSignalsDeltaChart
|
|
|
+ | ToggleDeckList
|
|
|
+ | SetDeckSortMethod Deck.DeckSortMethod
|
|
|
+ | IOGotSets (Result String (List String))
|
|
|
+
|
|
|
+
|
|
|
+startDraft : ChooseSetModel -> ( Model, Cmd Msg )
|
|
|
+startDraft initFlags =
|
|
|
+ case ( Draft.decode initFlags.draftData, Database.decode initFlags.setData initFlags.cardRatings ) of
|
|
|
( Ok draftData, Ok database ) ->
|
|
|
( Ready
|
|
|
{ draft = draftData
|
|
|
@@ -102,23 +139,20 @@ init flags =
|
|
|
( Error { error = "Error decoding draft data: " ++ draftError ++ ", set data: " ++ databaseError }, Cmd.none )
|
|
|
|
|
|
|
|
|
-type Msg
|
|
|
- = Increment
|
|
|
- | Decrement
|
|
|
- | Highlight String
|
|
|
- | FlipHighlightedCard
|
|
|
- | SetFocusStat FocusStat
|
|
|
- | SetDeckProgress DeckProgress
|
|
|
- | ToggleCMCChart
|
|
|
- | ToggleSignalsChart
|
|
|
- | ToggleSignalsDeltaChart
|
|
|
- | ToggleDeckList
|
|
|
- | SetDeckSortMethod Deck.DeckSortMethod
|
|
|
-
|
|
|
-
|
|
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
|
update msg model =
|
|
|
case model of
|
|
|
+ ChooseSet mdl ->
|
|
|
+ case msg of
|
|
|
+ IOGotSets (Ok sets) ->
|
|
|
+ ( ChooseSet { mdl | sets = Just sets }, Cmd.none )
|
|
|
+
|
|
|
+ IOGotSets (Err e) ->
|
|
|
+ ( Error { error = "Error fetching sets (" ++ e ++ ")" }, Cmd.none )
|
|
|
+
|
|
|
+ _ ->
|
|
|
+ ( ChooseSet mdl, Cmd.none )
|
|
|
+
|
|
|
Ready mdl ->
|
|
|
case msg of
|
|
|
Increment ->
|
|
|
@@ -176,6 +210,9 @@ update msg model =
|
|
|
SetDeckSortMethod method ->
|
|
|
( Ready { mdl | deckSortOrder = method }, Cmd.none )
|
|
|
|
|
|
+ IOGotSets _ ->
|
|
|
+ ( Ready mdl, Cmd.none )
|
|
|
+
|
|
|
Error mdl ->
|
|
|
( Error mdl, Cmd.none )
|
|
|
|
|
|
@@ -185,6 +222,9 @@ view model =
|
|
|
{ title = "Drafter"
|
|
|
, body =
|
|
|
[ case model of
|
|
|
+ ChooseSet mdl ->
|
|
|
+ viewChooseSet mdl
|
|
|
+
|
|
|
Ready mdl ->
|
|
|
viewReady mdl
|
|
|
|
|
|
@@ -194,6 +234,20 @@ view model =
|
|
|
}
|
|
|
|
|
|
|
|
|
+viewChooseSet : ChooseSetModel -> Html Msg
|
|
|
+viewChooseSet model =
|
|
|
+ div [ class "w-full h-full bg-slate-100 flex justify-center items-center" ]
|
|
|
+ [ div [ class "max-w-2xl max-h-2xl" ]
|
|
|
+ [ case model.sets of
|
|
|
+ Just sets ->
|
|
|
+ ul [] (List.map (\s -> li [] [ text s ]) sets)
|
|
|
+
|
|
|
+ Nothing ->
|
|
|
+ p [] [ text "Loading..." ]
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+
|
|
|
+
|
|
|
viewReady : ReadyModel -> Html Msg
|
|
|
viewReady model =
|
|
|
div [ class "grid grid-cols-12 gap-6 h-full bg-slate-100" ]
|