Methods
TiledUtils.colliderFromShape(parent: Object, data: table, x: number?, y: number?, properties: table?)
Creates a Collider based on a Tiled object shape.
@param parent — The object that the new Collider should be parented to.
@param data — The Tiled shape data.
@param x — An optional value defining the horizontal position of the collider.
@param y — An optional value defining the vertical position of the collider.
@param properties — A table defining additional properties for the collider.
@return collider — The new Collider instance.
Arguments:
| parent: Object | The object that the new Collider should be parented to. |
| data: table | The Tiled shape data. |
| x: number? | An optional value defining the horizontal position of the collider. |
| y: number? | An optional value defining the vertical position of the collider. |
| properties: table? | A table defining additional properties for the collider. |
Returns:
| collider: Collider | The new Collider instance. |
TiledUtils.parseColorProperty(property: string)
Converts a Tiled color property to an RGBA color table.
@param property — The property string to convert.
@return rgba — The converted RGBA table.
Arguments:
| property: string | The property string to convert. |
Returns:
| rgba: number[]? | The converted RGBA table. |
TiledUtils.parseFlagProperties(flag: string|nil, inverted: string|nil, value: string|nil, default_value: any, properties: table)
Returns a series of values used to determine the behavior of a flag property for a Tiled event.
@param flag — The name of the flag property.
@param inverted — The name of the property used to determine if the flag should be inverted.
@param value — The name of the property used to determine what the flag's value should be compared to.
@param default_value — If a property for the value name is not found, the value will be this instead.
@param properties — The properties table of a Tiled event's data.
@return flag — The name of the flag to check.
@return inverted — Whether the result of the check should be inverted.
@return value — The value that the flag should be compared to.
Arguments:
| flag: string|nil | The name of the flag property. |
| inverted: string|nil | The name of the property used to determine if the flag should be inverted. |
| value: string|nil | The name of the property used to determine what the flag's value should be compared to. |
| default_value: any | If a property for the |
| properties: table | The properties table of a Tiled event's data. |
Returns:
| flag: string | The name of the flag to check. |
| inverted: boolean | Whether the result of the check should be inverted. |
| value: any | The value that the flag should be compared to. |
TiledUtils.parsePropertyList(id: string, properties: table)
Returns a table with values based on Tiled properties.
The function will check for a series of numbered properties starting with the specified id string, eg. "id1", followed by "id2", etc.
@param id — The name the series of properties should all start with.
@param properties — The properties table of a Tiled event's data.
@return result — The list of property values found.
Arguments:
| id: string | The name the series of properties should all start with. |
| properties: table | The properties table of a Tiled event's data. |
Returns:
| result: table | The list of property values found. |
TiledUtils.parsePropertyMultiList(id: string, properties: table)
Returns an array of tables with values based on Tiled properties.
The function will check for a series of layered numbered properties started with the specified id string, eg. "id1_1", followed by "id1_2", "id2_1", "id2_2", etc.
The returned table will contain a list of tables correlating to each individual list.
For example, the first table in the returned array will contain the values for "id1_1" and "id1_2", the second table will contain "id2_1" and "id2_2", etc.
@param id — The name the series of properties should all start with.
@param properties — The properties table of a Tiled event's data.
@return result — The list of property values found.
Arguments:
| id: string | The name the series of properties should all start with. |
| properties: table | The properties table of a Tiled event's data. |
Returns:
| result: table | The list of property values found. |
TiledUtils.parseTileGid(id: number)
Returns the actual GID and flip flags of a tile.
@param id — The GID of the tile.
@return gid — The GID of the tile without the flags.
@return flip_x — Whether the tile should be flipped horizontally.
@return flip_y — Whether the tile should be flipped vertically.
@return flip_diag — Whether the tile should be flipped diagonally.
Arguments:
| id: number | The GID of the tile. |
Returns:
| gid: integer | The GID of the tile without the flags. |
| flip_x: boolean | Whether the tile should be flipped horizontally. |
| flip_y: boolean | Whether the tile should be flipped vertically. |
| flip_diag: boolean | Whether the tile should be flipped diagonally. |
TiledUtils.relativePathToAssetId(target_dir: string, asset_path: string, source_dir: string)
Attempts to resolve a relative path from a Tiled export to a valid asset id, given it points to a path inside the
target_dir of the current mod.
Relative directories (..) of the asset path are resolved by starting from the source_dir, which should match the
directory the Tiled data was exported to. Exporting to a different directory and copying/moving the exported data will
likely cause this relative search to fail.
@param target_dir — The Kristal folder to get the path relative to.
@param asset_path — The asset path from a Tiled export to resolve.
@param source_dir — Parent directory of the Tiled export, which the asset_path should be relative to.
@return success — Whether the path resolution was successful.
@return result — If resolution was successful, this is the asset path relative the target_dir without its extension. Otherwise, this is a reason the resolution failed.
@return final_path — The final path with its extension, possibly unresolved if resolution failed. Used for debugging.
result:
| "not under prefix"
| "path outside root"
Arguments:
| target_dir: string | The Kristal folder to get the path relative to. |
| asset_path: string | The asset path from a Tiled export to resolve. |
| source_dir: string | Parent directory of the Tiled export, which the |
Returns:
| success: boolean | Whether the path resolution was successful. |
| result: string|"not under prefix"|"path outside root" | If resolution was successful, this is the asset path relative the |
| final_path: string | The final path with its extension, possibly unresolved if resolution failed. Used for debugging. |