implement kit4nkit switch (including UI button)
4 files changed, 63 insertions(+), 20 deletions(-)

M src/Field.elm
M src/Main.elm
M src/Round.elm
M src/Types.elm
M src/Field.elm +11 -3
@@ 256,9 256,17 @@ inflowToW2OrW0 field =
     { field | w2 = w2New, w0 = w0New, inflow = [] }
 
 
-applyStep : ( FieldStep, FieldStep ) -> Model -> Model
-applyStep ( k, n ) model =
-    case ( k, n ) of
+applyStep : KITForNKIT -> ( FieldStep, FieldStep ) -> Model -> Model
+applyStep kitForNkit ( k, n ) model =
+    let
+        nkitFunction =
+            if kitForNkit then
+                k
+
+            else
+                n
+    in
+    case ( k, nkitFunction ) of
         ( Just x, Just y ) ->
             { model | kit = y model.kit, nkit = x model.nkit }
 

          
M src/Main.elm +31 -9
@@ 120,20 120,31 @@ update msg model =
 
                 S2 ->
                     -- S2 does S3
-                    ( chain <| applyStep ( Just <| conditionalScrap model.scrapLimit >> justDoneToDone >> wipToJustDone model.round, Just <| conditionalScrap model.scrapLimit >> justDoneToDone >> wipToJustDone model.round ) model, Cmd.none )
+                    let
+                        f =
+                            conditionalScrap model.scrapLimit >> justDoneToDone >> wipToJustDone model.round
+                    in
+                    ( chain <|
+                        applyStep model.kitForNkit
+                            ( Just f
+                            , Just f
+                            )
+                            model
+                    , Cmd.none
+                    )
 
                 -- FIXME: updatewaiting moves justDone to Done, which it shouldn't
                 S3 ->
-                    ( chain <| applyStep ( Just updateWaiting, Just updateWaiting ) model, Cmd.none )
+                    ( chain <| applyStep model.kitForNkit ( Just updateWaiting, Just updateWaiting ) model, Cmd.none )
 
                 S4 ->
-                    ( chain <| applyStep ( Nothing, Just inflowToW2OrW0 ) model, Cmd.none )
+                    ( chain <| applyStep model.kitForNkit ( Nothing, Just inflowToW2OrW0 ) model, Cmd.none )
 
                 S5 ->
-                    ( chain <| applyStep ( Just inflowToWip, Just <| w0ToWip ) model, Cmd.none )
+                    ( chain <| applyStep model.kitForNkit ( Just inflowToWip, Just <| w0ToWip ) model, Cmd.none )
 
                 S6 ->
-                    ( chain <| applyStep ( Just incompleteReqsFromWipToW2, Nothing ) model, Cmd.none )
+                    ( chain <| applyStep model.kitForNkit ( Just incompleteReqsFromWipToW2, Nothing ) model, Cmd.none )
 
                 S7 ->
                     let

          
@@ 141,7 152,7 @@ update msg model =
                         completeRound m =
                             { m | stats = trackStats m.round model.kit model.nkit m.stats, step = lastStepOfRound }
                     in
-                    ( completeRound <| applyStep ( Just fifo, Nothing ) { model | finishRound = False }, Cmd.none )
+                    ( completeRound <| applyStep model.kitForNkit ( Just fifo, Nothing ) { model | finishRound = False }, Cmd.none )
 
         SetReworksStart ->
             ( model, setReworksCmd model )

          
@@ 185,10 196,13 @@ update msg model =
 
         ChangedScrapLimit x ->
             if emptyField x then
-                ( applyStep ( Just noScrap, Just noScrap ) <| { model | scrapLimit = Nothing }, Cmd.none )
+                ( applyStep model.kitForNkit ( Just noScrap, Just noScrap ) <| { model | scrapLimit = Nothing }, Cmd.none )
 
             else
-                defaultToCurrentModel <| Maybe.map (\y -> applyStep ( Just <| identifyScrap y, Just <| identifyScrap y ) <| { model | scrapLimit = Just y }) <| validIntInput 0 500 x
+                defaultToCurrentModel <| Maybe.map (\y -> applyStep model.kitForNkit ( Just <| identifyScrap y, Just <| identifyScrap y ) <| { model | scrapLimit = Just y }) <| validIntInput 0 500 x
+
+        SwapKITForNKIT ->
+            ( { model | kitForNkit = not model.kitForNkit }, Cmd.none )
 
         SwapAutoPlay ->
             ( { model | autoPlay = not model.autoPlay }, Cmd.none )

          
@@ 415,6 429,9 @@ view model =
             else
                 [ text t1, el [ Font.bold ] <| text t2 ]
 
+        swapKITForNKITButton =
+            button [ centerX, width fill ] { onPress = Just SwapKITForNKIT, label = row [ spacing 5, width fill, spaceEvenly ] <| padXBy 5 <| highlightEnabled model.kitForNkit "ON" "OFF" }
+
         autoPlayButton =
             button [ centerX, width fill ] { onPress = Just SwapAutoPlay, label = row [ spacing 5, width fill, spaceEvenly ] <| padXBy 5 <| highlightEnabled model.autoPlay "ON" "OFF" }
 

          
@@ 431,13 448,18 @@ view model =
 
         playInterface =
             row [ spacing 10, padding 13, Font.size 12, width fill ]
-                [ autoPlayer
+                [ column [ width fill, height fill, spacing 7 ] [ autoPlayer, kitForNkit ]
                 , reworkProbInterface
                 , scrapLimitInterface
 
                 --, stopThresholds
                 ]
 
+        kitForNkit =
+            row [ Font.size 12, spacing 10, width fill ]
+                [ column [ spacing 5, Border.width 1, padding 5 ] [ text "KIT4NKIT", swapKITForNKITButton ]
+                ]
+
         autoPlayer =
             row [ Font.size 12, spacing 10, width fill ]
                 [ column [ spacing 5, Border.width 1, padding 5 ] [ text "AutoPlay", autoPlayButton ]

          
M src/Round.elm +14 -6
@@ 42,9 42,17 @@ fieldRound f r p l field =
     setReworksFieldWrapper p field2 |> Random.andThen (\x -> Random.constant (x |> f r l))
 
 
-bothFieldsRound : Round -> ProbPerRound -> Maybe ScrapLimit -> ( Field, Field, Stats ) -> Random.Generator ( Field, Field, Stats )
-bothFieldsRound r p l ( kf, nkf, stats ) =
-    Random.map (\( a, b ) -> ( a, b, trackStats (r + 1) a b stats )) <| Random.map2 Tuple.pair (fieldRound kitAfterReworks r p l kf) (fieldRound nkitAfterReworks r p l nkf)
+bothFieldsRound : KITForNKIT -> Round -> ProbPerRound -> Maybe ScrapLimit -> ( Field, Field, Stats ) -> Random.Generator ( Field, Field, Stats )
+bothFieldsRound kitForNkit r p l ( kf, nkf, stats ) =
+    let
+        nkitFunction =
+            if kitForNkit then
+                kitAfterReworks
+
+            else
+                nkitAfterReworks
+    in
+    Random.map (\( a, b ) -> ( a, b, trackStats (r + 1) a b stats )) <| Random.map2 Tuple.pair (fieldRound kitAfterReworks r p l kf) (fieldRound nkitFunction r p l nkf)
 
 
 

          
@@ 74,12 82,12 @@ nkitAfterReworks r l =
 
 fullRoundCmd : Model -> Cmd Msg
 fullRoundCmd model =
-    Random.generate FullRoundDone <| bothFieldsRound model.round model.reworkProbPerRound model.scrapLimit ( model.kit, model.nkit, model.stats )
+    Random.generate FullRoundDone <| bothFieldsRound model.kitForNkit model.round model.reworkProbPerRound model.scrapLimit ( model.kit, model.nkit, model.stats )
 
 
 fullRoundsCmd : Int -> Model -> Cmd Msg
 fullRoundsCmd n model =
-    Random.generate (FullRoundsDone (n - 1)) <| bothFieldsRound model.round model.reworkProbPerRound model.scrapLimit ( model.kit, model.nkit, model.stats )
+    Random.generate (FullRoundsDone (n - 1)) <| bothFieldsRound model.kitForNkit model.round model.reworkProbPerRound model.scrapLimit ( model.kit, model.nkit, model.stats )
 
 
 fullRoundsOnceCmd : Int -> Model -> Cmd Msg

          
@@ 87,7 95,7 @@ fullRoundsOnceCmd n model =
     let
         go togo currentRound p gen =
             if togo > 0 then
-                gen |> Random.andThen (\( kf2, nkf2, stats ) -> go (togo - 1) (currentRound + 1) p <| bothFieldsRound currentRound p model.scrapLimit ( kf2, nkf2, stats ))
+                gen |> Random.andThen (\( kf2, nkf2, stats ) -> go (togo - 1) (currentRound + 1) p <| bothFieldsRound model.kitForNkit currentRound p model.scrapLimit ( kf2, nkf2, stats ))
 
             else
                 gen

          
M src/Types.elm +7 -2
@@ 8,7 8,7 @@ import Time
 
 
 type alias Model =
-    { viewport : Maybe Dom.Viewport, kit : Field, nkit : Field, round : Round, step : StepVariant, finishRound : Bool, roundEmpty : Bool, stepEmpty : Bool, stopRoundEmpty : Bool, autoPlay : Bool, incrementMode : AutoPlayMode, reworkProbPerRound : Float, reworkProbPerRoundDot : Bool, reworkProbEmpty : Bool, scrapLimit : Maybe ScrapLimit, cyclesPerIncrement : Int, cyclesPerIncrementEmpty : Bool, chart0 : ChartingModel, chart1 : ChartingModel, chart3 : ChartingModel, chart5 : ChartingModel, stats : Stats }
+    { viewport : Maybe Dom.Viewport, kit : Field, nkit : Field, round : Round, step : StepVariant, kitForNkit : Bool, finishRound : Bool, roundEmpty : Bool, stepEmpty : Bool, stopRoundEmpty : Bool, autoPlay : Bool, incrementMode : AutoPlayMode, reworkProbPerRound : Float, reworkProbPerRoundDot : Bool, reworkProbEmpty : Bool, scrapLimit : Maybe ScrapLimit, cyclesPerIncrement : Int, cyclesPerIncrementEmpty : Bool, chart0 : ChartingModel, chart1 : ChartingModel, chart3 : ChartingModel, chart5 : ChartingModel, stats : Stats }
 
 
 initChart : ChartType -> ChartingModel

          
@@ 38,7 38,7 @@ chart5 =
 
 initModel : Model
 initModel =
-    { viewport = Nothing, nkit = initField, kit = initField, round = 0, step = S7, finishRound = False, roundEmpty = False, stepEmpty = False, stopRoundEmpty = False, autoPlay = False, incrementMode = RoundMode, reworkProbPerRound = 0.5, reworkProbPerRoundDot = False, reworkProbEmpty = False, scrapLimit = Nothing, cyclesPerIncrement = 1, cyclesPerIncrementEmpty = False, chart0 = chart0, chart1 = chart1, chart3 = chart3, chart5 = chart5, stats = { flowtimesSinglesNKIT = [], flowtimesSinglesKIT = [], justDonesNKIT = [], justDonesKIT = [], doneData = [] } }
+    { viewport = Nothing, nkit = initField, kit = initField, round = 0, step = S7, kitForNkit = False, finishRound = False, roundEmpty = False, stepEmpty = False, stopRoundEmpty = False, autoPlay = False, incrementMode = RoundMode, reworkProbPerRound = 0.5, reworkProbPerRoundDot = False, reworkProbEmpty = False, scrapLimit = Nothing, cyclesPerIncrement = 1, cyclesPerIncrementEmpty = False, chart0 = chart0, chart1 = chart1, chart3 = chart3, chart5 = chart5, stats = { flowtimesSinglesNKIT = [], flowtimesSinglesKIT = [], justDonesNKIT = [], justDonesKIT = [], doneData = [] } }
 
 
 type AutoPlayMode

          
@@ 46,6 46,10 @@ type AutoPlayMode
     | StepMode
 
 
+type alias KITForNKIT =
+    Bool
+
+
 type Msg
     = ReceivedViewport Dom.Viewport
     | GotNewWidth

          
@@ 58,6 62,7 @@ type Msg
     | ChangedScrapLimit String
     | ChangedCyclesPerIncrement String
     | ChangedStep String
+    | SwapKITForNKIT
     | SwapAutoPlay
     | SwapAutoPlayMode
     | SwapScrapLimit