Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Swapping out tilesets/graphics packs programmatically  (Read 1373 times)

Cobbler89

  • Bay Watcher
  • Cobbler cancels celebrate Caesar: mending soles
    • View Profile
Swapping out tilesets/graphics packs programmatically
« on: July 11, 2014, 11:19:01 pm »

Hullo, all,

This is probably (inevitably?) a very nooby question, but here goes. Last I checked, the various successors of the Lazy Newb Pack (maybe even the Lazy Newb Pack itself) had options to automatically update the files necessary to switch tilesets and/or graphics packs. I'm interested in developing a program or script that would do that without the rest of the Newb Pack experience (I don't use a lot of utilities besides Therapist and in general would rather have full manual control of setting up and tearing down whatever I do use).

So, here's the question: Is there anywhere I can quickly learn, or can anyone briefly explain, how these sorts of packs manage swapping out multiple different tilesets and graphics packs? (I could, of course, take some time, experiment with them and read over the source code to any that are open and figure it out myself eventually, but if anyone can easily enough save me some of that time I'd appreciate it!)

Thanks in advance.

[EDIT:] To clarify, I need a better understanding of what such a program would have to do, not how to code it (I may already know enough to do the latter once I know the former). So, for instance, are they all simple tileset switchers, or do they handle raw-modifying graphics sets as well (and if so, what's the basic idea of how)?
« Last Edit: July 12, 2014, 09:14:30 am by Cobbler89 »
Logged
Quote from: Mr S
You've struck embedded links. Praise the data miners!
Quote from: Strong Bad
The magma is seeping under the door.

Quote from: offspring
Quote from: Cobbler89
I have an idea. Let's play a game where you win by being as quiet as possible.
I get it, it's one of those games where losing is fun!
I spend most of your dimension's time outside of your dimension. I can't guarantee followup or followthrough on any comments, ideas, or plans.

Xangi

  • Bay Watcher
  • ɛkzændʒiː
    • View Profile
Re: Swapping out tilesets/graphics packs programmatically
« Reply #1 on: July 12, 2014, 01:57:09 am »

Hullo, all,

This is probably (inevitably?) a very nooby question, but here goes. Last I checked, the various successors of the Lazy Newb Pack (maybe even the Lazy Newb Pack itself) had options to automatically update the files necessary to switch tilesets and/or graphics packs. I'm interested in developing a program or script that would do that without the rest of the Newb Pack experience (I don't use a lot of utilities besides Therapist and in general would rather have full manual control of setting up and tearing down whatever I do use).

So, here's the question: Is there anywhere I can quickly learn, or can anyone briefly explain, how these sorts of packs manage swapping out multiple different tilesets and graphics packs? (I could, of course, take some time, experiment with them and read over the source code to any that are open and figure it out myself eventually, but if anyone can easily enough save me some of that time I'd appreciate it!)

Thanks in advance.
Just have the init point to a given graphics set and have the program rename graphics sets accordingly to switch which one is active. http://www.cplusplus.com/ is your friend, though if you're new to programming it might be a bit tricky. It also gets a bit more tricky for raw-modifying graphics sets, but for simple tilesets this should work.
Logged
A spooky ghost.

Previous mod (34.11):
<<Fear The Night!>>
http://www.bay12forums.com/smf/index.php?topic=103747.0

Cobbler89

  • Bay Watcher
  • Cobbler cancels celebrate Caesar: mending soles
    • View Profile
Re: Swapping out tilesets/graphics packs programmatically
« Reply #2 on: July 12, 2014, 09:22:24 am »

I've found http://www.cppreference.com/ to be more helpful personally, although last I checked they share most of the same content. I've also found shell scripting to be comparatively easy if all that's being done is managing files...
Logged
Quote from: Mr S
You've struck embedded links. Praise the data miners!
Quote from: Strong Bad
The magma is seeping under the door.

Quote from: offspring
Quote from: Cobbler89
I have an idea. Let's play a game where you win by being as quiet as possible.
I get it, it's one of those games where losing is fun!
I spend most of your dimension's time outside of your dimension. I can't guarantee followup or followthrough on any comments, ideas, or plans.

CLA

  • Bay Watcher
    • View Profile
Re: Swapping out tilesets/graphics packs programmatically
« Reply #3 on: July 12, 2014, 02:48:56 pm »

