Skip to content
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

Automapping: Rules with empty input don't affect top and left of map #3834

Open
eishiya opened this issue Oct 19, 2023 · 0 comments · May be fixed by #4115
Open

Automapping: Rules with empty input don't affect top and left of map #3834

eishiya opened this issue Oct 19, 2023 · 0 comments · May be fixed by #4115
Labels
bug Broken behavior.

Comments

@eishiya
Copy link
Contributor

eishiya commented Oct 19, 2023

Problem

When the input region for a rule is empty, the top and left of the map are unaffected, the size of the unaffected area depends on whether modX/modY are set to a value above 1. While this seems like an odd scenario, modX and modY are useful enough in their own right that it makes perfect sense to leave out any explicit input. For example, if I want to populate a layer with just a checkerboard grid, all I need for that is an empty input, an output, and modX/modY with the size of the output.

Some examples follow, I put them at the bottom as it's a rather long section. In short, you'll see that a non-empty input behaves much more consistently (though not without surprises), and the underlying cause of the issue is probably something odd that happens when the input region is empty.

Suggested changes

  1. When the input region of a rule is empty, treat it as being the same as that of the output, as that is most likely the intent. This'll avoid whatever strangeness is causing the margin, since the input region will just never be empty.
  2. (Bit of a side issue) "Ignore" should match tiles outside the map as long as any part of the input region is inside the map.
  3. In the Automapping documentation, explicitly state that the modX/modY behaviour is based on the input region, and not the combined region of the rule. The documentation current speaks of the rule "applying", which is ambiguous whether it's about input or output.

Test scenarios

My test rule in this case is a 2x2 green/brown circle as the output, varying modX/modY, and in some examples, "Ignore" special tiles in the input, which you will see on top of the output tiles. In all cases, offsetX/Y is unset. I have also experimented with different values for that, but different offset values never remove the empty area. The test map is 10x10 and empty before Automapping.

Scenarios with empty inputs

Scenario 1: modX/modY unset (1, according to the documentation, but 0 displayed in Tiled), empty input:
image
image
(The same result happens if modY and modY are explicitly set to 1)
The rule overwrites parts of itself and this is expected, but the 1 tile margin is unexpected.

Scenario 2: modX/modY set to 2, rule otherwise unchanged:
image
The rule produces a grid of the 2x2 pattern, but the 2-tile margin is unexpected.

Scenario 3: modX2, modY 3, rule otherwise unchanged:
image
Again results as expected, but again with the weird 2-tile margin.

Scenario 4: modX 4, modY 5, rule otherwise unchanged:
image
Once again, the results are exactly what I'd expect, save for the unexpected margin. The pattern continues, it seems like any value above 1 will cause a 2-tile margin.

Scenarios with non-empty inputs

Adding an actual input to the input layer reveals the likely source of the problem: the placement of the output is apparently calculated based on the position of the input region, and when the input is empty, it gets weird.

Scenario 5: modX/modY unset, input filled with "Ignore" special tiles in any of these three arrangements (i.e. the bounding box of the input region matches that of the output):
image image image
image
As expected, every part of the map is correctly filled with the output pattern, overlapping itself.

Scenario 6, modX 3, modY 3, rule otherwise unchanged from scenario 5:
image
Again, correct behaviour (though the fact that tiles outside the map apparently don't match "Ignore" is concerning! I expected the whole map to be filled with this pattern, not just the 3x3 regions that are wholly within it!)

Scenario 7: modX 3, modY 3, but with the "Ignore" tile in the top left of the rule:
image
image
Results as above, except now the whole map is filled because the "Ignore" gets to match tiles within the map.

Scenario 8: modX 3, modY 3, but with the "Ignore" tile in the bottom right of the rule:
image
The whole pattern is offset! This is why I'm guessing the issue has to do with the input region.

And finally of tests that are like scenarios 7-8, but with modX and modY unset:

Scenario 9: "Ignore" in the top left:
image
image

Scenario 10: "Ignore" in the bottom right:
image
image

In both of these, no mystery margin, but also rather meaningless results since the rule just overlaps itself. The slight difference in output is explained by the bottom left "Ignore" not matching tiles outside the map.

@eishiya eishiya added the bug Broken behavior. label Oct 19, 2023
bjorn added a commit to bjorn/tiled-dev that referenced this issue Dec 5, 2024
Rules with an empty input region were causing issues, because they don't
have a valid bounding rectangle. They are also commonly created by
accident. If intended as a rule that always matches, such a rule can be
made by placing the special "Ignore" tile in the rule's input.

Rules with empty output region are no longer matched because they would
not produce any output anyway.

As a drive-by, AutoMapper no longer derives from QObject, which appears
to have only been done to access the tr() function. This is now made
available using Q_DECLARE_TR_FUNCTIONS instead.

Closes mapeditor#3834
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Broken behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant