mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-12-22 22:54:16 +07:00
Use schematic/map names for filenames
This commit is contained in:
parent
f62096dbd1
commit
2db90408fe
@ -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){
|
||||
|
@ -190,7 +190,7 @@ public class Maps{
|
||||
maps.remove(other);
|
||||
file = other.file;
|
||||
}else{
|
||||
file = findFile();
|
||||
file = findFile(name);
|
||||
}
|
||||
|
||||
//create map, write it, etc etc etc
|
||||
@ -239,7 +239,7 @@ public class Maps{
|
||||
|
||||
/** Import a map, then save it. This updates all values and stored data necessary. */
|
||||
public void importMap(Fi file) throws IOException{
|
||||
Fi dest = findFile();
|
||||
Fi dest = findFile(file.name());
|
||||
file.copyTo(dest);
|
||||
|
||||
Map map = loadMap(dest, true);
|
||||
@ -429,13 +429,19 @@ public class Maps{
|
||||
}
|
||||
|
||||
/** Find a new filename to put a map to. */
|
||||
private Fi findFile(){
|
||||
//find a map name that isn't used.
|
||||
int i = maps.size;
|
||||
while(customMapDirectory.child("map_" + i + "." + mapExtension).exists()){
|
||||
i++;
|
||||
private Fi findFile(String unsanitizedName){
|
||||
String name = Strings.sanitizeFilename(unsanitizedName);
|
||||
if(name.isEmpty()) name = "blank";
|
||||
|
||||
Fi result = null;
|
||||
int index = 0;
|
||||
|
||||
while(result == null || result.exists()){
|
||||
result = customMapDirectory.child(name + (index == 0 ? "" : "_" + index) + "." + mapExtension);
|
||||
index ++;
|
||||
}
|
||||
return customMapDirectory.child("map_" + i + "." + mapExtension);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map loadMap(Fi file, boolean custom) throws IOException{
|
||||
|
@ -25,4 +25,4 @@ org.gradle.caching=true
|
||||
#used for slow jitpack builds; TODO see if this actually works
|
||||
org.gradle.internal.http.socketTimeout=100000
|
||||
org.gradle.internal.http.connectionTimeout=100000
|
||||
archash=2ef12ecfa1
|
||||
archash=56c0bbf95f
|
||||
|
Loading…
Reference in New Issue
Block a user