-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: modifiable map #1324
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: modifiable map #1324
Conversation
spydon
left a comment
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.
Looks good to me, just a few fixes that needs to be done.
spydon
left a comment
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.
Looks good! But you haven't run flutter format on it.
|
@lfraker could you review this small change too? :) |
|
OK! |
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.
It would be good to have a function that updates the visibilty of a layer and then calls refreshCache, because right now it will be a bit confusing for the user that doesn't know that updateCache needs to be called after a change to the map.
And some more dartdocs on the refreshCache function about when it should be used would be good too.
|
Well, I also added convenience functions to change the tileData and read all values: |
|
|
||
| /// Gets the Gid of the corresponding layer at the given position | ||
| Gid? getTileData({required int layerId, required int x, required int y}) { | ||
| final layer = map.layers[layerId] as TileLayer; |
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.
How do you know that this particular Layer is a TileLayer?
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.
Better now?
st-pasha
left a comment
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.
It looks to me that all 4 new methods operate on a layer, selected by its layerId. In this case it is better to have one method in RenderableTileMap to retrieve a layer with the given id, and then all other methods would belong to that layer class. Thus, instead of .setLayerVisibility(layerId, value), we'd have .layer(id).visibility = value;.
|
|
Unless you wrap it into your own |
How do you propose this should be done without creating new objects, an extension? We also need a reference to the |
|
@st-pasha I agree with @spydon That would be difficult. I would prefer a simple solution. In package tiled there is: abstract class Layer {
...
bool visible;
...
}
class TileLayer extends Layer {...}
class TiledMap {
...
List<Tileset> tilesets;
List<Layer> layers;
...
}
and in flame: class RenderableTiledMap {
...
final TiledMap map;
void refreshCache() {...}
void setLayerVisibility(int layerId, bool visibility) {
...
refreshCache();
...
}
void setTileData( ... ) { ... }
...
}Unfortunately, it is not possible to work with extension methods, as the references to |
|
@Schnurber did you see my response on the suggestion with the null check? |
Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
erickzanardo
left a comment
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.
LGTM
The map should be more flexible. For some game concepts, it could be useful to change the map at runtime.
In the proposed version, you can show and hide layers.
In addition, you can change the tile data and the cache can be updated afterwards.
See small example