|
| 1 | +package objEditing.abilities; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | +import java.io.FileReader; |
| 5 | +import java.io.IOException; |
| 6 | +import java.util.List; |
| 7 | +import java.util.Set; |
| 8 | + |
| 9 | +import utils.WEStrings; |
| 10 | + |
| 11 | +import com.csvreader.CsvReader; |
| 12 | +import com.google.common.base.Charsets; |
| 13 | +import com.google.common.collect.HashMultimap; |
| 14 | +import com.google.common.collect.Lists; |
| 15 | +import com.google.common.collect.Multimap; |
| 16 | +import com.google.common.collect.Sets; |
| 17 | +import com.google.common.io.Files; |
| 18 | + |
| 19 | +public class GenAbilities { |
| 20 | + static WEStrings strings = new WEStrings().parseFile(new File("./WorldEditStrings.txt")); |
| 21 | + static StringBuilder sb = new StringBuilder(); |
| 22 | + |
| 23 | + static void println(String s) { |
| 24 | + sb.append(s); |
| 25 | + sb.append("\n"); |
| 26 | + } |
| 27 | + static void print(String s) { |
| 28 | + sb.append(s); |
| 29 | + } |
| 30 | + |
| 31 | + |
| 32 | + static class FieldData { |
| 33 | + String id; |
| 34 | + String displayName; |
| 35 | + String type; |
| 36 | + int data; |
| 37 | + boolean useLevels; |
| 38 | + |
| 39 | + public FieldData(String id, String displayName, String type, int data, |
| 40 | + boolean useLevels) { |
| 41 | + this.id = id; |
| 42 | + this.displayName = displayName; |
| 43 | + this.type = type; |
| 44 | + this.data = data; |
| 45 | + this.useLevels = useLevels; |
| 46 | + } |
| 47 | + |
| 48 | + public void printFunc(Set<String> usedFuncs) { |
| 49 | + println(""); |
| 50 | + String funcName = camelize(displayName); |
| 51 | + int i=0; |
| 52 | + if (usedFuncs.contains(funcName)) { |
| 53 | + do { |
| 54 | + i++; |
| 55 | + } while(usedFuncs.contains(funcName + i)); |
| 56 | + funcName = funcName + i; |
| 57 | + } |
| 58 | + usedFuncs.add(funcName); |
| 59 | + |
| 60 | + print(" function set" + funcName + "("); |
| 61 | + if (useLevels) { |
| 62 | + print("int level, "); |
| 63 | + } |
| 64 | + print(type() + " value)"); |
| 65 | + println(""); |
| 66 | + print(" def.set"); |
| 67 | + if (useLevels) { |
| 68 | + print("LvlData"); |
| 69 | + } |
| 70 | + print(typePost()); |
| 71 | + print("(\""+id+"\", "); |
| 72 | + if (useLevels) { |
| 73 | + print("level, " + data + ", "); |
| 74 | + } |
| 75 | + println("value)"); |
| 76 | + |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + private String type() { |
| 81 | + switch (type) { |
| 82 | + case "string": return "string"; |
| 83 | + case "bool": return "bool"; |
| 84 | + case "int": return "int"; |
| 85 | + case "real": return "real"; |
| 86 | + case "unreal": return "real"; |
| 87 | + } |
| 88 | + return "string"; |
| 89 | + } |
| 90 | + |
| 91 | + private String typePost() { |
| 92 | + switch (type) { |
| 93 | + case "string": return "String"; |
| 94 | + case "bool": return "Boolean"; |
| 95 | + case "int": return "Int"; |
| 96 | + case "real": return "Real"; |
| 97 | + case "unreal": return "Unreal"; |
| 98 | + } |
| 99 | + return "String"; |
| 100 | + } |
| 101 | + |
| 102 | + |
| 103 | + } |
| 104 | + |
| 105 | + |
| 106 | + public static void main(String[] args) throws IOException { |
| 107 | + List<FieldData> commonData = Lists.newArrayList(); |
| 108 | + Multimap<String, FieldData> specificData = HashMultimap.create(); |
| 109 | + |
| 110 | + |
| 111 | + File metaData = new File("./AbilityMetaData.csv"); |
| 112 | + CsvReader reader = new CsvReader(new FileReader(metaData)); |
| 113 | + reader.readHeaders(); |
| 114 | + while (reader.readRecord()) { |
| 115 | + String id = reader.get("s"); |
| 116 | + String displayName = strings.get(reader.get("displayName")); |
| 117 | + if (displayName == null) { |
| 118 | + displayName = reader.get("field"); |
| 119 | + } |
| 120 | + String type = reader.get("type"); |
| 121 | + int data = Integer.parseInt(reader.get("data")); |
| 122 | + boolean useLevels = !reader.get("repeat").equals("0"); |
| 123 | + String useSpecific = reader.get("useSpecific"); |
| 124 | + |
| 125 | + FieldData fd = new FieldData(id, displayName, type, data, useLevels); |
| 126 | + |
| 127 | + if (useSpecific.isEmpty()) { |
| 128 | + commonData.add(fd); |
| 129 | + } else { |
| 130 | + for (String spell : useSpecific.split("[,\\.]")) { |
| 131 | + specificData.put(spell, fd); |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + println("package AbilityObjEditing"); |
| 139 | + println("import public ObjEditingNatives"); |
| 140 | + println(""); |
| 141 | + println("public class AbilityDefinition"); |
| 142 | + println(" protected ObjectDefinition def"); |
| 143 | + println(" "); |
| 144 | + println(" construct(string newAbilityId, string origAbilityId)"); |
| 145 | + println(" def = createObjectDefinition(\"w3a\", newAbilityId, origAbilityId)"); |
| 146 | + |
| 147 | + Set<String> usedNames = Sets.newHashSet(); |
| 148 | + for (FieldData fd : commonData) { |
| 149 | + fd.printFunc(usedNames); |
| 150 | + } |
| 151 | + |
| 152 | + |
| 153 | + for (String spell : specificData.keySet()) { |
| 154 | + usedNames.clear(); |
| 155 | + println(""); |
| 156 | + println(""); |
| 157 | + println(""); |
| 158 | + println("public class AbilityDefinition"+spell+" extends AbilityDefinition"); |
| 159 | + println(" construct(string newAbilityId)"); |
| 160 | + println(" super(newAbilityId, \""+spell+"\")"); |
| 161 | + for (FieldData fd : specificData.get(spell)) { |
| 162 | + fd.printFunc(usedNames); |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + System.out.println(sb.toString()); |
| 167 | + Files.write(sb, new File("./AbilityObjEditing.wurst"), Charsets.UTF_8); |
| 168 | + |
| 169 | + } |
| 170 | + public static String camelize(String displayName) { |
| 171 | + return displayName.replaceAll("[^a-zA-Z]", ""); |
| 172 | +// StringBuilder s = new StringBuilder(); |
| 173 | +// for (String part : displayName.split(" ")) { |
| 174 | +// s.append(part); |
| 175 | +// } |
| 176 | +// return s.toString(); |
| 177 | + } |
| 178 | + |
| 179 | + |
| 180 | +} |
0 commit comments