-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmobject_base.lua
181 lines (163 loc) · 9.27 KB
/
gmobject_base.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
---@meta _
--- The `GMObjectBase` class provides shared methods to the [GMObject](https://saturnyoshi.gitlab.io/RoRML-Docs/class/gmObject.html) and [ParentObject](https://saturnyoshi.gitlab.io/RoRML-Docs/class/parentObject.html) classes.
---
--- **Note**: Methods which return an [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) may return any [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) child class depending on the calling object.
---
---@class GMObjectBase
local GMObjectBase = {}
--- Finds the `n`th [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) of the object. Instances are sorted by the order they were created.
---
--- # Example
--- Print the IDs of the first 5 instances of the `eggplant` object.
--- ```lua
--- for i = 1, 5 do
--- local instance = eggplant:find(i)
--- print(instance.ID)
--- end
--- ```
---
---@param n number The number of the instance to find
---@return Instance? '' The [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) if found, otherwise nil
function GMObjectBase:find(n) end
--- Finds all [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) of the object.
---
--- # Example
--- Destroy all instances of the object `eggplant`.
--- ```lua
--- for _, instance in ipairs(eggplant:findAll()) do
--- instance:destroy()
--- end
--- ```
---
---@return Instance[] '' A numerically indexed table containing all the found [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html)
function GMObjectBase:findAll() end
--- TODO
---
---@return number _ TODO correct type?
function GMObjectBase:count() end
--- Finds all [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) of the object with matching key and value variable pairs.
---
--- Example:
--- Heal all Lemurians where `boost` is nil by 50 health,
--- and then sets `boost` to 1 so they're only healed once.
--- ```lua
--- local lizard = Object.find("lizard", "vanilla")
--- for _, v in ipairs(lizard:findMatching("boost", nil) do
--- v:set("hp", v:get("hp") + 50)
--- v:set("boost", 1)
--- end
--- ```
---
---@param key string The name of the first variable to match
---@param value string|number|nil The value of the first variable to match
---@param ... string|number|nil Any number of additional key and value pairs may be specified
---@return Instance[] '' A numerically indexed table containing all the matching [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html)
function GMObjectBase:findMatching(key, value, ...) end
---@alias FindMatchingOperator
---| '=='
---| '~='
---| '<'
---| '>'
---| '<='
---| '>='
--- Finds all [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) of the object with matching key and value variable pairs.
---
--- # Example
--- Kill all Lemurians with less than 30 remaining health.
--- ```lua
--- local lizard = Object.find("lizard", "vanilla")
--- for _, v in ipairs(lizard:findMatchingOp("hp", "<", 30) do
--- v:kill()
--- end
--- ```
---
---@param key string The name of the first variable to compare against
---@param operator FindMatchingOperator The operator to compare with
---@param value string|number|nil The value of the first variable to compare against
---@param ... string|number|nil|FindMatchingOperator Any number of additional key, operator and value sets may be specified
---@return Instance[] '' A numerically indexed table containing all the matching [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html)
function GMObjectBase:findMatchingOp(key, operator, value, ...) end
--- Finds the [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) of the object closest to a point.
---
--- # Example
--- Find the instance of the object `eggplant` closest to the instance `player`.
--- ```lua
--- local target = eggplant:findNearest(player.x, player.y)
--- ```
---
---@param x number The horizontal coordinate of the point to check from
---@param y number The vertical coordinate of the point to check from
---@return Instance '' The [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) if found, otherwise nil
function GMObjectBase:findNearest(x, y) end
--- Finds the [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) of the object furthest from a point.
---
--- # Example
--- Find the instance of the object `eggplant` farthest from the instance `player`.
--- ```lua
--- local target = eggplant:findFurthest(player.x, player.y)
--- ```
---
---@param x number The horizontal coordinate of the point to check from
---@param y number The vertical coordinate of the point to check from
---@return Instance '' The [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) if found, otherwise nil
function GMObjectBase:findFurthest(x, y) end
--- Finds a single [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) inside of the specified rectangle.
---
---@param x1 number First x coordinates of the rectangle to check
---@param y1 number First y coordinates of the rectangle to check
---@param x2 number Second x coordinates of the rectangle to check
---@param y2 number Second y coordinates of the rectangle to check
---@return Instance '' The first [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) found within the rectangle
function GMObjectBase:findRectangle(x1, y1, x2, y2) end
--- Finds all [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) inside of the specified rectangle.
---
---@param x1 number First x coordinates of the rectangle to check
---@param y1 number First y coordinates of the rectangle to check
---@param x2 number Second x coordinates of the rectangle to check
---@param y2 number Second y coordinates of the rectangle to check
---@return Instance[] '' A numerically indexed table of [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) found within the rectangle
function GMObjectBase:findAllRectangle(x1, y1, x2, y2) end
--- Finds a single [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) inside of the specified ellipse.
---
---@param x1 number First x coordinates of the ellipse bounding box to check
---@param y1 number First y coordinates of the ellipse bounding box to check
---@param x2 number Second x coordinates of the ellipse bounding box to check
---@param y2 number Second y coordinates of the ellipse bounding box to check
---@return Instance '' The first [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) found within the ellipse
function GMObjectBase:findEllipse(x1, y1, x2, y2) end
--- Finds all [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) inside of the specified ellipse.
---
---@param x1 number First x coordinates of the ellipse bounding box to check
---@param y1 number First y coordinates of the ellipse bounding box to check
---@param x2 number Second x coordinates of the ellipse bounding box to check
---@param y2 number Second y coordinates of the ellipse bounding box to check
---@return Instance[] '' A numerically indexed table of [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) found within the ellipse
function GMObjectBase:findAllEllipse(x1, y1, x2, y2) end
--- Finds a single [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) colliding with the specified line.
---
---@param x1 number The x coordinate of the first end of the line
---@param y1 number The y coordinate of the first end of the line
---@param x2 number The x coordinate of the second end of the line
---@param y2 number The y coordinate of the second end of the line
---@return Instance '' The first [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) colliding with the line
function GMObjectBase:findLine(x1, y1, x2, y2) end
--- Finds all [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) colliding with the specified line.
---
---@param x1 number The x coordinate of the first end of the line
---@param y1 number The y coordinate of the first end of the line
---@param x2 number The x coordinate of the second end of the line
---@param y2 number The y coordinate of the second end of the line
---@return Instance[] '' A numerically indexed table of [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) colliding with the line
function GMObjectBase:findAllLine(x1, y1, x2, y2) end
--- Finds a single [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) colliding with the specified point.
---
---@param x number The x coordinate of the point to check
---@param y number The y coordinate of the point to check
---@return Instance '' The first [Instance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) colliding with the point
function GMObjectBase:findPoint(x, y) end
--- Finds all [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) colliding with the specified point.
---
---@param x number The x coordinate of the point to check
---@param y number The y coordinate of the point to check
---@return Instance[] '' A numerically indexed table of [Instances](https://saturnyoshi.gitlab.io/RoRML-Docs/class/instance.html) colliding with the point
function GMObjectBase:findAllPoint(x, y) end