Comments (9)
You're right, this isn't possible currently. But since the path depends on the reader/cache used, it maybe makes more sense to include this as a ResourceCache method. Nevermind, as this would limit obtaining it only to intermediate resources. Perhaps it is OK to just store the path in Tileset
.
from rs-tiled.
I don't really like the idea of adding the path to the Tileset
struct, because I think it doesn't really belong there and for most use-cases it is enough to just be able to look up tilesets by their path in the ResourceCache
. However, for those cases where you do need the path I have to admit that I don't know a nice alternative either and I have solved this issue the same way in Tiled itself.
@LuckyTurtleDev Just out of curiosity, what use-case do you have where you need to know the path?
from rs-tiled.
BTW you theorically could create your own ResourceLoader and log the path of each tileset loaded that way.
from rs-tiled.
@LuckyTurtleDev Just out of curiosity, what use-case do you have where you need to know the path?
@bjorn I have writen a proc macro, with does convert the tiled map to a more easy app internal map format and check some requirements at compile time.
This macro must rerun every time the map files has change. Regular this does not happen because the macro is cached.
But if you use the include_bytes!()
macro inside your proc macro rust does automatically start watching the file and rerun the whole proc macro if the file has changed.
For the the main tmx map you can simple use the path from the input of the proc macro.
const _: &[u8] = ::core::include_bytes!(#path);
But this can not be done for the tileset, because the macro do not know where they are stored.
Currently I am using a workaround, to simple include all tileset of the workspace:
let mut tileset = quote!();
for path in glob("./**/*.tsx").unwrap() {
let path = path.unwrap().canonicalize().unwrap();
let path = path.to_str().unwrap();
tileset = quote! {
#tileset;
const _: &[u8] = ::core::include_bytes!(#path)
}
}
from rs-tiled.
Have you considered using a build script insead to convert your maps? You can select when to rerun it, and you won't need any macro usage in your app code.
from rs-tiled.
Have you considered using a build script insead to convert your maps?
I personal prefer using macros, because you can easier see, where the generated code is included. A build script instead does write in some "random" files and is run every time if I compile something.
However the current workaround does work for me.
from rs-tiled.
Related Issues (20)
- Make TileData of Tile in Tileset accessible HOT 3
- Improve Data/Wrapper docs
- Renaming the `0.11` branch to `next` and `master` to `current` HOT 2
- Yanking the 0.9.5 release HOT 1
- Polygon colliders load as Rect shapes HOT 5
- Support for Web Assembly HOT 15
- since tiled 1.9 object type is renamed into class HOT 3
- tiled::FiniteTileLayer::get_tile returns empty tiles HOT 7
- Optional GIDs feature HOT 1
- Default zstd feature is unhelpful for wasm builds HOT 2
- Add support for tileset offset
- Nicer way to iterate over layers of a given type HOT 2
- Expose map's staggeraxis and staggerindex options.
- Loading map with TSX tileset error "Missing attribute: tilecount" HOT 11
- More convenient way to load embedded maps HOT 8
- Image docs are outdated
- get rotaion of tile HOT 3
- Support for Tiled Custom Types HOT 2
- Unsigned indecies for getting a tile HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rs-tiled.