|
| 1 | +#!/bin/bash |
| 2 | +### Generates lua and cfg files to handle .ogg sounds for Factorio |
| 3 | +### Modified version of https://github.com/ZwerOxotnik/Mod-generator |
| 4 | + |
| 5 | + |
| 6 | +SOUNDS_LIST_FILE=sounds_list.lua |
| 7 | +CFG_FILE=sounds_list.cfg |
| 8 | + |
| 9 | + |
| 10 | +### Get mod name and version from info.json |
| 11 | +### https://stedolan.github.io/jq/ |
| 12 | +mod_name=`cat info.json|jq -r .name` |
| 13 | + |
| 14 | + |
| 15 | +echo "you're in $(pwd)" |
| 16 | +read -r -p "Complete path to folder of sounds: $mod_name/" folder_path |
| 17 | +read -r -p "Add sounds to programmable speakers? [Y/N] " response |
| 18 | +case "$response" in |
| 19 | + [yY][eE][sS]|[yY]) |
| 20 | + STATE=1 |
| 21 | + ;; |
| 22 | + *) |
| 23 | + STATE=2 |
| 24 | + ;; |
| 25 | +esac |
| 26 | +if [ $STATE -eq 1 ]; then |
| 27 | + read -r -p "Insert group name of sounds:" sound_group_name |
| 28 | + case "$sound_group_name" in "") |
| 29 | + sound_group_name=$mod_name |
| 30 | + ;; |
| 31 | + esac |
| 32 | +fi |
| 33 | + |
| 34 | + |
| 35 | +SOUNDS_LIST_PATH="$folder_path/$SOUNDS_LIST_FILE" |
| 36 | +rm -f $SOUNDS_LIST_PATH |
| 37 | +CFG_FILE="$sound_group_name".cfg |
| 38 | +rm -f $CFG_FILE |
| 39 | + |
| 40 | +if [ $STATE -eq 1 ]; then |
| 41 | + echo "### This file auto-generated by https://github.com/ZwerOxotnik/factorio-example-mod" >> $CFG_FILE |
| 42 | + echo "### Please, do not change this file manually!" >> $CFG_FILE |
| 43 | + echo "[programmable-speaker-instrument]" >> $CFG_FILE |
| 44 | + echo $sound_group_name=$sound_group_name >> $CFG_FILE |
| 45 | + echo "[programmable-speaker-note]" >> $CFG_FILE |
| 46 | +fi |
| 47 | +echo "-- This file auto-generated by https://github.com/ZwerOxotnik/factorio-example-mod" >> $SOUNDS_LIST_PATH |
| 48 | +echo "-- Please, do not change this file if you're not sure, except sounds_list.name and path!" >> $SOUNDS_LIST_PATH |
| 49 | +echo "-- You need require this file to your control.lua and add https://mods.factorio.com/mod/zk-lib in your dependencies" >> $SOUNDS_LIST_PATH |
| 50 | +echo "" >> $SOUNDS_LIST_PATH |
| 51 | +echo "local sounds_list = {" >> $SOUNDS_LIST_PATH |
| 52 | + |
| 53 | +if [ $STATE -eq 1 ]; then |
| 54 | + echo -e "\tname = \"$sound_group_name\", --change me, if you want to add these sounds to programmable speakers" >> $SOUNDS_LIST_PATH |
| 55 | +fi |
| 56 | +if [ $STATE -eq 2 ]; then |
| 57 | + echo -e "\tname = nil --change me, if you want to add these sounds to programmable speakers" >> $SOUNDS_LIST_PATH |
| 58 | +fi |
| 59 | +echo -e "\tpath = \"__"$mod_name"__/"$folder_path"/\", -- path to this folder" >> $SOUNDS_LIST_PATH |
| 60 | +echo -e "\tsounds = {" >> $SOUNDS_LIST_PATH |
| 61 | + |
| 62 | +format=*.ogg |
| 63 | +files=($(find . -name "$format" -type f)) |
| 64 | +for path in "${files[@]}"; do |
| 65 | + name="$(basename -- $path)" |
| 66 | + name=${name%.*} |
| 67 | + echo -e "\t\t{" >> $SOUNDS_LIST_PATH |
| 68 | + echo -e "\t\t\tname = \"$name\"", >> $SOUNDS_LIST_PATH |
| 69 | + echo -e "\t\t}," >> $SOUNDS_LIST_PATH |
| 70 | + if [ $STATE -eq 1 ]; then |
| 71 | + echo $name=$name >> $CFG_FILE |
| 72 | + fi |
| 73 | +done |
| 74 | +echo -e "\t}" >> $SOUNDS_LIST_PATH |
| 75 | +echo "}" >> $SOUNDS_LIST_PATH |
| 76 | +echo "" >> $SOUNDS_LIST_PATH |
| 77 | +echo if "puan_api then puan_api.add_sounds(sounds_list) end" >> $SOUNDS_LIST_PATH |
| 78 | +echo "" >> $SOUNDS_LIST_PATH |
| 79 | +echo "return sounds_list" >> $SOUNDS_LIST_PATH |
| 80 | + |
| 81 | +echo "You're almost ready!" |
| 82 | +echo "# You need to write 'require(\"__$mod_name__/$folder_path/sounds_list\")' in your $mod_name/control.lua" |
| 83 | +echo "# Add string \"zk-lib\" in dependencies of $mod_name/info.json, example: '\"dependencies\": [\"zk-lib\"]'" |
| 84 | +if [ $STATE -eq 1 ]; then |
| 85 | + echo "# Put $CFG_FILE in folder "$mod_name"/locale/en (it'll provide readable text in the game)" |
| 86 | +fi |
| 87 | + |
| 88 | +echo "" |
| 89 | +echo "" |
| 90 | + |
| 91 | +echo "if you found a bug or you have a problem with script etc, please, let me know" |
| 92 | +echo "This script created by ZwerOxotnik (source: https://github.com/ZwerOxotnik/factorio-example-mod)" |
0 commit comments