adds two renderers for buy/sell prices
This commit is contained in:
@@ -188,17 +188,17 @@ update msg model =
|
|||||||
( View <| Table.renderRowLevel renderItem (\_ -> []), Cmd.none )
|
( View <| Table.renderRowLevel renderItem (\_ -> []), Cmd.none )
|
||||||
|
|
||||||
IntoBuy ->
|
IntoBuy ->
|
||||||
( Buy <| Selection.init Nothing True, Cmd.none )
|
( Buy <| Selection.init Nothing (Just .base_price), Cmd.none )
|
||||||
|
|
||||||
IntoSell ->
|
IntoSell ->
|
||||||
( Sell <| Selection.init Nothing True, Cmd.none )
|
( Sell <| Selection.init Nothing (Just (\i -> i.base_price // 2)), Cmd.none )
|
||||||
|
|
||||||
IntoClaim claims ->
|
IntoClaim claims ->
|
||||||
let
|
let
|
||||||
initialSelection =
|
initialSelection =
|
||||||
List.map .loot_id claims
|
List.map .loot_id claims
|
||||||
in
|
in
|
||||||
( Claim <| Selection.init (Just initialSelection) False, Cmd.none )
|
( Claim <| Selection.init (Just initialSelection) Nothing, Cmd.none )
|
||||||
|
|
||||||
IntoAdd ->
|
IntoAdd ->
|
||||||
( New NewFromInventory.init, Cmd.none )
|
( New NewFromInventory.init, Cmd.none )
|
||||||
|
|||||||
@@ -15,14 +15,18 @@ type alias Selection =
|
|||||||
|
|
||||||
type Data a
|
type Data a
|
||||||
= NoData
|
= NoData
|
||||||
| Data (Dict Int a)
|
| Data (Dict Int a) PriceExtractor
|
||||||
|
|
||||||
|
|
||||||
|
type alias PriceExtractor =
|
||||||
|
Item -> Int
|
||||||
|
|
||||||
|
|
||||||
type Model
|
type Model
|
||||||
= Model Selection (Data Int)
|
= Model Selection (Data Int)
|
||||||
|
|
||||||
|
|
||||||
init : Maybe (List Int) -> Bool -> Model
|
init : Maybe (List Int) -> Maybe PriceExtractor -> Model
|
||||||
init maybeInitial hasData =
|
init maybeInitial hasData =
|
||||||
Model
|
Model
|
||||||
(case maybeInitial of
|
(case maybeInitial of
|
||||||
@@ -33,10 +37,10 @@ init maybeInitial hasData =
|
|||||||
Set.empty
|
Set.empty
|
||||||
)
|
)
|
||||||
(case hasData of
|
(case hasData of
|
||||||
True ->
|
Just getPrice ->
|
||||||
Data Dict.empty
|
Data Dict.empty getPrice
|
||||||
|
|
||||||
False ->
|
Nothing ->
|
||||||
NoData
|
NoData
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,12 +53,16 @@ view (Model selection data) loot =
|
|||||||
|
|
||||||
renderRight item =
|
renderRight item =
|
||||||
case data of
|
case data of
|
||||||
Data inner ->
|
Data inner getPrice ->
|
||||||
let
|
let
|
||||||
maybeMod =
|
maybeMod =
|
||||||
Dict.get item.id inner
|
Dict.get item.id inner
|
||||||
in
|
in
|
||||||
renderItemWithPrice .base_price isSelected maybeMod item
|
renderItemWithPrice
|
||||||
|
(getPrice item)
|
||||||
|
(isSelected item)
|
||||||
|
maybeMod
|
||||||
|
item.id
|
||||||
|
|
||||||
NoData ->
|
NoData ->
|
||||||
[]
|
[]
|
||||||
@@ -69,12 +77,13 @@ view (Model selection data) loot =
|
|||||||
loot
|
loot
|
||||||
|
|
||||||
|
|
||||||
renderItemWithPrice toPrice isSelected maybeMod item =
|
renderItemWithPrice : Int -> Bool -> Maybe Int -> Int -> List (Html Msg)
|
||||||
|
renderItemWithPrice price isSelected maybeMod itemId =
|
||||||
[ viewPriceWithModApplied
|
[ viewPriceWithModApplied
|
||||||
(Maybe.map (\i -> toFloatingMod i) maybeMod)
|
(Maybe.map (\i -> toFloatingMod i) maybeMod)
|
||||||
(toFloat item.base_price)
|
(toFloat price)
|
||||||
, if isSelected item then
|
, if isSelected then
|
||||||
viewPriceModifier item.id <|
|
viewPriceModifier itemId <|
|
||||||
case maybeMod of
|
case maybeMod of
|
||||||
Just mod ->
|
Just mod ->
|
||||||
String.fromInt mod
|
String.fromInt mod
|
||||||
@@ -143,7 +152,7 @@ selected (Model selection data) loot =
|
|||||||
modifiers : Model -> Loot -> List (Maybe Float)
|
modifiers : Model -> Loot -> List (Maybe Float)
|
||||||
modifiers (Model selection data) items =
|
modifiers (Model selection data) items =
|
||||||
case data of
|
case data of
|
||||||
Data inner ->
|
Data inner _ ->
|
||||||
List.map
|
List.map
|
||||||
(\item ->
|
(\item ->
|
||||||
Dict.get item.id inner
|
Dict.get item.id inner
|
||||||
@@ -166,11 +175,19 @@ totalSelectedPrice model loot =
|
|||||||
(Model selection data) =
|
(Model selection data) =
|
||||||
model
|
model
|
||||||
|
|
||||||
|
getPrice =
|
||||||
|
case data of
|
||||||
|
Data _ getPrice_ ->
|
||||||
|
getPrice_
|
||||||
|
|
||||||
|
NoData ->
|
||||||
|
.base_price
|
||||||
|
|
||||||
modifier item =
|
modifier item =
|
||||||
Maybe.withDefault 1.0 <|
|
Maybe.withDefault 1.0 <|
|
||||||
Maybe.map toFloatingMod <|
|
Maybe.map toFloatingMod <|
|
||||||
case data of
|
case data of
|
||||||
Data inner ->
|
Data inner _ ->
|
||||||
Dict.get item.id inner
|
Dict.get item.id inner
|
||||||
|
|
||||||
NoData ->
|
NoData ->
|
||||||
@@ -178,7 +195,7 @@ totalSelectedPrice model loot =
|
|||||||
in
|
in
|
||||||
Just <|
|
Just <|
|
||||||
List.foldl (+) 0.0 <|
|
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
|
itemInSelection : Selection -> Item -> Bool
|
||||||
@@ -215,7 +232,7 @@ update msg (Model selection data) =
|
|||||||
PriceModifierChanged id value ->
|
PriceModifierChanged id value ->
|
||||||
( Model selection <|
|
( Model selection <|
|
||||||
case data of
|
case data of
|
||||||
Data inner ->
|
Data inner getPrice ->
|
||||||
Data
|
Data
|
||||||
(Dict.insert
|
(Dict.insert
|
||||||
id
|
id
|
||||||
@@ -228,6 +245,7 @@ update msg (Model selection data) =
|
|||||||
)
|
)
|
||||||
inner
|
inner
|
||||||
)
|
)
|
||||||
|
getPrice
|
||||||
|
|
||||||
NoData ->
|
NoData ->
|
||||||
data
|
data
|
||||||
|
|||||||
Reference in New Issue
Block a user