-
Notifications
You must be signed in to change notification settings - Fork 1
/
missingPrefabs.sh
executable file
·86 lines (71 loc) · 1.64 KB
/
missingPrefabs.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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\t\n'
: "${F7D2D:?Please export F7D2D with 7D2D install folder}"
usage() {
echo >&2 "$0 [--parts] [--tiles] <prefab.xml> [<special.txt>]"
exit 1
}
while [[ $# -gt 0 && $1 == -* ]]; do
case "$1" in
--parts)
PARTS="1"
;;
--tiles)
TILES="1"
;;
*)
usage
;;
esac
shift
done
if [[ $# -lt 1 || $# -gt 2 ]]; then
usage
fi
BIN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
: "${SPECIAL_FOLDER:=${BIN}/special}"
: "${PARTS:=}"
: "${TILES:=}"
# "SPECIAL" used differently here than the exported version used by other scripts
if [[ $# -gt 1 && -n $2 ]]; then
SPECIAL="$2"
else
SPECIAL=''
fi
# 7d2d prefabs xml files come with "bom", which prevents the file from being read with "document"
# use the following to remove bom from files, if needed
# sed -i 's/\xef\xbb\xbf//' $filename
findIt() {
declare -A prefabs
mapfile -t < <(xmlstarlet sel -t -m "/prefabs/decoration/@name" -v . -n "$1" | sort -u)
for decoration in "${MAPFILE[@]}"; do
prefabs["${decoration}"]=1
done
mapfile -t < <( \
"${BIN}/listAllPrefabs.sh"
)
for prefab in "${MAPFILE[@]}"; do
if [[ -z "$PARTS" && "$prefab" == part_* ]]; then
continue
fi
if [[ -z "$TILES" && "$prefab" == rwg_tile_* ]]; then
continue
fi
if [[ -z ${prefabs["$prefab"]+abc} ]]; then
echo "$prefab"
fi
done
}
showIt() {
if [[ -n $SPECIAL ]]; then
findIt "$1" | grep -F -x -f "${SPECIAL_FOLDER}/${SPECIAL}"
else
findIt "$1"
fi
}
if [[ -t 1 ]]; then
showIt "$1" | column
else
showIt "$1"
fi