Giter Club home page Giter Club logo

Comments (9)

aleokdev avatar aleokdev commented on September 24, 2024 1

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.

bjorn avatar bjorn commented on September 24, 2024

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.

aleokdev avatar aleokdev commented on September 24, 2024

BTW you theorically could create your own ResourceLoader and log the path of each tileset loaded that way.

from rs-tiled.

LuckyTurtleDev avatar LuckyTurtleDev commented on September 24, 2024

@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.

aleokdev avatar aleokdev commented on September 24, 2024

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.

LuckyTurtleDev avatar LuckyTurtleDev commented on September 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.