<commit_before>package de.dakror.arise.settings;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


/**
 * @author Dakror
 */
public class Resources
{
	public enum Resource
	{
		GOLD("Gold", 2, 1, 1, true),
		PEOPLE("Einwohner", 0, 0, 0, false),
		WOOD("Holz", 3, 0, 4, true),
		STONE("Stein", 1, 1, 2, true),
		BUILDINGS("Gebäude", 3, 3, 0, false),
		SWORDFIGHTER("Schwertkämpfer", 4, 0, 0, false),
		LANCEBEARER("Lanzenträger", 4, 1, 0, false),
		ARMY("Truppen", 0, 4, 0, false),
		
		;
		
		private String name;
		private boolean usable;
		private int iconX, iconY, goldValue;
		
		private Resource(String name, int iconX, int iconY, int goldValue, boolean usable)
		{
			this.name = name;
			this.iconX = iconX;
			this.iconY = iconY;
			this.goldValue = goldValue;
			this.usable = usable;
		}
		
		public String getName()
		{
			return name;
		}
		
		public int getIconX()
		{
			return iconX;
		}
		
		public int getIconY()
		{
			return iconY;
		}
		
		public int getGoldValue()
		{
			return goldValue;
		}
		
		public boolean isUsable()
		{
			return usable;
		}
		
		public static Resource[] usable()
		{
			ArrayList<Resource> res = new ArrayList<>();
			
			for (Resource r : values())
				if (r.isUsable()) res.add(r);
			
			return res.toArray(new Resource[] {});
		}
		
		public static Resource[] usableNoGold()
		{
			ArrayList<Resource> res = new ArrayList<>();
			
			for (Resource r : values())
				if (r.isUsable() && r != GOLD) res.add(r);
			
			return res.toArray(new Resource[] {});
		}
	}
	
	public static final Resource[] serializableResources = { Resource.GOLD, Resource.WOOD, Resource.STONE, Resource.SWORDFIGHTER, Resource.LANCEBEARER };
	
	HashMap<Resource, Float> res = new HashMap<>();
	
	public Resources()
	{
		for (Resource t : Resource.values())
			res.put(t, 0f);
	}
	
	public Resources(JSONObject data) throws JSONException
	{
		this();
		
		JSONArray names = data.names();
		for (int i = 0; i < data.length(); i++)
		{
			res.put(Resource.valueOf(names.getString(i)), (float) data.getDouble(names.getString(i)));
		}
	}
	
	public Resources(byte[] data)
	{
		this();
		
		ByteBuffer bb = ByteBuffer.wrap(data);
		for (int i = 0; i < serializableResources.length; i++)
			set(serializableResources[i], bb.getFloat());
	}
	
	public int get(Resource t)<commit_msg>buildings don't get synced [ci skip]<commit_after>package de.dakror.arise.settings;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


/**
 * @author Dakror
 */
public class Resources
{
	public enum Resource
	{
		GOLD("Gold", 2, 1, 1, true),
		PEOPLE("Einwohner", 0, 0, 0, false),
		WOOD("Holz", 3, 0, 4, true),
		STONE("Stein", 1, 1, 2, true),
		BUILDINGS("Gebäude", 3, 3, 0, false),
		SWORDFIGHTER("Schwertkämpfer", 4, 0, 0, false),
		LANCEBEARER("Lanzenträger", 4, 1, 0, false),
		ARMY("Truppen", 0, 4, 0, false),
		
		;
		
		private String name;
		private boolean usable;
		private int iconX, iconY, goldValue;
		
		private Resource(String name, int iconX, int iconY, int goldValue, boolean usable)
		{
			this.name = name;
			this.iconX = iconX;
			this.iconY = iconY;
			this.goldValue = goldValue;
			this.usable = usable;
		}
		
		public String getName()
		{
			return name;
		}
		
		public int getIconX()
		{
			return iconX;
		}
		
		public int getIconY()
		{
			return iconY;
		}
		
		public int getGoldValue()
		{
			return goldValue;
		}
		
		public boolean isUsable()
		{
			return usable;
		}
		
		public static Resource[] usable()
		{
			ArrayList<Resource> res = new ArrayList<>();
			
			for (Resource r : values())
				if (r.isUsable()) res.add(r);
			
			return res.toArray(new Resource[] {});
		}
		
		public static Resource[] usableNoGold()
		{
			ArrayList<Resource> res = new ArrayList<>();
			
			for (Resource r : values())
				if (r.isUsable() && r != GOLD) res.add(r);
			
			return res.toArray(new Resource[] {});
		}
	}
	
	public static final Resource[] serializableResources = { Resource.GOLD, Resource.WOOD, Resource.STONE, Resource.BUILDINGS, Resource.SWORDFIGHTER, Resource.LANCEBEARER };
	
	HashMap<Resource, Float> res = new HashMap<>();
	
	public Resources()
	{
		for (Resource t : Resource.values())
			res.put(t, 0f);
	}
	
	public Resources(JSONObject data) throws JSONException
	{
		this();
		
		JSONArray names = data.names();
		for (int i = 0; i < data.length(); i++)
		{
			res.put(Resource.valueOf(names.getString(i)), (float) data.getDouble(names.getString(i)));
		}
	}
	
	public Resources(byte[] data)
	{
		this();
		
		ByteBuffer bb = ByteBuffer.wrap(data);
		for (int i = 0; i < serializableResources.length; i++)
			set(serializableResources[i], bb.getFloat());
	}
	
	public int get(Resource t)
{'fraction_non_alphanumeric': 0.145957011258956, 'fraction_numerical': 0.01105424769703173, 'mean_word_length': 3.3469750889679717, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6609671', 'n_tokens_mistral': 2056, 'n_tokens_neox': 1687, 'n_words': 443}