use of com.solinia.solinia.Factories.ISoliniaAARankTypeAdapterFactory in project solinia3-core by mixxit.
the class JsonAAAbilityRepository method reload.
@Override
public void reload() {
List<ISoliniaAAAbility> file = new ArrayList<ISoliniaAAAbility>();
try {
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.registerTypeAdapterFactory(new ISoliniaAARankTypeAdapterFactory(SoliniaAARank.class));
gsonbuilder.registerTypeAdapterFactory(new ISoliniaAAEffectTypeAdapterFactory(SoliniaAAEffect.class));
Gson gson = gsonbuilder.create();
BufferedReader br = new BufferedReader(new FileReader(filePath));
file = gson.fromJson(br, new TypeToken<List<SoliniaAAAbility>>() {
}.getType());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
aaabilities.clear();
for (ISoliniaAAAbility i : file) {
aaabilities.put(i.getId(), i);
}
System.out.println("Reloaded " + aaabilities.size() + " AA abilities");
}
use of com.solinia.solinia.Factories.ISoliniaAARankTypeAdapterFactory in project solinia3-core by mixxit.
the class JsonAAAbilityRepository method commit.
@Override
public void commit() {
// TODO Auto-generated method stub
GsonBuilder gsonbuilder = new GsonBuilder();
// gsonbuilder.setPrettyPrinting();
gsonbuilder.registerTypeAdapterFactory(new ISoliniaAARankTypeAdapterFactory(SoliniaAARank.class));
gsonbuilder.registerTypeAdapterFactory(new ISoliniaAAEffectTypeAdapterFactory(SoliniaAAEffect.class));
Gson gson = gsonbuilder.create();
String jsonOutput = gson.toJson(aaabilities.values(), new TypeToken<List<SoliniaAAAbility>>() {
}.getType());
try {
File file = new File(filePath);
if (!file.exists())
file.createNewFile();
FileOutputStream fileOut = new FileOutputStream(file);
OutputStreamWriter outWriter = new OutputStreamWriter(fileOut);
outWriter.append(jsonOutput);
outWriter.close();
fileOut.close();
System.out.println("Commited " + aaabilities.size() + " AA abilities");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations