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

Only move cars if needed

parent 651999e0
...@@ -86,7 +86,13 @@ clearError' now flags = ...@@ -86,7 +86,13 @@ clearError' now flags =
clearError : Time -> Carriage -> Carriage clearError : Time -> Carriage -> Carriage
clearError now car = clearError now car =
{ car | flags = clearError' now car.flags } case car.flags.error_until of
Just time ->
if time <= now
then { car | flags = clearError' now car.flags }
else car
Nothing ->
car
restingPlace : Carriage -> Maybe RT.Path restingPlace : Carriage -> Maybe RT.Path
restingPlace car = restingPlace car =
...@@ -200,7 +206,7 @@ renderCarriageAt flags attributes (a1,p1) (a2,p2) = ...@@ -200,7 +206,7 @@ renderCarriageAt flags attributes (a1,p1) (a2,p2) =
, SvgAttr.ry (toString carConfig.roundness_y) , SvgAttr.ry (toString carConfig.roundness_y)
] ]
carConfig.carLen carConfig.carWidth car_center car_angle carConfig.carLen carConfig.carWidth car_center car_angle
, SvgUtils.svgCenteredText [ SvgAttr.class "carLabel" ] (Debug.log "Rendering car" flags.label) car_center car_angle , SvgUtils.svgCenteredText [ SvgAttr.class "carLabel" ] flags.label car_center car_angle
-- , SvgUtils.svgAngledPoint <| { angle = a1, p = p1 } -- , SvgUtils.svgAngledPoint <| { angle = a1, p = p1 }
-- , SvgUtils.svgAngledPoint <| { angle = a2, p = p2 } -- , SvgUtils.svgAngledPoint <| { angle = a2, p = p2 }
-- , SvgUtils.svgAngledPoint <| { angle = car_angle, p = car_center } -- , SvgUtils.svgAngledPoint <| { angle = car_angle, p = car_center }
......
...@@ -45,6 +45,7 @@ import RailPuzzle.History exposing (History) ...@@ -45,6 +45,7 @@ import RailPuzzle.History exposing (History)
import Shunt import Shunt
import Char import Char
import P2D import P2D
import Debug
-- MODEL -- MODEL
type alias RawModel render_cache = type alias RawModel render_cache =
...@@ -407,22 +408,26 @@ fillRenderCache model = ...@@ -407,22 +408,26 @@ fillRenderCache model =
RT.boundingBox model.rt `SvgUtils.bboxUnion` RT.boundingBox root_bumper RT.boundingBox model.rt `SvgUtils.bboxUnion` RT.boundingBox root_bumper
}} }}
render_car rt idx car =
-- let _ = Debug.log "Moving car with index" idx in
Svg.g [] <|
C.renderCarriage
rt [Svg.Events.onMouseDown (CarIdxClicked idx)] car
view : Model -> Html Msg view : Model -> Html Msg
view model = view model =
let let
updateSelected : Int -> C.Carriage -> C.Carriage updateSelected : Int -> C.Carriage -> C.Carriage
updateSelected idx car = updateSelected idx car =
let carflags = car.flags in let carflags = car.flags in
{ car | flags = { carflags | selected = model.car_selected == idx } } if (model.car_selected == idx) /= car.flags.selected
car_attributes idx car = then { car | flags = { carflags | selected = model.car_selected == idx } }
[ Svg.Events.onMouseDown (CarIdxClicked idx) else car
]
cars = cars =
model.cars model.cars
|> Array.indexedMap updateSelected |> Array.indexedMap updateSelected
|> Array.indexedMap (\i c -> C.renderCarriage model.rt (car_attributes i c) c) |> Array.indexedMap (Svg.lazy3 render_car model.rt)
|> Array.toList |> Array.toList
|> List.concat
-- For Debugging: show the points for bbox computation -- For Debugging: show the points for bbox computation
-- bpoints = -- bpoints =
......
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