/*
* 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 transientlibs.bindedobjects.core.datasets.Action;
import java.io.File;
import transientlibs.tex.BranchList;
import transientlibs.tex.ReqList;
import transientlibs.tex.StringAnalyst;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.Binding;
import transientlibs.bindedobjects.core.Req;
import transientlibs.bindedobjects.core.Tex;
import transientlibs.bindedobjects.gamecontent.SoundsGDX;
import transientlibs.processors.tex.AbstractActivator;
import transientlibs.processors.misc.Detonator;
import transientlibs.objects.primitives.Int;
import transientlibs.objects.general.MapNode;
import transientlibs.tex.ActList;
import transientlibs.tex.Branch;
/**
*
* @author kibertoad
*/
public class LandmarksLoader extends BindedValueLoader {
public int tileSizeX = -1;
public int tileSizeY = -1;
public static ReqList globalCostReqs = new ReqList();
public static ActList globalCostActs = new ActList();
public LandmarksLoader(BindedValueContainer container) {
super(container);
}
public Landmarks lastLandmark() {
return (Landmarks) container.lastElement;
}
public void loadAllLandmarks() {
File dir = new File(Detonator.INSTANCE.currentModule.dirName + "landmarks");
String[] fileList = dir.list();
if (fileList == null) {
Log.warn(Detonator.INSTANCE.currentModule.dirName + "landmarks");
Log.warn("Specified directory does not exist!");
} else {
for (int x = 0; x < fileList.length; x++) {
if ((!(fileList[x].equals(".svn"))) && (fileList[x].endsWith(".dat"))) {
Log.info(fileList[x]);
//loadMap("maps/" + fileList[x]);
loadFromFile("landmarks/" + fileList[x]);
}
}
}
}
@Override
public void loadFromFile(String fromFile) {
globalCostReqs.clear();
globalCostActs.clear();
super.loadFromFile(fromFile);
}
@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("landmark")) {
//landmarks.add(new Landmarks());
//lastLandmark = landmarks.get(landmarks.size() - 1);
container.add(new Landmarks());
//lastLandmark().acts.hostID = "landmark";
lastLandmark().LName.value = analyst.getNextString();
lastLandmark().ID = Binding.getBinding(Binding.landmarkBinding, lastLandmark().LName.value);
if (!"".equals(globalGroup)) {
lastLandmark().group = globalGroup;
}
//Log.info(lastLandmark.LName.value+": "+lastLandmark.ID);
for (AbstractActivator a : globalCostActs) {
lastLandmark().costActs.add(a);
}
for (Req r : globalCostReqs) {
lastLandmark().costReqs.add(r);
}
withResult = true;
}
if (nowStr.equals("v")) {
String setKey = analyst.getNextString().toLowerCase();
int setValue = analyst.getNextNumber();
lastLandmark().values.put(setKey, new Int(setValue));
}
if (nowStr.equals("eval")) {
ReqList mainReqList = ReqList.lastReqList;
ActList mainActList = ActList.lastActList;
if (lastLandmark().eval == null) {
//Log.info("added eval branch");
lastLandmark().eval = new Branch();
Branch.lastBranch = lastLandmark().eval;
//if (Branch.lastBranch == null) {
// Log.error("Branch was not set!");
// }
}
Tex.continousAnalysisForTex(analyst);
ReqList.lastReqList = mainReqList;
ActList.lastActList = mainActList;
withResult = true;
}
if (nowStr.equals("door")) {
lastLandmark().doorDeltaX = analyst.getNextNumber();
lastLandmark().doorDeltaY = analyst.getNextNumber();
}
if (nowStr.equals("child")) {
MapNode childLandmark = new MapNode();
childLandmark.ID = analyst.getBinding(Binding.landmarkBinding);
childLandmark.MapCoords.x = analyst.getNextNumber();
childLandmark.MapCoords.y = analyst.getNextNumber();
lastLandmark().childLandmarks.add(childLandmark);
withResult = true;
}
if (nowStr.equals("costreqs")) {
ReqList.lastReqList = lastLandmark().costReqs;
Tex.continousAnalysisForTex(analyst);
withResult = true;
}
if (nowStr.equals("globalcostreqs")) {
ReqList.lastReqList = globalCostReqs;
Tex.continousAnalysisForTex(analyst);
withResult = true;
}
if (nowStr.equals("globalcostacts")) {
ActList.lastActList = globalCostActs;
Tex.continousAnalysisForTex(analyst);
withResult = true;
}
if (nowStr.equals("sizex")) {
lastLandmark().tileSizeX = analyst.getNextNumber();
withResult = true;
}
if (nowStr.equals("sizey")) {
lastLandmark().tileSizeY = analyst.getNextNumber();
withResult = true;
}
if (nowStr.equals("focussound")) {
lastLandmark().visitSound = SoundsGDX.getSoundByCode(analyst.getNextString());//Sounds.getSoundByCode(analyst.getNextString());
withResult = true;
}
//Add single main action
if (nowStr.equals("action")) {
lastLandmark().action = Action.getActionByCode(analyst.getNextString());
withResult = true;
}
//Add action to a list
if (nowStr.equals("action+")) {
lastLandmark().relatedActions.add(Action.getActionByCode(analyst.getNextString()));
withResult = true;
}
if (nowStr.equals("name")) {
lastLandmark().LName.value = analyst.restOfRow();
withResult = true;
}
if (nowStr.equals("tag")) {
lastLandmark().tags.add(analyst.getNextString());
withResult = true;
}
if (nowStr.equals("group")) {
lastLandmark().group = analyst.restOfRow();
withResult = true;
}
if (nowStr.equals("desc")) {
lastLandmark().desc = analyst.restOfRow();
withResult = true;
}
if (nowStr.equals("onvisit")) {
if (lastLandmark().onVisitTex == null) {
lastLandmark().onVisitTex = new BranchList();
lastLandmark().onVisitTex.addBranch(0);
BranchList.lastBranchList = lastLandmark().onVisitTex;
}
Tex.continousAnalysisForTex(analyst);
withResult = true;
}
if (nowStr.equals("image")) {
// Log.info(nowStr);
//lastLandmark.image = Images.imageList.get(Binding.readBinding(Binding.imageBinding, analyst.getNextString()));
lastLandmark().image = Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString());
withResult = true;
}
if (withResult == false) {
withResult = super.analyzeString(analyst.fullStr, analyst);
}
if ((withResult == false) && (nowStr.length() > 2) && (!nowStr.startsWith("//"))) {
Log.error("Unknown string: " + nowStr);
}
return withResult;
}
/*
public static Landmarks getLandmarkByCode(String getCode) {
return getLandmarkByID (Binding.getBinding(Binding.landmarkBinding, getCode));
}
public static Landmarks getLandmarkByID(int getCode) {
for (Landmarks l : landmarks) {
if (l.ID == getCode) {
return l;
}
}
Log.error("No landmark with code: "+getCode);
return null;
}
*/
}