adds two renderers for buy/sell prices

This commit is contained in:
2019-12-08 14:55:18 +01:00
parent b0ac8846fc
commit 5ec59f8a6d
2 changed files with 36 additions and 18 deletions

View File

@@ -15,14 +15,18 @@ type alias Selection =
type Data a
= NoData
| Data (Dict Int a)
| Data (Dict Int a) PriceExtractor
type alias PriceExtractor =
Item -> Int
type Model
= Model Selection (Data Int)
init : Maybe (List Int) -> Bool -> Model
init : Maybe (List Int) -> Maybe PriceExtractor -> Model
init maybeInitial hasData =
Model
(case maybeInitial of
@@ -33,10 +37,10 @@ init maybeInitial hasData =
Set.empty
)
(case hasData of
True ->
Data Dict.empty
Just getPrice ->
Data Dict.empty getPrice
False ->
Nothing ->
NoData
)
@@ -49,12 +53,16 @@ view (Model selection data) loot =
renderRight item =
case data of
Data inner ->
Data inner getPrice ->
let
maybeMod =
Dict.get item.id inner
in
renderItemWithPrice .base_price isSelected maybeMod item
renderItemWithPrice
(getPrice item)
(isSelected item)
maybeMod
item.id
NoData ->
[]
@@ -69,12 +77,13 @@ view (Model selection data) loot =
loot
renderItemWithPrice toPrice isSelected maybeMod item =
renderItemWithPrice : Int -> Bool -> Maybe Int -> Int -> List (Html Msg)
renderItemWithPrice price isSelected maybeMod itemId =
[ viewPriceWithModApplied
(Maybe.map (\i -> toFloatingMod i) maybeMod)
(toFloat item.base_price)
, if isSelected item then
viewPriceModifier item.id <|
(toFloat price)
, if isSelected then
viewPriceModifier itemId <|
case maybeMod of
Just mod ->
String.fromInt mod
@@ -143,7 +152,7 @@ selected (Model selection data) loot =
modifiers : Model -> Loot -> List (Maybe Float)
modifiers (Model selection data) items =
case data of
Data inner ->
Data inner _ ->
List.map
(\item ->
Dict.get item.id inner
@@ -166,11 +175,19 @@ totalSelectedPrice model loot =
(Model selection data) =
model
getPrice =
case data of
Data _ getPrice_ ->
getPrice_
NoData ->
.base_price
modifier item =
Maybe.withDefault 1.0 <|
Maybe.map toFloatingMod <|
case data of
Data inner ->
Data inner _ ->
Dict.get item.id inner
NoData ->
@@ -178,7 +195,7 @@ totalSelectedPrice model loot =
in
Just <|
List.foldl (+) 0.0 <|
List.map (\item -> toFloat item.base_price * modifier item) items
List.map (\item -> toFloat (getPrice item) * modifier item) items
itemInSelection : Selection -> Item -> Bool
@@ -215,7 +232,7 @@ update msg (Model selection data) =
PriceModifierChanged id value ->
( Model selection <|
case data of
Data inner ->
Data inner getPrice ->
Data
(Dict.insert
id
@@ -228,6 +245,7 @@ update msg (Model selection data) =
)
inner
)
getPrice
NoData ->
data