Commit bf8ae6cf authored by Thorsten Wißmann's avatar Thorsten Wißmann 🐧
Browse files

Force-Finish car motion before smv-step

parent e9fe9a47
......@@ -39,13 +39,9 @@ $ elm repl
* Highlight the next SMV step better
* Call .scrollIntoView() on the focused trace line
* What's wrong with data_422/256.sol?
* Must one ignore the last move command? See data_422/170.sol, data_422/256.sol?
* Force-finish animation on Smv step.
* show shunt names in the model
......@@ -99,6 +99,11 @@ targetPlace car =
Resting x -> x
Moving mf -> mf.final_point
finishMotion : Carriage -> Carriage
finishMotion car =
{ car | motion = Resting <| targetPlace car }
setSelected : Bool -> Carriage -> Carriage
setSelected selected c =
let f = c.flags
......
......@@ -150,6 +150,7 @@ update msg model =
case (Array.get model.traceline_idx (Array.fromList trace)) of
Just line ->
model
|> updateRails (RailPuzzle.update RailPuzzle.finishAnimation)
|> runTraceLine line
|> nextTraceCommand 1
|> (\m ->
......@@ -161,6 +162,10 @@ update msg model =
Nothing ->
(model, Cmd.none)
updateRails : (RailPuzzle.Model -> RailPuzzle.Model) -> Model -> Model
updateRails updater m =
{ m | rails = updater m.rails }
nextTraceCommand : Int -> Model -> Model
nextTraceCommand delta model =
case (model.validated_trace) of
......
......@@ -3,6 +3,7 @@ module RailPuzzle exposing
, Msg, init, update, subscriptions, view
, railTree , carPositions , updateMoveCar
, setQuery , getQuery
, finishAnimation
)
-- The actual state of the Puzzle
......@@ -55,6 +56,7 @@ type Msg =
| CarMove Int RT.Path -- Move car with idx to path
| CarMoveTime Int RT.Path Time -- same after having requested the time
| AnimationStep Time
| FinishAnimation -- force finish all the car animations
init : List RT.Path -> RailTree (Has RT.Hint ()) (Has RT.Angles ()) -> Model
init car_positions rail_net =
......@@ -95,6 +97,9 @@ setQuery query model =
getQuery : Model -> List Int
getQuery = (.query)
finishAnimation : Msg
finishAnimation = FinishAnimation
arrayUpdate : Int -> (a -> a) -> (Array a -> Array a)
arrayUpdate idx updater array =
case Array.get idx array of
......@@ -192,6 +197,10 @@ update msg m =
<| Array.map (C.animationStep m.rt now)
<< Array.map (C.clearError now)
FinishAnimation ->
carsUpdated m
<| Array.map C.finishMotion
-- tells whether the puzzle is solved, i.e. whether the cars are sorted
isSolved : Model -> Bool
isSolved model =
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment