-
Notifications
You must be signed in to change notification settings - Fork 1
/
drawPrefabs.sh
executable file
·170 lines (148 loc) · 4.91 KB
/
drawPrefabs.sh
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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\t\n'
: "${F7D2D:?Please export F7D2D with 7D2D install folder}"
if [[ $# -lt 3 || $# -gt 4 ]]; then
echo >&2 "$0 <prefabs.xml> <image> <size> [<spawnspoints.xml>]"
exit 1
fi
[[ ! -f splatmap.png ]] && convert splat3.png \
-alpha off -transparent black \
-fill '#9c8c7b' -opaque '#00ff00' \
-fill '#ceb584' -opaque '#ff0000' \
splatmap.png
coordsFor() {
declare -g tl br dim
declare COORDS DIM ROT
COORDS="$1"
DIM="$2"
ROT="$3"
WIDTH="${DIM%%,*}"
HEIGHT="${DIM##*,}"
if [[ $((ROT % 2)) -eq 1 ]]; then
tmp="$WIDTH"
WIDTH="$HEIGHT"
HEIGHT="$tmp"
fi
X1=$((${COORDS%%,*} + CENTER))
Z2=$((-(${COORDS##,*}) + CENTER))
X2=$((X1 + WIDTH))
Z1=$((Z2 - HEIGHT))
tl="$((X1)),$((Z1))"
br="$((X2)),$((Z2))"
tlb="$((X1 + 1)),$((Z1 + 1))"
brb="$((X2 - 2)),$((Z2 - 2))"
dim="${WIDTH},${HEIGHT}"
}
PREFABS="${F7D2D}/Data/Prefabs"
BIN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
XML="$1"
IMG="$2"
SIZE="$3"
SPAWN_XML="${4:-spawnspoints.xml}"
CENTER="$((SIZE / 2))"
NAME="${XML%.xml}"
DRAW="draw-${NAME}.txt"
ZONING="zoning-${NAME}.txt"
THUMB="thumb-${NAME}.txt"
SPAWN="spawn-${NAME}.txt"
SPAWNT="spawn-thumb-${NAME}.txt"
GRID="grid-${NAME}.txt"
COORDS="coords-${NAME}.txt"
PREVIEW="prefabs-${IMG}"
declare -g -A DIM
declare -g -A ZONE
declare -a MAPFILE
mapfile < <(xmlstarlet sel -t -m "/prefabs/decoration" -v "@name" -o ";" -v "@position" -o ";" -v "@rotation" -n - < "$XML")
echo "stroke-width 1 fill 'rgba(0,0,0,0.5)'" > "${DRAW}"
echo "stroke-width 3 fill none" > "${ZONING}"
echo "stroke-width 1 stroke black" > "${THUMB}"
for decoration in "${MAPFILE[@]}"; do
IFS=';' read -r prefab coords rotation <<<"$decoration"
#IFS=';' read tl br dim < <("${BIN}/prefabCoords.sh" "${prefab}" "${coords}" "${rotation}")
if [[ -n ${DIM["$prefab"]+abc} ]]; then
dim="${DIM["$prefab"]}"
else
dim="$("${BIN}/prefabSize.sh" "${prefab}")"
DIM["$prefab"]="$dim"
fi
coordsFor "${coords}" "${dim}" "${rotation}"
if [[ "${prefab}" =~ rwg_tile* && -f "${PREFABS}/RWGTiles/${prefab}.jpg" ]]; then
PREFAB_PREVIEW="${PREFABS}/RWGTiles/${prefab}.jpg"
x_offset=$((-WIDTH / 2))
z_offset=$((-HEIGHT / 2))
tl="$((X1 - x_offset)),$((Z1 - z_offset))"
{
echo "push graphic-context"
echo "translate ${tl}"
echo "rotate $(((4 - rotation) % 4 * 90))"
echo "image over ${x_offset},${z_offset} ${dim} '${PREFAB_PREVIEW}'"
echo "pop graphic-context"
} >> "${DRAW}"
else
PREFAB_PREVIEW="${PREFABS}/POIs/${prefab}.jpg"
if [[ ! -f "${PREFAB_PREVIEW}" ]]; then
PREFAB_PREVIEW="$(find "${PREFABS}" -name "${prefab}.jpg" -print)"
fi
if [[ -n "${PREFAB_PREVIEW}" && -f "${PREFAB_PREVIEW}" ]]; then
echo "image over ${tl} ${dim} '${PREFAB_PREVIEW}'" >> "${DRAW}"
else
echo >&2 "${prefab} not found!"
echo "rotate 0 rectangle ${tl} ${br}" >> "${DRAW}"
fi
fi
if [[ -n ${ZONE["$prefab"]+abc} ]]; then
zone="${ZONE["$prefab"]}"
else
zone="$("${BIN}/prefabZoningColor.sh" "${prefab}")"
ZONE["$prefab"]="$zone"
fi
echo "stroke $zone rectangle ${tlb} ${brb}" >> "${ZONING}"
echo "fill $zone rectangle ${tl} ${br}" >> "${THUMB}"
done
echo "stroke-width 2 stroke black fill white stroke-opacity 0.6 fill-opacity 0.6 stroke-dasharray 16 16" > "${GRID}"
echo "stroke-width 4 fill white stroke black stroke-opacity 0.6 fill-opacity 0.6" > "${COORDS}"
echo "font Helvetica-Bold font-size 96" >> "${COORDS}"
Ms=$((CENTER / 512 - 1))
for m in $(seq $((-Ms)) $((Ms))); do
P=$((m * 512 + CENTER))
echo "path 'M 0,$P L $SIZE,$P'" >> "${GRID}"
echo "path 'M $P,0 L $P,$SIZE'" >> "${GRID}"
{
printf "text %d,%d '%4d'" 4 $((P - 8)) $((-m * 512))
printf "text %d,%d '%4d'" $((SIZE - 264)) $((P - 8)) $((-m * 512))
printf "text %d,%d '%4d'" $((P + 8)) $((SIZE - 8)) $((m * 512))
printf "text %d,%d '%4d'" $((P + 8)) 72 $((m * 512))
} >> "${COORDS}"
done
echo "stroke-width 1 fill red" > "${SPAWN}"
echo "stroke-width 2 fill red" > "${SPAWNT}"
if [[ -f "$SPAWN_XML" ]]; then
mapfile < <(xmlstarlet sel -t -m "/spawnpoints/spawnpoint" -v "@position" -n - < "$SPAWN_XML")
for spawnpoint in "${MAPFILE[@]}"; do
IFS=',' read -r x _ y <<<"$spawnpoint"
x="${x%.*}"
y="${y%.*}"
x=$((x+CENTER))
y=$((-y+CENTER))
echo "circle $x,$y $((x+8)),$((y+8))" >> "${SPAWN}"
echo "circle $x,$y $((x+32)),$((y+32))" >> "${SPAWNT}"
done
fi
convert "${IMG}" \
-draw "@${DRAW}" \
-draw "@${ZONING}" \
-draw "@${GRID}" \
-draw "@${COORDS}" \
splatmap.png -composite \
-draw "@${SPAWN}" \
"${PREVIEW}"
mkdir -p thumbs
NAILSIZE="$((SIZE/16))"
convert "${IMG}" \
-draw "@${THUMB}" \
-draw "@${SPAWNT}" \
-depth 8 \
-resize "${NAILSIZE}x${NAILSIZE}" \
"thumbs/${IMG}"
echo "${PREVIEW}"