AustinEast / heaps-aseprite

An Aseprite File Parser for Heaps
https://lib.haxe.org/p/heaps-aseprite/
MIT License
28 stars 8 forks source link

Dictionary macro v2 #5

Closed deepnight closed 3 years ago

deepnight commented 3 years ago

Slightly better than previous PR :)

This class extracts various identifiers from an Aseprite file on compilation time. This creates a typed structure that allows some type-safety: if an identifier changes in your Aseprite file (for example a tag), your compilation will show errors wherever this identifier was used. Example:

var tagsDictionary = aseprite.Dictionary.getTags( hxd.Res.myFile ); // now uses actual Res identifier :)

trace(tagsDictionary); // { run:"run", idle:"idle", attackA:"attackA" }

someAnimManager.play( tagsDictionary.run ); // if "run" tag is renamed in Aseprite, this will show an error here
AustinEast commented 3 years ago

Thanks for the PR! This'll be super handy 😁

For the next step, I might try to figure out if its possible to add these methods directly to the aseprite.res.Aseprite class - It would be really cool to be able to just do something like var myTags = hxd.Res.myfile.getTags(); 🤔

deepnight commented 3 years ago

I couldn't find a way to do that unfortunately, because this would require to make hxd.Res.myFile return a specific class that inherits Aseprite, for it to be populated with "tag fields". And I don't see how to plug that with hxd.Res 🤔

I get lost in the Macro inception and my mind just blows up at this point.