excaliburjs / excalibur-tiled

Adds Tiled Map Editor File support to Excalibur
https://excaliburjs.com/docs/tiled-plugin
BSD 2-Clause "Simplified" License
49 stars 22 forks source link

Tile custom colliders on isometric map causes error on load #391

Closed mattjennings closed 10 months ago

mattjennings commented 2 years ago

I'm not sure if tile custom colliders are officially supported, but an error is thrown when trying to use them.

Log.ts:173 [Error] :  Error loading resources, things may not behave properly TypeError: Cannot read properties of undefined (reading 'split')
    at B.getCollidersForGid (tiled-map-resource.ts:513:35)
    at B._createTileMap (tiled-map-resource.ts:664:45)
    at tiled-map-resource.ts:412:18

It seems the polygon data structure is not what it expects:

CleanShot 2022-07-21 at 23 21 28@2x

(inspecting polygon.polygon)

Steps to Reproduce

See repro: https://github.com/mattjennings/excalibur-iso-tiled-collider-bug

npm install
npm run dev

I've added both an isometric and orthogonal tilemap that uses the same tileset. When loading the isometric, the above error occurs on load. However, the orthogonal map does not cause the error, so the polygon data must be different in isometric vs orthogonal?

Expected Result

Isometric custom tile colliders to be loaded

Actual Result

An error is thrown

Environment

Current Workaround

None

eonarheim commented 2 years ago

@mattjennings Thanks for the bug!

I bet this a bug in the TSX vs TSJ parsing. The XML version stores the points in an odd string representation that needs parsing. It appears the TSJ is far more convenient. Should be a quick fix to support the TSJ hopefully🤞

I've had a few of these types of bugs, I might spend some after fixing this to refactor the tiled parsing to be more robust.

eonarheim commented 2 years ago

I have something that mostly works, needs more testing. Vite really resists npm link!

image
mattjennings commented 2 years ago

@eonarheim I spent some time trying to get @excaliburjs/plugin-tiled propertly symlinking with vite myself and the following vite.config.js is what worked for me:

import { defineConfig } from 'vite'

export default defineConfig({
  optimizeDeps: {    
    force: true, // vite 3.0.0 feature, busts node_modules prebundle cache
  },
  resolve: {
    preserveSymlinks: true,
    dedupe: ['excalibur']
  }
})

However I use pnpm to both install and link my packages (pnpm link path/to/excalibur-tiled), so possibly there's some differences there with npm link, but this is what finally made it work reliably for me