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

Opening empty tsj results in error #3542

Closed
solerante opened this issue Dec 11, 2022 · 4 comments
Closed

Opening empty tsj results in error #3542

solerante opened this issue Dec 11, 2022 · 4 comments
Assignees
Labels
bug Broken behavior.

Comments

@solerante
Copy link

Describe the bug
opening an empty tsj file created by script results in an error:
"Error opening [path.tsj]: Invalid tileset parameters for tileset '[tileset name]"

To Reproduce
Steps to reproduce the behavior:
let path = `${pathtoproject}/test.tsj`; unknowns = new Tileset("test_tileset"); tiled.tilesetFormat("json").write(unknowns,path); tiled.open(path);

compared to a tsx:
let path = `${pathtoproject}/test.tsx`; unknowns = new Tileset("test_tileset"); tiled.tilesetFormat("tsx").write(unknowns,path); tiled.open(path);

manually editing the tsj files to have a non-zero value for tileheight and tilewidth allowed the tsj to be opened.

Expected behavior
The empty tsj tileset should open like the tsx.

Media
Screenshot (40)

Specifications:

  • OS: Windows 10
  • Tiled Version: 1.9.2
@solerante solerante added the bug Broken behavior. label Dec 11, 2022
@solerante
Copy link
Author

I see my tsx tileset loaded in the background is misleading because it has tiles loaded in. It's just a screenshot from when the problem originally cropped up and not a clean demo showing that the tsx can load empty.

@eishiya
Copy link
Contributor

eishiya commented Dec 12, 2022

Could you please clarify what you mean by "empty" TSJ? From reading your issue, it sounds like a non-empty Image Collection (i.e. an Image Collection that has tiles) with unset dimensions on the tiles?

Does the TSX file you save have tile size on the tiles? Does the TSJ file?
My hunch is that this isn't a reading issue, but a writing one, perhaps TSJ explicitly writes out the unset tile size as 0 when you use TilesetFormat.write().

@solerante
Copy link
Author

using the code in the steps to reproduce, empty tsx file looks like this

<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.9" tiledversion="1.9.2" name="test_tileset" tilewidth="0" tileheight="0" tilecount="0" columns="0"/>

empty tsj file looks like this

{ "columns":0,
 "margin":0,
 "name":"test_tileset",
 "spacing":0,
 "tilecount":0,
 "tiledversion":"1.9.2",
 "tileheight":0,
 "tilewidth":0,
 "type":"tileset",
 "version":"1.9"
}

In an issue I am running into at the moment, the following tsj is generated:

{ "columns":0,
 "margin":0,
 "name":"Favorites",
 "spacing":0,
 "tilecount":1,
 "tiledversion":"1.9.2",
 "tileheight":0,
 "tiles":[
        {
         "id":0,
         "image":"images\/fd_laser.png",
         "imageheight":32,
         "imagewidth":32,
         "properties":[
                {
                 "name":"cdda_id",
                 "type":"string",
                 "value":"fd_laser"
                }]
        }],
 "tilewidth":0,
 "type":"tileset",
 "version":"1.9"
}

In this case, I am adding a single tile to a newly generated tileset "favorites" and it is referring to a valid path. It found the correct dimensions for the image, but did not pass it to tilewidth and tileheight. However, if I select 2 images or more to add to favorites, it seems to load the values:

{ "columns":0,
 "grid":
    {
     "height":0,
     "orientation":"orthogonal",
     "width":0
    },
 "margin":0,
 "name":"Favorites",
 "spacing":0,
 "tilecount":2,
 "tiledversion":"1.9.2",
 "tileheight":32,
 "tiles":[
        {
         "id":0,
         "image":"images\/sharp_rock.png",
         "imageheight":32,
         "imagewidth":32,
         "properties":[
                {
                 "name":"cdda_id",
                 "type":"string",
                 "value":"sharp_rock"
                }]
        }, 
        {
         "id":1,
         "image":"images\/splinter.png",
         "imageheight":32,
         "imagewidth":32,
         "properties":[
                {
                 "name":"cdda_id",
                 "type":"string",
                 "value":"splinter"
                }]
        }],
 "tilewidth":32,
 "type":"tileset",
 "version":"1.9"
}

The section of code that is generating it:

...
tiles = tiled.activeAsset.selectedTiles;
...
let favorites;
    if(!File.exists(config.pathToFavoritesTSJ)){
        favorites = new Tileset("Favorites");
        tiled.tilesetFormat("json").write(favorites,config.pathToFavoritesTSJ);
    } else {
        favorites = tiled.open(config.pathToFavoritesTSJ);
    }
...
  for(let tile of tiles){
        let path_to_image;
        if(!is_image_collection){
            path_to_image = FileInfo.toNativeSeparators(`${pathToFavoriteImages}/${tile.property(`cdda_id`)}.png`)
            if(!File.exists(path_to_image)){
                let [x,y] = cte.getTileXY(tile)
                let croppedImage = cte.cropImage(tileset.image,x,y);
                croppedImage.save(path_to_image);
            };
        } else {
            path_to_image = tile.imageFileName
        }
        let new_image_tile = favorites.addTile()
        new_image_tile.setProperty("cdda_id",tile.property(`cdda_id`))
        new_image_tile.imageFileName = path_to_image
        tiled.log(`'${tile.property(`cdda_id`)}' added to favorites.`)
    }
    tiled.tilesetFormat("json").write(favorites,config.pathToFavoritesTSJ);
    tiled.reload(tiled.activeAsset)
    tiled.open(originalAsset.fileName)

so using that script, it doesn't actually try to open the tileset the first time, so it saves a single tile to it successfully. However, next time, it will try to open it and fail if a single tile was added at once, but will succeed if multiple tiles were added at once.

When I was doing this with tsx files, I could make an empty tileset and later open it to do whatever. With the tsj, it seems something is off since it should open even without any tiles, but returns an error instead.

In my previous example in discord, I was working on a section to add 'unknown' tiles and made some mistakes about the path of the file. Those tilesets should still have opened then since tiled just shows a fallback icon for bad paths to images in tilesets. Once the paths were fixed, the error stopped occurring, I think because the maps I import using that function rarely have a single undefined tile. On the other hand, adding a tile to favorites is often done 1 by 1, so the issue has resurfaced.

It's interesting that adding 2 tiles fills the width and height.

@bjorn
Copy link
Member

bjorn commented Jan 18, 2023

The bug appears to be, that it complains about tileset parameters for an image collection tileset, where a tilewidth of 0 should be considered valid since for image collections this value represents the maximum tile width, which would be 0 when the collection is still empty.

@bjorn bjorn closed this as completed in b1454c9 Mar 21, 2023
@bjorn bjorn self-assigned this Mar 21, 2023
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

No branches or pull requests

3 participants