package de.siphalor.was.game;

import de.siphalor.was.WhatAStorage;
import de.siphalor.was.content.lang.I18n;

import java.util.Locale;
import java.util.prefs.Preferences;

public class Options {
	private boolean autoRefillQuests;
	private boolean allowQuestResolving;

	public boolean getAllowQuestResolving() {
		return allowQuestResolving;
	}

	public void setAllowQuestResolving(boolean allowQuestResolving) {
		this.allowQuestResolving = allowQuestResolving;
	}

	public boolean getAutoRefillQuests() {
		return autoRefillQuests;
	}

	public void setAutoRefillQuests(boolean autoRefillQuests) {
		this.autoRefillQuests = autoRefillQuests;
	}

	private Preferences getPreferences() {
		return Preferences.userNodeForPackage(WhatAStorage.class);
	}

	public void load() {
		Preferences preferences = getPreferences();
		autoRefillQuests = preferences.getBoolean("auto-refill-quests", false);
		allowQuestResolving = preferences.getBoolean("allow-quest-resolving", true);

		String lang = preferences.get("preferred-lang", Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry());
		I18n.getInstance().setLang(lang, WhatAStorage.getInstance().getContentManager());
	}

	public void save() {
		Preferences preferences = getPreferences();
		preferences.putBoolean("auto-refill-quests", autoRefillQuests);
		preferences.putBoolean("allow-quest-resolving", allowQuestResolving);
		preferences.put("preferred-lang", I18n.getInstance().getLang().getCode());
	}
}
