@quenty/buttondragmodel 1.15.0 → 1.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.15.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttondragmodel@1.15.0...@quenty/buttondragmodel@1.15.1) (2025-04-05)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Add types to packages ([2374fb2](https://github.com/Quenty/NevermoreEngine/commit/2374fb2b043cfbe0e9b507b3316eec46a4e353a0))
12
+
13
+
14
+
15
+
16
+
6
17
  # [1.15.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttondragmodel@1.14.2...@quenty/buttondragmodel@1.15.0) (2025-04-02)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/buttondragmodel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/buttondragmodel",
3
- "version": "1.15.0",
3
+ "version": "1.15.1",
4
4
  "description": "Model for dragging buttons around",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,15 +25,15 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/baseobject": "^10.8.0",
29
- "@quenty/inputobjectutils": "^4.18.0",
30
- "@quenty/loader": "^10.8.0",
31
- "@quenty/maid": "^3.4.0",
32
- "@quenty/rx": "^13.17.0",
33
- "@quenty/valueobject": "^13.17.0"
28
+ "@quenty/baseobject": "^10.8.1",
29
+ "@quenty/inputobjectutils": "^4.18.1",
30
+ "@quenty/loader": "^10.8.1",
31
+ "@quenty/maid": "^3.4.1",
32
+ "@quenty/rx": "^13.17.1",
33
+ "@quenty/valueobject": "^13.17.1"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "e8ea56930e65322fcffc05a1556d5df988068f0b"
38
+ "gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
39
39
  }
@@ -12,6 +12,8 @@ local BaseObject = require("BaseObject")
12
12
  local Maid = require("Maid")
13
13
  local InputObjectUtils = require("InputObjectUtils")
14
14
  local ValueObject = require("ValueObject")
15
+ local _Observable = require("Observable")
16
+ local _Brio = require("Brio")
15
17
 
16
18
  local ButtonDragModel = setmetatable({}, BaseObject)
17
19
  ButtonDragModel.ClassName = "ButtonDragModel"
@@ -23,7 +25,7 @@ ButtonDragModel.__index = ButtonDragModel
23
25
  @param initialButton GuiButton? -- Optional
24
26
  @return ButtonDragModel
25
27
  ]=]
26
- function ButtonDragModel.new(initialButton)
28
+ function ButtonDragModel.new(initialButton: GuiButton?)
27
29
  local self = setmetatable(BaseObject.new(), ButtonDragModel)
28
30
 
29
31
  self._isMouseDown = self._maid:Add(ValueObject.new(false, "boolean"))
@@ -48,16 +50,18 @@ function ButtonDragModel.new(initialButton)
48
50
  self:SetButton(initialButton)
49
51
  end
50
52
 
51
- self._maid:GiveTask(self._button:ObserveBrio(function(button)
52
- return button ~= nil
53
- end):Subscribe(function(brio)
54
- if brio:IsDead() then
55
- return
56
- end
53
+ self._maid:GiveTask(self._button
54
+ :ObserveBrio(function(button)
55
+ return button ~= nil
56
+ end)
57
+ :Subscribe(function(brio)
58
+ if brio:IsDead() then
59
+ return
60
+ end
57
61
 
58
- local maid, button = brio:ToMaidAndValue()
59
- self:_setupDragging(maid, button)
60
- end))
62
+ local maid, button = brio:ToMaidAndValue()
63
+ self:_setupDragging(maid, button)
64
+ end))
61
65
 
62
66
  return self
63
67
  end
@@ -67,7 +71,7 @@ end
67
71
 
68
72
  @return boolean
69
73
  ]=]
70
- function ButtonDragModel:IsPressed()
74
+ function ButtonDragModel:IsPressed(): boolean
71
75
  return self._isPressed.Value
72
76
  end
73
77
 
@@ -76,30 +80,30 @@ end
76
80
 
77
81
  @return Observable<boolean>
78
82
  ]=]
79
- function ButtonDragModel:ObserveIsPressed()
83
+ function ButtonDragModel:ObserveIsPressed(): _Observable.Observable<boolean>
80
84
  return self._isPressed:Observe()
81
85
  end
82
86
 
83
87
  --[=[
84
88
  @return Observable<Brio<true>>
85
89
  ]=]
86
- function ButtonDragModel:ObserveIsPressedBrio()
90
+ function ButtonDragModel:ObserveIsPressedBrio(): _Observable.Observable<_Brio.Brio<boolean>>
87
91
  return self._isPressed:ObserveBrio(function(value)
88
92
  return value
89
93
  end)
90
94
  end
91
95
 
92
96
  --[=[
93
- @return Observable<Vector2 | nil>
97
+ @return Observable<Vector2?>
94
98
  ]=]
95
- function ButtonDragModel:ObserveDragDelta()
99
+ function ButtonDragModel:ObserveDragDelta(): _Observable.Observable<Vector2?>
96
100
  return self._dragDelta:Observe()
97
101
  end
98
102
 
99
103
  --[=[
100
- @return Vector2 | nil
104
+ @return Vector2?
101
105
  ]=]
102
- function ButtonDragModel:GetDragDelta()
106
+ function ButtonDragModel:GetDragDelta(): Vector2?
103
107
  return self._dragDelta.Value
104
108
  end
105
109
 
@@ -108,9 +112,9 @@ end
108
112
 
109
113
  This is reletive to the GUI, so top left is 0, 0
110
114
 
111
- @return Vector2 | nil
115
+ @return Vector2?
112
116
  ]=]
113
- function ButtonDragModel:GetDragPosition()
117
+ function ButtonDragModel:GetDragPosition(): Vector2?
114
118
  return self._dragPosition.Value
115
119
  end
116
120
 
@@ -119,9 +123,9 @@ end
119
123
 
120
124
  This is reletive to the GUI, so top left is 0, 0
121
125
 
122
- @return Observable<Vector2 | nil>
126
+ @return Observable<Vector2?>
123
127
  ]=]
124
- function ButtonDragModel:ObserveDragPosition()
128
+ function ButtonDragModel:ObserveDragPosition(): _Observable.Observable<Vector2?>
125
129
  return self._dragPosition:Observe()
126
130
  end
127
131
 
@@ -129,7 +133,7 @@ end
129
133
  Sets whether to clamp the results within the button bounds
130
134
  @param clampWithinButton boolean
131
135
  ]=]
132
- function ButtonDragModel:SetClampWithinButton(clampWithinButton)
136
+ function ButtonDragModel:SetClampWithinButton(clampWithinButton: boolean)
133
137
  self._clampWithinButton.Value = clampWithinButton
134
138
  end
135
139
 
@@ -139,7 +143,7 @@ end
139
143
  @param button GuiButton
140
144
  @return () -> () -- Cleanup function
141
145
  ]=]
142
- function ButtonDragModel:SetButton(button)
146
+ function ButtonDragModel:SetButton(button: GuiButton): () -> ()
143
147
  assert(typeof(button) == "Instance" or button == nil, "Bad button")
144
148
 
145
149
  self._button.Value = button
@@ -151,7 +155,7 @@ function ButtonDragModel:SetButton(button)
151
155
  end
152
156
  end
153
157
 
154
- function ButtonDragModel:_setupDragging(maid, button)
158
+ function ButtonDragModel:_setupDragging(maid: Maid.Maid, button: GuiButton)
155
159
  maid:GiveTask(self._clampWithinButton.Changed:Connect(function()
156
160
  self:_updateCurrentPosition()
157
161
  end))
@@ -200,12 +204,12 @@ function ButtonDragModel:_setupDragging(maid, button)
200
204
  end))
201
205
  end
202
206
 
203
- function ButtonDragModel:_updateMouseTracking(button)
207
+ function ButtonDragModel:_updateMouseTracking(button: GuiButton)
204
208
  local maid = Maid.new()
205
209
 
206
- local lastMousePosition = nil
210
+ local lastMousePosition: Vector3? = nil
207
211
 
208
- local function setMousePosition(inputObject)
212
+ local function setMousePosition(inputObject: InputObject)
209
213
  local previous = lastMousePosition
210
214
  local current = inputObject.Position
211
215
 
@@ -256,7 +260,7 @@ function ButtonDragModel:_updateMouseTracking(button)
256
260
  return maid
257
261
  end
258
262
 
259
- function ButtonDragModel:_trackTouch(buttonMaid, button, inputObject)
263
+ function ButtonDragModel:_trackTouch(buttonMaid: Maid.Maid, button: GuiButton, inputObject: InputObject)
260
264
  buttonMaid[inputObject] = nil
261
265
 
262
266
  if inputObject.UserInputState == Enum.UserInputState.End then
@@ -292,22 +296,22 @@ function ButtonDragModel:_trackTouch(buttonMaid, button, inputObject)
292
296
  maid[inputObject] = maid
293
297
  end
294
298
 
295
- function ButtonDragModel:_stopTouchTrack(buttonMaid, inputObject)
299
+ function ButtonDragModel:_stopTouchTrack(buttonMaid: Maid.Maid, inputObject: InputObject)
296
300
  -- Clears the input tracking as we slide off the button
297
301
  buttonMaid[inputObject] = nil
298
302
  end
299
303
 
300
- function ButtonDragModel:_toButtonSpace(button, position)
304
+ function ButtonDragModel:_toButtonSpace(button: GuiButton, position: Vector2): Vector2
301
305
  local pos = button.AbsolutePosition
302
306
  local size = button.AbsoluteSize
303
307
 
304
- return (Vector2.new(position.x, position.y) - pos)/size
308
+ return (Vector2.new(position.X, position.Y) - pos) / size
305
309
  end
306
310
 
307
311
  function ButtonDragModel:_updateCurrentPosition()
308
312
  local current = Vector2.zero
309
313
  local count = 0
310
- for _, item in pairs(self._activePositions) do
314
+ for _, item in self._activePositions do
311
315
  current = current + item
312
316
  count = count + 1
313
317
  end
@@ -317,9 +321,9 @@ function ButtonDragModel:_updateCurrentPosition()
317
321
  return
318
322
  end
319
323
 
320
- current = current/count
321
- local x = current.x
322
- local y = current.y
324
+ current = current / count
325
+ local x = current.X
326
+ local y = current.Y
323
327
 
324
328
  if self._clampWithinButton.Value then
325
329
  x = math.clamp(x, 0, 1)
@@ -334,9 +338,9 @@ function ButtonDragModel:_updateCurrentPosition()
334
338
  end
335
339
  end
336
340
 
337
- function ButtonDragModel:_incrementDragDelta(delta)
338
- local current = self._dragDelta.Value or Vector2.zero
339
- self._dragDelta.Value = current + Vector2.new(delta.x, delta.y)
341
+ function ButtonDragModel:_incrementDragDelta(delta: Vector3)
342
+ local current: Vector2 = self._dragDelta.Value or Vector2.zero
343
+ self._dragDelta.Value = current + Vector2.new(delta.X, delta.Y)
340
344
  end
341
345
 
342
346
  return ButtonDragModel