doom_generate_maps_meta_recursively.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/sh
  2. #set -x
  3. # Mapea formato a engine por defecto
  4. engine_for_format() {
  5. format=$1
  6. game=$2
  7. case "$format" in
  8. vanilla)
  9. case "$game" in
  10. heretic) echo "chocolate-heretic" ;;
  11. hexen) echo "chocolate-hexen" ;;
  12. *) echo "chocolate-doom" ;;
  13. esac
  14. ;;
  15. limit-removing)
  16. case "$game" in
  17. heretic) echo "crispy-heretic" ;;
  18. hexen) echo "crispy-hexen" ;;
  19. *) echo "crispy-doom" ;;
  20. esac
  21. ;;
  22. boom|mbf) echo "prboom+" ;;
  23. mbf21) echo "dsda-doom" ;;
  24. gzdoom) echo "gzdoom" ;;
  25. zdoom) echo "zdoom" ;;
  26. eternity) echo "eternity" ;;
  27. vavoom) echo "vavoom" ;;
  28. legacy) echo "legacy" ;;
  29. *) echo "unknown" ;;
  30. esac
  31. }
  32. get_game_from_path() {
  33. # Va dos niveles arriba desde el WAD para obtener el juego base
  34. dirname "$(dirname "$(pwd)")" | sed 's#.*/##'
  35. }
  36. slugify() {
  37. echo "$1" | tr '[:upper:]' '[:lower:]' | tr ' ' '_' | tr -cd '[:alnum:]_-.'
  38. }
  39. for format_dir in */; do
  40. [ -d "$format_dir" ] || continue
  41. cd "$format_dir" || continue
  42. for wad_dir in */; do
  43. [ -d "$wad_dir" ] || continue
  44. cd "$wad_dir" || continue
  45. ini_file="meta.ini"
  46. wad_name=$(basename "$wad_dir")
  47. format=$(basename "$(dirname "$(pwd)")")
  48. title="$wad_name"
  49. game=$(get_game_from_path)
  50. engine=$(engine_for_format "$format" "$game")
  51. tags=""
  52. args=""
  53. iwad=""
  54. # Buscar todos los .txt excluyendo los irrelevantes
  55. found_txts=""
  56. for txt in *.txt; do
  57. [ -f "$txt" ] || continue
  58. case "$(echo "$txt" | tr '[:upper:]' '[:lower:]')" in
  59. *changelog*|*readme*|*history*|*credits*|*dmatch*|*singcoop*|*weapons*|*story*|*about*|*_dm*|*instructions*|*mp3*)
  60. continue
  61. ;;
  62. *)
  63. found_txts="$found_txts $txt"
  64. ;;
  65. esac
  66. done
  67. # Procesar cada .txt válido
  68. for txt_file in $found_txts; do
  69. grep -iq "slaughter" "$txt_file" && tags="$tags,slaughter"
  70. grep -iq "puzzle" "$txt_file" && tags="$tags,puzzle"
  71. grep -iq "megawad" "$txt_file" && tags="$tags,megawad"
  72. grep -iq "cooperative" "$txt_file" && tags="$tags,cooperative"
  73. # Buscar complevel
  74. complevel=$(grep -i "complevel" "$txt_file" | head -n 1 | sed 's/[^0-9]*\([0-9][0-9]*\).*/\1/')
  75. [ -n "$complevel" ] && args="$args -complevel $complevel"
  76. # # Buscar IWAD
  77. # iwad_line=$(grep -i "^Game[[:space:]]*:" "$txt_file" | head -n 1)
  78. # case "$(echo "$iwad_line" | tr '[:upper:]' '[:lower:]')" in
  79. # *doom 2*|*doom2*|*doom ii*) iwad="doom2" ;;
  80. # *tnt*) iwad="tnt" ;;
  81. # *plutonia*) iwad="plutonia" ;;
  82. # *heretic*) iwad="heretic" ;;
  83. # *hexen*) iwad="hexen" ;;
  84. # *strife*) iwad="strife" ;;
  85. # esac
  86. done
  87. # Añadir tag si el formato es deathmatch
  88. echo "$format" | grep -iq "deathmatch" && tags="$tags,deathmatch"
  89. # Limpiar coma inicial o dobles
  90. tags=$(echo "$tags" | sed 's/^,//;s/,,/,/g')
  91. # Escribir INI
  92. {
  93. echo "title=$title"
  94. echo "engine=$engine"
  95. echo "format=$format"
  96. [ -n "$iwad" ] && echo "iwad=$iwad"
  97. [ -n "$tags" ] && echo "tags=$tags"
  98. [ -n "$complevel" ] && echo "complevel=$complevel"
  99. [ -n "$args" ] && echo "args=$args"
  100. } > "$ini_file"
  101. cd ..
  102. done
  103. cd ..
  104. done