Skip to content

Commit

Permalink
Improve API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Madour committed Jun 19, 2024
1 parent 4953802 commit 80ce1ea
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 50 deletions.
32 changes: 3 additions & 29 deletions doc/Entity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ classes:
> To get the correct sprite data of the Entity as it is shown in the editor,
> you should use `hasSprite` to check if the Entity has a sprite,
> and then `getTexturePath` and `getTextureRect` to get the texture data.
parent: FieldsContainer

fields:
layer:
Expand Down Expand Up @@ -48,8 +49,8 @@ classes:
- decl: ldtk::Entity::getGridPosition() const -> const ldtk::IntPoint&
desc: Returns the position in grid coordinates of the Entity.

getGridPosition:
- decl: ldtk::Entity::getGridPosition() const -> const ldtk::IntPoint&
getWorldPosition:
- decl: ldtk::Entity::getWorldPosition() const -> const ldtk::IntPoint&
desc: Returns the computed position in pixels of the Entity relative to the World.

getPivot:
Expand Down Expand Up @@ -84,30 +85,3 @@ classes:
- decl: ldtk::Entity::allTags() const -> const std::vector<std::string>&
desc: Returns a vector containing all tags of the Entity.

getField<T>:
- decl: |
template <typename T>
ldtk::Entity::getField<T>(const std::string& name) const -> const ldtk::Field<T>&
desc: |
Returns the field matching the given name and type. Returned field can be null.
`T` can either be a `ldtk::FieldType` value, or one of the following types: `int`, `float`,
`bool`, `std::string`, `ldtk::Color` , `ldtk::Point`, `ldtk::Enum`, `ldtk::FilePath`.
For example, if your entity has a field of type color named "hair_color", you can either do :
```c++
const auto& field = my_entity.getField<ldtk::Color>("hair_color")
if (!field.is_null()) {
// do something with field.value()
}
```
or
```c++
const auto& field = my_entity.getField<ldtk::FieldType::Color>("hair_color")
if (!field.is_null()) {
// do something with field.value()
}
```
4 changes: 2 additions & 2 deletions doc/Enum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ structs:
hasIcons:
- decl: ldtk::Enum::hasIcons() const -> bool
desc: Returns true if the Enum has icons, returns false otherwise.
desc: Returns `true` if the Enum has icons, returns `false` otherwise.

getIconsTileset:
- decl: ldtk::Enum::getIconsTileset() const -> const ldtk::Tileset&
Expand Down Expand Up @@ -59,7 +59,7 @@ structs:
hasIcon:
- decl: ldtk::EnumValue::hasIcon() const -> bool
desc: |
Returns true if the EnumValue has an icon, returns false otherwise.
Returns `true` if the EnumValue has an icon, returns `false` otherwise.
getIconTileset:
- decl: ldtk::EnumValue::getIconTileset() const -> const ldtk::Tileset&
Expand Down
51 changes: 39 additions & 12 deletions doc/Layer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ title: Layer
filename: LDtkLoader/Layer.hpp
classes:
- name: Layer
desc: A Layer is a part of a Level and can contain Tiles or Entities
desc: A Layer is a part of a Level and can contain Tiles or Entities.
fields:
level:
decl: const ldtk::Level* ldtk::Layer::level
Expand All @@ -23,7 +23,7 @@ classes:

isVisible:
- decl: ldtk::Layer::isVisible() const -> bool
desc: Returns `true` if the Layer is visible in the editor, `false` otherwise.
desc: Returns `true` if the Layer is visible in the editor, returns `false` otherwise.

getCellSize:
- decl: ldtk::Layer::getCellSize() const -> int
Expand All @@ -43,7 +43,7 @@ classes:

hasTileset:
- decl: ldtk::Layer::hasTileset() const -> bool
desc: Returns `true` if the Layer has a Tileset, `false` otherwise.
desc: Returns `true` if the Layer has a Tileset, returns `false` otherwise.

getTileset:
- decl: ldtk::Layer::getTileset() const -> const ldtk::Tileset&
Expand All @@ -61,14 +61,39 @@ classes:
desc: |
Returns the Tile located at (x, y) grid position.
Returns `ldtk::Tile::None` if there is none.
Returns `ldtk::Tile::None` if there is no tile at the position.
getIntGridValue:
- decl: ldtk::Layer::getIntGridValue(int x, int y) const -> const IntGridValue&
getTilesByEnumTag:
- decl: |
ldtk::Layer::getTilesByEnumTag(const EnumValue&) const -> const std::vector<std::reference_wrapper<Tile>>&;
desc: |
Returns the IntGrid value located at (x, y) grid position.
Returns a vector containing reference wrappers of Tiles tagged with the given EnumValue.
Because the returned vector contains reference wrappers, using `auto` won't work as expected,
you have to explicitly specify the type when iterating :
```c++
const auto& chest_enumval = world.getEnum("Items")["Chest"];
for (const ldtk::Tile& chest_tiles : layer.getTilesByEnumTag(chest_enumval)) {
// ...
}
```
Returns `ldtk::IntGridValue::None` if there is none.
getIntGridVal:
- decl: ldtk::Layer::getIntGridVal(int x, int y) const -> const IntGridValue&
desc: |
Returns the IntGridValue value located at (x, y) grid position.
Returns `ldtk::IntGridValue::None` if there is no IntGridValue at the position.
getIntGridValPositions:
- decl: ldtk::Layer::getIntGridValPositions(int value) const -> const std::vector<IntPoint>&
desc: |
Returns a vector containing the grid positions of all tiles of the given IntGridValue value.
- decl: ldtk::Layer::getIntGridValPositions(const std::string& name) const -> const std::vector<IntPoint>&
desc: |
Returns a vector containing the grid positions of all tiles of the given IntGridValue name.
hasEntity:
- decl: ldtk::Layer::hasEntity(const std::string& name) const -> bool
Expand All @@ -82,12 +107,13 @@ classes:
- decl: |
ldtk::Layer::getEntitiesByName(const std::string& name) const -> const std::vector<std::reference_wrapper<Entity>>&
desc: |
Returns a vector containing reference wrappers of Entities named `<name>`.
Returns a vector containing reference wrappers of Entities named as the provided name.
Because the returned vector contains reference wrappers, using `auto` won't work like expected, you have to explicitly specify the type when iterating :
Because the returned vector contains reference wrappers, using `auto` won't work as expected,
you have to explicitly specify the type when iterating :
```c++
for (const ldtk::Entity& door : layer.getEntitiesByName("Door")) {
for (const ldtk::Entity& slime : layer.getEntitiesByName("Slime")) {
// ...
}
```
Expand All @@ -98,7 +124,8 @@ classes:
desc: |
Returns a vector containing reference wrappers of Entities tagged with the provided tag name.
Because the returned vector contains reference wrappers, using `auto` won't work like expected, you have to explicitly specify the type when iterating :
Because the returned vector contains reference wrappers, using `auto` won't work as expected,
you have to explicitly specify the type when iterating :
```c++
for (const ldtk::Entity& actionable : layer.getEntitiesByTag("actionable")) {
Expand Down
6 changes: 5 additions & 1 deletion doc/Level.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ classes:

position:
decl: const ldtk::IntPoint ldtk::Level::position
desc: Position in pixels of the Level in the World.
desc: Position in pixels of the Level relatively to the World.

bg_color:
decl: const ldtk::Color ldtk::Level::bg_color
desc: Background color of the Level.

depth:
decl: const int ldtk::Level::depth
desc: Depth of the Level. 0 by default.

methods:
allLayers:
- decl: ldtk::Level::allLayers() const -> const std::vector<ldtk::Layer>&
Expand Down
56 changes: 56 additions & 0 deletions doc/Tile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
title: Tile
filename: LDtkLoader/Tile.hpp
classes:
- name: Tile
desc: Represents a tile on a Layer
fields:
layer:
decl: const ldtk::Layer* const ldtk::Tile::layer
desc: Pointer to the Layer object that contains the Tile.

coordId:
decl: const int ldtk::Tile::coordId
desc: Coordinate ID of the Tile. Used to retrieve grid position of the Tile.

tileId:
decl: const int ldtk::Tile::tileId
desc: Unique ID that identifies the Tile on its Tileset.

flipX:
decl: const bool ldtk::Tile::flipX
desc: Equals `true` if the Tile is flipped alongside the X axis. Equals `false` otherwise.

flipY:
decl: const bool ldtk::Tile::flipY
desc: Equals `true` if the Tile is flipped alongside the Y axis. Equals `false` otherwise.

alpha:
decl: const float ldtk::Tile::alpha
desc: A value between 0.0 and 1.0 that represnets the opacity of the Tile.

methods:
getPosition:
- decl: ldtk::Tile::getPosition() const -> ldtk::IntPoint
desc: Returns the position of the Tile in pixels, relatively to the Level (i.e. after applying Layer offset).

getGridPosition:
- decl: ldtk::Tile::getGridPosition() const -> ldtk::IntPoint
desc: Returns the grid position of the Tile.


getWorldPosition:
- decl: ldtk::Tile::getWorldPosition() const -> ldtk::IntPoint
desc: |
Returns the position of the Tile in pixels, relatively to the World
(i.e. after applying Layer and Level offsets).
getTextureRect:
- decl: ldtk::Tile::getTextureRect() const -> ldtk::IntRect
desc: Returns the IntRect corresponding to the Tile area on the Tileset texture.

getVertices:
- decl: ldtk::Tile::getVertices() const -> std::array<ldtk::Vertex, 4>
desc: |
Returns an array containing 4 vertices, corresponding the graphical representation of a Tile quad.
See Vertex.
12 changes: 6 additions & 6 deletions doc/Tileset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ classes:

path:
decl: const std::string ldtk::Tileset::path
desc: Relative path to the image file.
desc: Relative path to the Tileset's texture image file.

texture_size:
decl: const ldtk::IntPoint ldtk::Tileset::texture_size
desc: Size in pixels of the Texture.
desc: Size in pixels of the Tileset's texture.

tile_size:
decl: const int ldtk::Tileset::tile_size
Expand All @@ -36,21 +36,21 @@ classes:
methods:
getTileTexturePos:
- decl: ldtk::Tileset::getTileTexturePos(int tile_id) const -> ldtk::IntPoint
desc: Returns the texture coordinates of the tile ID.
desc: Returns the texture coordinates of the Tile ID.

getTileCustomData:
- decl: |
ldtk::Tileset::getTileCustomData(int tile_id) const -> const std::string&
desc: Returns the custom data of the tile ID.
desc: Returns the custom data associated with the Tile ID.
getTileEnumTags:
- decl: |
ldtk::Tileset::getTileEnumTags(int tile_id) const -> const std::vector<std::reference_wrapper<const EnumValue>>&
desc: Returns a vector containing the EnumTags associated with the tile ID.
desc: Returns a vector containing the EnumTags associated with the Tile ID.
hasEnumTags:
- decl: ldtk::Tileset::hasEnumTags() const -> bool
desc: Returns true if the Tileset has enum tags associated to tiles, false otherwise.
desc: Returns `true` if the Tileset has enum tags associated to tiles, `false` otherwise.

getEnumTagsEnum:
- decl: ldtk::Tileset::getEnumTagsEnum() const -> const Enum&
Expand Down

0 comments on commit 80ce1ea

Please sign in to comment.