AppSettings use seems to be limited to jME Settings

I’m trying to use AppSettings to store and load settings other than those defined by jME. Storing works fine. All my settings appear in the Registry as desired. When I attempt to load them, however, no setting other than the jME settings are loaded from the registry. I’ve tracked this down to the following method:

[java]

public void load(String preferencesKey) throws BackingStoreException {

Preferences prefs = Preferences.userRoot().node(preferencesKey);

String[] keys = prefs.keys();

if (keys != null) {

for (String key : keys) {

Object defaultValue = defaults.get(key);

if (defaultValue instanceof Integer) {

put(key, prefs.getInt(key, (Integer) defaultValue));

} else if (defaultValue instanceof String) {

put(key, prefs.get(key, (String) defaultValue));

} else if (defaultValue instanceof Boolean) {

put(key, prefs.getBoolean(key, (Boolean) defaultValue));

}

}

}

}

[/java]



The following suggestion extends the functionality that the AppSettings currently has, but allows non-jME default settings to be read as well. The only limitation is that all non-jME settings will be stored as Strings.



[java]

public void load(String preferencesKey) throws BackingStoreException {

Preferences prefs = Preferences.userRoot().node(preferencesKey);

String[] keys = prefs.keys();

if (keys != null) {

for (String key : keys) {



Object defaultValue = defaults.get(key);

if (defaultValue instanceof Integer) {

put(key, prefs.getInt(key, (Integer) defaultValue));

} else if (defaultValue instanceof String) {

put(key, prefs.get(key, (String) defaultValue));

} else if (defaultValue instanceof Boolean) {

put(key, prefs.getBoolean(key, (Boolean) defaultValue));

} else if (defaultValue == null) {

put(key, prefs.get(key, (String) defaultValue));

}

}

}

}

[/java]

Why not a simple .cfg file where you could store your game’s settings?

That is, ofcourse, also an option, but we want to keep all the settings, jME and our own, centralized. Also, when deploying updates of our games to different systems this manner will allow the settings to stay persisent, instead of being overwritten during every new deployment.

You could still use the preferences API and just store your stuff separately. Maybe not as convenient was what you are trying to do but would achieve your goals that a .cfg file might not.

Its not going to work.

If you write your data as boolean for example and you try to read it as boolean it will fail because its not a boolean its a string.

So we cannot apply this unfortunately

What about allowing the developer to expand the default settings? The current structure would stay applicable and the problem would also be solved.

preferences Api works fine for me.

You can consider true / false / True / False as Booleans instead of strings, just use Boolean.parseBoolean(string).