-
Notifications
You must be signed in to change notification settings - Fork 1
/
JourneyMapCombiner.java
88 lines (88 loc) · 3.17 KB
/
JourneyMapCombiner.java
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
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import javax.imageio.ImageIO;
public class JourneyMapCombiner{
public static void main(String[] args) throws IOException{
if(args.length<3){
System.out.println("There should be at least 3 arguments: 2 (or more) source directory paths and 1 destination directory path.");
System.exit(1);
}
File[] worlds=new File[args.length-1];
ArrayList<File> dimensions=new ArrayList<File>();
for(int x=0;x<worlds.length;x++){
worlds[x]=new File(args[x]);
File[] subList=worlds[x].listFiles();
for(File subFile:subList){
if(subFile.isDirectory()&&subFile.getName().startsWith("DIM")){//only the folders we want
dimensions.add(subFile);
}
}
}//now we have our dimension Files
ArrayList<String> dimensionPaths=getUniquePaths(dimensions);//get all the dimension paths
ArrayList<File> levels=new ArrayList<File>();
for(File dim:dimensions){
levels.addAll(Arrays.asList(dim.listFiles()));//assuming there's no extra files
}//now we have our level Files
ArrayList<String> levelPaths=getUniquePaths(levels);//get all level paths
ArrayList<File> images=new ArrayList<File>();
for(File level:levels){
images.addAll(Arrays.asList(level.listFiles()));
}//now we have our image files
ArrayList<String> imagePaths=getUniquePaths(images);//get all image paths
for(String levelPath:levelPaths){
File outDir=new File(args[args.length-1]+File.separator+levelPath);
outDir.mkdirs();
}
for(String imagePath:imagePaths){//the main loop
if(!imagePath.endsWith(".png"))
continue;
System.out.println(imagePath);//so user knows what it's doing
ArrayList<File> comparables=new ArrayList<File>();
for(File f:images){
if(f.getPath().endsWith(imagePath)){
comparables.add(f);
}
}
boolean moreSorting=true;
while(moreSorting){//bubble sort
moreSorting=false;
for(int x=1;x<comparables.size();x++){
if(comparables.get(x-1).lastModified()>comparables.get(x).lastModified()){
moreSorting=true;
File temp=comparables.get(x);
comparables.set(x,comparables.get(x-1));
comparables.set(x-1,temp);
}
}
}//now comparables is sorted oldest to newest (by date last modified), so the newer map is drawn overtop the old
BufferedImage buffI=ImageIO.read(comparables.get(0));
Graphics2D g2=buffI.createGraphics();
for(int x=1;x<comparables.size();x++){
g2.drawImage(ImageIO.read(comparables.get(x)),0,0,null);
}
g2.dispose();
File outFile=new File(args[args.length-1]+File.separator+imagePath);
ImageIO.write(buffI,"png",outFile);
outFile.setLastModified(comparables.get(comparables.size()-1).lastModified());
}
}
public static ArrayList<String> getUniquePaths(ArrayList<File> files) throws IOException{
ArrayList<String> paths=new ArrayList<String>();
for(File f:files){
String path=f.getPath();
path=path.substring(path.indexOf("DIM"));
int y;
for(y=0;y<paths.size();y++){
if(paths.get(y).equals(path))
break;
}
if(y==paths.size())//path isn't already in paths
paths.add(path);
}
return paths;
}
}