Re: [Program] FTL Homeworld
Posted: Wed Jul 31, 2013 12:54 am
please help?
Official Forum for FTL: Faster Than Light and Into the Breach
https://subsetgames.com/forum/
Should be: C:\\roza3436 wrote: ftlDatsPath=C\:\\Program Files (x86)\\FTL\\resources
ftlSavePath=C\:\\Users\\Student_2\\Documents\\My Games\\FasterThanLight
ComaToes had that set up before I came on board.iceburg333 wrote:I'm having trouble with the apache logger dependency. I have your source code working in eclipse as I managed to get Maven working. [...]
When I run my program from inside eclipse, it runs but I get this error and no log info works:I'm guessing that the secret lies in moving your log4j2.xmls over to my project, or doing some kind of maven transfer/transfusion.Code: Select all
log4j:WARN No appenders could be found for logger (org.iceburg.ftl.homeworld.core.FTLHomeworld). log4j:WARN Please initialize the log4j system properly.
The editor's looks like that too:kartoFlane wrote:Should be: C:\\roza3436 wrote: ftlDatsPath=C\:\\Program Files (x86)\\FTL\\resources
ftlSavePath=C\:\\Users\\Student_2\\Documents\\My Games\\FasterThanLight
Most likely a typo in the program's config-saving function.
Guess you can change it yourself in your config and save it, it shouldn't get overwritten unless you change it during runtime.
Code: Select all
#FTL Profile Editor - Config File
#Tue Feb 19 23:13:56 EST 2013
ftlDatsPath=E\:\\Games\\FasterThanLight\\resources
useDefaultUI=false
"For each entry the key string is written, then an ASCII =, then the associated element string. [...] The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded."
Huh. I've never noticed that, though now that I look through the config files of my other programs, they also have escaped colons...Vhati wrote:Apparently, escaping colons is normal behavior for configs written with Java's Properties.store().
would imply that the error occurs somewhere here:roza3436 wrote:It says error saving to homeworld.cfg.
Code: Select all
try {
out = new FileOutputStream(propFile);
config.store( out, "FTL Homeworld - Config File" );
} catch (IOException e) {
// log.error( "Error saving config to " + propFile.getPath(), e );
showErrorDialog( "Error saving config to " + propFile.getPath() );
e.printStackTrace();
}
Thanks for answering this! I snooped into Maven's repository, but I think I only saw the beta1.jar and missed the -api jar. I'll look back around and look into the xml. I'm glad I figured out how to make the program run without the dependencies, so if I don't figure it out it's no big deal, but I did like the logging functionality and I would like to learn how to add it. So thank you for pointing me in the right direction. I'll let you know if I figure it out. Thanks!Vhati wrote:From the editor thread...
ComaToes had that set up before I came on board.![]()
According to the editor's Maven pom.xml, there are two dependencies: log4j-api and log4j-core (ver 2.0-beta1)
Snooping around "~/.m2/repository/", Maven cached these files:You'll need the log4j stuff in your classpath, either embedded in the jar, or somehow mentioned in meta-inf with jars in the same folder.
- log4j-core-2.0-beta1.jar
- log4j-api-2.0-beta1.jar
log4j2.xml is the config. The logger expects it. I have a little experience editing that file...
The other similar xml's are alternate configs there to be optionally chosen by name with a commandline arg.
@KartoFlane: Thank you for bugshooting (as well as Vhati). I'm scraping by on figuring this out, so my solutions and bugshooting is practically non-existant for java, so I really appreciate you guys helping Roza. My config file/writing the config file is nearly completely copied from FTL Editor, so while I could have made a code error, I don't think it's due to my novice-ness... Roza, does FTL Profile Editor work for you?kartoFlane wrote:@roza3436
Could you also paste the stack trace (crash log) here? It's generally much more helpful in troubleshooting
Huh. I've never noticed that, though now that I look through the config files of my other programs, they also have escaped colons...Vhati wrote:Apparently, escaping colons is normal behavior for configs written with Java's Properties.store().
Took a brief look through the code, thiswould imply that the error occurs somewhere here:roza3436 wrote:It says error saving to homeworld.cfg.Can't see anything inherently wrong with it, though. propFile is never null, and should exist at that point (even if not, FOS should create it automatically, IIRC). Input stream on the properties file is closed. config variable is always created, too. I guess it might be an issue with permissions, or one of the key-value pairs being null, or something *shrug* without the stack trace it's all just guessing though.Code: Select all
try { out = new FileOutputStream(propFile); config.store( out, "FTL Homeworld - Config File" ); } catch (IOException e) { // log.error( "Error saving config to " + propFile.getPath(), e ); showErrorDialog( "Error saving config to " + propFile.getPath() ); e.printStackTrace(); }
Code: Select all
//Decrease count
//TODO Crashing here!? - not finding test in the map, why not?
String test = w.getWeaponId();
int testVal = startMap.get(test); //Crashes on this line
if (testVal > 1) {
startMap.put(w.getWeaponId(), (startMap.get(w) - 1));
((WeaponItem) startBox.getSelectedItem()).setTitle(
DataManager.get().getWeapon(w.getWeaponId()).getTitle()
+ " x"+ startMap.get(w));
}
else {
startMap.remove(w);
startBox.remove(startBox.getSelectedIndex());
}
Code: Select all
//Convert weapons list to string array for combo box - use hashmap for count
public ArrayList<WeaponItem> weaponToString(ShipState state, HashMap<String, Integer> map) {
ArrayList<WeaponItem> al = new ArrayList<WeaponItem>();
map = new HashMap<String, Integer>();
//String s = new String("No Weapons!");
if (state.getWeaponList().size() > 0){
for (WeaponState w: state.getWeaponList()) {
//multiple missles = Hull Missiles x2
if (map.containsKey(w.getWeaponId())) {
//increase the item's count
map.put(w.getWeaponId(), (map.get(w.getWeaponId()) + 1));
}
else {
//add the first item
map.put(w.getWeaponId(), 1);
}
}
//convert hashmap to string
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
// System.out.println(pairs.getKey() + " = " + pairs.getValue());
WeaponState w = new WeaponState((String)pairs.getKey(), false, 0);
al.add(new WeaponItem(w, DataManager.get().getWeapon(w.getWeaponId()).getTitle()
+ " x"+ pairs.getValue()));
// it.remove(); // avoids a ConcurrentModificationException
}
}
Code: Select all
map = new HashMap<String, Integer>();
Well, yeah, you were essentially overwriting the argument with a new HashMap each time you called the function.public ArrayList<WeaponItem> weaponToString(ShipState state, HashMap<String, Integer> map) {
....ArrayList<WeaponItem> al = new ArrayList<WeaponItem>();
....map = new HashMap<String, Integer>();
.......