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

Template property override #310

Closed
phlafoo opened this issue Sep 3, 2024 · 4 comments · Fixed by #311
Closed

Template property override #310

phlafoo opened this issue Sep 3, 2024 · 4 comments · Fixed by #311

Comments

@phlafoo
Copy link

phlafoo commented Sep 3, 2024

I have an ellipse object that triggers some functionality when the player enters the zone defined by the ellipse shape. I have some custom properties for this object so I have converted it into a template to reuse in many places.

The issue I'm having is that when I try to resize the ellipse, the new width and height is not in the ObjectData anywhere. It only gives me the width and height that is defined in the template file. Perhaps I am missing something but I couldn't find anything in the docs about this.

Here is the object from my .tmx file:

<object id="8" template="../templates/Trigger.tx" type="Trigger" x="617" y="5565" width="100" height="100">

And here is the template:

<template>
 <object type="Trigger" width="111" height="289">
<!-- custom properties -->
  <ellipse/>
 </object>
</template>

In this case the ObjectData only contains a width of 111 and height of 289 but I would expect it to have a width and height of 100. Is this the intended behaviour? I have another similar template with the same issue but it is a rectangle.

I am new to Tiled so let me know if there is a better way to go about this.

@phlafoo
Copy link
Author

phlafoo commented Sep 3, 2024

Looking at the code here I think I found the problem.

// Possibly copy properties from the template into the object
// Any that already exist in the object's map don't get copied over
if let Some(templ) = template {
    shape.get_or_insert(templ.object.shape.clone());

    for (k, v) in &templ.object.properties {
        if !properties.contains_key(k) {
            properties.insert(k.clone(), v.clone());
        }
    }
}

When I am using the template, the object in the level file does not have the ellipse tag so the shape is not parsed at all. When this code is reached, shape is None and so the template shape is used. So it seems that the correct width and height can only be used after getting the shape from the template since the type of shape cannot be known from the object xml alone.

@aleokdev
Copy link
Contributor

aleokdev commented Sep 3, 2024

This looks incorrect, but I'll wait for @bjorn's response

@bjorn
Copy link
Member

bjorn commented Sep 3, 2024

Hmm, yes this is a bug. It is correct to inherit the shape from the template, but the size can be overridden by the object. This is also broken for point shapes, where the position stored in the shape currently ends up being the one of the template. I'm working on a fix.

bjorn added a commit that referenced this issue Sep 3, 2024
Template instances of rectangle, ellipse and text objects can override
the width and height of the template object. This is now taken into
account when reading out the attributes and when inheriting the shape
from the template.

Template instances of point objects are now also correctly storing the
instance position in the Point shape, instead of the position of the
template object.

Closes #310
bjorn added a commit that referenced this issue Sep 3, 2024
Template instances of rectangle, ellipse and text objects can override
the width and height of the template object. This is now taken into
account when reading out the attributes and when inheriting the shape
from the template.

Template instances of point objects are now also correctly storing the
instance position in the Point shape, instead of the position of the
template object.

Closes #310
bjorn added a commit that referenced this issue Sep 3, 2024
Template instances of rectangle, ellipse and text objects can override
the width and height of the template object. This is now taken into
account when reading out the attributes and when inheriting the shape
from the template.

Template instances of point objects are now also correctly storing the
instance position in the Point shape, instead of the position of the
template object.

Closes #310
@bjorn
Copy link
Member

bjorn commented Sep 3, 2024

@phlafoo The issue should be fixed by #311, though I didn't do a test yet.

bjorn added a commit that referenced this issue Sep 3, 2024
Template instances of rectangle, ellipse and text objects can override
the width and height of the template object. This is now taken into
account when reading out the attributes and when inheriting the shape
from the template.

Template instances of point objects are now also correctly storing the
instance position in the Point shape, instead of the position of the
template object.

Added a small test for the resized templated object case.

Closes #310
@bjorn bjorn closed this as completed in #311 Sep 3, 2024
@bjorn bjorn closed this as completed in 1ffab03 Sep 3, 2024
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 a pull request may close this issue.

3 participants