forked from EBonura/bonnie-32
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
275 lines (230 loc) · 8.98 KB
/
Copy pathbuild.rs
File metadata and controls
275 lines (230 loc) · 8.98 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
//! Build script to generate manifests for WASM builds
//!
//! Scans asset directories and creates manifests listing all files, since WASM
//! can't enumerate directories at runtime.
use std::fs;
use std::io::Write;
use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=assets/samples/textures");
println!("cargo:rerun-if-changed=assets/samples/texture-packs");
println!("cargo:rerun-if-changed=assets/samples/levels");
println!("cargo:rerun-if-changed=assets/samples/assets");
println!("cargo:rerun-if-changed=assets/samples/meshes");
println!("cargo:rerun-if-changed=assets/samples/songs");
generate_texture_manifest();
generate_texture_packs_manifest();
generate_levels_manifest();
generate_models_manifest();
generate_meshes_manifest();
generate_songs_manifest();
}
/// Generate manifest for UserTexture RON files in textures/
fn generate_texture_manifest() {
let textures_dir = Path::new("assets/samples/textures");
let manifest_path = Path::new("assets/samples/textures/manifest.txt");
let mut manifest = String::new();
if textures_dir.exists() {
let mut textures: Vec<_> = fs::read_dir(textures_dir)
.unwrap()
.filter_map(|e| e.ok())
.filter(|e| {
let path = e.path();
path.is_file()
&& path
.extension()
.map(|ext| ext.to_ascii_lowercase() == "ron")
.unwrap_or(false)
})
.collect();
textures.sort_by_key(|e| e.file_name());
for tex_entry in textures {
let tex_name = tex_entry.file_name().to_string_lossy().to_string();
manifest.push_str(&format!("{}\n", tex_name));
}
}
// Write manifest file
if let Some(parent) = manifest_path.parent() {
let _ = fs::create_dir_all(parent);
}
let mut file = fs::File::create(manifest_path).unwrap();
file.write_all(manifest.as_bytes()).unwrap();
}
/// Generate manifests for texture packs (PNG source images)
/// Creates:
/// - texture-packs/manifest.txt (list of pack names)
/// - texture-packs/{pack}/manifest.txt (list of PNGs in each pack)
fn generate_texture_packs_manifest() {
let packs_dir = Path::new("assets/samples/texture-packs");
if !packs_dir.exists() {
return;
}
let mut packs: Vec<_> = fs::read_dir(packs_dir)
.unwrap()
.filter_map(|e| e.ok())
.filter(|e| e.path().is_dir())
.collect();
packs.sort_by_key(|e| e.file_name());
// Generate top-level manifest listing pack names
let mut packs_manifest = String::new();
for pack_entry in &packs {
let pack_path = pack_entry.path();
let pack_name = pack_entry.file_name().to_string_lossy().to_string();
// Get all PNG files in the pack
let mut textures: Vec<_> = fs::read_dir(&pack_path)
.unwrap()
.filter_map(|e| e.ok())
.filter(|e| {
e.path()
.extension()
.map(|ext| ext.to_ascii_lowercase() == "png")
.unwrap_or(false)
})
.collect();
textures.sort_by_key(|e| e.file_name());
if !textures.is_empty() {
// Add to packs manifest
packs_manifest.push_str(&format!("{}\n", pack_name));
// Generate per-pack manifest
let mut pack_manifest = String::new();
for tex_entry in textures {
let tex_name = tex_entry.file_name().to_string_lossy().to_string();
pack_manifest.push_str(&format!("{}\n", tex_name));
}
let pack_manifest_path = pack_path.join("manifest.txt");
let mut file = fs::File::create(pack_manifest_path).unwrap();
file.write_all(pack_manifest.as_bytes()).unwrap();
}
}
// Write top-level packs manifest
let packs_manifest_path = packs_dir.join("manifest.txt");
let mut file = fs::File::create(packs_manifest_path).unwrap();
file.write_all(packs_manifest.as_bytes()).unwrap();
}
/// Generate manifest for levels (for WASM builds)
fn generate_levels_manifest() {
let levels_dir = Path::new("assets/samples/levels");
let manifest_path = Path::new("assets/samples/levels/manifest.txt");
let mut manifest = String::new();
if levels_dir.exists() {
let mut levels: Vec<_> = fs::read_dir(levels_dir)
.unwrap()
.filter_map(|e| e.ok())
.filter(|e| {
let path = e.path();
// Only include .ron files, skip directories
path.is_file() && path
.extension()
.map(|ext| ext.to_ascii_lowercase() == "ron")
.unwrap_or(false)
})
.collect();
levels.sort_by_key(|e| e.file_name());
for level_entry in levels {
let level_name = level_entry.file_name().to_string_lossy().to_string();
manifest.push_str(&format!("{}\n", level_name));
}
}
// Write manifest file
if let Some(parent) = manifest_path.parent() {
let _ = fs::create_dir_all(parent);
}
let mut file = fs::File::create(manifest_path).unwrap();
file.write_all(manifest.as_bytes()).unwrap();
}
/// Generate manifest for models/assets (for WASM builds)
fn generate_models_manifest() {
let models_dir = Path::new("assets/samples/assets");
let manifest_path = Path::new("assets/samples/assets/manifest.txt");
let mut manifest = String::new();
if models_dir.exists() {
let mut models: Vec<_> = fs::read_dir(models_dir)
.unwrap()
.filter_map(|e| e.ok())
.filter(|e| {
let path = e.path();
// Only include .ron files, skip directories
path.is_file()
&& path
.extension()
.map(|ext| ext.to_ascii_lowercase() == "ron")
.unwrap_or(false)
})
.collect();
models.sort_by_key(|e| e.file_name());
for model_entry in models {
let model_name = model_entry.file_name().to_string_lossy().to_string();
manifest.push_str(&format!("{}\n", model_name));
}
}
// Write manifest file
if let Some(parent) = manifest_path.parent() {
let _ = fs::create_dir_all(parent);
}
let mut file = fs::File::create(manifest_path).unwrap();
file.write_all(manifest.as_bytes()).unwrap();
}
/// Generate manifest for meshes (for WASM builds)
fn generate_meshes_manifest() {
let meshes_dir = Path::new("assets/samples/meshes");
let manifest_path = Path::new("assets/samples/meshes/manifest.txt");
let mut manifest = String::new();
if meshes_dir.exists() {
let mut meshes: Vec<_> = fs::read_dir(meshes_dir)
.unwrap()
.filter_map(|e| e.ok())
.filter(|e| {
let path = e.path();
// Only include .obj files, skip directories
path.is_file()
&& path
.extension()
.map(|ext| ext.to_ascii_lowercase() == "obj")
.unwrap_or(false)
})
.collect();
meshes.sort_by_key(|e| e.file_name());
for mesh_entry in meshes {
let mesh_name = mesh_entry.file_name().to_string_lossy().to_string();
manifest.push_str(&format!("{}\n", mesh_name));
}
}
// Write manifest file
if let Some(parent) = manifest_path.parent() {
let _ = fs::create_dir_all(parent);
}
let mut file = fs::File::create(manifest_path).unwrap();
file.write_all(manifest.as_bytes()).unwrap();
}
/// Generate manifest for songs (for WASM builds)
fn generate_songs_manifest() {
let songs_dir = Path::new("assets/samples/songs");
let manifest_path = Path::new("assets/samples/songs/manifest.txt");
let mut manifest = String::new();
if songs_dir.exists() {
let mut songs: Vec<_> = fs::read_dir(songs_dir)
.unwrap()
.filter_map(|e| e.ok())
.filter(|e| {
let path = e.path();
// Only include .ron files, skip directories
path.is_file()
&& path
.extension()
.map(|ext| ext.to_ascii_lowercase() == "ron")
.unwrap_or(false)
})
.collect();
songs.sort_by_key(|e| e.file_name());
for song_entry in songs {
let song_name = song_entry.file_name().to_string_lossy().to_string();
manifest.push_str(&format!("{}\n", song_name));
}
}
// Write manifest file (create directory if needed)
if let Some(parent) = manifest_path.parent() {
let _ = fs::create_dir_all(parent);
}
let mut file = fs::File::create(manifest_path).unwrap();
file.write_all(manifest.as_bytes()).unwrap();
}