[Spoiler] FTL Profile/SavedGame Editor v27 (2018-01-12)

All your guides, strategy discussions, request for help on how to play go here. Please use [SPOILER] if relevant.
Targetstar
Posts: 37
Joined: Sun Sep 16, 2012 3:53 pm

Re: [Spoiler] FTL Editor v16 - Unlock ships, Edit SavedGames

Postby Targetstar » Sun Jul 07, 2013 11:09 pm

Dose this mod let you change the name of your crew during the game?
Vhati
Posts: 792
Joined: Thu Oct 25, 2012 12:01 pm

Re: [Spoiler] FTL Editor v16 - Unlock ships, Edit SavedGames

Postby Vhati » Mon Jul 08, 2013 2:21 am

iceburg333 wrote:I can't get a [savedgame file] rename function to work!

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."
A) Before moving, check that the destination isn't the same as the source.
B) You can't rename/delete the file if it's still got an open stream on it.

Usually any time you have a try/catch reading a stream, include a finally block that makes sure the stream gets closed. There are plenty of examples of that in the editor's source.
iceburg333
Posts: 67
Joined: Tue Jun 25, 2013 8:52 pm

Re: [Spoiler] FTL Editor v16 - Unlock ships, Edit SavedGames

Postby iceburg333 » Mon Jul 08, 2013 3:03 pm

Thanks for getting back so quickly!
Vhati wrote:A) Before moving, check that the destination isn't the same as the source.

It can't be that because I only try to save it

Code: Select all

if (!newFile.exists())
=/

Vhati wrote:B) You can't rename/delete the file if it's still got an open stream on it.

Usually any time you have a try/catch reading a stream, include a finally block that makes sure the stream gets closed. There are plenty of examples of that in the editor's source.


That's^ it! You were on the money! I had copied the finally close block for reading the files, but not for writing them, so when I created a new file to test on, I was keeping it write protected. I never would have thought of that! All of my tests are working now! Thank you!
Alright, I've got to make sure I'm properly incrementing the in/out streams and then I'm ready to work on my gui/main. I'll keep working on figuring out github too. =D

Targetstar wrote:Dose this mod let you change the name of your crew during the game?

Hey Targetstar, I saw your post while replying to Vhati. This isn't a mod so much as a standalone program, and I just opened it and was able to change the name, race, and a bunch of other stuff for my crew. Vhati and ComaToes have done a really good job with it, I recommend you download it and check it out. :)
Image
iceburg333
Posts: 67
Joined: Tue Jun 25, 2013 8:52 pm

Re: [Spoiler] FTL Editor v16 - Unlock ships, Edit SavedGames

Postby iceburg333 » Thu Jul 11, 2013 2:43 am

Hey Vhati!
I've got a working program and it's completely functional, I'm just trying to clean up / make the UI better. I have the UI show you each of your saves by showing you their name and beacons jumped to, as well as a button to board or dock that ship, and it works on saves. I've also added my code to github! I'd like to add a picture of the ship to the description, but I'm having trouble with the data manager. I get no compile errors, but on run time a null pointer exception is thrown.

Code: Select all

//      ShipBlueprint ship = DataManager.get().getShips()
//            .get(myShips[i].getPlayerShipBlueprintId());
//      ImageIcon shipPic = new ImageIcon("img/ship/" + ship.getGraphicsBaseName() + "_base.png");
//      JLabel lblShipID = new JLabel("", shipPic, JLabel.CENTER);
//      frmSpaceDock.getContentPane().add(lblShipID);
      
      for ( ShipBlueprint ship : DataManager.get().getPlayerShips() ) {
         ImageIcon shipPic = new ImageIcon("img/ship/" + ship.getGraphicsBaseName() + "_base.png");
         JLabel lblShipID = new JLabel("", shipPic, JLabel.CENTER);
         frmSpaceDock.getContentPane().add(lblShipID);
      }

