Skip to content

Setting object.polygon in script makes all points (0,0) #3845

Closed
@IoriBranford

Description

Describe the bug
When a script assigns a new polygon to a MapObject, all the polygon points will end up as (0,0).

To Reproduce
Steps to reproduce the behavior:

  1. Install the test script
/// <reference types="@mapeditor/tiled-api" />

const TouchPolygon = tiled.registerAction("Touch Polygon", (action) => {
    let asset = tiled.activeAsset
    let selected = asset.selectedObjects
    if (!selected) {
        return
    }
    
    for (let object of selected) {
        let polygon = object.polygon
        if (!polygon)
            continue
        asset.macro("Touch Polygon", () => {
            // Doc says: "To modify the polygon of a MapObject, change or set up the polygon array and then assign it to MapObject.polygon"
            object.polygon = polygon.map((p) => ({ x: p.x, y: p.y }))
            tiled.log(polygon)
            tiled.log(object.polygon)
        })
    }
})
TouchPolygon.text = "Touch Polygon"

tiled.extendMenu("MapView.Objects", [
    { action: "Touch Polygon" }
])
  1. Create a polygon or polyline object
  2. Right-click on the object and select "Touch Polygon"
  3. See console output

Expected behavior
The polygon is unchanged and two identical point arrays are output to console.

Actual behavior
The polygon collapses as all its points are zeroed. This is confirmed by console output, in which the second array has the same number of points but they are all QPointF(0,0).

Specifications:

  • OS: Linux Mint Vera
  • Tiled Version: 1.10.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugBroken behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions