Package transientlibs.bindedobjects.core.loaders

Source Code of transientlibs.bindedobjects.core.loaders.LesserBindedValueLoader

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

import transientlibs.bindedobjects.core.datasets.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import transientlibs.objects.primitives.Int;
import transientlibs.slick2d.util.Log;
import transientlibs.objects.primitives.TString;
import transientlibs.processors.misc.Detonator;
import transientlibs.tex.StringAnalyst;

/**
*
* @author kibertoad
*/
public class LesserBindedValueLoader implements ILoader {

    public LesserBindedValueContainer container;
    //public static LesserBindedValue lastLesserValue;
    public TString LName = new TString("-");
    public String desc;
    public String group;
    public ArrayList<String> tags = new ArrayList<String>();
    public ArrayList<String> definedCustomFields = new ArrayList<String>();
    public ArrayList<String> definedCustomIntFields = new ArrayList<String>();
    public ArrayList<String> definedCustomImageFields = new ArrayList<String>();
    public String globalGroup;
    //public HashMap<String, String> customFields = new HashMap<String, String>();
    //public HashMap<String, Int> customIntFields = new HashMap<String, Int>();

    public LesserBindedValueLoader(LesserBindedValueContainer container) {
        this.container = container;
    }

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

    public void loadFromFile(String theOne) {
        if (StringAnalyst.isFileExist(theOne)) {

            globalGroup = "";

            StringAnalyst reader = new StringAnalyst();

            reader.openFile(theOne);

            while (!reader.eof) {


                reader.readRow();
                analyzeString(reader);
            }

            reader.closeFile();
        }
    }

    public void outputAll(ArrayList fromList) {

        LesserBindedValue nowValue;

        Log.info("Start outputting all values");
        Iterator<LesserBindedValue> i = fromList.iterator();

        while (i.hasNext()) {
            nowValue = i.next();
            Log.info(nowValue.LName + ", ID " + nowValue.ID);
        }
        Log.info("End outputting all values");

    }

    public int returnCustomIntValueIndex(String byCode) {
        int x = 0;

        for (String s : definedCustomIntFields) {
            if (s.equals(byCode)) {
                return x;
            }
            x++;
        }
        return -1;
    }

    public int returnCustomValueIndex(String byCode) {
        int x = 0;

        for (String s : definedCustomFields) {
            if (s.equals(byCode)) {
                return x;
            }
            x++;
        }
        return -1;
    }

    public int returnCustomImageValueIndex(String byCode) {
        int x = 0;

        for (String s : definedCustomImageFields) {
            if (s.equals(byCode)) {
                return x;
            }
            x++;
        }
        return -1;
    }

    public boolean analyzeStringForCustomValue(String getString, StringAnalyst analyst) {

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

        analyst.checkForAliases();
        boolean withResult = false;

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


        if (returnCustomValueIndex(nowStr) != -1) {
            nowStr2 = analyst.restOfRow();

            lastElement().customFields.put(nowStr, nowStr2);
            withResult = true;
        }

        if (returnCustomIntValueIndex(nowStr) != -1) {
            nowStr2 = analyst.restOfRow();

            lastElement().customIntFields.put(nowStr, new Int(Integer.parseInt(nowStr2)));
            withResult = true;
        }

        if (returnCustomImageValueIndex(nowStr) != -1) {
            nowStr2 = analyst.getNextString();

            lastElement().customImageFields.put(nowStr, Detonator.INSTANCE.imageProvider.getImage(nowStr2));
            withResult = true;
        }


        return withResult;
    }

    public LesserBindedValue lastElement() {
        return container.lastElement;
    }

    @Override
    public boolean analyzeString(String getString, StringAnalyst analyst) {


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

        analyst.checkForAliases();
        boolean withResult = false;

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

        if (nowStr.equals("definevalue")) {
            nowStr = analyst.getNextString();

            if (nowStr.equals("string")) {
                nowStr = analyst.getNextString();

                definedCustomFields.add(nowStr);
                withResult = true;
            } else

            if (nowStr.equals("int")) {
                nowStr = analyst.getNextString();

                definedCustomIntFields.add(nowStr);
                withResult = true;
            } else

            if (nowStr.equals("image")) {
                nowStr = analyst.getNextString();

                definedCustomImageFields.add(nowStr);
                withResult = true;
            } else {
                Log.error("Unknown define type: " + nowStr);
            }



        }

        if (nowStr.equals("name")) {
            lastElement().LName.value = analyst.restOfRow();
            lastElement().desc = lastElement().LName.value;

            //Log.warn("Action name set to: "+lastElement().LName);

            withResult = true;
        }

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

        if (nowStr.equals("desc+")) {

            StringBuilder tmpStr = new StringBuilder();
            tmpStr.append(lastElement().desc);
            tmpStr.append("\n");
            tmpStr.append(analyst.restOfRow());

            lastElement().desc = tmpStr.toString();
            withResult = true;
        }

        if (nowStr.equals("globalgroup")) {
            globalGroup = analyst.getNextString();
            withResult = true;
        }
       
        if (nowStr.equals("group")) {
            lastElement().group = analyst.getNextString();
            withResult = true;
        }       

       
       
        if (nowStr.equals("tag")) {
            lastElement().tags.add(analyst.getNextString());
            withResult = true;
        }


        if (withResult == false) {
            withResult = analyzeStringForCustomValue(getString, analyst);
        }

        return withResult;
    }
}
TOP

Related Classes of transientlibs.bindedobjects.core.loaders.LesserBindedValueLoader

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.