[EDIT:] To clarify, I need a better understanding of what such a program would have to do, not how to code it (I may already know enough to do the latter once I know the former). So, for instance, are they all simple tileset switchers, or do they handle raw-modifying graphics sets as well (and if so, what's the basic idea of how)?

4 things that need to be changed:
  • Tilesets and init files
    init.txt has entries that point to the tileset df is supposed to use. It must be located in data/art/. Either a png with alpha transparency or a bmp with magenta as transparency. You also set GRAPHICS to YES or NO to tell DF whether or not to use creature graphics there.
    d_init.txt has some entries which tiles are supposed to be used for certain things (minecart tracks, the new trees, pillar, sky, etc), and some other settings (varied ground tiles, engravings, toggling numerical display of water).
    You need to keep a backup/reference of the default init.txt and d_init.txt and generate these files depending on the tileset/graphic set. It's sufficient to just copy the tileset in data/art. you don't need to overwrite or delete anything there.

  • Colors
    data/init/colors.txt
    Must be named colors.txt
    You need to keep a backup/reference of the default colors.txt and generate colors.txt depending on the tileset/graphic set.

  • Font
    data/art/font.ttf
    Must be named font.ttf
    You need to keep a backup/reference of the default font.ttf and generate font.ttf depending on the tileset/graphic set.

  • Creature graphics and raw changes
    located in /raw/ and data/save/<your save folder name>/raw
    creature graphics (png tilesets) go in the raw/graphics folder.
    They need a text file (usually named identical to the respective creature graphic tileset) that tells DF what tiles to use for what creature
    by default DF comes with a graphics_example.txt and example tiles for dwarves
    Most graphic sets change several raw files to use different tiles for objects (for example ores and stones)
    You need to keep a backup/reference of the default raws. ]
    You need to delete graphics_example.txt or replace it with an empty dummy file.
    You need to delete the creature graphic folder and restore the default raws before switching to/applying another graphic set.

Furthermore, you'd need the tilesets/graphic sets to be prepared correctly. Most of them have downloads that already have the correct folder hierarchy and you would just have to drop them into the DF folder to install. Separate tilesets, fonts, etc would be less trivial. So you probably want to have both an automatic process (with something like a preview or log: "found tileset in : mygraphicset_df_40.02.zip/data/art/mytileset.png; found init.txt in mygraphicset_df_40.02.zip/data/init/init.txt", etc)and let the user choose elements he wants to install.


That's all I can think of.
The procedure for changing any tileset or graphic set would possibly look something like this:

  • create backup of current tileset/graphic set configuration
  • prepare files to install (and generate as necessary - for example an init.txt file in case you only want to install a new tileset)
  • restore all defaults, delete creature graphics folder
  • copy  all relevant files in the correct folders, overwriting as necessary



There's probably more, but that should give you a start for testing.
Also note that some users reported a problem with the LNP:
Upon installing CLA (I don't know about other graphic sets) with the LNP, data/art/mouse.png seems to be missing, which prevents DF from starting.
I speculate that this might be because the LNP purges all files from data/art before installing a new tileset, and since CLA only includes files that need to be changed, mouse.png is missing afterwards.
Logged
CLA - an ASCII-like Graphic Pack with simplified letter-like creature graphics. The simple and clean looks of ASCII with distinct creature graphics - best of both worlds!

http://www.bay12forums.com/smf/index.php?topic=105376.0

Cobbler89

  • Bay Watcher
  • Cobbler cancels celebrate Caesar: mending soles
    • View Profile
Re: Swapping out tilesets/graphics packs programmatically
« Reply #4 on: July 12, 2014, 09:08:47 pm »

So, in short,
1) Delete current raw files.
2) Put a copy of all original files back, except for raw\graphics\graphics_example.txt.
3) Copy over the set's files.

Have I got that right?

And the files are:
data\init\init.txt
data\init\d_init.txt
data\init\colors.txt
data\art\font.ttf
data\art\*.bmp
data\art\*.png
everything in raw and its subfolders (and the saves' raw folders also)

Have I got that right too?
Logged
Quote from: Mr S
You've struck embedded links. Praise the data miners!
Quote from: Strong Bad
The magma is seeping under the door.

Quote from: offspring
Quote from: Cobbler89
I have an idea. Let's play a game where you win by being as quiet as possible.
I get it, it's one of those games where losing is fun!
I spend most of your dimension's time outside of your dimension. I can't guarantee followup or followthrough on any comments, ideas, or plans.

CLA

  • Bay Watcher
    • View Profile
Re: Swapping out tilesets/graphics packs programmatically
« Reply #5 on: July 13, 2014, 05:39:01 am »

So, in short,
1) Delete current raw files.
2) Put a copy of all original files back, except for raw\graphics\graphics_example.txt.
3) Copy over the set's files.

Have I got that right?

And the files are:
data\init\init.txt
data\init\d_init.txt
data\init\colors.txt
data\art\font.ttf
data\art\*.bmp
data\art\*.png
everything in raw and its subfolders (and the saves' raw folders also)

Have I got that right too?

1)Yes
2)Yes. This is mostly to ensure compatibility. Some graphic sets change the raws x and y, others y and z. Some change colors.txt and font.ttf, some don't. If you would just overwrite with the new files you'd get problems in a lot of cases. If you replace everything with the defaults first, you should be good.
3)Yes

>And the files are[...]
correct.
Although to clarify, it's data/art/<tilesetname>.bmp/png. Or "all files except for the default image files".
Logged
CLA - an ASCII-like Graphic Pack with simplified letter-like creature graphics. The simple and clean looks of ASCII with distinct creature graphics - best of both worlds!

http://www.bay12forums.com/smf/index.php?topic=105376.0