forked from carltheperson/blockamok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall_to_h.sh
24 lines (20 loc) · 906 Bytes
/
all_to_h.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# When you run this script, every file in the current directory will be processed into a .cpp and .h file. These two files can then be imported and embedded into the game as assets.
for file in *; do
if [ -f "$file" ]; then
filename="${file%.*}" # Extract filename without extension
extension="${file##*.}" # Extract file extension
# Convert the file to a C++ file using xxd
echo "#include \"${filename}.h\"" > "$filename.cpp"
echo "" >> "$filename.cpp"
xxd -i "$file" >> "$filename.cpp"
# Set the two initial underscores based on whether the filename starts with a number
if [[ $filename =~ ^[0-9] ]]; then
us="__"
else
us=""
fi
# Create a header file for the C++ file
echo "extern unsigned char ${us}${filename}_${extension}[];" > "$filename.h"
echo "extern unsigned int ${us}${filename}_${extension}_len;" >> "$filename.h"
fi
done