movedOverPoints: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(13 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{stub|lastPath-format specified, define/explain return value, examples}}
{{MacroFunction
{{MacroFunction
|name=movedOverPoints
|name=movedOverPoints
|version=1.3.b75
|version=1.3.b75
|description=
|description=
Use to check if a token has moved through a shape that is defined by an array of pixel coordinates (formatted like the one received from {{func|getLastPath}} or the {{code|onTokenMove}} event.


This function can be used to check if a token has moved through a shape that is defined by an array of cell coordinates (formatted like the one received from {{func|getLastPath}} or the onTokenMove-events macro.args).  
Returns a JSON array with coordinates of all cells in the token's path that overlap with the area defined by the given points.


Where each coordinate pair returned is dependent on the grid type:
* Square:  Coordinates are the top-left corner.
* Hex:  Coordinates are the center point of the cell.
* Isometric:  Coordinates are the right-most point of the cell.
* Gridless: Returns just the top-left corner of the token's ending location.


{{code|movedOverPoints}} returns a json array with coordinates of all cells that have been a) in the defined shape and b) traversed by the token.
|usage=
<syntaxhighlight lang="mtmacro" line>
movedOverPoints(points)
movedOverPoints(points,path)
</syntaxhighlight>


'''Parameters'''
{{param|points|JSON array of X/Y coordinate X/Y pairs that defines a polygon}}
{{param|path|JSON array of X/Y coordinate such as that returned by {{func|getLastPath}}}}


|usage=
|example=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
<!-- lets define a shape -->
<!-- lets define a shape -->


Line 18: Line 32:
     json.set("", "x",  0, "y", 100),
     json.set("", "x",  0, "y", 100),
     json.set("", "x", 100, "y", 100),
     json.set("", "x", 100, "y", 100),
     json.set("", "x",  0, "y", 100)
     json.set("", "x",  100, "y", 0)
)]
)]
<!-- check if token in context has moved through that shape -->
<!-- check if token in context has moved through that shape -->
[r: movedOverPoints(jsonArray)]
[r: movedOverPoints(jsonArray)]
</source>
</syntaxhighlight>
 
'''With Second Parameter'''


<syntaxhighlight lang="mtmacro" line>
[h: jsonArray = json.append("",
    json.set("", "x", 250, "y", 250),
    json.set("", "x", 250, "y", 550),
    json.set("", "x", 550, "y", 550),
    json.set("", "x", 550, "y", 250)
)]
Last Path: [r: lastPath = getLastPath()]
<br>
Moved Over: [r: movedOverPoints(jsonArray,lastPath)]
</syntaxhighlight>


{{stub|lastPath-format specified, define/explain return value, examples}}
}}
}}
[[Category:Miscellaneous Function]]
[[Category:Miscellaneous Function]]

Latest revision as of 23:59, 14 March 2023

 This article is a stub, you can help the RPTools Wiki project by contributing content to expand this article.
 This article needs: lastPath-format specified, define/explain return value, examples

movedOverPoints() Function

Introduced in version 1.3.b75
Use to check if a token has moved through a shape that is defined by an array of pixel coordinates (formatted like the one received from getLastPath() or the onTokenMove event.

Returns a JSON array with coordinates of all cells in the token's path that overlap with the area defined by the given points.

Where each coordinate pair returned is dependent on the grid type:

  • Square: Coordinates are the top-left corner.
  • Hex: Coordinates are the center point of the cell.
  • Isometric: Coordinates are the right-most point of the cell.
  • Gridless: Returns just the top-left corner of the token's ending location.

Usage

movedOverPoints(points)
movedOverPoints(points,path)

Parameters

  • points - JSON array of X/Y coordinate X/Y pairs that defines a polygon
  • path - JSON array of X/Y coordinate such as that returned by getLastPath()

Example

<!-- lets define a shape -->

[h: jsonArray = json.append("",
    json.set("", "x",   0, "y",   0),
    json.set("", "x",   0, "y", 100),
    json.set("", "x", 100, "y", 100),
    json.set("", "x",   100, "y", 0)
)]

<!-- check if token in context has moved through that shape -->
[r: movedOverPoints(jsonArray)]

With Second Parameter

[h: jsonArray = json.append("",
    json.set("", "x", 250, "y", 250),
    json.set("", "x", 250, "y", 550),
    json.set("", "x", 550, "y", 550),
    json.set("", "x", 550, "y", 250)
)]

Last Path: [r: lastPath = getLastPath()]
<br>
Moved Over: [r: movedOverPoints(jsonArray,lastPath)]