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 =
clearError : Time -> Carriage -> Carriage
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 car =
......@@ -200,7 +206,7 @@ renderCarriageAt flags attributes (a1,p1) (a2,p2) =
, SvgAttr.ry (toString carConfig.roundness_y)
]
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 = a2, p = p2 }
-- , SvgUtils.svgAngledPoint <| { angle = car_angle, p = car_center }
......
......@@ -45,6 +45,7 @@ import RailPuzzle.History exposing (History)
import Shunt
import Char
import P2D
import Debug
-- MODEL
type alias RawModel render_cache =
......@@ -407,22 +408,26 @@ fillRenderCache model =
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 =
let
updateSelected : Int -> C.Carriage -> C.Carriage
updateSelected idx car =
let carflags = car.flags in
{ car | flags = { carflags | selected = model.car_selected == idx } }
car_attributes idx car =
[ Svg.Events.onMouseDown (CarIdxClicked idx)
]
if (model.car_selected == idx) /= car.flags.selected
then { car | flags = { carflags | selected = model.car_selected == idx } }
else car
cars =
model.cars
|> 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
|> List.concat
-- For Debugging: show the points for bbox computation
-- 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