-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathupdateMaps.sh
More file actions
executable file
·109 lines (87 loc) · 3.26 KB
/
updateMaps.sh
File metadata and controls
executable file
·109 lines (87 loc) · 3.26 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
#!/bin/bash
set -e
customBaseFolder="$1"
filterArg="$2"
if [[ "$customBaseFolder" == "output" ]]; then
echo "Error: 'output' cannot be used as the custom base folder."
exit 1
fi
if [[ -n "$customBaseFolder" ]]; then
cleanMapPath="./maps/w3c_maps/$customBaseFolder"
else
cleanMapPath="./maps/w3c_maps/clean_maps"
fi
IFS=',' read -r -a filterPrefixes <<< "$filterArg"
filterEnabled=false
if [[ -n "$filterArg" ]]; then
filterEnabled=true
fi
mapExtractionPath="./maps/map.w3x"
outputMapPath="./maps/w3c_maps/output"
mpqPath="./MPQEditor.exe"
currentDateTime=$(date '+%y%m%d_%H%M')
buildMapPath="./maps/w3c_maps/tmp.w3x"
rm -rf "$outputMapPath" && mkdir "$outputMapPath"
prefixList=("1v1_" "2v2_" "3v3_" "4v4_" "FFA_")
while IFS= read -r -d '' fullPath; do
fileName="$(basename $fullPath)"
dirName="$(dirname $fullPath)"
relFolder="${dirName#${cleanMapPath}}"
matchedModes=()
strippedName="$fileName"
mapIdPrefix=
if [[ "$fileName" == *@* ]]; then
mapIdPrefix="${fileName%@*}_"
strippedName="${fileName#*@}"
fi
while :; do
matched=false
for prefix in "${prefixList[@]}"; do
if [[ "$strippedName" == "$prefix"* ]]; then
mode="${prefix%_}"
if [[ "$filterEnabled" = false || " ${filterPrefixes[*]} " == *" $mode "* ]]; then
matchedModes+=("$mode")
fi
strippedName="${strippedName#${prefix}}"
matched=true
break
fi
done
[[ "$matched" = false ]] && break
done
if [[ "$filterEnabled" = true && ${#matchedModes[@]} -eq 0 ]]; then
printf "\nSkipping $fileName from folder '$relFolder'...\n\n"
continue
else
printf "\nProcessing $fileName from folder '$relFolder'...\n\n"
fi
rm -rf "$mapExtractionPath" && mkdir "$mapExtractionPath"
printf "Running: \"$mpqPath\" extract \"$fullPath\" \"*\" \"$mapExtractionPath\" \"/fp\" \n"
"$mpqPath" extract "$fullPath" "*" "$mapExtractionPath" "/fp"
rm -rf dist/ && npm run build "$dirName"
mv ./maps/w3c_maps/map.w3x "$buildMapPath"
newFileName="${mapIdPrefix}w3c_${currentDateTime}_$strippedName"
if [[ ${#matchedModes[@]} -gt 0 ]]; then
for mode in "${matchedModes[@]}"; do
targetDir="$outputMapPath/$mode"
mkdir -p "$targetDir"
printf "\nMoving map to $targetDir/$newFileName\n\n"
cp "$buildMapPath" "$targetDir/$newFileName"
done
else
if [[ -z "$relFolder" ]]; then
targetDir="$outputMapPath"
else
targetDir="$outputMapPath/$relFolder"
fi
mkdir -p "$targetDir"
printf "\nMoving map to $targetDir/$newFileName\n\n"
mv "$buildMapPath" "$targetDir/$newFileName"
fi
rm -rf "$buildMapPath"
done < <(find "$cleanMapPath" -type f \( -iname '*.w3m' -o -iname '*.w3x' \) -print0)
rm -f "$buildMapPath"
cleanMapsCount=$(find "$cleanMapPath" -type f \( -iname '*.w3m' -o -iname '*.w3x' \) | wc -l)
completedMapsCount=$(find "$outputMapPath" -type f \( -iname '*.w3m' -o -iname '*.w3x' \) -printf "%f\n" | sort -u | wc -l)
echo "Processed $cleanMapsCount maps and output $completedMapsCount maps."
echo "Map updates completed successfully."