Bay 12 Games Forum

Dwarf Fortress => DF Modding => Utilities and 3rd Party Applications => Topic started by: Meph on May 03, 2015, 11:19:09 am

Title: Strange question about tilesets and websites
Post by: Meph on May 03, 2015, 11:19:09 am
Hey guys,

A thought randomly popped into my head today: Using DF tilesets to draw a comic for a community fortress. I'd take the workshop draw utility and draw a scene, screenshot it and use the image... but why stop there? Would be a lot more fun if people that saw it could change the color scheme and tileset.

I did not find any utility for this, but maybe it's possible to write a website that does it, some java or html5 that reads out the data?

No idea how easy/hard that would be, just throwing the idea out there.
Title: Re: Strange question about tilesets and websites
Post by: Vherid on May 03, 2015, 03:44:28 pm
Hey guys,

A thought randomly popped into my head today: Using DF tilesets to draw a comic for a community fortress. I'd take the workshop draw utility and draw a scene, screenshot it and use the image... but why stop there? Would be a lot more fun if people that saw it could change the color scheme and tileset.

I did not find any utility for this, but maybe it's possible to write a website that does it, some java or html5 that reads out the data?

No idea how easy/hard that would be, just throwing the idea out there.

So you're saying, a web app that could somehow read an image, redisplay it in a canvas and allow people to change the tileset and colors.
That sounds pretty hard with my experience.

Unless you have a application that can spit out the picture in some form of data that is far more easily readable and then you could probably use a console library like rot.js, and from that point changing tiles and colors might be far easier.
Title: Re: Strange question about tilesets and websites
Post by: Max™ on May 03, 2015, 10:30:54 pm
How does the .cmv movie player on the map viewer site work? I noticed that the .cmv was exported in vanilla tiles and resolution/etc, then the movie player translates that into something flash can work with, might be handy to dig around in there to see what they did?
Title: Re: Strange question about tilesets and websites
Post by: milo christiansen on May 04, 2015, 11:58:25 am
I have some CMV rendering code that could easily be re-purposed to make a rendering server. Currently I use something like that to render on-the-fly workshop previews for addon description pages in the Rubble web UI.

Obviously someone would have to be willing to host such a server...

Such a server would need an image description, and a set of tilesets/colors which it would use to render images as needed and cache commonly requested ones.

