/
Apply.purs
65 lines (61 loc) · 1.88 KB
/
Apply.purs
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
module Config.Apply where
import Tupc.Internal
applyConfig ::
forall a.
JsonConfig ->
{ maxX :: Int, maxY :: Int } ->
Map a Pos -> Map a EnrichedPos
applyConfig jsonConfig bounds mapPos = mapPos <#> f
where
scale = jsonConfig.scale
scaleX = jsonConfig.scaleX # fromMaybe scale
scaleY = jsonConfig.scaleY # fromMaybe scale
directionX = jsonConfig.directionX
directionY = jsonConfig.directionY
multiplierX = case directionX of
DirXLeft -> (-1)
DirXRight -> 1
multiplierY = case directionY of
DirYUp -> (-1)
DirYDown -> 1
originX = jsonConfig.originX
originY = jsonConfig.originY
subX = case originX of
OriXLeft -> 0
OriXRight -> bounds.maxX
subY = case originY of
OriYUp -> 0
OriYDown -> bounds.maxY
centerStartX pos = case directionX of
DirXLeft -> pos.xRight
DirXRight -> pos.xLeft
centerStartY pos = case directionY of
DirYUp -> pos.yBot
DirYDown -> pos.yTop
f :: Pos -> EnrichedPos
f (Pos pos) = EnrichedPos
let
xLeft = (pos.xLeft - subX) * scaleX * multiplierX
xRight = (pos.xRight - subX) * scaleX * multiplierX
yTop = (pos.yTop - subY) * scaleY * multiplierY
yBot = (pos.yBot - subY) * scaleY * multiplierY
xWidth = (pos.xRight - pos.xLeft) * scaleX
yHeight = (pos.yBot - pos.yTop) * scaleY
xCenter = centerStartX { xLeft: xLeft, xRight: xRight } + (xWidth / 2)
yCenter = centerStartY { yTop: yTop, yBot: yBot } + (yHeight / 2)
in
{ xLeft: xLeft
, xRight: xRight
, yTop: yTop
, yBot: yBot
, xWidth: xWidth
, yHeight: yHeight
, xCenter: xCenter
, yCenter: yCenter
}
-- from origin Left direction Right
-- 0 -- 10 -- 20
-- to origin Right direction Right
-- -20 -- -10 -- 0
-- to origin Right direction Left
-- 20 -- 10 -- 0