-
Notifications
You must be signed in to change notification settings - Fork 1
/
traderBiomes.sh
executable file
·104 lines (85 loc) · 2.08 KB
/
traderBiomes.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
#!/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> <biomes.png> <size> [<seed>]"
exit 1
fi
coordsFor() {
declare -g bl human
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
X=$((${COORDS%%,*}))
Z=$((${COORDS##,*}))
X1=$((X + CENTER))
Z2=$((-Z + CENTER))
bl="$((X1)),$((Z2))"
if [[ $Z -lt 0 ]]; then
human="$((-Z)) S"
else
human="$Z N"
fi
if [[ $X -lt 0 ]]; then
human="$human $((-X)) W"
else
human="$human $X E"
fi
}
BIN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
XML="$1"
IMG="$2"
SIZE="$3"
SEED="${4:-}"
NAME="$SEED-$SIZE"
CENTER="$((SIZE / 2))"
OUTPUT="$NAME-traders.txt"
declare -g -A DIM
declare -a MAPFILE
declare -A BIOMES
# Replace colors with biome names
BIOMES[Forest]='0,64,0'
BIOMES[Burnt Forest]='186,0,255'
BIOMES[Wasteland]='255,168,0'
BIOMES[Desert]='255,228,119'
BIOMES[Snow]='255,255,255'
SUBST=""
for biome in "${!BIOMES[@]}"; do
SUBST="${SUBST:+${SUBST};}s/${BIOMES[$biome]}/$biome/"
done
getTraderData() {
mapfile < <(xmlstarlet sel -t -m "/prefabs/decoration" -v "@name" -o ";" -v "@position" -o ";" -v "@rotation" -n - < "$XML")
for decoration in "${MAPFILE[@]}"; do
if [[ ! $decoration =~ trader* ]]; then
continue
fi
IFS=';' read -r prefab coords rotation <<<"$decoration"
if [[ -n ${DIM["$prefab"]+abc} ]]; then
dim="${DIM["$prefab"]}"
else
dim="$("${BIN}/prefabSize.sh" "${prefab}")"
DIM["$prefab"]="$dim"
fi
coordsFor "${coords}" "${dim}" "${rotation}"
echo -n "$prefab $human "
convert "$IMG[1x1+${bl/,/+}]" \
-format "%[fx:floor(255*u.r)],%[fx:floor(255*u.g)],%[fx:floor(255*u.b)]\n" \
info:- \
| sed -Ee "$SUBST"
done
}
if [[ $# -eq 4 ]]; then
getTraderData > "${OUTPUT}"
echo "${OUTPUT}"
else
getTraderData
fi