Whether I comment the first or second block of code, both throw the null point exception. This is a generalized question and I realize my problem could be elsewhere in the code. It's all there on github, but I realize asking you to look through it would be asking you to do my job/possibly send you on a wild goose chase. I'm going to keep working on it, but thought I'd post just as an update / in case you might be able to point me in the right direction.
I copied a lot of the initialization code, so I have the user select the data.dat, but now that I think about it, it's not generating a config file. I'll look into that. :)

EDIT: I think I just got it to work, I wasn't writing a config file, so I think that was my problem. I'll update once I've got it ironed out, but I don't want to waste your time since I might have it. :D
Vhati
Posts: 792
Joined: Thu Oct 25, 2012 12:01 pm

Re: [Spoiler] FTL Editor v16 - Unlock ships, Edit SavedGames

Postby Vhati » Thu Jul 11, 2013 9:57 am

This'll pull the image out of resource.dat.

Code: Select all

private BufferedImage getResourceImage(String innerPath) {
  // If caching, you can get(innerPath) from a HashMap and return the pre-loaded pic.
  InputStream in = null;
  try {
    in = DataManager.get().getResourceInputStream(innerPath);
    BufferedImage result = ImageIO.read(in);
    return result;  // If caching, put result in the map before returning.
  }
  catch (IOException e) {
    log.error( "Failed to load resource image ("+ innerPath +")", e );
  }
  finally {
    try {if (in != null) in.close();}
    catch (IOException f) {}
  }
}


Code: Select all

// Set during init. Don't use the hard drive to buffer streams during ImageIO.read().
ImageIO.setUseCache(false);  // Small images don't need extra buffering.

// ...

BufferedImage baseImage = getResourceImage("img/ship/"+ ship.getGraphicsBaseName() +"_base.png");
JLabel lblShipID = new JLabel("", new ImageIcon(baseImage), JLabel.CENTER);
frmSpaceDock.getContentPane().add(lblShipID);


Tip: An ImageIcon that's constructed directly from a path-string caches the image... somewhere. In big apps, it can be inconvenient to later clear old images (link, more info). So I try to avoid that method.

ImageIO.read() doesn't do that. Each read() returns a unique image object that dies on its own when abandoned (When a cache is needed, a HashMap<String,BufferedImage> will suffice).
More relevant to your project, ImageIO can read a stream from DataManager.
iceburg333
Posts: 67
Joined: Tue Jun 25, 2013 8:52 pm

Re: [Spoiler] FTL Editor v16 - Unlock ships, Edit SavedGames

Postby iceburg333 » Fri Jul 12, 2013 3:14 pm

Haha, thank you! You solved my next problem before I could ask! I had removed the null pointer exception, but my image wasn't showing up, and I believe your post was the reason why. :D
I'm currently working through a java swing tutorial, but when I get done I'll come back and work on implementing this.
Thanks Vhati! :D


EDIT: So I was in the middle of typing a message to you explaining why I didn't get what was going on, when I figured it out! So now I have terribly large pictures of ships, but it worked! :D Once I learn better gui stuff I'll work on resizing them, but for now I'll clean up the code and push it to GitHub. Thank you so much for helping me with that part!

Now, about:
Vhati wrote:Tip: An ImageIcon that's constructed directly from a path-string caches the image... somewhere. In big apps, it can be inconvenient to later clear old images (link, more info). So I try to avoid that method.

ImageIO.read() doesn't do that. Each read() returns a unique image object that dies on its own when abandoned (When a cache is needed, a HashMap<String,BufferedImage> will suffice).
More relevant to your project, ImageIO can read a stream from DataManager.


Pics like the Krestel ship will be used over and over again in all likelihood as the player probably will have a lot of the same ship saves, so I shouldn't buffer them, but I should cache them, correct? (Or do I need to buffer them in order to cache them!?) I've made a background that I'm going to try to display that's the size of the ship select background (1280 by 700 or so), so I'll definitely buffer that guy.

EDIT: Here's a shot of the progress. It's coming along!!! :D
Image
Vhati
Posts: 792
Joined: Thu Oct 25, 2012 12:01 pm

Re: [Spoiler] FTL Editor v16 - Unlock ships, Edit SavedGames

Postby Vhati » Sat Jul 13, 2013 1:32 am

iceburg333 wrote:Pics like the Krestel ship will be used over and over again in all likelihood as the player probably will have a lot of the same ship saves, so I shouldn't buffer them, but I should cache them, correct? (Or do I need to buffer them in order to cache them!?)
That boolean thing is only to tweak ImageIO's read(). It doesn't affect any other part of your code.

To add caching, look at the comments in my previous post. A HashMap is all you need. Just before reading a requested image, check if the map already has it, and return immediately with that. If it's not in there, go ahead and read(), then put the image in the map before returning.

You may want a getScaledResourceImage(innerPath, width, height) method that calls getResourceImage() and only caches the tiny pics: HashMap< String, HashMap<Dimension,BufferedImage> > if you wanna handle multiple sizes.

Maybe add a boolean shouldThisGetCached arg to getResourceImage() if you want to cache unscaled images too, but only sometimes.


iceburg333 wrote:I've made a background that I'm going to try to display that's the size of the ship select background (1280 by 700 or so), so I'll definitely buffer that guy.
I don't know how large is large enough to justify setting ImageIO.setUseCache(true).

Unless you happen to get better performance by turning it on (usually introducing disk thrashing just slows things down), don't bother until you get OutOfMemoryErrors (like 3500x5000 and 5000x7000).
iceburg333
Posts: 67
Joined: Tue Jun 25, 2013 8:52 pm

Re: [Spoiler] FTL Editor v16 - Unlock ships, Edit SavedGames

Postby iceburg333 » Sat Jul 13, 2013 7:11 pm

Vhati:
Thank you! Hashmap had me confused at first, but I believe I have it working now, after reading through both of your posts a couple times. :) Literally everything is working inside eclipse. And I've got the manifest correct so it depends on FTLEditor's jar. However, I'm having trouble accessing the background image from inside the jar (though it works fine in eclipse).

The rest of the code is available on github.
My googling is turning up lots of getclass().getresource() stuff, but whatever I use doesn't seem to work. My png is in the root jar/resource folder.
Would you be willing to help me with this (hopefully) last brain teaser?
I'll keep googling around.
Thanks again Vhati!
Ice

EDIT: Got it working! I'll be uploading the program itself/updating github. Once done I'll post a link to the thread for the new program. :D
You rock Vhati!

EDIT 2: You still rock, but my program actually doesn't work yet. It tries to read the profile file like a save and crashes, so I need to fix that real fast, lol. :D
iceburg333
Posts: 67
Joined: Tue Jun 25, 2013 8:52 pm

Re: [Spoiler] FTL Editor v16 - Unlock ships, Edit SavedGames

Postby iceburg333 » Mon Jul 15, 2013 6:18 pm

Alright, just wanted to let you know that I've finally released it! Here's the thread for Spacedock! I also made a WIP thread so I won't clutter this one up anymore.
Thank you so much for your help!
Ice
Image
Mogh
Posts: 2
Joined: Mon Jul 22, 2013 10:31 pm

Re: [Spoiler] FTL Editor v16 - Unlock ships, Edit SavedGames

Postby Mogh » Mon Jul 22, 2013 10:38 pm

Hi! I just picked up Spacedock and this editor but I'm having some problems. The first time I ran "FTLProfileEditor-v16.jar" it had me search out my data file, and I did so. But now any time I run it it does nothing. In task manager I can see Java start up for a second, then it just blinks off. No crash or error or anything.

Similar issue with Stardock. First time I ran it it had me find the data file, fine, but now when I run it I get the message "Error parsing FTL files"

Any suggestions? I assume Stardock isn't working because the editor isn't working, so I chose this thread in which to post.

I'd attach the log generated by the emergency launcher, but I'm not allowed apparently.

::edit::

Ah, actually, even though this is mostly Greek to me it looks like it's crashing loading blueprints. I have a mod that adds ships, this must not be compatible. Bummer.