Skip to content

Support specified z index #24

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

Merged
merged 4 commits into from
Jan 22, 2021

Conversation

agmcleod
Copy link
Contributor

@agmcleod agmcleod commented Jan 5, 2021

#23

@@ -91,19 +91,21 @@ function stringifyNode(nodeProperties, contentProperties = {}) {
}
str += ']\n';
for (const [key, value] of Object.entries(contentProperties)) {
str += this.stringifyKeyValue(key, value, false, true) + '\n';
if (value !== undefined) {
str += this.stringifyKeyValue(key, value, false, true) + '\n';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to have a cleaner set of options above for passing the z_index, but don't know if theres legit cases to include undefined in the scene file.

@@ -100,7 +100,7 @@ class GodotTilemapExporter {
if (!ld.isEmpty) {
const tileMapName = idx === 0 ? layer.name || "TileMap " + i : ld.tileset.name || "TileMap " + i + "_" + idx;
this.mapLayerToTileset(layer.name, ld.tilesetID);
this.tileMapsString += this.getTileMapTemplate(tileMapName, ld.tilesetID, ld.poolIntArrayString, ld.parent, layer.map.tileWidth, layer.map.tileHeight, layer.property("groups"));
this.tileMapsString += this.getTileMapTemplate(tileMapName, ld.tilesetID, ld.poolIntArrayString, ld.parent, layer.map.tileWidth, layer.map.tileHeight, layer.property("groups"), parseInt(layer.properties()['z_index'], 10));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the change looks fine to me, at this point since we're passing in 4 parameters that are taken from the layer, I'd change the function to take layer itself as parameter instead.

groups = splitCommaSeparated(groups);
getTileMapTemplate(tileMapName, tilesetID, poolIntArrayString, layer, parent = ".") {
const tileWidth = layer.map.tileWidth || 16;
const tileHeight = layer.map.tileHeight || 16;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure what these default values of "16" were for, but I don't think they make sense here. I guess this code currently means that when the tile size is somehow set to 0, it will take 16 instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was their previous default, i didn't want to impact any functional change.

Copy link
Member

@bjorn bjorn Jan 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But function parameter defaults don't work this way, right? The previous code said "if nothing is passed, take 16" (though actually, there was always something passed) while the new code says "if it's something that evaluates to false, take 16".

Not that it is likely to happen, but it appears to me that it would be better to just remove the || 16 parts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah fair point, i added ternary to check for undefined specifically. If @MikeMnD is fine with removing the default aspect of it though, I can.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just learned that the behavior of default parameter values in JS is not what I had expected. Indeed, it appears to take this value even when you explicitly pass in a value, but that value happens to be undefined. So yeah, with your latest code it indeed behaves the same way. :-)

Still, a value of undefined is basically impossible for the expression layer.map.tileWidth, so unless @MikeMnD had a particular reason to have these defaults I still think they can just be removed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I remember the 16 was just cause I've had 16x16px tiles for the my tilemap case. So it's fine to drop them now.

@MikeMnD MikeMnD merged commit 021b0e6 into mapeditor:master Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants