Skip to content

Commit

Permalink
Documentation for AssetPaths (#42)
Browse files Browse the repository at this point in the history
* Documentation for AssetPaths

To address this HaxeFlixel/flixel-docs#265

* Address review issues

* address review issues

remove "more control" (will be in other doc)
add @see tags

* a note about where is this class from

* add left *

* aork around vscode md issues, shorten

---------

Co-authored-by: George FunBook <[email protected]>
  • Loading branch information
T1mL3arn and Geokureli authored Mar 6, 2023
1 parent 4dee8fe commit 2290b3c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions default/source/AssetPaths.hx
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
package;

/**
* Helper class to access asset paths in a type-safe manner.
*
* **NOTE:** this class is created when you use [`flixel template` command](https://haxeflixel.com/documentation/hello-world/#create-a-new-haxeflixel-project).
*
* `AssetPaths`'s static fields are autogenerated by a neat [Haxe macro](http://haxe.org/manual/macro.html)
* from the contents of [Project.xml's `<assets>`](https://lime.openfl.org/docs/project-files/xml-format/#assets)
* tag, so you can easily reference them in your code. For example, rather than using the string path
* `"assets/sounds/mySound.wav"`, this class will generate `AssetPaths.mySound__wav` that you can pass into
* `FlxG.sound.play` calls.
*
* Static fields available on `AssetPaths` will change whenever you add, remove, rename or move a file.
* If you remove a file that is still referenced via `AssetPaths` you'll get a compile error,
* this could be handy compared to using string paths, which only cause a runtime error if the file is missing.
*
* ## Ignored Assets
*
* In some cases `AssetPaths` will ignore your assets. The following cases will result in a warning
* at compile:
*
* - **Invalid haxe fields**: For example, the file `assets/1.ogg` will give a warning since
* `1__ogg` is not a valid haxe field name.
*
* - **Duplicate file names**: If you have assets with the same file names, whichever file is nested
* deeper or found later will be ignored. for example if you have assets `assets/hero/walk.png` and
* `assets/enemies/ranger/walk.png`, the latter will be ignored and the compiler will show a warning.
*
* @see [FlxAssets.buildFileReferences()](https://api.haxeflixel.com/flixel/system/FlxAssets.html#buildFileReferences) is used by `AssetPaths`
* and provides you some control on how `AssetPaths`'s fields are built.
* @see [Flixel 5.0.0 Migration guide - AssetPaths has less caveats](https://github.com/HaxeFlixel/flixel/wiki/Flixel-5.0.0-Migration-guide#assetpaths-has-less-caveats-2575)
**/
@:build(flixel.system.FlxAssets.buildFileReferences("assets", true))
class AssetPaths {}

0 comments on commit 2290b3c

Please sign in to comment.