Use schematic/map names for filenames

This commit is contained in:
Anuken
2023-04-16 12:07:57 -04:00
parent f62096dbd1
commit 2db90408fe
3 changed files with 29 additions and 10 deletions

View File

@@ -320,11 +320,24 @@ public class Schematics implements Loadable{
return block.size + maxLoadoutSchematicPad*2;
}
Fi findFile(String schematicName){
if(schematicName.isEmpty()) schematicName = "empty";
Fi result = null;
int index = 0;
while(result == null || result.exists()){
result = schematicDirectory.child(schematicName + (index == 0 ? "" : "_" + index) + "." + schematicExtension);
index ++;
}
return result;
}
/** Adds a schematic to the list, also copying it into the files.*/
public void add(Schematic schematic){
all.add(schematic);
try{
Fi file = schematicDirectory.child(Time.millis() + "." + schematicExtension);
Fi file = findFile(Strings.sanitizeFilename(schematic.name()));
write(schematic, file);
schematic.file = file;
}catch(Exception e){