Package transientlibs.bindedobjects.core

Source Code of transientlibs.bindedobjects.core.GDXFonts

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.bindedobjects.core;

import transientlibs.bindedobjects.core.datasets.LesserBindedValue;
import java.util.ArrayList;

import transientlibs.slick2d.util.Log;

import transientlibs.processors.misc.Detonator;
import transientlibs.preui.objects.gui.elements.TransientGDXFont;
import transientlibs.tex.StringAnalyst;

/**
*
** @author kibertoad
*/
public class GDXFonts extends LesserBindedValue {

    public static ArrayList<GDXFonts> fonts = new ArrayList<GDXFonts>();
    public TransientGDXFont font = null;
    public static GDXFonts lastFont;
    public static TransientGDXFont defaultFont;
    public static GDXFonts defaultFonts;
    public static String defaultReference = "droid_20_sans";
   
    public String file1;
    public String file2;
   

    public static void loadGlobalFonts() {

        /*
         String path = " ";
         try {
         path = new java.io.File(".").getCanonicalPath();
         } catch (IOException ex) {
         Logger.getLogger(Fonts.class.getName()).log(Level.SEVERE, null, ex);
         }
         Log.info("Nowpath: "+path);
         */

        StringAnalyst reader = new StringAnalyst();
        reader.openGlobalFile("data/init/fonts.dat");

        while (!reader.eof) {
            reader.readRow();
            analyzeStringForFontss(reader);
        }

        reader.closeFile();

        Detonator.INSTANCE.fontProvider.setDefaultFonts();              
    }

    public static void loadFonts() {


        StringAnalyst reader = new StringAnalyst();
        reader.openFile("fonts.dat");

        while (!reader.eof) {
            reader.readRow();
            analyzeStringForFontss(reader);
        }

        reader.closeFile();
    }

    public static void analyzeStringForFontss(StringAnalyst analyst) {
        analyzeStringForFontss("-NO-", analyst);
    }

    public static TransientGDXFont getFontFromFile(String fromString) {

        return new TransientGDXFont(fromString + ".fnt", fromString + "_0.png");
    }


    public static void analyzeStringForFontss(String getString, StringAnalyst analyst) {

        if (!"-NO-".equals(getString)) {
            analyst.fullStr = getString;
        }

        analyst.getNextString();
        String nowStr = analyst.lastStr;

        boolean withResult = false;

        if (nowStr.equals("font")) {

            fonts.add(new GDXFonts());
            lastFont = fonts.get(fonts.size() - 1);
            lastFont.LName.value = analyst.getNextString();
            lastFont.ID = Binding.getBinding(Binding.fontBinding, lastFont.LName.value);
           
            Log.info("Just loaded font: "+lastFont.LName.value);

            withResult = true;
        }




        if (nowStr.equals("file")) {
            StringBuilder pathName = new StringBuilder();
            if (Detonator.INSTANCE.pathToData != null) {
                pathName.append(Detonator.INSTANCE.pathToData);
            }
            //pathName.append(Detonator.INSTANCE.gameDataDir);
            pathName.append("data/init/fonts/");
            pathName.append(analyst.getNextString());

            /*
             * try { lastFont.font = new
             * AngelCodeFont(pathName.toString()+".fnt",
             * pathName.toString()+"_0.png"); } catch (SlickException ex) {
             * Logger.getLogger(Fonts.class.getName()).log(Level.SEVERE, null,
             * ex); }
             */

            lastFont.font = getFontFromFile(pathName.toString());
            lastFont.font.fontInfo = lastFont;
           
            lastFont.file1 = pathName.toString() + ".fnt";
            lastFont.file2 = pathName.toString() + "_0.png";
                   
           


            withResult = true;
        }

        if (nowStr.equals("name")) {
            lastFont.LName.value = analyst.getNextString();
            withResult = true;
        }

        if (nowStr.equals("desc")) {
            lastFont.desc = analyst.restOfRow();
            withResult = true;
        }


        if ((withResult == false) && (nowStr.length() > 2) && (!nowStr.startsWith("//"))) {
            Log.error("Unknown string: " + nowStr);
        }

    }



    public static GDXFonts getFontByID(int getCode) {
        if (getCode != -1) {
        return fonts.get(getCode);
        } else
            return null;
    }


    public static GDXFonts getFontByCode(String getCode) {


        int setCode = Binding.readBinding(Binding.fontBinding, getCode.toLowerCase());

        if ((setCode != -1) && (fonts.size() >= setCode)) {
            return fonts.get(setCode);
        } else {
            return (null);
        }

    }


}
TOP

Related Classes of transientlibs.bindedobjects.core.GDXFonts

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.