-
Notifications
You must be signed in to change notification settings - Fork 41
/
Model.elm
1708 lines (1423 loc) · 51.4 KB
/
Model.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module Animation.Model exposing (..)
import Task
import Time
type Animation msg
= Animation
{ steps : List (Step msg)
, style : List Property
, timing : Timing
, running : Bool
, interruption : List ( Time.Posix, List (Step msg) )
}
type alias Timing =
{ current : Time.Posix
, dt : Time.Posix
}
type Tick
= Tick Time.Posix
{-| -}
type Step msg
= Step
| To (List Property)
| ToWith (List Property)
| Set (List Property)
| Wait Time.Posix
| Send msg
| Repeat Int (List (Step msg))
| Loop (List (Step msg))
type Interpolation
= Spring
{ stiffness : Float
, damping : Float
}
| Easing
{ progress : Float
, duration : Time.Posix
, start : Float
, ease : Float -> Float
}
| AtSpeed { perSecond : Float }
{-| For each 'value' of a property, we track position, velocity, interpolation, and target.
-}
type Property
= ExactProperty String String
| ColorProperty String Motion Motion Motion Motion
| ShadowProperty String Bool ShadowMotion
| Property String Motion
| Property2 String Motion Motion
| Property3 String Motion Motion Motion
| Property4 String Motion Motion Motion Motion
| AngleProperty String Motion
| Points (List ( Motion, Motion ))
| Path (List PathCommand)
type alias Motion =
{ position : Float
, velocity : Float
, target : Float
, interpolation : Interpolation
, unit : String
, interpolationOverride : Maybe Interpolation
}
type alias ShadowMotion =
{ offsetX : Motion
, offsetY : Motion
, size : Motion
, blur : Motion
, red : Motion
, green : Motion
, blue : Motion
, alpha : Motion
}
{-| Describe a path. To be used in conjunction with the 'd' property for styling svg.
`To` versions of the commands are absolute, while others are relative.
-}
type PathCommand
= Move Motion Motion
| MoveTo Motion Motion
| Line Motion Motion
| LineTo Motion Motion
| Horizontal Motion
| HorizontalTo Motion
| Vertical Motion
| VerticalTo Motion
| Curve CubicCurveMotion
| CurveTo CubicCurveMotion
| Quadratic QuadraticCurveMotion
| QuadraticTo QuadraticCurveMotion
| SmoothQuadratic (List ( Motion, Motion ))
| SmoothQuadraticTo (List ( Motion, Motion ))
| Smooth (List ( Motion, Motion ))
| SmoothTo (List ( Motion, Motion ))
| ClockwiseArc ArcMotion
| AntiClockwiseArc ArcMotion
| Close
type alias CubicCurveMotion =
{ control1 : ( Motion, Motion )
, control2 : ( Motion, Motion )
, point : ( Motion, Motion )
}
type alias QuadraticCurveMotion =
{ control : ( Motion, Motion )
, point : ( Motion, Motion )
}
type alias ArcMotion =
{ x : Motion
, y : Motion
, radius : Motion
, startAngle : Motion
, endAngle : Motion
}
propertyName : Property -> String
propertyName prop =
case prop of
ExactProperty name _ ->
name
ColorProperty name _ _ _ _ ->
name
ShadowProperty name _ _ ->
name
Property name _ ->
name
Property2 name _ _ ->
name
Property3 name _ _ _ ->
name
Property4 name _ _ _ _ ->
name
AngleProperty name _ ->
name
Points _ ->
"points"
Path _ ->
"path"
mapToMotion : (Motion -> Motion) -> Property -> Property
mapToMotion fn prop =
case prop of
ExactProperty name value ->
ExactProperty name value
ColorProperty name m1 m2 m3 m4 ->
ColorProperty name
(fn m1)
(fn m2)
(fn m3)
(fn m4)
ShadowProperty name inset shadow ->
let
offsetX =
shadow.offsetX
offsetY =
shadow.offsetY
size =
shadow.size
blur =
shadow.blur
red =
shadow.red
green =
shadow.green
blue =
shadow.blue
alpha =
shadow.alpha
in
ShadowProperty
name
inset
{ offsetX = fn offsetX
, offsetY = fn offsetY
, size = fn size
, blur = fn blur
, red = fn red
, green = fn green
, blue = fn blue
, alpha = fn alpha
}
Property name m1 ->
Property name
(fn m1)
Property2 name m1 m2 ->
Property2 name
(fn m1)
(fn m2)
Property3 name m1 m2 m3 ->
Property3 name
(fn m1)
(fn m2)
(fn m3)
Property4 name m1 m2 m3 m4 ->
Property4 name
(fn m1)
(fn m2)
(fn m3)
(fn m4)
AngleProperty name m1 ->
AngleProperty name
(fn m1)
Points ms ->
Points <|
List.map
(\( x, y ) ->
( fn x
, fn y
)
)
ms
Path cmds ->
Path <|
List.map
(mapPathMotion fn)
cmds
mapPathMotion : (Motion -> Motion) -> PathCommand -> PathCommand
mapPathMotion fn cmd =
let
mapCoords coords =
List.map
(\( x, y ) ->
( fn x
, fn y
)
)
coords
in
case cmd of
Move m1 m2 ->
Move
(fn m1)
(fn m2)
MoveTo m1 m2 ->
MoveTo
(fn m1)
(fn m2)
Line m1 m2 ->
Line
(fn m1)
(fn m2)
LineTo m1 m2 ->
LineTo
(fn m1)
(fn m2)
Horizontal motion ->
Horizontal
(fn motion)
HorizontalTo motion ->
HorizontalTo
(fn motion)
Vertical motion ->
Vertical
(fn motion)
VerticalTo motion ->
VerticalTo
(fn motion)
Curve { control1, control2, point } ->
Curve
{ control1 =
( fn (Tuple.first control1)
, fn (Tuple.second control1)
)
, control2 =
( fn (Tuple.first control2)
, fn (Tuple.second control2)
)
, point =
( fn (Tuple.first point)
, fn (Tuple.second point)
)
}
CurveTo { control1, control2, point } ->
CurveTo
{ control1 =
( fn (Tuple.first control1)
, fn (Tuple.second control1)
)
, control2 =
( fn (Tuple.first control2)
, fn (Tuple.second control2)
)
, point =
( fn (Tuple.first point)
, fn (Tuple.second point)
)
}
Quadratic { control, point } ->
Quadratic
{ control =
( fn (Tuple.first control)
, fn (Tuple.second control)
)
, point =
( fn (Tuple.first point)
, fn (Tuple.second point)
)
}
QuadraticTo { control, point } ->
QuadraticTo
{ control =
( fn (Tuple.first control)
, fn (Tuple.second control)
)
, point =
( fn (Tuple.first point)
, fn (Tuple.second point)
)
}
SmoothQuadratic coords ->
SmoothQuadratic <| mapCoords coords
SmoothQuadraticTo coords ->
SmoothQuadraticTo <| mapCoords coords
Smooth coords ->
Smooth <| mapCoords coords
SmoothTo coords ->
SmoothTo <| mapCoords coords
ClockwiseArc arc ->
ClockwiseArc <|
let
x =
arc.x
y =
arc.y
radius =
arc.radius
startAngle =
arc.startAngle
endAngle =
arc.endAngle
in
{ arc
| x = fn x
, y = fn y
, radius = fn radius
, startAngle = fn startAngle
, endAngle = fn endAngle
}
AntiClockwiseArc arc ->
AntiClockwiseArc <|
let
x =
arc.x
y =
arc.y
radius =
arc.radius
startAngle =
arc.startAngle
endAngle =
arc.endAngle
in
{ arc
| x = fn x
, y = fn y
, radius = fn radius
, startAngle = fn startAngle
, endAngle = fn endAngle
}
Close ->
Close
updateAnimation : Tick -> Animation msg -> ( Animation msg, Cmd msg )
updateAnimation (Tick now) (Animation model) =
let
-- set current and dt time
timing =
refreshTiming now model.timing
-- Resolve potential interrutions
( readyInterruption, queuedInterruptions ) =
List.map
(\( wait, mySteps ) ->
( Time.millisToPosix (Time.posixToMillis wait - Time.posixToMillis timing.dt), mySteps )
)
model.interruption
|> List.partition
(\( wait, mySteps ) -> Time.posixToMillis wait <= 0)
-- if there is more than one matching interruptions,
-- we only take the first, which is the one that was most recently assigned.
-- If an interruption does occur, we need to clear any interpolation overrides.
( steps, style ) =
case List.head readyInterruption of
Just ( wait, interrupt ) ->
( interrupt
, List.map (mapToMotion (\m -> { m | interpolationOverride = Nothing })) model.style
)
Nothing ->
( model.steps, model.style )
( revisedStyle, sentMessages, revisedSteps ) =
resolveSteps style steps timing.dt
in
( Animation
{ model
| timing = timing
, interruption = queuedInterruptions
, running =
List.length revisedSteps
/= 0
|| List.length queuedInterruptions
/= 0
, steps = revisedSteps
, style = revisedStyle
}
, Cmd.batch <| List.map (\m -> Task.perform identity (Task.succeed m)) sentMessages
)
refreshTiming : Time.Posix -> Timing -> Timing
refreshTiming now timing =
let
dt =
Time.posixToMillis now - Time.posixToMillis timing.current
-- dt is set to one frame (16.66) if it is a large dt(more than 2 frames),
-- A large dt means one of the following:
-- * the user left the browser window and came back
-- * the animation subscription has stopped calling for updates for a while and started running again
--
-- We also have a special case when timing.current == 0, which is happens at startup.
in
{ current = now
, dt =
if dt > 34 || Time.posixToMillis timing.current == 0 then
Time.millisToPosix (round 16.666)
else
Time.millisToPosix dt
}
resolveSteps : List Property -> List (Step msg) -> Time.Posix -> ( List Property, List msg, List (Step msg) )
resolveSteps currentStyle steps dt =
case List.head steps of
Nothing ->
( currentStyle, [], [] )
Just currentStep ->
case currentStep of
Wait n ->
if Time.posixToMillis n <= 0 then
resolveSteps currentStyle (List.drop 1 steps) dt
else
-- What about a slight overage of time?
( currentStyle, [], (Wait <| Time.millisToPosix (Time.posixToMillis n - Time.posixToMillis dt)) :: List.drop 1 steps )
Send msg ->
let
( newStyle, msgs, remainingSteps ) =
resolveSteps currentStyle (List.drop 1 steps) dt
in
( newStyle, msg :: msgs, remainingSteps )
To target ->
-- Add starting time to any properties with duration/easing
-- The boolean is to override interpolation or not
if alreadyThere currentStyle target then
( currentStyle
, []
, List.drop 1 steps
)
else
resolveSteps
(startTowards False currentStyle target)
(Step :: List.drop 1 steps)
dt
ToWith target ->
if alreadyThere currentStyle target then
( currentStyle
, []
, List.drop 1 steps
)
else
-- Add starting time to any properties with duration/easing
-- The boolean is to override interpolation or not
resolveSteps
(startTowards True currentStyle target)
(Step :: List.drop 1 steps)
dt
Set props ->
resolveSteps
(replaceProps currentStyle props)
(List.drop 1 steps)
dt
Step ->
let
stepped =
step dt currentStyle
in
if List.all isDone stepped then
( List.map (mapToMotion (\m -> { m | interpolationOverride = Nothing })) stepped
, []
, List.drop 1 steps
)
else
( stepped
, []
, steps
)
Loop substeps ->
resolveSteps
currentStyle
(substeps ++ [ Loop substeps ])
dt
Repeat n substeps ->
if n <= 0 then
resolveSteps currentStyle (List.drop 1 steps) dt
else
resolveSteps
currentStyle
(substeps ++ [ Repeat (n - 1) substeps ] ++ List.drop 1 steps)
dt
alreadyThere : List Property -> List Property -> Bool
alreadyThere current target =
startTowards False current target
|> step (Time.millisToPosix 0)
|> List.all isDone
{-| -}
replaceProps : List Property -> List Property -> List Property
replaceProps props replacements =
let
replacementNames =
List.map propertyName replacements
removed =
List.filter (\prop -> not <| List.member (propertyName prop) replacementNames) props
in
removed ++ replacements
{-| Property is done?
TODO: What about interlaced property animations?
-}
isDone : Property -> Bool
isDone property =
let
motionDone motion =
let
runningInterpolation =
Maybe.withDefault
motion.interpolation
motion.interpolationOverride
in
case runningInterpolation of
Spring _ ->
motion.velocity == 0 && motion.position == motion.target
Easing eased ->
eased.progress == 1 || (eased.progress == 0 && motion.position == motion.target)
AtSpeed speed ->
motion.position == motion.target
in
case property of
ExactProperty _ _ ->
True
ColorProperty _ m1 m2 m3 m4 ->
List.all motionDone [ m1, m2, m3, m4 ]
ShadowProperty _ _ shadow ->
List.all
motionDone
[ shadow.offsetX
, shadow.offsetY
, shadow.size
, shadow.blur
, shadow.red
, shadow.green
, shadow.blue
, shadow.alpha
]
Property _ m1 ->
motionDone m1
Property2 _ m1 m2 ->
motionDone m1 && motionDone m2
Property3 _ m1 m2 m3 ->
List.all motionDone [ m1, m2, m3 ]
Property4 _ m1 m2 m3 m4 ->
List.all motionDone [ m1, m2, m3, m4 ]
AngleProperty _ m1 ->
motionDone m1
Points ms ->
List.all (\( x, y ) -> motionDone x && motionDone y) ms
Path cmds ->
List.all isCmdDone cmds
isCmdDone : PathCommand -> Bool
isCmdDone cmd =
let
motionDone motion =
motion.velocity == 0 && motion.position == motion.target
in
case cmd of
Move m1 m2 ->
motionDone m1 && motionDone m2
MoveTo m1 m2 ->
motionDone m1 && motionDone m2
Line m1 m2 ->
motionDone m1 && motionDone m2
LineTo m1 m2 ->
motionDone m1 && motionDone m2
Horizontal motion ->
motionDone motion
HorizontalTo motion ->
motionDone motion
Vertical motion ->
motionDone motion
VerticalTo motion ->
motionDone motion
Curve { control1, control2, point } ->
(motionDone <| Tuple.first control1)
&& (motionDone <| Tuple.second control1)
&& (motionDone <| Tuple.first control2)
&& (motionDone <| Tuple.second control2)
&& (motionDone <| Tuple.first point)
&& (motionDone <| Tuple.second point)
CurveTo { control1, control2, point } ->
(motionDone <| Tuple.first control1)
&& (motionDone <| Tuple.second control1)
&& (motionDone <| Tuple.first control2)
&& (motionDone <| Tuple.second control2)
&& (motionDone <| Tuple.first point)
&& (motionDone <| Tuple.second point)
Quadratic { control, point } ->
(motionDone <| Tuple.first control)
&& (motionDone <| Tuple.second control)
&& (motionDone <| Tuple.first point)
&& (motionDone <| Tuple.second point)
QuadraticTo { control, point } ->
(motionDone <| Tuple.first control)
&& (motionDone <| Tuple.second control)
&& (motionDone <| Tuple.first point)
&& (motionDone <| Tuple.second point)
SmoothQuadratic coords ->
List.all (\( x, y ) -> motionDone x && motionDone y) coords
SmoothQuadraticTo coords ->
List.all (\( x, y ) -> motionDone x && motionDone y) coords
Smooth coords ->
List.all (\( x, y ) -> motionDone x && motionDone y) coords
SmoothTo coords ->
List.all (\( x, y ) -> motionDone x && motionDone y) coords
ClockwiseArc arc ->
motionDone arc.x
&& motionDone arc.y
&& motionDone arc.radius
&& motionDone arc.startAngle
&& motionDone arc.endAngle
AntiClockwiseArc arc ->
motionDone arc.x
&& motionDone arc.y
&& motionDone arc.radius
&& motionDone arc.startAngle
&& motionDone arc.endAngle
Close ->
True
{-| Set a new target for a style.
If a property doesn't exist in the current style, issue a warning and do nothing with that property.
If a property doesn't exist as a target, then leave it as is.
Order matters (mostly for transformation stacking)
-}
startTowards : Bool -> List Property -> List Property -> List Property
startTowards overrideInterpolation current target =
List.filterMap
(\propPair ->
case propPair of
( cur, Just to ) ->
Just <| setTarget overrideInterpolation cur to
( prop, Nothing ) ->
Just prop
)
(zipPropertiesGreedy current target)
setTarget : Bool -> Property -> Property -> Property
setTarget overrideInterpolation current newTarget =
let
setMotionTarget motion targetMotion =
let
newMotion =
if overrideInterpolation then
{ motion
| interpolationOverride = Just targetMotion.interpolation
}
else
motion
in
case newMotion.interpolationOverride of
Nothing ->
case newMotion.interpolation of
Easing ease ->
{ newMotion
| target = targetMotion.position
, interpolation =
Easing
{ ease
| start = motion.position
, progress = 0
}
}
_ ->
{ newMotion
| target = targetMotion.position
}
Just override ->
case override of
Easing ease ->
{ newMotion
| target = targetMotion.position
, interpolationOverride =
Just <|
Easing
{ ease
| start = motion.position
, progress = 0
}
}
_ ->
{ newMotion
| target = targetMotion.position
}
in
case current of
ExactProperty name value ->
ExactProperty name value
ColorProperty name m1 m2 m3 m4 ->
case newTarget of
ColorProperty _ t1 t2 t3 t4 ->
ColorProperty name
(setMotionTarget m1 t1)
(setMotionTarget m2 t2)
(setMotionTarget m3 t3)
(setMotionTarget m4 t4)
_ ->
current
ShadowProperty name inset shadow ->
case newTarget of
ShadowProperty _ _ targetShadow ->
ShadowProperty
name
inset
{ offsetX = setMotionTarget shadow.offsetX targetShadow.offsetX
, offsetY = setMotionTarget shadow.offsetY targetShadow.offsetY
, size = setMotionTarget shadow.size targetShadow.size
, blur = setMotionTarget shadow.blur targetShadow.blur
, red = setMotionTarget shadow.red targetShadow.red
, green = setMotionTarget shadow.green targetShadow.green
, blue = setMotionTarget shadow.blue targetShadow.blue
, alpha = setMotionTarget shadow.alpha targetShadow.alpha
}
_ ->
current
Property name m1 ->
case newTarget of
Property _ t1 ->
Property name
(setMotionTarget m1 t1)
_ ->
current
Property2 name m1 m2 ->
case newTarget of
Property2 _ t1 t2 ->
Property2 name
(setMotionTarget m1 t1)
(setMotionTarget m2 t2)
_ ->
current
Property3 name m1 m2 m3 ->
case newTarget of
Property3 _ t1 t2 t3 ->
Property3 name
(setMotionTarget m1 t1)
(setMotionTarget m2 t2)
(setMotionTarget m3 t3)
_ ->
current
Property4 name m1 m2 m3 m4 ->
case newTarget of
Property4 _ t1 t2 t3 t4 ->
Property4 name
(setMotionTarget m1 t1)
(setMotionTarget m2 t2)
(setMotionTarget m3 t3)
(setMotionTarget m4 t4)
_ ->
current
AngleProperty name m1 ->
case newTarget of
AngleProperty _ t1 ->
AngleProperty name
(setMotionTarget m1 t1)
_ ->
current
Points currentPts ->
case newTarget of
Points targetPts ->
let
( m1s, m2s ) =
matchPoints currentPts targetPts
in
Points <|
List.map2
(\( x1, y1 ) ( x2, y2 ) ->
( setMotionTarget x1 x2
, setMotionTarget y1 y2
)
)
m1s
m2s
_ ->
current
Path cmds ->
case newTarget of
Path targets ->
Path <|
List.map2
setPathTarget
cmds
targets
_ ->
current
setPathTarget : PathCommand -> PathCommand -> PathCommand
setPathTarget cmd targetCmd =
let
setMotionTarget motion targetMotion =
case motion.interpolation of
Easing ease ->
{ motion
| target = targetMotion.position
, interpolation =
Easing
{ ease | start = motion.position }
}
_ ->
{ motion | target = targetMotion.position }
in
case cmd of
Move m1 m2 ->
case targetCmd of
Move t1 t2 ->
Move
(setMotionTarget m1 t1)
(setMotionTarget m2 t2)
_ ->
cmd
MoveTo m1 m2 ->
case targetCmd of
MoveTo t1 t2 ->
MoveTo
(setMotionTarget m1 t1)