You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Tiled, tilesets can be external, which means they can be shared across multiple maps. By allowing the separate loading of these external tilesets, we can optimize asset loading by ensuring that the same tileset isn't loaded multiple times. Furthermore, for certain use-cases, there's a need to load tilesets without associating them with any map.
Proposal
Introduce a TiledTilesetResource class that would allow for the separate loading of tilesets, independent of the map they may be associated with. This would not only cater to external tilesets in Tiled but also provide more flexibility for developers who may want to load tilesets without a map.
Here's a possible implementation of the TiledTilesetResource class:
import{Resource,ImageSource,SpriteSheet}from'excalibur';import{TiledTileset,RawTiledTileset,parseExternalTsx,parseExternalJson}from'@excaliburjs/plugin-tiled';importtype{Loadable}from'excalibur';exportclassTiledTilesetResourceimplementsLoadable<TiledTileset|null>{protected_resource: Resource<RawTiledTileset>/** * Data associated with a loadable */publicdata: TiledTileset|null=null;publicimage: ImageSource|null=null;publicspriteSheet: SpriteSheet|null=null;getraw(){returnthis._resource.data;}constructor(publicpath: string,publicisJson: boolean=false){this._resource=newResource<RawTiledTileset>(path,isJson ? 'json' : 'text');}/** * Begins loading the resource and returns a promise to be resolved on completion */publicasyncload(): Promise<TiledTileset>{letrawTileSet=awaitthis._resource.load();if(this.isJson){this.data=parseExternalJson(rawTileSet,0,this.path);}else{this.data=parseExternalTsx(rawTileSetasunknownasstring,0,this.path);}if(this.data.image){this.image=newImageSource(this.convertPath(this.path,this.data.image));awaitthis.image.load();constrows=this.data.tileCount/this.data.columns;this.spriteSheet=SpriteSheet.fromImageSource({image: this.image,grid: {rows: rows,columns: this.data.columns,spriteWidth: this.data.tileWidth,spriteHeight: this.data.tileHeight},});}returnthis.data;}/** * Returns true if the loadable is loaded */publicisLoaded(): boolean{returnthis._resource.isLoaded();}protectedconvertPath(originPath: string,relativePath: string){// Use absolute path if specifiedif(relativePath.indexOf('/')===0){returnrelativePath;}constoriginSplit=originPath.split('/');constrelativeSplit=relativePath.split('/');// if origin path is a file, remove it so it's a directoryif(originSplit[originSplit.length-1].includes('.')){originSplit.pop();}returnoriginSplit.concat(relativeSplit).join('/');}}
With this class in place, developers can have better control over the loading of tilesets, thus enhancing the efficiency and flexibility of asset management.
The text was updated successfully, but these errors were encountered:
This PR will remove the old xml parser/logic and replace it with a hand crafted parser developed here https://github.com/eonarheim/tiled-xml-parser
Features in this update
* Parser supports parsing _all_ tiled properties, however the plugin doesn't support rendering all of them in Excalibur
* New file mapping to work with various bundlers
* Tiled Template Support
* External Separate Tileset loading Closes#455
* Infinite Tile Maps!!!
* Actor Factory to provide your own implementations based on Tiled class
- Get props passed to objects excaliburjs/Excalibur#2847
- Global class identification Closes#451
Fixes
* New Parser - Closes#391
* New Loader - Closes#387
In addition to replacing the parser this PR also updates the API to be more supportable and friendlier to use. The old `TiledMapResource` type will be marked deprecated
* [x] Headless mode - Closes#478
* [x] Optional file loader implementation - Closes#478
* [x] Isometric
* [x] Integration tests
* [x] Unit tests
* [x] New Documentation
* [ ] Update Samples
Context
In Tiled, tilesets can be external, which means they can be shared across multiple maps. By allowing the separate loading of these external tilesets, we can optimize asset loading by ensuring that the same tileset isn't loaded multiple times. Furthermore, for certain use-cases, there's a need to load tilesets without associating them with any map.
Proposal
Introduce a
TiledTilesetResource
class that would allow for the separate loading of tilesets, independent of the map they may be associated with. This would not only cater to external tilesets in Tiled but also provide more flexibility for developers who may want to load tilesets without a map.Here's a possible implementation of the
TiledTilesetResource
class:With this class in place, developers can have better control over the loading of tilesets, thus enhancing the efficiency and flexibility of asset management.
The text was updated successfully, but these errors were encountered: