Stage modern creature assets through WarcraftXL host
This commit is contained in:
+29
-8
@@ -43,13 +43,21 @@ fn build_mpq(
|
||||
.default_compression(flags::ZLIB)
|
||||
.listfile_option(ListfileOption::Generate);
|
||||
|
||||
let mut archive_names = std::collections::HashSet::new();
|
||||
let loose_sources: std::collections::HashSet<PathBuf> = creatures
|
||||
.into_iter()
|
||||
.flat_map(|generated| generated.assets.iter())
|
||||
.filter_map(|(source, _)| source.canonicalize().ok())
|
||||
.collect();
|
||||
|
||||
for entry in WalkDir::new(&base)
|
||||
.into_iter()
|
||||
.filter_map(|e| e.ok())
|
||||
.filter(|e| e.file_type().is_file())
|
||||
{
|
||||
let full_path = entry.path().canonicalize()?;
|
||||
if loose_sources.contains(&full_path) {
|
||||
continue;
|
||||
}
|
||||
let rel_path = match full_path.strip_prefix(&base) {
|
||||
Ok(p) => p,
|
||||
Err(_) => {
|
||||
@@ -62,17 +70,10 @@ fn build_mpq(
|
||||
continue;
|
||||
}
|
||||
println!(" Adding: {}", archive_path);
|
||||
archive_names.insert(archive_path.to_ascii_lowercase());
|
||||
builder = builder.add_file(&full_path, &archive_path);
|
||||
}
|
||||
|
||||
if let Some(generated) = creatures {
|
||||
for (source, archive_path) in &generated.assets {
|
||||
if archive_names.insert(archive_path.to_ascii_lowercase()) {
|
||||
println!(" Adding generated creature asset: {}", archive_path);
|
||||
builder = builder.add_file(source, archive_path);
|
||||
}
|
||||
}
|
||||
println!(" Adding generated: WXLFileData.csv");
|
||||
builder = builder.add_file_data(generated.file_data_csv.clone(), "WXLFileData.csv");
|
||||
println!(" Adding generated: WXLSpellOverrides.tsv");
|
||||
@@ -94,6 +95,22 @@ fn build_mpq(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn stage_loose_assets(
|
||||
output_dir: &Path,
|
||||
creatures: &GeneratedCreatures,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let loose_root = output_dir.join("Data").join("Patch-WXL.MPQ");
|
||||
for (source, archive_path) in &creatures.assets {
|
||||
let destination = loose_root.join(archive_path.replace('/', "\\"));
|
||||
if let Some(parent) = destination.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
fs::copy(source, &destination)?;
|
||||
println!("Staging loose modern asset: {}", archive_path);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
@@ -114,6 +131,10 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
.to_path_buf();
|
||||
let generated_creatures = creatures::prepare(&project_root)?;
|
||||
|
||||
if let Some(generated) = generated_creatures.as_ref() {
|
||||
stage_loose_assets(&output_dir, generated)?;
|
||||
}
|
||||
|
||||
let data_dir = src_dir.join("Data");
|
||||
if !data_dir.exists() {
|
||||
return Err(format!("Data/ not found inside src_dir: {}", src_dir.display()).into());
|
||||
|
||||
Reference in New Issue
Block a user