/*
* 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 transientlibs.tex.ActList;
import transientlibs.tex.Branch;
import transientlibs.tex.ReqList;
import transientlibs.tex.BranchList;
import transientlibs.tex.StringAnalyst;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.Binding;
import transientlibs.bindedobjects.core.Req;
import transientlibs.bindedobjects.core.Tex;
import transientlibs.processors.tex.AbstractActivator;
import transientlibs.processors.misc.Detonator;
/**
*
* @author kibertoad
*/
public class ActionLoader 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 ReqList mainReqList;
public static ActList mainActList;
//public static ArrayList<Action> actions = new ArrayList<Action>();
//public static Action lastAction;
public ActionLoader(BindedValueContainer setContainer) {
super(setContainer);
}
public Action lastAction() {
return (Action) container.lastElement;
}
public void loadAllActions() {
File dir = new File(Detonator.INSTANCE.currentModule.dirName + "actions");
String[] fileList = dir.list();
if (fileList == null) {
Log.warn(Detonator.INSTANCE.currentModule.dirName + "actions");
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]);
globalActs.clear();
globalActivationReq.clear();
globalTags.clear();
globalReqs.clear();
globalGroup = "-";
loadFromFile("actions/" + fileList[x]);
}
}
}
}
@Override
public void analyzeString(StringAnalyst analyst) {
analyzeString("-NO-", analyst);
}
@Override
public boolean analyzeString(String getString, StringAnalyst analyst) {
if (!"-NO-".equals(getString)) {
analyst.fullStr = getString;
}
analyst.checkForAliases();
analyst.getNextString();
String nowStr = analyst.lastStr;
boolean withResult = false;
if (nowStr.equals("action")) {
container.add(new Action());
container.getID(analyst);
//TODO - FIX LATER
//BindedValue.lastBindedValue = lastAction;
//LesserBindedValue.lastValue = lastAction;
ReqList.lastReqList = lastAction().reqs;
ReqList.lastActiveReqList = lastAction().reqsToActivate;
ActList.lastActList = lastAction().acts;
for (AbstractActivator a : globalActs) {
ActList.lastActList.add(a);
}
for (Req r : globalActivationReq) {
ReqList.lastActiveReqList.add(r);
}
for (Req r : globalReqs) {
ReqList.lastReqList.add(r);
}
for (String s : globalTags) {
lastAction().tags.add(s);
}
if (!"-".equals(globalGroup)) {
lastAction().group = globalGroup;
lastAction().ofType = Binding.getBinding(Binding.actionGroupBinding, globalGroup);
}
withResult = true;
}
if (nowStr.equals("activereqs")) {
ReqList.lastReqList = lastAction().reqsToActivate;
withResult = true;
}
if (nowStr.equals("globalactivereqs")) {
ReqList.lastReqList = globalActivationReq;
withResult = true;
}
if (nowStr.equals("globalreqs")) {
ReqList.lastReqList = globalReqs;
withResult = true;
}
if (nowStr.equals("globaltag")) {
globalTags.add(analyst.getNextString());
withResult = true;
}
if (nowStr.equals("globalacts")) {
ActList.lastActList = globalActs;
withResult = true;
}
if (nowStr.equals("reqs")) {
ReqList.lastReqList = lastAction().reqs;
withResult = true;
}
/*
if (nowStr.equals("name")) {
lastAction.LName.value = analyst.restOfRow();
lastAction.desc = lastAction.LName.value;
withResult = true;
}
*/
if (nowStr.equals("image")) {
lastAction().image = Detonator.INSTANCE.imageProvider.getImage(analyst.getBinding(Binding.transientImageBinding));
withResult = true;
}
if (nowStr.equals("animation")) {
//lastAction.unitAnimation = Animations.getAnimationByID(analyst.getBinding(Binding.animationBinding)).animation;
Log.notImplemented();
withResult = true;
}
/*
if (nowStr.equals("tag")) {
lastAction.tags.add(analyst.getNextString());
withResult = true;
}
*/
if (nowStr.equals("group")) {
lastAction().ofType = analyst.getBinding(Binding.actionGroupBinding);
lastAction().group = analyst.lastStr;
withResult = true;
}
if (nowStr.equals("notselectable")) {
lastAction().isSelectable = false;
withResult = true;
}
/*
if (nowStr.equals("desc")) {
lastAction.desc = analyst.restOfRow();
withResult = true;
}
if (nowStr.equals("desc+")) {
StringBuilder tmpStr = new StringBuilder();
tmpStr.append(lastAction.desc);
tmpStr.append("\n");
tmpStr.append(analyst.restOfRow());
lastAction.desc = tmpStr.toString();
withResult = true;
}
*/
if (nowStr.equals("tex")) {
mainReqList = ReqList.lastReqList;
mainActList = ActList.lastActList;
if (lastAction().tex == null) {
lastAction().tex = new BranchList();
BranchList.lastBranchList = lastAction().tex;
}
Tex.continousAnalysisForTex(analyst);
Log.warn("TEXT TEXT TEX happened");
ReqList.lastReqList = mainReqList;
ActList.lastActList = mainActList;
withResult = true;
}
if (nowStr.equals("eval")) {
mainReqList = ReqList.lastReqList;
mainActList = ActList.lastActList;
if (lastAction().eval == null) {
//Log.info("added eval branch");
lastAction().eval = new Branch();
Branch.lastBranch = lastAction().eval;
//if (Branch.lastBranch == null) {
// Log.error("Branch was not set!");
// }
}
Tex.continousAnalysisForTex(analyst);
ReqList.lastReqList = mainReqList;
ActList.lastActList = mainActList;
withResult = true;
}
if (withResult == false) {
withResult = Tex.analyzeStringForTex(analyst.fullStr, analyst, false);
}
if (withResult == false) {
withResult = super.analyzeString(analyst.fullStr, analyst);
}
/*
if (withResult == false) {
withResult = Req.analyzeStringForReqs(analyst.fullStr, analyst);
}
if (withResult == false) {
withResult = Activator.analyzeStringForActs(analyst.fullStr, analyst);
}
*/
//if (withResult == false) {withResult = Tex.analyzeStringForTex(analyst.fullStr, analyst, true);}
if ((withResult == false) && (nowStr.length() > 2) && (!nowStr.startsWith("//"))
&& (!nowStr.startsWith("#"))) {
Log.error("Unknown string: " + nowStr);
}
return withResult;
}
}