-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrm2png.sh
executable file
·126 lines (97 loc) · 2.93 KB
/
frm2png.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
set -eu
readonly dir_output=docs
readonly frm2png=tools/frm2png/Build/frm2png
readonly options=
if [[ ! -f "$frm2png" ]]; then
echo ::group::frm2png
git clone --recurse-submodules https://github.com/rotators/frm2png.git tools/frm2png
cmake -S tools/frm2png/Source -B tools/frm2png/Build
cmake --build tools/frm2png/Build
echo ::endgroup::
fi
# while frm2png can process multiple files at once,
# it can't really be used here as output is intended to be in different directory with normalized filename
function png-name()
{
local frm="$1"
local suffix=
if (( $# > 1 )); then
suffix="$2"
fi
frm="${frm//\.\//}"
frm_dir="$(dirname "$frm")"
frm_base="$(basename "$frm")"
frm_name="${frm_base%.*}"
echo "$dir_output/$frm_dir/${frm_name^^}${suffix}.png"
}
#
function ignore-frm()
{
local frm="$1"
local frm_dir="$(dirname "$frm")"
local frm_base="$(basename "$frm")"
local frm_anim=
if [[ "${frm_base:0:1}" == "_" ]]; then
frm_anim=${frm_base:7:2}
else
frm_anim=${frm_base:6:2}
fi
frm_anim=${frm_anim^^}
if [[ "$frm_dir" =~ ^_IGNORE_/ ]]; then
echo "SKIPPED"
return 0
fi
if [[ $frm_anim == "NA" ]]; then
return 0
fi
return 1
}
#
function process-frm()
{
find . -iname "*.frm" | sort | while read frm; do
frm="${frm//\.\//}"
if ignore-frm "$frm"; then
continue
fi
echo "::group::$frm"
mkdir -p "$dir_output/$(dirname "$frm")"
$frm2png $options -g anim -o "$(png-name "$frm")" "$frm"
# >/dev/null, so frm info will be displayed only once
$frm2png $options -g anim-packed -o "$(png-name "$frm")" "$frm" > /dev/null
$frm2png $options -g static -o "$(png-name "$frm" .static)" "$frm" > /dev/null
echo ::endgroup::
done
}
#
function process-frX()
{
for dir in $(seq 0 5); do
find . -iname "*.fr$dir" | sort | while read frm; do
frm="${frm//\.\//}"
if ignore-frm "$frm"; then
continue
fi
echo "::group::$frm"
mkdir -p "$dir_output/$(dirname "$frm")"
$frm2png $options -g anim -o "$(png-name "$frm" _$dir)" "$frm"
# >/dev/null, so frm info will be displayed only once
$frm2png $options -g static -o "$(png-name "$frm" _$dir.static)" "$frm" > /dev/null
echo ::endgroup::
done
# frm2png adds "_<direction>" to filenames when using `anim` generator;
# .fr[0-5] always use direction=0, so intended filename must be restored
find $dir_output/ -iname "*_${dir}_0.png" | while read png; do
png_new="${png//_${dir}_0/_${dir}}"
mv "$png" "$png_new"
done
done
}
#
rm -fr $dir_output
process-frm
process-frX
(cd $dir_output && LC_COLLATE=C tree --sort=name -H . -P *.png > index.html)
echo
du -hd0 $dir_output/