-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathPackConverter.java
More file actions
91 lines (72 loc) · 2.98 KB
/
PackConverter.java
File metadata and controls
91 lines (72 loc) · 2.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
package net.hypixel.resourcepack;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import joptsimple.OptionSet;
import net.hypixel.resourcepack.impl.*;
import net.hypixel.resourcepack.pack.Pack;
import java.io.IOException;
import java.nio.file.Files;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
public class PackConverter {
public static final boolean DEBUG = true;
protected final OptionSet optionSet;
protected final Gson gson;
protected final Map<Class<? extends Converter>, Converter> converters = new LinkedHashMap<>();
public PackConverter(OptionSet optionSet) {
this.optionSet = optionSet;
GsonBuilder gsonBuilder = new GsonBuilder();
if (!this.optionSet.has(Options.MINIFY)) gsonBuilder.setPrettyPrinting();
this.gson = gsonBuilder.create();
// this needs to be run first, other converters might reference new directory names
this.registerConverter(new NameConverter(this));
this.registerConverter(new PackMetaConverter(this));
this.registerConverter(new ModelConverter(this));
this.registerConverter(new SpacesConverter(this));
this.registerConverter(new SoundsConverter(this));
this.registerConverter(new ParticleConverter(this));
this.registerConverter(new BlockStateConverter(this));
this.registerConverter(new AnimationConverter(this));
this.registerConverter(new MapIconConverter(this));
}
public void registerConverter(Converter converter) {
converters.put(converter.getClass(), converter);
}
public <T extends Converter> T getConverter(Class<T> clazz) {
//noinspection unchecked
return (T) converters.get(clazz);
}
public void run() throws IOException {
Files.list(optionSet.valueOf(Options.INPUT_DIR))
.map(Pack::parse)
.filter(Objects::nonNull)
.forEach(pack -> {
try {
System.out.println("Converting " + pack);
pack.getHandler().setup();
System.out.println(" Running Converters");
for (Converter converter : converters.values()) {
if (PackConverter.DEBUG) {
System.out.println(" Running " + converter.getClass().getSimpleName());
}
converter.convert(pack);
}
pack.getHandler().finish();
} catch (Throwable t) {
System.err.println("Failed to convert!");
Util.propagate(t);
}
});
}
public Gson getGson() {
return gson;
}
@Override
public String toString() {
return "PackConverter{" +
"optionSet=" + optionSet +
", converters=" + converters +
'}';
}
}