Skip to content

Commit c791b6b

Browse files
committedMar 28, 2013
script to generare AbilityObjEditing.wurst from AbilityMetaData
1 parent df923b9 commit c791b6b

File tree

9 files changed

+24706
-124
lines changed

9 files changed

+24706
-124
lines changed
 

‎HelperScripts/.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>HelperScripts</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

‎HelperScripts/AbilityMetaData.csv

+631
Large diffs are not rendered by default.

‎HelperScripts/AbilityObjEditing.wurst

+8,156
Large diffs are not rendered by default.

‎HelperScripts/WorldEditStrings.txt

+7,597
Large diffs are not rendered by default.

‎HelperScripts/javacsv.jar

13.3 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
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+
}
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package utils;
2+
3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.FileNotFoundException;
6+
import java.io.FileReader;
7+
import java.io.IOException;
8+
import java.util.Map;
9+
10+
import com.google.common.collect.Maps;
11+
12+
public class WEStrings {
13+
14+
private Map<String, String> data = Maps.newHashMap();
15+
16+
public WEStrings parseFile(File file) {
17+
try {
18+
BufferedReader br = new BufferedReader(new FileReader(file));
19+
String line;
20+
while ((line = br.readLine()) != null) {
21+
parseLine(line);
22+
}
23+
br.close();
24+
} catch (FileNotFoundException e) {
25+
e.printStackTrace();
26+
} catch (IOException e) {
27+
e.printStackTrace();
28+
}
29+
return this;
30+
}
31+
32+
33+
34+
private void parseLine(String line) {
35+
if (line.contains("=")) {
36+
int pos = line.indexOf("=");
37+
String key = line.substring(0, pos);
38+
String val = line.substring(pos+1);
39+
if (val.startsWith("\"")) {
40+
val = val.substring(1, val.length()-1);
41+
}
42+
data.put(key, val);
43+
}
44+
}
45+
46+
public String get(String key) {
47+
return data.get(key);
48+
}
49+
50+
}

‎Wurstpack/wurstscript/lib/objediting/AbilityObjEditing.wurst

+8,072-121
Large diffs are not rendered by default.

‎Wurstpack/wurstscript/lib/objediting/SpellPreset.wurst

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ public class SpellPreset extends AbilityDefinition
77

88
construct(string newAbilityId, string origAbilityId, int lvls)
99
super(newAbilityId, origAbilityId)
10-
setLevels(0, lvls)
10+
setLevels(lvls)
1111
this.lvl = lvls
1212

1313
function setIcon(string name)
1414
string s = "ReplaceableTextures\\CommandButtons\\" + name
1515
if not name.endsWith(".blp")
1616
s += ".blp"
1717

18-
setIconResearch(0, s)
19-
setIconNormal(0, s)
18+
setIconResearch(s)
19+
setIconNormal(s)
2020

2121

2222

0 commit comments

Comments
 (0)
Please sign in to comment.