XaiJu
fantasytowngenerator
fantasytowngenerator

patreon


Development Update - Layout edit

Hey! One of my main focuses right now is to get Fantasy Town Generator ready for a full release. One of the last things on my list before that happens is a refactor of how the roads are persisted. Why does this matter? Basically, doing this now will save me a whole lot of headache later while I can still delete the existing towns. If you've edited a town, you’ve probably noticed that the road and (non-existent) background controls aren't great. How can we improve them?

Let’s tackle the background editing issue first. For clarity, when I say background, I mean the areas under the roads and buildings, and not the water. For example, the white main town tiles, and the farmland tiles are background pieces. How should controls for these be exposed? One idea is to just connect a bunch of points together, and then fill that in. That works (and I’ll hopefully implement that eventually) but when you just want to change the background in the area between roads, that’s a lot of clicks, is there a better way? Well, I think a fill tool sounds perfect for this - just a click of a button and the area between roads will change. Something like this:


Great, let’s do that! How? We need to convert the fill area into a list of points (like before, just now this tool is doing the heavy lifting). First step is to find one of the roads that is around this area. From there, we can use a classic maze trick of just following that road and taking the leftmost path at each junction - eventually we’ll get back to where we started, and the list of junction coordinates that we passed through is the fill points, done! In practice, finding the first road can be done by using raycasting.

That just leaves the following the leftmost path. Given a previous point, a current point, and a list of next point options, using a bit of maths we can work out the left-most point. One small problem though - currently, roads are persisted as just a start and end coordinates. This makes it very difficult to figure out how different roads are connected. Now we get onto what I’ve been working on recently, changing how the roads are persisted so I keep track of that intersection data. That’s done by giving each intersection an id (so an intersection is just an id and a coordinate), and then changing roads to be defined as a start intersection id and an end intersection id. That means it’s very easy for me to say if two roads are connected - they will have the exact same intersection id on one of the ends. I can’t easily do that with the previous coordinate data due to fun floating point number rounding errors. This is also the reason I wanted to do this now while I can still delete towns - migrating the old roads to the new format would be a difficult, time consuming process. 

This new representation introduces some new challenges when editing roads. Primarily, we now need to maintain this intersection data and have it match what the user wants. It would be a terrible experience if you had to click on the exact coordinate of an existing intersection to create a proper road layout, so we want some form of snapping to solve this. Also, roads can’t overlap with other roads without creating a new intersection - if they did, when we use the fill we’d get some weird results when we try to follow the left hand path. Thankfully, we can also snap the road to the first crossing to prevent this happening. Taking all this together, here’s the in progress new road editing feature:

This’ll be available in the next update of Fantasy Town Generator, and will require a reset of the existing towns. I’m hoping the next update will be the ‘full release’, which basically just means I’ll stop deleting towns. As part of that, I’m currently looking into a proper login flow and having different types of users (free vs patreon). Not entirely sure what the patreon only features will be yet. The fill feature, and other editing updates will hopefully come shortly after the full release.

So that’s the current state of Fantasy Town Generator, and a look at what I’ve been working on recently. As I said, next up is looking at a proper login flow. Let me know what you thought of this post! Do you like this kind of development insight? Are there any other types of post you’d like to see? As always, if you have any thoughts / ideas feel free to drop me a message.

Thomas


More Creators