New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom level layouts in config #3
Conversation
@@ -63,3 +108,67 @@ impl Default for Theme { | |||
} | |||
} | |||
} | |||
|
|||
fn deserialize_map_data<'de, D>(deserializer: D) -> Result<MapData, D::Error> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit hairy, I agree, but I really really wanted to use an authoring-friendly format for custom maps, instead of something cursed like:
[map.data]
0 = [ "wall", "wall", "empty", ...]
1 = ...
So, I followed the Serde docs on how to create a custom deserialization for a type. In this case I could just make this method instead using the decorator you see in line 57.
Basically we write this dummy struct that implements visitor
. It has 1 required method, expecting
, for the syntax error message, and optional visit_{type}
methods. In this case I wanted to build the type from a string, so I implemented visit_str
, and call deserializer.deserialize_str
with the visitor. It is a bit clunky for something so simple but it kind of makes sense for more general visitors.
In the visit method, I split the input into lines and collect the characters into a MapData
, which later will be used to spawn the actual entities.
There currently is a strange bug where the screen is sometimes for some reason wider than it should be, but I can't repro consistently, might be something funky on my PC. |
Is the map supposed to have a message or something? 馃 I must be dumb |
Yeah 馃榿 |
I'll merge this in! I was planning on later down the line getting support for more complex maps, LDtk seems really neat and I think it has support for Bevy, though I haven't looked into it too much. That's going to be in a while though so having the option for faster to make ASCII maps is a good idea. |
I actually haven't seen this meme before! I'll add it to my collection 馃槄 |
I imagine this is something you might want to do yourself, but if you need some inspiration you can use this PR as a reference! Do not feel like you need to merge this. 馃槄
Basically, I removed the
grid_width
,grid_height
andcorner_walls
fields fromConfig
, and instead created an enum calledMap
, which can be one of two variants:Box
layout, which has the aforementioned properties and uses the existing level generation code;Custom
layout, which allows whoever is writingconfig.toml
to draw a map with ASCII.To be able to do that, I had to refactor the coordinate conversion function to use a new unified resource for the grid dimensions, since it can be obtained from possibly many locations now.
Here's how
config.toml
feels like now, using a custom map (before you ask, yes, it is. 馃槃):Or using the generation algorithm: