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 "mcrespath=%MINECRAFT_PATH%\resourcepacks"
set "mutual_snd_path=assets\minecraft\sounds\ambient\cave" set "mutual_snd_path=assets\minecraft\sounds\ambient\cave"
rem main branch
set "mcversion=" set "mcversion="
if "%1" equ "/?" goto :help if "%1" equ "/?" goto :help
@ -19,17 +20,15 @@ if "%1" equ "build" (
) )
goto :prepare goto :prepare
) else if "%1" equ "clean" ( ) else if "%1" equ "clean" (
call :clean rd /S /Q ".\build"
echo Build directory cleaned.
goto :EOF goto :EOF
) else ( ) else (
goto :help goto :help
) )
:prepare
call :clean
set "packname=anti-cave-noises-%mcversion%.zip"
:build :build
set "packname=anti-cave-noises-%mcversion%.zip"
set "pm_out=%output_dir%\pack.mcmeta" set "pm_out=%output_dir%\pack.mcmeta"
set "snd_src=%input_dir%\%mutual_snd_path%\" set "snd_src=%input_dir%\%mutual_snd_path%\"
set "snd_out=%output_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_%mcversion%.mcmeta" "%pm_out%"
copy "%input_dir%\pack.png" "%output_dir%\pack.png" copy "%input_dir%\pack.png" "%output_dir%\pack.png"
call :amkdir %snd_out% call :amkdir %snd_out%
if "%mcversion%" equ "1.7" || "%mcversion%" equ "1.8" (
set cave_sounds_limit=13 set cave_sounds_limit=13
) else if "%mcversion%" equ "1.9" ( if "%mcversion%" equ "1.9" do (
set cave_sounds_limit=14 set cave_sounds_limit=14
) else if "%mcversion%" equ "1.10" ( ) else if "%mcversion%" equ "1.10" do (
set cave_sounds_limit=16 set cave_sounds_limit=16
) else if "%mcversion%" equ "1.12" ( ) else if "%mcversion%" equ "1.12" do (
set cave_sounds_limit=18 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 ( for /L %%i in (1, 1, %cave_sounds_limit%) do (
set cur_file="%snd_src%\cave%%i.ogg" set cur_file="%snd_src%\cave%%i.ogg"
if exist %cur_file% ( if exist %cur_file% (
copy %cur_file% "%snd_out%" copy %cur_file% "%snd_out%"
set last_existent_snd=%cur_file% set last_existent_snd=%cur_file%
) else ( ) else if defined %last_existent_snd% do (
copy %last_existent_snd% "%snd_out%" copy %last_existent_snd% "%snd_out%"
) )
if "%errorlevel%" gtr 0 exit 2
) )
copy "%snd_src%\cave_%mcversion%.json" "%snd_out%\cave.json" copy "%snd_src%\cave_%mcversion%.json" "%snd_out%\cave.json"
rem xcopy /Y /E "%input_dir%\assets" "%output_dir%\assets" rem xcopy /Y /E "%input_dir%\assets" "%output_dir%\assets"
:compile :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 pause
goto :EOF goto :EOF
@ -71,7 +82,6 @@ goto :EOF
call :adel "%output_dir%\*.*" call :adel "%output_dir%\*.*"
call :adel "%output_dir%\%mutual_snd_path%\*.*" call :adel "%output_dir%\%mutual_snd_path%\*.*"
call :ard "%output_dir%\%mutual_snd_path%" call :ard "%output_dir%\%mutual_snd_path%"
echo Build directory cleaned.
exit /b exit /b
:help :help

View File

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