Vhati wrote:Since Java is primarily an object-oriented language, unless a method is explicitly "public
static void foo() {...}", that method only exists as part of instantiated objects of the relevant class. In other words you either have to do the following...
Code: Select all
ShipSaveParser parser = new ShipSaveParser();
ShipSaveParser.ShipSave ss2 = parser.readShipSave(testFile);;
Or declare the method "static" so that it becomes part of the class itself, rather than of objects.
You've got an extra semicolon up there, btw.
Thank you! It makes more sense now, static vs object.... I think I'm just now coming to grips with the theory behind it, though the idea of a 'new parser' still hurts my brain.
lol. Silly semicolons. Thanks.

...
Vhati wrote:Correct. InputStreams let you consume bytes from a source in the order they appear (some will allow limited buffering to repeat bytes that just passed to mimic backtracking). Streams will let you skip forward (read and ignore bytes) but...
The continue.sav file format doesn't store data at absolute offsets.
Values take up varying amounts of bytes (for example, lists of more/fewer crew names, even the name strings have different lengths), and the next value just appears wherever the previous one ended, not at the Nth byte from the beginning.
So you have to read the whole file to know where anything is.
Just read the entire game state, then pick out what you're interested in...
Thanks, that's what I was figuring, but I appreciate you getting back to me before I wracked my brain try to figure out if that was really the case. I'm getting better at combing through the code/looking at java source, but you still saved me at least an hour of pulling my hair out, if not three.
I only hesitated to read the whole file because I want to load multiple files (a save game selector, if you will) and I didn't want it to take a long time. Happily, all of the data I need is in that first section, so I shouldn't have to read too much code!
Vhati wrote:The DataManager's necessary because the only way to know how many doors to expect in the saved game (how many bytes to read before the next thing), is to have read the ship layout txt beforehand. And the only way to know the layout for a ship's blueprintId, is to have read the <shipBlueprint> xml for that blueprintId.
Wow, the more I look at this code, the more I think you and ComaToes did some beast work. Again, thank you for making it open source!
I'm certain that my program will require FTL Editor, so my ShipSaveParser class is modled after your SavedGameParser and calls classes from/extends your parser and datamanager, so I should be good just calling those functions. (and that bit is working, it's just pulling the wrong bytes since I cherry picked what data I wanted).
I'm going to start adapting my Parser to handle the input/output stream and test it, and I also spent a couple hours yesterday working to get github working, I'm going to keep doing that so I can share more code. However, in the meantime would you be willing to answer another question? (If I'm wearing you out, please let me know, it's just so nice to have a pro to answer questions.)
I'm working on making a savegame manager (calling it a space dock) where you see all of your ships (save files) and choose one to play with (board) while all the others are 'docked'. Your current ship is "continue.sav" while your others are named iteratively "continue_1.sav" etc. Everything is setting up nicely (I figured out a while loop to give the right name to docked ships), but I can't get a rename function to work! My code is this:
Code: Select all
public boolean boardShip(ShipSave ss1) {
boolean success = false;
File oldFile = ss1.getshipFilePath();
File newFile = new File("continue.sav");
if (!newFile.exists()) {
//success = oldFile.renameTo(newFile);
Path source = oldFile.toPath();
try {
Files.move(source, newFile.toPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
ss1.setshipFilePath(newFile);
return success;
}
When I run it I get an IO error like this:
Code: Select all
"java.nio.file.FileSystemException: continue_3.sav -> continue.sav: The process cannot access the file because it is being used by another process."
The commented out renameTo method also fails. My google searches tell me that my file is locked by my program and that I may need to lock the directory, but that doesn't make any sense. Would you be able to point me in the right direction?
Thanks again Vhati!
Ice