-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·238 lines (211 loc) · 5.09 KB
/
build.sh
File metadata and controls
executable file
·238 lines (211 loc) · 5.09 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/bin/bash
lua=luajit
os=$(uname)
lpp_path=./libs/LPP/preprocess-cl.lua
gv=$(git log -1 --format='v%cd.%h' --date=short 2>/dev/null)
data=dev
handler=handler.lua
padding=4
dir_modules=modules
dir_res=res
dir_output=output_dev
dir_source=src
dir_sub=(assemblages components shaders states systems)
appdata=~/.local/share/love/rememberinghome
meta_exclude_modules=(
spec docs example test love-sdf-text-testing rockspecs main.lua .travis
.git examples .travis.yml changelog.txt README.md MakeSingle.mak bench
CHANGELOG.md *.rockspec config.ld performance_test.lua USAGE.md img
)
exclude_modules=()
for e in "${meta_exclude_modules[@]}"; do
exclude_modules+=("--exclude=$e")
done
function create_output_dir()
{
if [ ! -d "$dir_output" ]; then
echo "creating $dir_output..."
mkdir $dir_output && echo "created $dir_output"
fi
}
function process_src()
{
for file in "$1"/*; do
if [ -d "$file" ]; then
local subd=$(echo "$file" | rev | cut -d'/' -f-1 | rev)
if [ ! -d "$dir_output"/"$subd" ]; then
mkdir "$dir_output"/"$subd"
fi
process_src "$file" "$subd"
elif [ -f "$file" ]; then
process_file "$file" "$2"
fi
done
}
function process_file()
{
local filename="${1##*/}"
local file=$(basename "$filename" .lua2p)
local ext="${filename##*.}"
local out=$dir_output/$2/$file
if [ "$ext" == "lua2p" ]; then
$lua "$lpp_path" --handler="$handler" --data="$data $gv $padding" --outputpaths "$1" "$out".lua --silent;
if [ $? -ne 0 ]; then
echo "error in $1"
exit;
fi
else
cp "$1" "$out"
fi
}
function check()
{
# https://luacheck.readthedocs.io/en/stable/cli.html
local file="$dir_output"
if [ $# -eq 2 ]; then
if [[ $2 == src* ]]; then
file="${file}/${2:4}"
else
file="${file}/$2"
fi
fi
luacheck $file -q \
--exclude-files "output_dev/modules/**/*.lua" \
--std luajit \
--globals love stringx mathx tablex pretty intersect timer \
--no-max-line-length \
--ignore 611 \
--jobs 2
}
function gen_atlas()
{
eta_path=./libs/ExportTextureAtlas/
output_path=./res/images/atlases
source_path=./res/exported
exported_dirs=("$@")
input_dirs=()
output_dirs=()
data_dirs=()
ignores=()
for cur_dir in "${exported_dirs[@]}"; do
in_dir="$source_path/$cur_dir/"
out_dir="$output_path/$cur_dir.png"
data_dir="./src/atlases/atlas_$cur_dir.lua"
ignore="$source_path/$cur_dir/$cur_dir.png"
input_dirs+=("$in_dir")
output_dirs+=("$out_dir")
data_dirs+=("$data_dir")
ignores+=("$ignore")
echo "gen atlas: '$in_dir' -> '$out_dir' + '$data_dir' !'$ignore'"
done
love "$eta_path" \
-input "${input_dirs[@]}" \
-output "${output_dirs[@]}" \
-dataOutput "${data_dirs[@]}" \
-ignore "${ignores[@]}" \
-removeFileExtension \
-padding "$padding" \
-template "./scripts/atlas_template.lua"
}
function copy_modules()
{
echo "copying modules..."
rsync -a "$dir_modules" "$dir_output" "${exclude_modules[@]}" && echo "copied modules to ${dir_output}"
rsync -a "$dir_modules" "$dir_source" "${exclude_modules[@]}" && echo "copied modules to ${dir_source}"
}
function copy_res()
{
echo "copying resources..."
rsync -a "$dir_res" "$dir_output" && echo "copied resources to ${dir_output}"
rsync -a "$dir_res" "$dir_source" && echo "copied resources to ${dir_source}"
rsync -a "slab.style" "$dir_output" && echo "copied slab.style"
}
function clean()
{
echo "cleaning $dir_output..."
rm -rf $dir_output/* && echo "cleaned $dir_output"
}
function clean_logs()
{
echo "cleaning $appdata..."
rm $appdata/* && echo "removed $appdata"
}
function init()
{
create_output_dir
copy_modules
process_src "$dir_source"
local exported_dirs=(
intro
kitchen
living_room
outside
storage_room
utility_room
office1
)
gen_atlas "${exported_dirs[@]}"
copy_res
}
function rebuild()
{
clean
init
cp slab.style $dir_output
}
function run2p()
{
echo "Running build.sh"
process_src "$dir_source"
if [ $(uname -r | sed -n 's/.*\( *Microsoft *\).*/\1/ip') ]; then
echo "This is Windows WSL!"
./build_win.sh run
else
echo "This is Linux"
love "$dir_output"
fi
echo "Completed build.sh"
}
function run()
{
love "$dir_source" --dev --git="$(git rev-parse --verify HEAD)"
}
function profile()
{
data=prof
dir_output=output_dev
run && prof_viewer
}
function prof_viewer()
{
if [ $(uname -r | sed -n 's/.*\( *Microsoft *\).*/\1/ip') ]; then
echo "This is Windows WSL!"
./build_win.sh prof_viewer
else
echo "This is Linux"
love modules/jprof rememberinghome prof.mpack
fi
}
function get_love_build()
{
if [[ $(uname) == "Darwin" ]]; then
local OUT="libs/love-build.zip"
wget -O "${OUT}" "https://github.com/ellraiser/love-build/releases/download/v0.9/love-build-0.9-macos.zip"
unzip "${OUT}" -d "libs/"
chmod u+rwx "libs/love-build.app"
chmod -R u+rwX "libs/love-build.app"
xattr -dr com.apple.quarantine "libs/love-build.app"
chmod +x "libs/love-build.app/Contents/MacOS/love"
mkdir -p "release"
else
echo "Not yet implemented for this OS"
fi
}
function lovebuild() {
"libs/love-build.app/Contents/MacOS/love" "src/main.lua"
}
if [ $# -eq 0 ]; then
echo "Must pass command: init, rebuild, clean, run, gen_atlas, copy_res, copy_modules"
else
"$@"
fi