Skip to content

Commit f28bdc2

Browse files
Merge pull request #49 from CommonWealthRobotics/kh/cadoodle-compat
Kh/cadoodle compat
2 parents 08252b7 + f1e7f5e commit f28bdc2

File tree

7 files changed

+104
-45
lines changed

7 files changed

+104
-45
lines changed

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ api group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.6'
176176

177177
api group: 'org.reactfx', name: 'reactfx', version: '2.0-SNAPSHOT'
178178

179-
api group: 'org.codehaus.groovy', name: 'groovy', version:'2.3.7';
180-
//make grapes work
181-
api group: 'org.apache.ivy', name:'ivy', version:'2.2.0'
179+
// https://mvnrepository.com/artifact/org.apache.groovy/groovy
180+
api group: 'org.apache.groovy', name: 'groovy', version: '4.0.22'
181+
//make grapes work
182+
api group: 'org.apache.ivy', name: 'ivy', version: '2.5.1'
182183

183184
//compile group: 'org.controlsfx', name: 'controlsfx', version: '8.0.6'
184185
api group: 'commons-lang', name: 'commons-lang', version: '2.6'

src/main/java/com/neuronrobotics/bowlerstudio/assets/ConfigurationDatabase.java

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import java.io.IOException;
66
import java.io.PrintWriter;
77
import java.lang.reflect.Type;
8+
import java.util.Collections;
89
import java.util.HashMap;
910
import java.util.Map;
11+
import java.util.Set;
1012

1113
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
1214
import org.kohsuke.github.GHMyself;
@@ -30,50 +32,109 @@ public class ConfigurationDatabase {
3032
//private static String gitSource = null; // madhephaestus
3133
private static String dbFile = "database.json";
3234
private static boolean checked;
33-
private static HashMap<String, HashMap<String, Object>> database = null;
35+
private static Map<String, HashMap<String, Object>> database = null;
3436
private static final Type TT_mapStringString = new TypeToken<HashMap<String, HashMap<String, Object>>>() {
3537
}.getType();
3638
// chreat the gson object, this is the parsing factory
3739
private static Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
3840
private static IssueReportingExceptionHandler reporter = new IssueReportingExceptionHandler();
3941
//private static String loggedInAs = null;
40-
static {
4142

43+
public static void clear(String key) {
44+
getDatabase();
45+
synchronized(database){
46+
getParamMap(key).clear();
47+
}
48+
4249
}
50+
public static Set<String> keySet(String name) {
51+
Set<String> keySet ;
52+
getDatabase();
53+
synchronized(database){
54+
keySet= ConfigurationDatabase.getParamMap(name).keySet();
55+
}
56+
return keySet;
57+
}
58+
public static boolean containsKey(String paramsKey, String string) {
59+
boolean containsKey = false;
60+
synchronized(database){
61+
containsKey = ConfigurationDatabase.getParamMap(paramsKey).containsKey(string);
62+
}
63+
return containsKey;
4364

44-
public static synchronized Object getObject(String paramsKey, String objectKey, Object defaultValue) {
45-
if (getParamMap(paramsKey).get(objectKey) == null) {
46-
//System.err.println("Cant find: " + paramsKey + ":" + objectKey);
47-
setObject(paramsKey, objectKey, defaultValue);
65+
}
66+
public static String getKeyFromValue(String controllerName, String mappedValue) {
67+
String ret=null;
68+
getDatabase();
69+
synchronized(database){
70+
HashMap<String, Object> paramMap = ConfigurationDatabase.getParamMap(controllerName);
71+
for (String key : paramMap.keySet()) {
72+
String string = (String) paramMap.get(key);
73+
if (string.contentEquals(mappedValue)) {
74+
ret= key;
75+
break;
76+
}
77+
}
78+
}
79+
return ret;
80+
}
81+
public static Object get(String paramsKey, String objectKey) {
82+
return getObject(paramsKey, objectKey, null);
83+
}
84+
public static Object get(String paramsKey, String objectKey, Object defaultValue) {
85+
return getObject(paramsKey, objectKey, defaultValue);
86+
}
87+
public static Object getObject(String paramsKey, String objectKey, Object defaultValue) {
88+
Object ret=null;
89+
getDatabase();
90+
synchronized(database){
91+
if (getParamMap(paramsKey).get(objectKey) == null) {
92+
//System.err.println("Cant find: " + paramsKey + ":" + objectKey);
93+
setObject(paramsKey, objectKey, defaultValue);
94+
}
95+
ret= getParamMap(paramsKey).get(objectKey);
4896
}
49-
return getParamMap(paramsKey).get(objectKey);
97+
return ret;
5098
}
5199

52100
public static HashMap<String, Object> getParamMap(String paramsKey) {
53-
if (getDatabase().get(paramsKey) == null) {
54-
getDatabase().put(paramsKey, new HashMap<String, Object>());
101+
if (database.get(paramsKey) == null) {
102+
database.put(paramsKey, new HashMap<String, Object>());
55103
}
56-
return getDatabase().get(paramsKey);
104+
return database.get(paramsKey);
57105
}
58-
59-
public static synchronized Object setObject(String paramsKey, String objectKey, Object value) {
60-
Object put = getParamMap(paramsKey).put(objectKey, value);
106+
public static Object put(String paramsKey, String objectKey, Object value) {
107+
return setObject(paramsKey, objectKey, value);
108+
}
109+
110+
public static Object setObject(String paramsKey, String objectKey, Object value) {
111+
Object put =null;
112+
getDatabase();
113+
synchronized(database){
114+
put=getParamMap(paramsKey).put(objectKey, value);
115+
}
61116
save();
62117
return put;
63118
}
64-
65-
public static synchronized Object removeObject(String paramsKey, String objectKey) {
66-
Object remove = getParamMap(paramsKey).remove(objectKey);
119+
public static Object remove(String paramsKey, String objectKey) {
120+
return removeObject(paramsKey, objectKey);
121+
}
122+
public static Object removeObject(String paramsKey, String objectKey) {
123+
Object remove=null;
124+
getDatabase();
125+
synchronized(database){
126+
remove= getParamMap(paramsKey).remove(objectKey);
127+
}
67128
save();
68129
return remove;
69130
}
70131

71-
public static synchronized void save() {
132+
public static void save() {
72133
String writeOut = null;
73134
getDatabase();
74-
//synchronized(database){
135+
synchronized(database){
75136
writeOut = gson.toJson(database, TT_mapStringString);
76-
//}
137+
}
77138
File f=loadFile();
78139

79140

@@ -88,14 +149,15 @@ public static synchronized void save() {
88149
}
89150

90151
@SuppressWarnings("unchecked")
91-
public static HashMap<String, HashMap<String, Object>> getDatabase() {
152+
public static void getDatabase() {
92153
if (database != null) {
93-
return database;
154+
return ;
94155
}
95156
File loadFile = loadFile();
96157
if(loadFile.exists())
97158
try {
98-
database = (HashMap<String, HashMap<String, Object>>) ScriptingEngine.inlineFileScriptRun(loadFile, null);
159+
database = Collections.synchronizedMap((HashMap<String, HashMap<String, Object>>) ScriptingEngine.inlineFileScriptRun(loadFile, null));
160+
99161
} catch (Exception e) {
100162
// TODO Auto-generated catch block
101163
e.printStackTrace();
@@ -106,7 +168,7 @@ public static HashMap<String, HashMap<String, Object>> getDatabase() {
106168
// new Exception().printStackTrace();
107169
}
108170

109-
return database;
171+
return ;
110172
}
111173

112174
public static File loadFile() {
@@ -140,4 +202,5 @@ public static File loadFile() {
140202

141203

142204

205+
143206
}

src/main/java/com/neuronrobotics/bowlerstudio/assets/StudioBuildInfo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,12 @@ public static void setBaseBuildInfoClass(Class c) {
131131
}
132132

133133
public static String getName() {
134-
return "Bowler Studio "
134+
return getAppName()
135135
+ getProtocolVersion() + "." + getSDKVersion() + "("
136136
+ getBuildVersion() + ")";
137137
}
138+
139+
public static String getAppName() {
140+
return getTag("app.name");
141+
}
138142
}

src/main/java/com/neuronrobotics/bowlerstudio/scripting/GroovyHelper.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ private Object inline(Object code, ArrayList<Object> args) throws Exception {
2323
CompilerConfiguration cc = new CompilerConfiguration();
2424
cc.addCompilationCustomizers(new ImportCustomizer()
2525
.addStarImports(ScriptingEngine.getImports())
26-
.addStaticStars(
27-
"com.neuronrobotics.sdk.util.ThreadUtil",
28-
"eu.mihosoft.vrl.v3d.Transform",
29-
"com.neuronrobotics.bowlerstudio.vitamins.Vitamins")
26+
3027
);
3128

3229
Binding binding = new Binding();

src/main/java/com/neuronrobotics/bowlerstudio/scripting/ScriptingEngine.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public class ScriptingEngine {// this subclasses boarder pane for the widgets
110110
"com.neuronrobotics.bowlerstudio.scripting", "com.neuronrobotics.bowlerstudio.tabs",
111111
"com.neuronrobotics.bowlerstudio.physics", "com.neuronrobotics.bowlerstudio.physics",
112112
"com.neuronrobotics.bowlerstudio.vitamins", "com.neuronrobotics.bowlerstudio.creature",
113-
"com.neuronrobotics.bowlerstudio.threed" };
113+
"com.neuronrobotics.bowlerstudio.threed","com.neuronrobotics.sdk.util.ThreadUtil",
114+
"eu.mihosoft.vrl.v3d.Transform",
115+
"com.neuronrobotics.bowlerstudio.vitamins.Vitamins" };
114116

115117
private static HashMap<String, File> filesRun = new HashMap<>();
116118

src/main/java/com/neuronrobotics/sdk/addons/gamepad/PersistantControllerMap.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public static boolean areAllAxisMapped(String controllerName) {
2525
return true;
2626
}
2727
public static void clearMapping(String controllerName) {
28-
ConfigurationDatabase.getParamMap(controllerName).clear();
28+
ConfigurationDatabase.clear(controllerName);
2929

3030
}
3131
public static String getMappedAxisName(String controllerName, String incomingName) {
32-
Object object = ConfigurationDatabase.getParamMap(controllerName).get(incomingName);
32+
Object object = ConfigurationDatabase.getObject(controllerName,incomingName,incomingName);
3333
if (object == null)
3434
return incomingName;
3535
return (String) object;
@@ -41,14 +41,7 @@ public static boolean isMapedAxis(String controllerName, String mappedValue) {
4141

4242

4343
public static String getHardwareAxisFromMappedValue(String controllerName, String mappedValue) {
44-
HashMap<String, Object> paramMap = ConfigurationDatabase.getParamMap(controllerName);
45-
for (String key : paramMap.keySet()) {
46-
String string = (String) paramMap.get(key);
47-
if (string.contentEquals(mappedValue)) {
48-
return key;
49-
}
50-
}
51-
return null;
44+
return ConfigurationDatabase.getKeyFromValue(controllerName, mappedValue);
5245
}
5346

5447
public static void map(String name,String controllerVal, String persistantVal) {
@@ -57,8 +50,7 @@ public static void map(String name,String controllerVal, String persistantVal) {
5750
}
5851

5952
public static Set<String> getMappedAxis(String name) {
60-
// TODO Auto-generated method stub
61-
return ConfigurationDatabase.getParamMap(name).keySet();
53+
return ConfigurationDatabase.keySet(name);
6254
}
6355

6456

0 commit comments

Comments
 (0)