-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprefabZoningColor.sh
More file actions
executable file
·143 lines (129 loc) · 3.23 KB
/
prefabZoningColor.sh
File metadata and controls
executable file
·143 lines (129 loc) · 3.23 KB
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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\t\n'
: "${F7D2D:?Please export F7D2D with 7D2D install folder}"
PREFABS="${F7D2D}/Data/Prefabs"
if [[ $# -eq 0 ]]; then
echo >&2 "$0 <prefab_name>"
exit 1
fi
declare -a zones
# TODO: make zones an associative array instead?
hasZone() {
local IFS='|'
PATTERN="($*)"
IFS=$','
if [[ ",${zones[*]}," =~ ,${PATTERN}, ]]; then
return 0
else
return 1
fi
}
for prefab; do
zones=()
if [[ $prefab =~ trader* ]]; then
zones+=(trader)
fi
if [[ $prefab == *field* ]]; then
zones+=(crop)
fi
if [[ "$prefab" =~ rwg_tile* ]]; then
prefabZone="${prefab#rwg_tile_}"
if [[ $prefabZone == wasteland* ]]; then
zones+=(wasteland)
prefabZone="${prefabZone#wasteland}"
fi
case "${prefabZone}" in
citycenter*)
zones+=(citycenter)
;;
downtown*)
zones+=(downtown)
;;
commercial*)
zones+=(commercial)
;;
countryresidential*)
zones+=(countryresidential)
;;
countrytown*)
zones+=(countrytown)
;;
rural*)
zones+=(rural)
;;
residential*)
zones+=(residential)
;;
ghosttown* | oldwest*)
zones+=(oldwest)
;;
industrial*)
zones+=(industrial)
;;
*)
zones+=(any)
;;
esac
FILE="${PREFABS}/RWGTiles/${prefab}.xml"
else
FILE="${PREFABS}/POIs/${prefab}.xml"
fi
[[ -f "${FILE}" ]] || FILE="$(find "${PREFABS}" -name "${prefab}.xml" -print)"
mapfile -d ' ' -O ${#zones[@]} -t zones < <(xmlstarlet sel -t -m /prefab -v "property[@name='Tags']/@value" \
"${FILE}" | tr '[:upper:],' '[:lower:] ' || :)
# Existing tags:
# citycenter x
# commercial x
# countryresidential x
# countrytown x -- smaller than city and town
# downtown x
# industrial x
# oldwest x
# residential x
# rural x -- outskirt of cities and towns (but not countrytown)
# test
# trader x
# wastelandcommercial x
# wastelandcountryresidential x
# wastelandcountrytown x
# wastelanddowntown x
# wastelandindustrial x
# wastelandresidential x
# wilderness x
# Preempt any other zones
if hasZone trader; then
echo magenta
continue
elif hasZone crop; then
echo olive
continue
elif hasZone any; then
echo white
continue
elif hasZone oldwest; then
echo saddlebrown
continue
fi
# Zones used in combos for special colors
hasZone residential && RESIDENTIAL_NEW=1 || RESIDENTIAL_NEW=""
hasZone countryresidential && RESIDENTIAL_OLD=1 || RESIDENTIAL_OLD=""
hasZone residential countryresidential && RESIDENTIAL=1 || RESIDENTIAL=""
hasZone industrial && INDUSTRIAL=1 || INDUSTRIAL=""
hasZone commercial && COMMERCIAL=1 || COMMERCIAL=""
hasZone downtown citycenter && DOWNTOWN=1 || DOWNTOWN=""
# First match wins
if [[ -n $DOWNTOWN && -n $COMMERCIAL && -n $INDUSTRIAL ]]; then echo orange
elif [[ -n $DOWNTOWN && -n $RESIDENTIAL ]]; then echo teal
elif [[ -n $DOWNTOWN && -n $COMMERCIAL ]]; then echo slategray
elif [[ -n $DOWNTOWN ]]; then echo gray
elif [[ -n $RESIDENTIAL_NEW ]]; then echo chartreuse
elif [[ -n $RESIDENTIAL_OLD ]]; then echo green
elif [[ -n $COMMERCIAL ]]; then echo blue
elif [[ -n $INDUSTRIAL ]]; then echo yellow
elif hasZone rural; then echo olivedrab
elif hasZone countrytown; then echo sandybrown
elif hasZone wilderness; then echo saddlebrown
else echo black
fi
done