@quenty/cooldown 11.20.3 → 11.20.4-canary.11a5dcf.0

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,22 @@
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
+ ## [11.20.4-canary.11a5dcf.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/cooldown@11.20.3...@quenty/cooldown@11.20.4-canary.11a5dcf.0) (2025-05-10)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Additional type checking updates ([05ba29a](https://github.com/Quenty/NevermoreEngine/commit/05ba29a03efc9f3feed74b34f1d9dfb237496214))
12
+
13
+
14
+ ### Features
15
+
16
+ * Add even more types ([b31717d](https://github.com/Quenty/NevermoreEngine/commit/b31717d8c9f7620c457f5018a2affa760a65334a))
17
+
18
+
19
+
20
+
21
+
6
22
  ## [11.20.3](https://github.com/Quenty/NevermoreEngine/compare/@quenty/cooldown@11.20.2...@quenty/cooldown@11.20.3) (2025-04-10)
7
23
 
8
24
  **Note:** Version bump only for package @quenty/cooldown
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/cooldown",
3
- "version": "11.20.3",
3
+ "version": "11.20.4-canary.11a5dcf.0",
4
4
  "description": "Generalized networked cooldown system for Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,26 +25,26 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/attributeutils": "^14.17.3",
29
- "@quenty/baseobject": "^10.8.3",
30
- "@quenty/binder": "^14.19.3",
31
- "@quenty/ducktype": "^5.8.4",
32
- "@quenty/instanceutils": "^13.17.3",
33
- "@quenty/loader": "^10.8.3",
34
- "@quenty/maid": "^3.4.3",
35
- "@quenty/promise": "^10.10.4",
36
- "@quenty/propertyvalue": "^7.17.3",
37
- "@quenty/remoting": "^12.18.3",
38
- "@quenty/rx": "^13.17.3",
39
- "@quenty/rxbinderutils": "^14.19.3",
40
- "@quenty/servicebag": "^11.11.4",
41
- "@quenty/signal": "^7.10.3",
42
- "@quenty/table": "^3.7.4",
43
- "@quenty/timesyncservice": "^13.18.3",
44
- "@quenty/valueobject": "^13.17.3"
28
+ "@quenty/attributeutils": "14.17.4-canary.11a5dcf.0",
29
+ "@quenty/baseobject": "10.8.4-canary.11a5dcf.0",
30
+ "@quenty/binder": "14.19.4-canary.11a5dcf.0",
31
+ "@quenty/ducktype": "5.8.5-canary.11a5dcf.0",
32
+ "@quenty/instanceutils": "13.17.4-canary.11a5dcf.0",
33
+ "@quenty/loader": "10.8.4-canary.11a5dcf.0",
34
+ "@quenty/maid": "3.4.4-canary.11a5dcf.0",
35
+ "@quenty/promise": "10.10.5-canary.11a5dcf.0",
36
+ "@quenty/propertyvalue": "7.17.4-canary.11a5dcf.0",
37
+ "@quenty/remoting": "12.18.4-canary.11a5dcf.0",
38
+ "@quenty/rx": "13.17.4-canary.11a5dcf.0",
39
+ "@quenty/rxbinderutils": "14.19.4-canary.11a5dcf.0",
40
+ "@quenty/servicebag": "11.11.5-canary.11a5dcf.0",
41
+ "@quenty/signal": "7.10.4-canary.11a5dcf.0",
42
+ "@quenty/table": "3.7.5-canary.11a5dcf.0",
43
+ "@quenty/timesyncservice": "13.18.4-canary.11a5dcf.0",
44
+ "@quenty/valueobject": "13.17.4-canary.11a5dcf.0"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public"
48
48
  },
49
- "gitHead": "b06c070ae91d5dab7bd8de6e290ad2caabb15d8f"
49
+ "gitHead": "11a5dcf7d4c7a0bfbf3337e97d30e8346ea09d3f"
50
50
  }
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  Handles cooldown on the client. See [CooldownBase] for details.
3
4
 
@@ -7,13 +8,21 @@
7
8
 
8
9
  local require = require(script.Parent.loader).load(script)
9
10
 
10
- local CooldownBase = require("CooldownBase")
11
11
  local Binder = require("Binder")
12
+ local CooldownBase = require("CooldownBase")
13
+ local ServiceBag = require("ServiceBag")
12
14
 
13
15
  local CooldownClient = setmetatable({}, CooldownBase)
14
16
  CooldownClient.ClassName = "CooldownClient"
15
17
  CooldownClient.__index = CooldownClient
16
18
 
19
+ export type CooldownClient = typeof(setmetatable(
20
+ {} :: {
21
+ _serviceBag: ServiceBag.ServiceBag,
22
+ },
23
+ {} :: typeof({ __index = CooldownClient })
24
+ )) & CooldownBase.CooldownBase
25
+
17
26
  --[=[
18
27
  Constructs a new cooldown. Should be done via [CooldownBindersClient]. To create an
19
28
  instance of this in Roblox, see [CooldownUtils.create].
@@ -22,14 +31,14 @@ CooldownClient.__index = CooldownClient
22
31
  @param serviceBag ServiceBag
23
32
  @return Cooldown
24
33
  ]=]
25
- function CooldownClient.new(numberValue, serviceBag)
26
- local self = setmetatable(CooldownBase.new(numberValue, serviceBag), CooldownClient)
34
+ function CooldownClient.new(numberValue: NumberValue, serviceBag: ServiceBag.ServiceBag): CooldownClient
35
+ local self: CooldownClient = setmetatable(CooldownBase.new(numberValue, serviceBag) :: any, CooldownClient)
27
36
 
28
37
  self._maid:GiveTask(self.Done:Connect(function()
29
- self._obj:Remove()
38
+ (self._obj :: any):Remove()
30
39
  end))
31
40
 
32
41
  return self
33
42
  end
34
43
 
35
- return Binder.new("Cooldown", CooldownClient)
44
+ return Binder.new("Cooldown", CooldownClient :: any) :: Binder.Binder<CooldownClient>
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  @class CooldownServiceClient
3
4
  ]=]
@@ -6,9 +7,9 @@ local require = require(script.Parent.loader).load(script)
6
7
 
7
8
  local CooldownServiceClient = {}
8
9
  CooldownServiceClient.ServiceName = "CooldownServiceClient"
9
- local _ServiceBag = require("ServiceBag")
10
+ local ServiceBag = require("ServiceBag")
10
11
 
11
- function CooldownServiceClient:Init(serviceBag: _ServiceBag.ServiceBag)
12
+ function CooldownServiceClient:Init(serviceBag: ServiceBag.ServiceBag)
12
13
  assert(not self._serviceBag, "Already initialized")
13
14
  self._serviceBag = assert(serviceBag, "No serviceBag")
14
15
 
@@ -20,4 +21,4 @@ function CooldownServiceClient:Init(serviceBag: _ServiceBag.ServiceBag)
20
21
  self._serviceBag:GetService(require("CooldownShared"))
21
22
  end
22
23
 
23
- return CooldownServiceClient
24
+ return CooldownServiceClient
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  Represents a cooldown state with a time limit. See [CooldownBase] for more API.
3
4
 
@@ -7,17 +8,28 @@
7
8
 
8
9
  local require = require(script.Parent.loader).load(script)
9
10
 
10
- local CooldownBase = require("CooldownBase")
11
- local TimeSyncService = require("TimeSyncService")
12
- local CooldownConstants = require("CooldownConstants")
13
11
  local AttributeValue = require("AttributeValue")
14
12
  local Binder = require("Binder")
13
+ local CooldownBase = require("CooldownBase")
14
+ local CooldownConstants = require("CooldownConstants")
15
15
  local PropertyValue = require("PropertyValue")
16
+ local ServiceBag = require("ServiceBag")
17
+ local TimeSyncService = require("TimeSyncService")
16
18
 
17
19
  local Cooldown = setmetatable({}, CooldownBase)
18
20
  Cooldown.ClassName = "Cooldown"
19
21
  Cooldown.__index = Cooldown
20
22
 
23
+ export type Cooldown = typeof(setmetatable(
24
+ {} :: {
25
+ _serviceBag: ServiceBag.ServiceBag,
26
+ _syncedClock: TimeSyncService.SyncedClock,
27
+ _finishTime: PropertyValue.PropertyValue<number>,
28
+ _startTime: AttributeValue.AttributeValue<number>,
29
+ },
30
+ {} :: typeof({ __index = Cooldown })
31
+ )) & CooldownBase.CooldownBase
32
+
21
33
  --[=[
22
34
  Constructs a new cooldown. Should be done via [Binder].
23
35
 
@@ -25,20 +37,22 @@ Cooldown.__index = Cooldown
25
37
  @param serviceBag ServiceBag
26
38
  @return Cooldown
27
39
  ]=]
28
- function Cooldown.new(numberValue, serviceBag)
29
- local self = setmetatable(CooldownBase.new(numberValue, serviceBag), Cooldown)
40
+ function Cooldown.new(numberValue: NumberValue, serviceBag: ServiceBag.ServiceBag): Cooldown
41
+ local self: Cooldown = setmetatable(CooldownBase.new(numberValue, serviceBag) :: any, Cooldown)
30
42
 
31
43
  self._serviceBag = assert(serviceBag, "No serviceBag")
32
- self._syncedClock = self._serviceBag:GetService(TimeSyncService):GetSyncedClock()
44
+ self._timeSyncService = self._serviceBag:GetService(TimeSyncService) :: any
45
+ self._syncedClock = assert(self._timeSyncService:GetSyncedClock(), "No synced clock")
33
46
 
34
47
  self._finishTime = PropertyValue.new(self._obj, "Value")
35
- self._startTime = AttributeValue.new(self._obj, CooldownConstants.COOLDOWN_START_TIME_ATTRIBUTE, self._syncedClock:GetTime())
48
+ self._startTime =
49
+ AttributeValue.new(self._obj, CooldownConstants.COOLDOWN_START_TIME_ATTRIBUTE, self._syncedClock:GetTime())
36
50
 
37
51
  self._maid:GiveTask(self.Done:Connect(function()
38
- self._obj:Remove()
52
+ (self._obj :: any):Remove()
39
53
  end))
40
54
 
41
55
  return self
42
56
  end
43
57
 
44
- return Binder.new("Cooldown", Cooldown)
58
+ return Binder.new("Cooldown", Cooldown :: any) :: Binder.Binder<Cooldown>
@@ -1,15 +1,16 @@
1
+ --!strict
1
2
  --[=[
2
3
  @class CooldownService
3
4
  ]=]
4
5
 
5
6
  local require = require(script.Parent.loader).load(script)
6
7
 
7
- local _ServiceBag = require("ServiceBag")
8
+ local ServiceBag = require("ServiceBag")
8
9
 
9
10
  local CooldownService = {}
10
11
  CooldownService.ServiceName = "CooldownService"
11
12
 
12
- function CooldownService:Init(serviceBag: _ServiceBag.ServiceBag)
13
+ function CooldownService:Init(serviceBag: ServiceBag.ServiceBag)
13
14
  assert(not self._serviceBag, "Already initialized")
14
15
  self._serviceBag = assert(serviceBag, "No serviceBag")
15
16
 
@@ -21,4 +22,4 @@ function CooldownService:Init(serviceBag: _ServiceBag.ServiceBag)
21
22
  self._serviceBag:GetService(require("CooldownShared"))
22
23
  end
23
24
 
24
- return CooldownService
25
+ return CooldownService
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  Base object for a cooldown. Provides calculation utilties.
3
4
  @class CooldownBase
@@ -6,16 +7,30 @@
6
7
  local require = require(script.Parent.loader).load(script)
7
8
 
8
9
  local BaseObject = require("BaseObject")
9
- local TimeSyncService = require("TimeSyncService")
10
10
  local CooldownConstants = require("CooldownConstants")
11
11
  local CooldownModel = require("CooldownModel")
12
12
  local RxAttributeUtils = require("RxAttributeUtils")
13
13
  local RxInstanceUtils = require("RxInstanceUtils")
14
+ local ServiceBag = require("ServiceBag")
15
+ local Signal = require("Signal")
16
+ local TimeSyncService = require("TimeSyncService")
14
17
 
15
18
  local CooldownBase = setmetatable({}, BaseObject)
16
19
  CooldownBase.ClassName = "CooldownBase"
17
20
  CooldownBase.__index = CooldownBase
18
21
 
22
+ export type CooldownBase = typeof(setmetatable(
23
+ {} :: {
24
+ _obj: NumberValue,
25
+ _serviceBag: ServiceBag.ServiceBag,
26
+ _cooldownModel: CooldownModel.CooldownModel,
27
+ _timeSyncService: TimeSyncService.TimeSyncService,
28
+ _syncedClock: TimeSyncService.SyncedClock,
29
+ Done: Signal.Signal<()>,
30
+ },
31
+ {} :: typeof({ __index = CooldownBase })
32
+ )) & BaseObject.BaseObject
33
+
19
34
  --[=[
20
35
  Constructs a new Cooldown.
21
36
 
@@ -23,27 +38,32 @@ CooldownBase.__index = CooldownBase
23
38
  @param serviceBag ServiceBag
24
39
  @return CooldownBase
25
40
  ]=]
26
- function CooldownBase.new(numberValue, serviceBag)
27
- local self = setmetatable(BaseObject.new(numberValue), CooldownBase)
41
+ function CooldownBase.new(numberValue: NumberValue, serviceBag: ServiceBag.ServiceBag): CooldownBase
42
+ local self: CooldownBase = setmetatable(BaseObject.new(numberValue) :: any, CooldownBase)
28
43
 
29
44
  self._serviceBag = assert(serviceBag, "No serviceBag")
30
- self._timeSyncService = self._serviceBag:GetService(TimeSyncService)
45
+ self._timeSyncService = self._serviceBag:GetService(TimeSyncService) :: any
31
46
 
32
47
  self._cooldownModel = self._maid:Add(CooldownModel.new())
33
- self._maid:GivePromise(self._timeSyncService:PromiseSyncedClock())
34
- :Then(function(syncedClock)
35
- self._syncedClock = syncedClock
36
-
37
- -- Setup
38
- self._cooldownModel:SetStartTime(RxAttributeUtils.observeAttribute(self._obj, CooldownConstants.COOLDOWN_START_TIME_ATTRIBUTE, syncedClock:GetTime()))
39
- self._cooldownModel:SetLength(RxInstanceUtils.observeProperty(self._obj, "Value"))
40
-
41
- self._cooldownModel:SetClock(function()
42
- return self._syncedClock:GetTime()
43
- end)
48
+ self._maid:GivePromise(self._timeSyncService:PromiseSyncedClock()):Then(function(syncedClock)
49
+ self._syncedClock = syncedClock
50
+
51
+ -- Setup
52
+ self._cooldownModel:SetStartTime(
53
+ RxAttributeUtils.observeAttribute(
54
+ self._obj,
55
+ CooldownConstants.COOLDOWN_START_TIME_ATTRIBUTE,
56
+ syncedClock:GetTime()
57
+ )
58
+ )
59
+ self._cooldownModel:SetLength(RxInstanceUtils.observeProperty(self._obj, "Value"))
60
+
61
+ self._cooldownModel:SetClock(function()
62
+ return self._syncedClock:GetTime()
44
63
  end)
64
+ end)
45
65
 
46
- --[=[
66
+ --[=[
47
67
  Event that fires when the cooldown is done.
48
68
  @prop Done Signal<()>
49
69
  @within CooldownBase
@@ -53,7 +73,7 @@ function CooldownBase.new(numberValue, serviceBag)
53
73
  return self
54
74
  end
55
75
 
56
- function CooldownBase:GetCooldownModel()
76
+ function CooldownBase.GetCooldownModel(self: CooldownBase): CooldownModel.CooldownModel
57
77
  return self._cooldownModel
58
78
  end
59
79
 
@@ -61,7 +81,7 @@ end
61
81
  Gets the Roblox instance of the cooldown.
62
82
  @return Instance
63
83
  ]=]
64
- function CooldownBase:GetObject()
84
+ function CooldownBase.GetObject(self: CooldownBase): NumberValue
65
85
  return self._obj
66
86
  end
67
87
 
@@ -69,7 +89,7 @@ end
69
89
  Gets the time passed
70
90
  @return number?
71
91
  ]=]
72
- function CooldownBase:GetTimePassed()
92
+ function CooldownBase.GetTimePassed(self: CooldownBase): number?
73
93
  return self._cooldownModel:GetTimePassed()
74
94
  end
75
95
 
@@ -77,7 +97,7 @@ end
77
97
  Gets the time remaining
78
98
  @return number?
79
99
  ]=]
80
- function CooldownBase:GetTimeRemaining()
100
+ function CooldownBase.GetTimeRemaining(self: CooldownBase): number?
81
101
  return self._cooldownModel:GetTimeRemaining()
82
102
  end
83
103
 
@@ -85,7 +105,7 @@ end
85
105
  Gets the syncronized time stamp the cooldown is ending at
86
106
  @return number?
87
107
  ]=]
88
- function CooldownBase:GetEndTime()
108
+ function CooldownBase.GetEndTime(self: CooldownBase): number?
89
109
  return self._cooldownModel:GetEndTime()
90
110
  end
91
111
 
@@ -93,7 +113,7 @@ end
93
113
  Gets the syncronized time stamp the cooldown is starting at
94
114
  @return number?
95
115
  ]=]
96
- function CooldownBase:GetStartTime()
116
+ function CooldownBase.GetStartTime(self: CooldownBase): number?
97
117
  return self._cooldownModel:GetStartTime()
98
118
  end
99
119
 
@@ -101,8 +121,8 @@ end
101
121
  Gets the length of the cooldown
102
122
  @return number
103
123
  ]=]
104
- function CooldownBase:GetLength()
124
+ function CooldownBase.GetLength(self: CooldownBase): number
105
125
  return self._cooldownModel:GetLength()
106
126
  end
107
127
 
108
- return CooldownBase
128
+ return CooldownBase
@@ -1,17 +1,26 @@
1
+ --!strict
1
2
  --[=[
2
3
  @class CooldownShared
3
4
  ]=]
4
5
 
5
6
  local require = require(script.Parent.loader).load(script)
6
7
 
7
- local CooldownBase = require("CooldownBase")
8
8
  local Binder = require("Binder")
9
+ local CooldownBase = require("CooldownBase")
10
+ local ServiceBag = require("ServiceBag")
9
11
 
10
12
  local CooldownShared = setmetatable({}, CooldownBase)
11
13
  CooldownShared.ClassName = "CooldownShared"
12
14
  CooldownShared.__index = CooldownShared
13
15
 
14
- function CooldownShared.new(numberValue, serviceBag)
16
+ export type CooldownShared = typeof(setmetatable(
17
+ {} :: {
18
+ _serviceBag: ServiceBag.ServiceBag,
19
+ },
20
+ {} :: typeof({ __index = CooldownShared })
21
+ )) & CooldownBase.CooldownBase
22
+
23
+ function CooldownShared.new(numberValue: NumberValue, serviceBag: ServiceBag.ServiceBag)
15
24
  local self = setmetatable(CooldownBase.new(numberValue, serviceBag), CooldownShared)
16
25
 
17
26
  self._serviceBag = assert(serviceBag, "No serviceBag")
@@ -19,4 +28,4 @@ function CooldownShared.new(numberValue, serviceBag)
19
28
  return self
20
29
  end
21
30
 
22
- return Binder.new("Cooldown", CooldownShared)
31
+ return Binder.new("Cooldown", CooldownShared :: any) :: Binder.Binder<CooldownShared>
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  Holds constants for the cooldown.
3
4
  @class CooldownConstants
@@ -8,6 +9,6 @@ local require = require(script.Parent.loader).load(script)
8
9
  local Table = require("Table")
9
10
 
10
11
  return Table.readonly({
11
- COOLDOWN_TIME_NAME = "CooldownTime";
12
- COOLDOWN_START_TIME_ATTRIBUTE = "CooldownStartTime";
13
- })
12
+ COOLDOWN_TIME_NAME = "CooldownTime",
13
+ COOLDOWN_START_TIME_ATTRIBUTE = "CooldownStartTime",
14
+ })
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  Helper methods for cooldown. See [RxCooldownUtils] for [Rx] utilities.
3
4
  @class CooldownUtils
@@ -17,7 +18,7 @@ local CooldownUtils = {}
17
18
  @param length number
18
19
  @return Instance
19
20
  ]=]
20
- function CooldownUtils.create(parent, length)
21
+ function CooldownUtils.create(parent: Instance, length: number): NumberValue
21
22
  assert(typeof(parent) == "Instance", "Bad parent")
22
23
  assert(type(length) == "number", "Bad length")
23
24
  assert(length > 0, "Bad length")
@@ -39,20 +40,19 @@ end
39
40
  @param parent Instance
40
41
  @return Cooldown? | CooldownClient?
41
42
  ]=]
42
- function CooldownUtils.findCooldown(cooldownBinder, parent)
43
+ function CooldownUtils.findCooldown(cooldownBinder, parent: Instance)
43
44
  assert(cooldownBinder, "Bad cooldownBinder")
44
45
  assert(typeof(parent) == "Instance", "Bad parent")
45
46
 
46
47
  return BinderUtils.findFirstChild(cooldownBinder, parent)
47
48
  end
48
49
 
49
-
50
50
  --[=[
51
51
  Makes a copy of the cooldown
52
52
  @param cooldown Instance
53
53
  @return Instance
54
54
  ]=]
55
- function CooldownUtils.clone(cooldown)
55
+ function CooldownUtils.clone(cooldown: NumberValue): NumberValue
56
56
  assert(typeof(cooldown) == "Instance", "Bad cooldown")
57
57
 
58
58
  local copy = cooldown:Clone()
@@ -60,4 +60,4 @@ function CooldownUtils.clone(cooldown)
60
60
  return copy
61
61
  end
62
62
 
63
- return CooldownUtils
63
+ return CooldownUtils
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  @class CooldownModel
3
4
  ]=]
@@ -5,17 +6,36 @@
5
6
  local require = require(script.Parent.loader).load(script)
6
7
 
7
8
  local BaseObject = require("BaseObject")
8
- local ValueObject = require("ValueObject")
9
- local Signal = require("Signal")
10
- local Rx = require("Rx")
11
9
  local DuckTypeUtils = require("DuckTypeUtils")
10
+ local Rx = require("Rx")
11
+ local Signal = require("Signal")
12
+ local ValueObject = require("ValueObject")
12
13
 
13
14
  local CooldownModel = setmetatable({}, BaseObject)
14
15
  CooldownModel.ClassName = "CooldownModel"
15
16
  CooldownModel.__index = CooldownModel
16
17
 
17
- function CooldownModel.new()
18
- local self = setmetatable(BaseObject.new(), CooldownModel)
18
+ export type Clock = () -> number
19
+
20
+ export type CooldownModel = typeof(setmetatable(
21
+ {} :: {
22
+ _length: ValueObject.ValueObject<number>,
23
+ _startTime: ValueObject.ValueObject<number>,
24
+ _clock: ValueObject.ValueObject<Clock>,
25
+ _doneFired: boolean,
26
+ Done: Signal.Signal<()>,
27
+ _cleanup: any,
28
+ },
29
+ {} :: typeof({ __index = CooldownModel })
30
+ )) & BaseObject.BaseObject
31
+
32
+ --[=[
33
+ Creates a new cooldown model
34
+
35
+ @return CooldownModel
36
+ ]=]
37
+ function CooldownModel.new(): CooldownModel
38
+ local self: CooldownModel = setmetatable(BaseObject.new() :: any, CooldownModel)
19
39
 
20
40
  self._length = self._maid:Add(ValueObject.new(0, "number"))
21
41
  self._startTime = self._maid:Add(ValueObject.new(os.clock(), "number"))
@@ -36,10 +56,10 @@ function CooldownModel.new()
36
56
  end
37
57
 
38
58
  self._maid:GiveTask(Rx.combineLatestDefer({
39
- length = self._length:Observe();
40
- clock = self._clock:Observe();
41
- startTime = self._startTime:Observe();
42
- }):Subscribe(function(state)
59
+ length = self._length:Observe(),
60
+ clock = self._clock:Observe(),
61
+ startTime = self._startTime:Observe(),
62
+ }):Subscribe(function(state: any)
43
63
  local now = state.clock()
44
64
  local waitTime = state.length + state.startTime - now
45
65
 
@@ -56,39 +76,56 @@ function CooldownModel.new()
56
76
  return self
57
77
  end
58
78
 
59
- function CooldownModel.isCooldownModel(value)
79
+ --[=[
80
+ Returns true if the value is a CooldownModel
81
+ @param value any
82
+ @return boolean
83
+ ]=]
84
+ function CooldownModel.isCooldownModel(value: any): boolean
60
85
  return DuckTypeUtils.isImplementation(CooldownModel, value)
61
86
  end
62
87
 
63
- function CooldownModel:SetClock(clock)
88
+ --[=[
89
+ Sets the clock to use for the cooldown
90
+ @param clock Clock
91
+ ]=]
92
+ function CooldownModel.SetClock(self: CooldownModel, clock: ValueObject.Mountable<Clock>): () -> ()
64
93
  if self._doneFired then
65
94
  warn("[CooldownModel] - Done already fired")
66
95
  end
67
96
 
68
- self._clock:Mount(clock)
97
+ return self._clock:Mount(clock)
69
98
  end
70
99
 
71
- function CooldownModel:SetStartTime(startTime)
100
+ --[=[
101
+ Sets the start time for the cooldown
102
+ @param startTime number
103
+ ]=]
104
+ function CooldownModel.SetStartTime(self: CooldownModel, startTime: ValueObject.Mountable<number>): () -> ()
72
105
  if self._doneFired then
73
106
  warn("[CooldownModel] - Done already fired")
74
107
  end
75
108
 
76
- self._startTime:Mount(startTime)
109
+ return self._startTime:Mount(startTime)
77
110
  end
78
111
 
79
- function CooldownModel:SetLength(length)
112
+ --[=[
113
+ Sets the length of the cooldown
114
+ @param length number
115
+ ]=]
116
+ function CooldownModel.SetLength(self: CooldownModel, length: ValueObject.Mountable<number>): () -> ()
80
117
  if self._doneFired then
81
118
  warn("[CooldownModel] - Done already fired")
82
119
  end
83
120
 
84
- self._length:Mount(length)
121
+ return self._length:Mount(length)
85
122
  end
86
123
 
87
124
  --[=[
88
125
  Gets the syncronized time stamp the cooldown is starting at
89
126
  @return number
90
127
  ]=]
91
- function CooldownModel:GetStartTime()
128
+ function CooldownModel.GetStartTime(self: CooldownModel): number
92
129
  return self._startTime.Value
93
130
  end
94
131
 
@@ -96,13 +133,17 @@ end
96
133
  Gets the time remaining
97
134
  @return number
98
135
  ]=]
99
- function CooldownModel:GetTimeRemaining()
136
+ function CooldownModel.GetTimeRemaining(self: CooldownModel): number
100
137
  local endTime = self:GetEndTime()
101
138
 
102
139
  return math.max(0, endTime - self._clock.Value())
103
140
  end
104
141
 
105
- function CooldownModel:GetTimePassed()
142
+ --[=[
143
+ Gets the time passed
144
+ @return number
145
+ ]=]
146
+ function CooldownModel.GetTimePassed(self: CooldownModel): number
106
147
  local startTime = self._startTime.Value
107
148
  return self._clock.Value() - startTime
108
149
  end
@@ -111,13 +152,16 @@ end
111
152
  Gets the syncronized time stamp the cooldown is ending at
112
153
  @return number?
113
154
  ]=]
114
- function CooldownModel:GetEndTime()
155
+ function CooldownModel.GetEndTime(self: CooldownModel)
115
156
  return self._startTime.Value + self:GetLength()
116
157
  end
117
158
 
118
- function CooldownModel:GetLength()
159
+ --[=[
160
+ Gets the length of the cooldown
161
+ @return number
162
+ ]=]
163
+ function CooldownModel.GetLength(self: CooldownModel): number
119
164
  return self._length.Value
120
165
  end
121
166
 
122
-
123
- return CooldownModel
167
+ return CooldownModel
@@ -1,36 +1,58 @@
1
+ --!strict
1
2
  --[=[
3
+ Helps track the active cooldown that is running.
4
+
2
5
  @class CooldownTrackerModel
3
6
  ]=]
4
7
 
5
8
  local require = require(script.Parent.loader).load(script)
6
9
 
7
10
  local BaseObject = require("BaseObject")
8
- local ValueObject = require("ValueObject")
11
+ local Brio = require("Brio")
12
+ local CooldownModel = require("CooldownModel")
9
13
  local DuckTypeUtils = require("DuckTypeUtils")
14
+ local Observable = require("Observable")
15
+ local ValueObject = require("ValueObject")
10
16
 
11
17
  local CooldownTrackerModel = setmetatable({}, BaseObject)
12
18
  CooldownTrackerModel.ClassName = "CooldownTrackerModel"
13
19
  CooldownTrackerModel.__index = CooldownTrackerModel
14
20
 
15
- function CooldownTrackerModel.new()
16
- local self = setmetatable(BaseObject.new(), CooldownTrackerModel)
21
+ export type CooldownTrackerModel = typeof(setmetatable(
22
+ {} :: {
23
+ _currentCooldownModel: ValueObject.ValueObject<CooldownModel.CooldownModel?>,
24
+ },
25
+ {} :: typeof({ __index = CooldownTrackerModel })
26
+ )) & BaseObject.BaseObject
17
27
 
18
- self._currentCooldownModel = self._maid:Add(ValueObject.new(nil))
28
+ --[=[
29
+ Creates a new cooldown tracker model
19
30
 
20
- self._maid:GiveTask(self._currentCooldownModel:ObserveBrio(function(value)
21
- return value ~= nil
22
- end):Subscribe(function(brio)
23
- if brio:IsDead() then
24
- return
25
- end
31
+ @return CooldownTrackerModel
32
+ ]=]
33
+ function CooldownTrackerModel.new(): CooldownTrackerModel
34
+ local self: CooldownTrackerModel = setmetatable(BaseObject.new() :: any, CooldownTrackerModel)
26
35
 
27
- local maid, cooldown = brio:ToMaidAndValue()
28
- maid:GiveTask(cooldown.Done:Connect(function()
29
- if self._currentCooldownModel.Value == cooldown then
30
- self._currentCooldownModel.Value = nil
36
+ self._currentCooldownModel = self._maid:Add(ValueObject.new(nil))
37
+
38
+ self._maid:GiveTask(self._currentCooldownModel
39
+ :ObserveBrio(function(value)
40
+ return value ~= nil
41
+ end)
42
+ :Subscribe(function(brio)
43
+ if brio:IsDead() then
44
+ return
31
45
  end
46
+
47
+ local maid, cooldown = brio:ToMaidAndValue()
48
+ assert(cooldown, "Must have cooldown")
49
+
50
+ maid:GiveTask(cooldown.Done:Connect(function()
51
+ if self._currentCooldownModel.Value == cooldown then
52
+ self._currentCooldownModel.Value = nil
53
+ end
54
+ end))
32
55
  end))
33
- end))
34
56
 
35
57
  return self
36
58
  end
@@ -39,21 +61,39 @@ function CooldownTrackerModel.isCooldownTrackerModel(value: any): boolean
39
61
  return DuckTypeUtils.isImplementation(CooldownTrackerModel, value)
40
62
  end
41
63
 
42
- function CooldownTrackerModel:IsCoolingDown(): boolean
64
+ function CooldownTrackerModel.IsCoolingDown(self: CooldownTrackerModel): boolean
43
65
  return self._currentCooldownModel.Value ~= nil
44
66
  end
45
67
 
46
- function CooldownTrackerModel:ObserveActiveCooldownModel()
68
+ function CooldownTrackerModel.ObserveActiveCooldownModel(
69
+ self: CooldownTrackerModel
70
+ ): Observable.Observable<CooldownModel.CooldownModel?>
47
71
  return self._currentCooldownModel:Observe()
48
72
  end
49
73
 
50
- function CooldownTrackerModel:ObserveActiveCooldownModelBrio()
74
+ --[=[
75
+ Observes the active cooldown model, but only fires when it is not nil
76
+
77
+ @return Observable<Brio<CooldownModel>>
78
+ ]=]
79
+ function CooldownTrackerModel.ObserveActiveCooldownModelBrio(self: CooldownTrackerModel): Observable.Observable<
80
+ Brio.Brio<CooldownModel.CooldownModel>
81
+ >
51
82
  return self._currentCooldownModel:ObserveBrio(function(value)
52
83
  return value ~= nil
53
- end)
84
+ end) :: any
54
85
  end
55
86
 
56
- function CooldownTrackerModel:SetCooldownModel(cooldownModel)
87
+ --[=[
88
+ Sets the cooldown model. Returns a function to unmount the model.
89
+
90
+ @param cooldownModel CooldownModel
91
+ @return function
92
+ ]=]
93
+ function CooldownTrackerModel.SetCooldownModel(
94
+ self: CooldownTrackerModel,
95
+ cooldownModel: ValueObject.Mountable<CooldownModel.CooldownModel?>
96
+ ): () -> ()
57
97
  self._currentCooldownModel:Mount(cooldownModel)
58
98
 
59
99
  return function()
@@ -62,9 +102,9 @@ function CooldownTrackerModel:SetCooldownModel(cooldownModel)
62
102
  end
63
103
 
64
104
  if self._currentCooldownModel.Value == cooldownModel then
65
- self._currentCooldownModel.Value = nil
105
+ self._currentCooldownModel:Mount(nil)
66
106
  end
67
107
  end
68
108
  end
69
109
 
70
- return CooldownTrackerModel
110
+ return CooldownTrackerModel
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  [Observable] utilities for [Cooldown] class.
3
4
  @class RxCooldownUtils
@@ -5,6 +6,8 @@
5
6
 
6
7
  local require = require(script.Parent.loader).load(script)
7
8
 
9
+ local Brio = require("Brio")
10
+ local Observable = require("Observable")
8
11
  local RxBinderUtils = require("RxBinderUtils")
9
12
 
10
13
  local RxCooldownUtils = {}
@@ -15,8 +18,8 @@ local RxCooldownUtils = {}
15
18
  @param parent Instance
16
19
  @return Observable<Brio<Cooldown | CooldownClient>>
17
20
  ]=]
18
- function RxCooldownUtils.observeCooldownBrio(cooldownBinder, parent)
21
+ function RxCooldownUtils.observeCooldownBrio(cooldownBinder, parent: Instance): Observable.Observable<Brio.Brio<any>>
19
22
  return RxBinderUtils.observeBoundChildClassBrio(cooldownBinder, parent)
20
23
  end
21
24
 
22
- return RxCooldownUtils
25
+ return RxCooldownUtils
@@ -7,10 +7,10 @@ local require = require(script.Parent.loader).load(script)
7
7
 
8
8
  local BaseObject = require("BaseObject")
9
9
  local CooldownShared = require("CooldownShared")
10
- local ValueObject = require("ValueObject")
11
- local RxBinderUtils = require("RxBinderUtils")
12
10
  local CooldownTrackerModel = require("CooldownTrackerModel")
13
11
  local Maid = require("Maid")
12
+ local RxBinderUtils = require("RxBinderUtils")
13
+ local ValueObject = require("ValueObject")
14
14
 
15
15
  local CooldownTracker = setmetatable({}, BaseObject)
16
16
  CooldownTracker.ClassName = "CooldownTracker"
@@ -32,8 +32,8 @@ function CooldownTracker.new(serviceBag, parent)
32
32
  end))
33
33
 
34
34
  -- Handle not running
35
- self._maid:GiveTask(RxBinderUtils.observeBoundChildClassBrio(self._cooldownBinder, self._obj)
36
- :Subscribe(function(brio)
35
+ self._maid:GiveTask(
36
+ RxBinderUtils.observeBoundChildClassBrio(self._cooldownBinder, self._obj):Subscribe(function(brio)
37
37
  if brio:IsDead() then
38
38
  return
39
39
  end
@@ -56,7 +56,8 @@ function CooldownTracker.new(serviceBag, parent)
56
56
  self.CurrentCooldown.Value = nil
57
57
  end
58
58
  end)
59
- end))
59
+ end)
60
+ )
60
61
 
61
62
  return self
62
63
  end
@@ -83,4 +84,4 @@ function CooldownTracker:_handleNewCooldown(new, _old)
83
84
  self._maid._cooldownMaid = maid
84
85
  end
85
86
 
86
- return CooldownTracker
87
+ return CooldownTracker