]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Update check-cvars.sh to only disallow changing extra settings in custom balance...
authorotta8634 <k9wolf@pm.me>
Sat, 1 Mar 2025 11:09:08 +0000 (19:09 +0800)
committerotta8634 <k9wolf@pm.me>
Sat, 1 Mar 2025 11:24:44 +0000 (19:24 +0800)
Now custom balance files like balance-overkill.cfg don't have to change every single cvar balance-xonotic.cfg does, so that the same defaults don't need to repeated for every single balance file.
The only requirement now is that balance-overkill.cfg can't set any cvars which aren't also set in balance-xonotic.cfg.
This doesn't apply to the hud cfg files, since they're compared against _hud_descriptions.cfg, which doesn't set defaults, so they must do it themselves.
Changes weren't made to the cfg files in question yet.

check-cvars.sh

index 387d93720392d660fccf6b43b8dd9ca37c05a0ad..a14ad20566557d1e80a12ce1207df65869f993af 100755 (executable)
@@ -4,36 +4,53 @@ errord=false
 
 check_files()
 {
-       countw=`awk ''"$3"' { print $2; }' "$1" | sort -u | tr -d '\r' | git hash-object --stdin | cut -c 1-32`
-       for b in $2; do
-               if [ "$b" = "balance-testing.cfg" ] || [ "$b" = "balance-testingxpm.cfg" ]; then
+       for b in $2
+       do
+               if [ "$b" = "balance-testing.cfg" ] || [ "$b" = "balance-testingxpm.cfg" ]
+               then
                        continue
                fi
 
-               countb=`awk ''"$3"' { print $2; }' "$b" | sort -u | tr -d '\r' | git hash-object --stdin | cut -c 1-32`
-               if [ "$countw" != "$countb" ]; then
-                       echo "Mismatch between $1 and $b. Aborting."
-                       echo "Differences are:"
-                       echo "< missing in $b"
-                       echo "> must get removed from $b"
-                       A=`mktemp || echo a.tmp`
-                       B=`mktemp || echo b.tmp`
-                       awk ''"$3"' { print $2; }' "$1" | sort -u | tr -d '\r' > "$A"
-                       awk ''"$3"' { print $2; }' "$b" | sort -u | tr -d '\r' > "$B"
-                       diff "$A" "$B" | grep '^[<>]' | sort
-                       rm -f "$A" "$B"
+               A=`mktemp || echo a.tmp`
+               B=`mktemp || echo b.tmp`
+               awk ''"$3"' { print $2; }' "$1" | sort -u | tr -d '\r' > "$A"
+               awk ''"$3"' { print $2; }' "$b" | sort -u | tr -d '\r' > "$B"
+               extra=""
+               if $4
+               then
+                       extra="$(diff "$A" "$B" | grep '^>' | sort)"
+                       # only extract cvars that are in $b but not $1
+                       #   $b is allowed to override $1, but not change anything else
+               else
+                       extra="$(diff "$A" "$B" | grep '^[<>]' | sort)"
+               fi
+               if [ "$extra" != "" ]
+               then
+                       echo "Cvar mismatch between $1 and $b. Aborting."
+                       if $4
+                       then
+                               echo "The following are missing from $1, so must be either added to $1 or more likely removed from $b:"
+                       else
+                               echo "Differences are:"
+                               echo "< missing in $b"
+                               echo "> must be removed from $b"
+                       fi
+                       echo "$extra"
                        errord=true
                fi
+               rm -f "$A" "$B"
        done
 }
 
-check_files "balance-xonotic.cfg" "balance-*.cfg" "/^seta? g_/"
-check_files "bal-wep-xonotic.cfg" "bal-wep-*.cfg" "/^seta? g_/"
-check_files "_hud_descriptions.cfg" "hud_*.cfg" "/^seta? hud_/"
+check_files "balance-xonotic.cfg"    "balance-*.cfg"  "/^seta? +g_/"    true
+check_files "bal-wep-xonotic.cfg"    "bal-wep-*.cfg"  "/^seta? +g_/"    true
+check_files "_hud_descriptions.cfg"  "hud_*.cfg"      "/^seta? +hud_/"  false
 
-if $errord; then
-    if [ "$CMAKE" != "" ]; then
-           exit 1
+if $errord
+then
+       if [ "$CMAKE" != "" ]
+       then
+               exit 1
        fi
        echo "Please wait for 30 seconds, so you have had enough time to read this..."
        sleep 30