Search in sources :

Example 1 with ISoliniaAAEffectTypeAdapterFactory

use of com.solinia.solinia.Factories.ISoliniaAAEffectTypeAdapterFactory 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");
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) ISoliniaAARankTypeAdapterFactory(com.solinia.solinia.Factories.ISoliniaAARankTypeAdapterFactory) SoliniaAAEffect(com.solinia.solinia.Models.SoliniaAAEffect) ISoliniaAAEffectTypeAdapterFactory(com.solinia.solinia.Factories.ISoliniaAAEffectTypeAdapterFactory) SoliniaAARank(com.solinia.solinia.Models.SoliniaAARank) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List) ISoliniaAAAbility(com.solinia.solinia.Interfaces.ISoliniaAAAbility)

Example 2 with ISoliniaAAEffectTypeAdapterFactory

use of com.solinia.solinia.Factories.ISoliniaAAEffectTypeAdapterFactory 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();
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) ISoliniaAARankTypeAdapterFactory(com.solinia.solinia.Factories.ISoliniaAARankTypeAdapterFactory) IOException(java.io.IOException) SoliniaAAEffect(com.solinia.solinia.Models.SoliniaAAEffect) ISoliniaAAEffectTypeAdapterFactory(com.solinia.solinia.Factories.ISoliniaAAEffectTypeAdapterFactory) ISoliniaAAAbility(com.solinia.solinia.Interfaces.ISoliniaAAAbility) SoliniaAAAbility(com.solinia.solinia.Models.SoliniaAAAbility) TypeToken(com.google.gson.reflect.TypeToken) FileOutputStream(java.io.FileOutputStream) SoliniaAARank(com.solinia.solinia.Models.SoliniaAARank) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Aggregations

Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 ISoliniaAAEffectTypeAdapterFactory (com.solinia.solinia.Factories.ISoliniaAAEffectTypeAdapterFactory)2 ISoliniaAARankTypeAdapterFactory (com.solinia.solinia.Factories.ISoliniaAARankTypeAdapterFactory)2 ISoliniaAAAbility (com.solinia.solinia.Interfaces.ISoliniaAAAbility)2 SoliniaAAEffect (com.solinia.solinia.Models.SoliniaAAEffect)2 SoliniaAARank (com.solinia.solinia.Models.SoliniaAARank)2 FileNotFoundException (java.io.FileNotFoundException)2 TypeToken (com.google.gson.reflect.TypeToken)1 SoliniaAAAbility (com.solinia.solinia.Models.SoliniaAAAbility)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1