package projectzombie.settings;

import bdf.classes.BdfClassManager;
import bdf.classes.IBdfClassManager;
import bdf.file.BdfFileManager;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import bdf.types.BdfTypes;
import projectzombie.display.DisplayRenderUI;
import projectzombie.entity.EntityParticle;
import projectzombie.world.chunk.Chunk;

public class Settings implements IBdfClassManager
{
	public static final BdfClassManager SETTINGS = new BdfClassManager(new Settings());
	private static BdfFileManager FILE_MANAGER;

	@Override
	public void BdfClassLoad(BdfObject bdf) {
		BdfNamedList nl = bdf.getNamedList();
		
		if(nl.get("render_distance").getType() == BdfTypes.INTEGER) {
			Chunk.RENDER_DISTANCE = nl.get("render_distance").getInteger();
		} else {
			Chunk.RENDER_DISTANCE = 2;
		}
		
		if(nl.get("show_fps").getType() == BdfTypes.BOOLEAN) {
			DisplayRenderUI.showFPS = nl.get("show_fps").getBoolean();
		} else {
			DisplayRenderUI.showFPS = false;
		}
		
		if(nl.get("debug").getType() == BdfTypes.BOOLEAN) {
			DisplayRenderUI.debug = nl.get("debug").getBoolean();
		} else {
			DisplayRenderUI.debug = false;
		}
	}

	@Override
	public void BdfClassSave(BdfObject bdf) {
		BdfNamedList nl = bdf.getNamedList();
		nl.set("render_distance", BdfObject.withInteger(Chunk.RENDER_DISTANCE));
		nl.set("show_fps", BdfObject.withBoolean(DisplayRenderUI.showFPS));
		nl.set("debug", BdfObject.withBoolean(DisplayRenderUI.debug));
	}
	
	public static void init() {
		FILE_MANAGER = new BdfFileManager(Environment.gdir + "/settings.bdf");
		SETTINGS.load(FILE_MANAGER);
	}
	
	public static void update() {
		SETTINGS.save(FILE_MANAGER);
		FILE_MANAGER.saveDatabase();
	}

}
