1
0
Fork 0

building scripts: revision 2

1. Add a comment inside each script to indicate main execution branch
2. Ask before overwriting the resulting resource pack in the resource
   pack directory of Minecraft. Windows CMD script uses `move /-Y ...`,
   Bash script uses `mv -i ...`.
3. Ensure that no errors pass during the `cave_sounds_limit` loop
4. Improve version checking algorithm
5. Merge functions `prepare` and `build` as `build`
6. Move some of the features of `clean` function outside
7. Split `packname` into `packname`, `packname_prefix`, `packname_ext`
   for cleaning function and to improve code maintainability
8. build.bat: Fix the mistake of using `||` as the operator to indicate
   logical OR in condition
9. build.sh: Do not `exit` from functions
10. build.sh: Ensure that the indentation style is consistent
11. build.sh: Extract function `pause`
12. build.sh: In `amkdir`, call `mkdir` as `mkdir -p ...` to create
    directories recursively
13. build.sh: Move the initial constants into the beginning of file
14. build.sh: Remove dead code
This commit is contained in:
transpiler 2023-08-22 19:57:04 +03:00
parent 280da35d33
commit 8274928c2e
2 changed files with 69 additions and 46 deletions

View File

@ -4,6 +4,7 @@ set "output_dir=build"
set "mcrespath=%MINECRAFT_PATH%\resourcepacks"
set "mutual_snd_path=assets\minecraft\sounds\ambient\cave"
rem main branch
set "mcversion="
if "%1" equ "/?" goto :help
@ -19,17 +20,15 @@ if "%1" equ "build" (
)
goto :prepare
) else if "%1" equ "clean" (
call :clean
rd /S /Q ".\build"
echo Build directory cleaned.
goto :EOF
) else (
goto :help
)
:prepare
call :clean
set "packname=anti-cave-noises-%mcversion%.zip"
:build
set "packname=anti-cave-noises-%mcversion%.zip"
set "pm_out=%output_dir%\pack.mcmeta"
set "snd_src=%input_dir%\%mutual_snd_path%\"
set "snd_out=%output_dir%\%mutual_snd_path%\"
@ -37,33 +36,45 @@ set "snd_out=%output_dir%\%mutual_snd_path%\"
copy "%input_dir%\pack_%mcversion%.mcmeta" "%pm_out%"
copy "%input_dir%\pack.png" "%output_dir%\pack.png"
call :amkdir %snd_out%
if "%mcversion%" equ "1.7" || "%mcversion%" equ "1.8" (
set cave_sounds_limit=13
) else if "%mcversion%" equ "1.9" (
set cave_sounds_limit=13
if "%mcversion%" equ "1.9" do (
set cave_sounds_limit=14
) else if "%mcversion%" equ "1.10" (
) else if "%mcversion%" equ "1.10" do (
set cave_sounds_limit=16
) else if "%mcversion%" equ "1.12" (
) else if "%mcversion%" equ "1.12" do (
set cave_sounds_limit=18
) else if "%mcversion%" equ "1.20" (
set cave_sounds_limit=19
)
set 1_13_x_plus=0
if "%mcversion%" equ "1.13" set 1_13_x_plus=1
if "%mcversion%" equ "1.14" set 1_13_x_plus=1
if "%mcversion%" equ "1.15" set 1_13_x_plus=1
if "%mcversion%" equ "1.16" set 1_13_x_plus=1
if "%mcversion%" equ "1.17" set 1_13_x_plus=1
if "%mcversion%" equ "1.18" set 1_13_x_plus=1
if "%mcversion%" equ "1.19" set 1_13_x_plus=1
if "%mcversion%" equ "1.20" set 1_13_x_plus=1
if "%1_13_x_plus%" equ "1" set cave_sounds_limit=19
for /L %%i in (1, 1, %cave_sounds_limit%) do (
set cur_file="%snd_src%\cave%%i.ogg"
if exist %cur_file% (
copy %cur_file% "%snd_out%"
set last_existent_snd=%cur_file%
) else (
) else if defined %last_existent_snd% do (
copy %last_existent_snd% "%snd_out%"
)
if "%errorlevel%" gtr 0 exit 2
)
copy "%snd_src%\cave_%mcversion%.json" "%snd_out%\cave.json"
rem xcopy /Y /E "%input_dir%\assets" "%output_dir%\assets"
:compile
7z.exe a -r -x!%0 -mx0 "%mcrespath%\%packname%" "%input_dir%\*"
cd "%output_dir%"
7z.exe a -r -x!%0 -mx0 "..\%packname%" "*"
cd ..
move /-Y "%packname%" "%mcrespath%\%packname%"
pause
goto :EOF
@ -71,7 +82,6 @@ goto :EOF
call :adel "%output_dir%\*.*"
call :adel "%output_dir%\%mutual_snd_path%\*.*"
call :ard "%output_dir%\%mutual_snd_path%"
echo Build directory cleaned.
exit /b
:help

View File

@ -1,29 +1,41 @@
#!/bin/bash
prepare() {
clean
packname="anti-cave-noises-$mcversion.zip"
build
input_dir="./src"
output_dir="./build"
mcrespath="$MINECRAFT_PATH/resourcepacks"
packname_prefix="anti-cave-noises-"
packname_ext="zip"
mutual_snd_path="assets/minecraft/sounds/ambient/cave"
pause() {
read -n 1 -sp "Press any key to continue..."
echo
}
build() {
pm_out="$output_dir/pack.mcmeta"
snd_src="$input_dir/$mutual_snd_path/"
snd_out="$output_dir/$mutual_snd_path/"
packname="$packname_prefix$mcversion.$packname_ext"
amkdir "$output_dir"
pm_out="$output_dir/pack.mcmeta"
snd_src="$input_dir/$mutual_snd_path"
snd_out="$output_dir/$mutual_snd_path"
amkdir "$snd_out/"
cp "$input_dir/pack_$mcversion.mcmeta" "$pm_out"
cp "$input_dir/pack.png" "$output_dir/pack.png"
amkdir "$snd_out"
if [ "$mcversion" = "1.7" ] || [ "$mcversion" = "1.8" ]; then
cave_sounds_limit=13
elif [ "$mcversion" = "1.9" ]; then
cave_sounds_limit=13
if [ "$mcversion" = "1.9" ]; then
cave_sounds_limit=14
elif [ "$mcversion" = "1.10" ]; then
elif [ "$mcversion" = "1.10" ] || [ "$mcversion" = "1.11" ]; then
cave_sounds_limit=16
elif [ "$mcversion" = "1.12" ]; then
cave_sounds_limit=18
elif [ "$mcversion" = "1.20" ]; then
elif [ "$mcversion" = "1.13" ] || [ "$mcversion" = "1.14" ] ||
[ "$mcversion" = "1.15" ] || [ "$mcversion" = "1.15" ] ||
[ "$mcversion" = "1.16" ] || [ "$mcversion" = "1.17" ] ||
[ "$mcversion" = "1.18" ] || [ "$mcversion" = "1.19" ] ||
[ "$mcversion" = "1.20" ]; then
cave_sounds_limit=19
fi
@ -34,9 +46,12 @@ build() {
if [ -e "$cur_file" ]; then
cp "$cur_file" "$snd_out"
last_existent_snd="$cur_file"
else
elif [ -e "$last_existent_snd" ]; then
cp "$last_existent_snd" "$snd_out"
fi
if [ $? -gt 0 ]; then
exit 2
fi
done
cp "$snd_src/cave_$mcversion.json" "$snd_out/cave.json"
@ -45,25 +60,26 @@ build() {
}
compile() {
7z a -r -x!$0 -mx0 "$mcrespath/$packname" "$input_dir/*"
read -p "Press Enter to continue..."
exit 0
cd "$output_dir"
7z a -r -x!$0 -mx0 "../$packname" "../$input_dir/*"
cd ..
mv -i "$packname" "$mcrespath/$packname"
pause
}
clean() {
adel "$output_dir/*.*"
adel "$output_dir/$mutual_snd_path/*.*"
adel "./$packname_prefix*.$packname_ext"
ard "$output_dir/$mutual_snd_path"
echo "Build directory cleaned."
exit 0
}
display_help() {
echo "Usage: $0 <command> <target Minecraft version>"
echo "Commands:"
echo "/?,"
echo "-h,"
echo "--help : Displays this help message"
echo "-h,"
echo "--help : Displays this help message"
echo "build : Builds the resource pack"
echo "clean : Cleans the build directory"
echo
@ -75,7 +91,6 @@ display_available_versions() {
echo "- 1.12"
echo "- 1.20"
echo
exit 0
}
adel() {
@ -92,14 +107,11 @@ ard() {
amkdir() {
if [ ! -d "$1" ]; then
mkdir "$1"
mkdir -p "$1"
fi
}
input_dir="src"
output_dir="build"
mcrespath="$MINECRAFT_PATH/resourcepacks"
mutual_snd_path="assets/minecraft/sounds/ambient/cave"
# main branch
mcversion=""
if [ "$1" = "/?" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
@ -114,13 +126,14 @@ if [ "$1" = "build" ]; then
else
mcversion="$2"
fi
prepare
clean
build
elif [ "$1" = "clean" ]; then
clean
exit 0
rm -rf "$output_dir"
echo "Build directory cleaned."
else
display_help
exit 1
fi
prepare
exit 0