package electrosphere.renderer.ui.font;

import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.main.Globals;
import electrosphere.renderer.ActorUtils;
import electrosphere.renderer.Model;
import electrosphere.renderer.ModelUtils;
import electrosphere.renderer.ui.font.RawFontMap.Glyph;
import java.util.HashMap;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.joml.Vector3i;

/**
 *
 * @author amaterasu
 */
public class FontUtils {
    
    static RawFontMap rawFontMap;
    
    static HashMap<Character,Vector3f> positionMap = new HashMap();
    static HashMap<Character,Vector3f> dimensionMap = new HashMap();
    
    static int width = 10;
    static int height = 10;
    
    public static Vector3f getPositionOfCharacter(char character){
        Vector3f position;
        if((position = positionMap.get(character))!=null){
            position = new Vector3f(position);
            position.x = position.x / rawFontMap.imageWidth;
            position.y = position.y / rawFontMap.imageHeight;
        } else {
            position = new Vector3f();
        }
        return position;
    }
    
    public static Vector3f getDimensionOfCharacter(char character){
        Vector3f dimension;
        if((dimension = dimensionMap.get(character))!=null){
            dimension = new Vector3f(dimension);
            dimension.x = dimension.x / rawFontMap.imageWidth;
            dimension.y = dimension.y / rawFontMap.imageHeight;
        } else {
            dimension = new Vector3f(0.5f,0.5f,0f);
        }
        return dimension;
    }
    
    public static Vector3f getDimensionOfCharacterDiscrete(char character){
        Vector3f dimension;
        if((dimension = dimensionMap.get(character))!=null){
            dimension = new Vector3f(dimension);
        } else {
            dimension = new Vector3f(12,14,0f);
        }
        return dimension;
    }
    
    public static int getFontHeight(){
        return height;
    }
    
    public static void setFontDataMap(RawFontMap map){
        rawFontMap = map;
        width = map.imageWidth;
        height = map.imageHeight;
        //fill position map
        positionMap.clear();
        for(Glyph glyph : rawFontMap.glyphs){
            char charVal = glyph.symbol.charAt(0);
            Vector3f position = new Vector3f(glyph.startX,glyph.startY,0);
            positionMap.put(charVal,position);
        }
        //fill dimension map
        dimensionMap.clear();
        for(Glyph glyph : rawFontMap.glyphs){
            char charVal = glyph.symbol.charAt(0);
            Vector3f dimension = new Vector3f(glyph.width,glyph.height,0);
            dimensionMap.put(charVal,dimension);
        }
    }
    
    
}
