/*
* 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.io.File;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.Binding;
import transientlibs.bindedobjects.core.datasets.LesserBindedValue;
import transientlibs.bindedobjects.gamecontent.CombatEffect;
import transientlibs.processors.misc.Detonator;
import transientlibs.preui.objects.gui.interfaces.IImage;
import transientlibs.objects.primitives.Int;
import transientlibs.tex.ActList;
import transientlibs.tex.ReqList;
import transientlibs.tex.StringAnalyst;
/**
*
* @author kibertoad
*/
public class ItemsLoader extends BindedValueLoader {
public static ReqList globalReqs = new ReqList();
public static ReqList globalActivationReq = new ReqList();
public static ActList globalActs = new ActList();
public static ArrayList<String> globalTags = new ArrayList<String>();
//public static String globalGroup = "-";
//public static ArrayList<Items> items = new ArrayList<Items>();
//public static Items lastItem;
public ItemsLoader(LesserBindedValueContainer container) {
super(container);
}
public Items lastItem (){
return (Items) container.lastElement;
}
public void loadAllItems() {
File dir = new File(Detonator.INSTANCE.currentModule.dirName + "items");
String[] fileList = dir.list();
if (fileList == null) {
Log.warn(Detonator.INSTANCE.currentModule.dirName + "items");
Log.warn("Specified directory does not exist!");
} else {
for (int x = 0; x < fileList.length; x++) {
if (fileList[x].endsWith(".dat")) {
Log.info(fileList[x]);
//loadMap("maps/" + fileList[x]);
globalActs.clear();
globalActivationReq.clear();
globalTags.clear();
globalReqs.clear();
globalGroup = "-";
this.loadFromFile("items/" + fileList[x]);
//loadItems("items/" + fileList[x]);
}
}
}
}
@Override
public boolean analyzeString(String getString, StringAnalyst analyst) {
if (!"-NO-".equals(getString)) {
analyst.fullStr = getString;
}
analyst.getNextString();
String nowStr = analyst.lastStr;
boolean withResult = false;
if (nowStr.equals("item")) {
container.add(new Items());
//lastItem = items.get(items.size() - 1);
//lastItem.ID = analyst.getBinding(Binding.itemBinding);
container.getID(analyst);
//ReqList.lastReqList = lastItems.trainReqs;
withResult = true;
}
if (nowStr.equals("combateffect")) {
lastItem().stats = new CombatEffect();
CombatEffect.lastCombatEffect = lastItem().stats;
CombatEffect.continousAnalysisForCombatEffect(analyst);
withResult = true;
}
if (nowStr.equals("type")) {
lastItem().itemType = analyst.readBinding(Binding.itemTypeBinding);
withResult = true;
}
//Add action to a list
if (nowStr.equals("action+")) {
lastItem().relatedActions.add(Action.getActionByCode(analyst.getNextString()));
withResult = true;
}
/*
if (nowStr.equals("name")) {
lastItem.LName.value = analyst.restOfRow();
withResult = true;
}
if (nowStr.equals("desc")) {
lastItem.desc = analyst.restOfRow();
withResult = true;
}
*/
if (nowStr.equals("image")) {
//Log.info(nowStr);
//lastItem.image = SlickImageCatalog.imageList.get(Binding.readBinding(Binding.imageBinding, analyst.getNextString())).image;
lastItem().image = Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString());
withResult = true;
}
if (nowStr.equals("largeimage")) {
//Log.info(nowStr);
lastItem().largeImage = Detonator.INSTANCE.imageProvider.getImage(Binding.readBinding(Binding.transientImageBinding, analyst.getNextString()));
withResult = true;
}
if (withResult == false) {
super.analyzeString(analyst.fullStr, analyst);
}
if ((withResult == false) && (nowStr.length() > 2) && (!nowStr.startsWith("//"))) {
Log.error("Unknown string: " + nowStr);
}
return withResult;
}
}