/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.bindedobjects.gamecontent;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.Binding;
import transientlibs.objects.general.Node;
import transientlibs.tex.StringAnalyst;
/**
*
* @author kibertoad
*/
public class ShipModule extends Node {
String LName;
String desc;
public int damage;
public int range;
public int energyUse;
public int maxAmmo;
public int defense;
public int maxHP;
public int cost;
public int size;
public int weight;
public static ArrayList<ShipModule> shipModules = new ArrayList<ShipModule>();
public static ShipModule lastShipModule;
public static void loadShipModules (){
if (StringAnalyst.isFileExist("modules.dat")) {
StringAnalyst reader = new StringAnalyst();
reader.openFile("modules.dat");
while (!reader.eof) {
reader.readRow();
analyzeStringForShipModules (reader);
}
reader.closeFile();
}
}
public static void analyzeStringForShipModules (StringAnalyst analyst) {
analyzeStringForShipModules ("-NO-", analyst);
}
public static void analyzeStringForShipModules (String getString, StringAnalyst analyst) {
if (!"-NO-".equals(getString)) {analyst.fullStr = getString;}
analyst.getNextString();
String nowStr = analyst.lastStr;
boolean withResult = false;
if (nowStr.equals("module")) {
shipModules.add (new ShipModule ());
lastShipModule = shipModules.get(shipModules.size()-1);
lastShipModule.ID = analyst.getBinding (Binding.shipModuleBinding);
//ReqList.lastReqList = lastShipModule.trainReqs;
withResult = true;
}
if (nowStr.equals("name")) {
lastShipModule.LName = analyst.getNextString();
withResult = true;
}
if (nowStr.equals("desc")) {
lastShipModule.desc = analyst.restOfRow();
withResult = true;
}
if (nowStr.equals("damage")) {
lastShipModule.damage = analyst.getNextNumber();
withResult = true;
}
if (nowStr.equals("energyuse")) {
lastShipModule.energyUse = analyst.getNextNumber();
withResult = true;
}
if (nowStr.equals("range")) {
lastShipModule.range = analyst.getNextNumber();
withResult = true;
}
if (nowStr.equals("maxammo")) {
lastShipModule.maxAmmo = analyst.getNextNumber();
withResult = true;
}
if (nowStr.equals("hp")) {
lastShipModule.maxHP = analyst.getNextNumber();
withResult = true;
}
if (nowStr.equals("weight")) {
lastShipModule.weight = analyst.getNextNumber();
withResult = true;
}
if (nowStr.equals("size")) {
lastShipModule.size = analyst.getNextNumber();
withResult = true;
}
if (nowStr.equals("cost")) {
lastShipModule.cost = analyst.getNextNumber();
withResult = true;
}
if (nowStr.equals("defense")) {
lastShipModule.defense = analyst.getNextNumber();
withResult = true;
}
if ((withResult == false) && (nowStr.length()>2) && (!nowStr.startsWith("//"))) {
Log.error("Unknown string: "+nowStr); }
}
@Override
public String name (){
return LName;
}
}