Skip to content

Commit a14fbb7

Browse files
committed
Add "Handle sounds", "Build html" tasks
1 parent bfb27f1 commit a14fbb7

File tree

2 files changed

+114
-3
lines changed

2 files changed

+114
-3
lines changed

.scripts/handle_sounds.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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)"

.vscode/tasks.json

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,29 @@
77
"problemMatcher": [],
88
"command": "bash",
99
"args": [".scripts/zip_mod.sh"],
10-
"group": "build",
11-
"presentation": {
10+
"group": "build",
11+
"presentation": {
1212
"reveal": "silent",
13-
}
13+
}
14+
},
15+
{
16+
"label": "Build html",
17+
"type": "shell",
18+
"problemMatcher": [],
19+
"command": "sphinx-build -b html predocs docs/_build/html",
20+
"args": [""],
21+
"group": "build",
22+
"presentation": {
23+
"reveal": "silent",
24+
}
25+
},
26+
{
27+
"label": "Handle sounds",
28+
"type": "shell",
29+
"problemMatcher": [],
30+
"command": "bash",
31+
"args": [".scripts/handle_sounds.sh"],
32+
"group": "build"
1433
}
1534
]
1635
}

0 commit comments

Comments
 (0)