package mnm.mods.achget;

import java.io.File;
import java.io.IOException;

import mnm.mods.achget.StatAchievement.JsonAchievement;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.common.AchievementPage;

import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.Logger;

import com.google.gson.GsonBuilder;

public class CommonProxy {

    public void init(File f) {
        Logger logger = AchievementGet.logger;
        // The default
        String json = "[{\n" // [{
                + "\t\"id\": \"walk1000\",\n" // "id": "walk100",
                + "\t\"name\": \"Kilo\",\n" // "name": "Kilo",
                + "\t\"desc\": \"Walk 1km\",\n" // "desc": "Walk 100m",
                + "\t\"stat\": \"stat.walkOneCm\",\n" // "stat": "stat.walkOneCm",
                + "\t\"count\": 1000,\n" // "count": 100",
                + "\t\"xPos\": 0,\n" // "xPos": 0,
                + "\t\"yPos\": 0\n" // "yPos": 0
                + "}]"; // }]
        try {
            if (f.exists())
                json = FileUtils.readFileToString(f, Charsets.UTF_8);
            else
                FileUtils.write(f, json);
        } catch (IOException e) {
            logger.warn("Unable to load achievements.", e);
        }
        JsonAchievement[] achieves = new GsonBuilder()
                .registerTypeAdapter(IChatComponent.class, new IChatComponent.Serializer()).create()
                .fromJson(json, JsonAchievement[].class);
        AchievementGet instance = AchievementGet.instance;
        instance.achievements = new StatAchievement[achieves.length];

        if (achieves.length == 0) {
            logger.info("No achievements registered");
            return;
        }
        // load achievements
        for (int i = 0; i < achieves.length; i++) {
            instance.achievements[i] = new StatAchievement(achieves[i]);
        }
        // register page
        AchievementPage page = new AchievementPage("Achievement Get", AchievementGet.instance.achievements);
        AchievementPage.registerAchievementPage(page);
    }
}

@@ -503,16 +503,33 @@
  default
+ TODO externalize
 %0A       
@@ -777,24 +777,19 @@
     
-+ %22%5Ct%5C
+// 
 %22stat
-%5C
 %22: 
-%5C
 %22sta
@@ -803,26 +803,43 @@
 neCm
-%5C
 %22,
-%5Cn%22 // 
+%0A                + %22%5Ct%5C
 %22stat
+%5C
 %22: 
+%5C
 %22sta
@@ -841,34 +841,41 @@
 %5C%22stat.walkOneCm
+%5C
 %22,
+%5Cn%22 //
 %0A               
@@ -1679,120 +1679,73 @@
     
-if (achieves.length == 0) %7B%0A            logger.info(%22No achievements registered%22);%0A            return;%0A        %7D
+logger.info(%22Registering %22 + achieves.length + %22 achievements.%22);
 %0A   

Print how many achievements are registered.