Some kind of client side system would also work, but I don't know anything about that so I can't help there.
Title: Re: Strange question about tilesets and websites
Post by: palu on May 07, 2015, 12:14:56 pm
You could have some JavaScript that draws the images from a tileset onto a canvas. Does anyone know how DF colors tiles?
Title: Re: Strange question about tilesets and websites
Post by: lethosor on May 07, 2015, 03:02:21 pm
That's definitely possible - an extension on the wiki and BenLubar's cmvjs library do it, for example.
Title: Re: Strange question about tilesets and websites
Post by: Meph on May 08, 2015, 01:36:40 am
I was kinda thinking of the way that "workshop draw" works. You can already paint with it, 32x32 and change colors and tilesets, but if I would have to make a screenshot and upload it for each tileset... by hand, instead of offering a dropdown menu.
Title: Re: Strange question about tilesets and websites
Post by: palu on May 11, 2015, 03:11:44 pm
Here's how it worked back in 40d, no idea how much its changed since then:
http://dwarffortresswiki.org/index.php/40d:Tilesets#How_colors_other_than_white_and_magenta_work
Title: Re: Strange question about tilesets and websites
Post by: lethosor on May 11, 2015, 04:37:45 pm
It could depend on whether that page refers to 40d or 40d# (e.g. 40d19) - the latter included the graphics improvements by Baughn (and others), although I'm not sure if the way colors were handled in graphics sets was affected.
Title: Re: Strange question about tilesets and websites
Post by: milo christiansen on May 16, 2015, 11:46:59 am
What I do (with the Go "image/draw" package) is draw a sold block of the background color, then draw a solid block of the foreground color over that using the tile as a mask. I am not sure of the specifics of how "image/draw" handles the mask, but the result looks the same as what comes out of DF, so I am happy :)
Title: Re: Strange question about tilesets and websites
Post by: DragonDePlatino on May 16, 2015, 12:03:00 pm
Hey, this is a pretty neat idea! And why not use Tiled (http://www.mapeditor.org/) as your workshop program? It's a very simple tool I use for all of my mockups and it's really flexible. The tool handles layers, non-aligned objects and you can edit sheets while the program is open and it'll update in real time. It's pretty compact too, with all of the map data stored in a single .xml file.
Title: Re: Strange question about tilesets and websites
Post by: Meph on May 16, 2015, 12:12:38 pm
Hey, this is a pretty neat idea! And why not use Tiled (http://www.mapeditor.org/) as your workshop program? It's a very simple tool I use for all of my mockups and it's really flexible. The tool handles layers, non-aligned objects and you can edit sheets while the program is open and it'll update in real time. It's pretty compact too, with all of the map data stored in a single .xml file.
Couldnt get more meta than making a patreon-funded web-comic using a patreon-funded program. :D (tiled is also on patreon.)
Title: Re: Strange question about tilesets and websites
Post by: Pidgeot on May 16, 2015, 04:44:02 pm
What I do (with the Go "image/draw" package) is draw a sold block of the background color, then draw a solid block of the foreground color over that using the tile as a mask. I am not sure of the specifics of how "image/draw" handles the mask, but the result looks the same as what comes out of DF, so I am happy :)

This is where the Wanderlust (http://www.bay12forums.com/smf/index.php?topic=145362.msg5782418#msg5782418) tileset is very handy, because its use of shading catches several edge cases. Based on your description, I don't think your code will do the right thing here.

The proper calculation is blend(bgrgb, fgrgb*tilergb, tilea), where the blend function refers to alpha blending (http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending) (linear interpolation such that alpha=0 returns the first input, and alpha=1 returns the second input). Typically, the alpha blending aspect will be handled automatically when drawing the two on top of each other, so if you have that, you just need to do the multiplication to get the tile foreground and then just overlay it onto the background.

(EDIT: Some tilesets don't actually contain an alpha channel. For these, all pixels colored #FF00FF (magenta) should be considered transparent (alpha=0), and the rest opaque (alpha=1).)

For a webcomic, there are ways to do this with CSS, but AFAIK, they're not universally supported (IIRC, IE11 doesn't do it, not sure about others). You'd need to look for a Javascript library to handle that operation.
Title: Re: Strange question about tilesets and websites
Post by: Meph on May 17, 2015, 04:11:15 am
Or instead of offering 30 tilesets that are automated, I take the 3-4 most popular ones and do it by hand.
Title: Re: Strange question about tilesets and websites
Post by: Pidgeot on May 17, 2015, 05:56:57 am
Or instead of offering 30 tilesets that are automated, I take the 3-4 most popular ones and do it by hand.

You can do that, but remember that you have to do this for every combination of tileset and color you want to support (so 16 colors per scheme per tileset). At 4 tilesets, that's 64 versions per colorscheme.
Title: Re: Strange question about tilesets and websites
Post by: Meph on May 17, 2015, 06:03:34 am
No color schemes. If I do it with workshop draw, it would use the default one. Same for the other programs that load up tilesets for previews, they dont accept color schemes.

Why 16x4x4? If I use 4 color schemes in theory, wouldnt it make 4x4=16 sets?

But yeah, color schemes would require automation. :/
Title: Re: Strange question about tilesets and websites
Post by: Pidgeot on May 17, 2015, 07:16:17 am
No color schemes. If I do it with workshop draw, it would use the default one. Same for the other programs that load up tilesets for previews, they dont accept color schemes.

I only mentioned it because you mentioned the colorscheme in your first post.

Why 16x4x4? If I use 4 color schemes in theory, wouldnt it make 4x4=16 sets?

16 (colors) * 4 (colorschemes) * 4 (tilesets).

You can organize it such that you have a complete colorscheme in one file, sure, but you also need to "index" properly into this to get the right color. This is doable, certainly, but it's something you need to have in mind when writing the HTML/CSS/Javascript needed to render everything (because I'm assuming you don't want to generate all the renderings manually for every comic).
Title: Re: Strange question about tilesets and websites
Post by: Quietust on May 17, 2015, 07:47:58 am
How does the .cmv movie player on the map viewer site work? I noticed that the .cmv was exported in vanilla tiles and resolution/etc, then the movie player translates that into something flash can work with, might be handy to dig around in there to see what they did?
The CMV doesn't contain any tileset information - it just has the character indices and colors, and the player has to use its own tileset in order to display those characters (which could potentially just be an ordinary font, such as "Terminal" on Windows).

Incidentally, this is why you shouldn't record movies while you're using a custom graphics set - unless the person playing the movie is using the same custom graphics set, everything will look strange.
Title: Re: Strange question about tilesets and websites
Post by: Meph on May 17, 2015, 12:56:41 pm
No color schemes. If I do it with workshop draw, it would use the default one. Same for the other programs that load up tilesets for previews, they dont accept color schemes.

I only mentioned it because you mentioned the colorscheme in your first post.

Why 16x4x4? If I use 4 color schemes in theory, wouldnt it make 4x4=16 sets?

16 (colors) * 4 (colorschemes) * 4 (tilesets).

You can organize it such that you have a complete colorscheme in one file, sure, but you also need to "index" properly into this to get the right color. This is doable, certainly, but it's something you need to have in mind when writing the HTML/CSS/Javascript needed to render everything (because I'm assuming you don't want to generate all the renderings manually for every comic).
I would actually do that manually.
Title: Re: Strange question about tilesets and websites
Post by: PeridexisErrant on May 17, 2015, 07:45:53 pm
What Pidgeot isn't mentioning is that he's just made something similar (https://bitbucket.org/Pidgeot/python-lnp/pull-request/49).  Maybe we could adapt that?
Title: Re: Strange question about tilesets and websites
Post by: Pidgeot on May 17, 2015, 09:48:05 pm
What Pidgeot isn't mentioning is that he's just made something similar (https://bitbucket.org/Pidgeot/python-lnp/pull-request/49).  Maybe we could adapt that?

Dammit, PE, I was trying to keep that as a surprise :P
Title: Re: Strange question about tilesets and websites
Post by: PeridexisErrant on May 17, 2015, 10:17:35 pm
A surprise.  On the internet.  Publicly developed.  Under a permissive license??
Title: Re: Strange question about tilesets and websites
Post by: Meph on May 17, 2015, 10:19:52 pm
Well, I'm surprised, so it worked. :P