@quenty/humanoidtracker 8.3.1-canary.d08dd64.0 → 8.4.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,9 +3,12 @@
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
- ## [8.3.1-canary.d08dd64.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/humanoidtracker@8.3.0...@quenty/humanoidtracker@8.3.1-canary.d08dd64.0) (2024-01-01)
6
+ # [8.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/humanoidtracker@8.3.0...@quenty/humanoidtracker@8.4.0) (2024-01-08)
7
7
 
8
- **Note:** Version bump only for package @quenty/humanoidtracker
8
+
9
+ ### Features
10
+
11
+ * Add HumanoidTrackerService API methods that allow for use on server too ([e674fda](https://github.com/Quenty/NevermoreEngine/commit/e674fda95746f87e052da7087aea298084dfb381))
9
12
 
10
13
 
11
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/humanoidtracker",
3
- "version": "8.3.1-canary.d08dd64.0",
3
+ "version": "8.4.0",
4
4
  "description": "HumanoidTracker for Roblox - Tracks a player's character's humanoid",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,14 +25,15 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/loader": "7.1.1-canary.d08dd64.0",
29
- "@quenty/maid": "2.6.0",
30
- "@quenty/promise": "7.1.1-canary.d08dd64.0",
31
- "@quenty/signal": "3.1.1-canary.d08dd64.0",
32
- "@quenty/valueobject": "8.3.1-canary.d08dd64.0"
28
+ "@quenty/baseobject": "^7.2.0",
29
+ "@quenty/loader": "^7.3.0",
30
+ "@quenty/maid": "^2.6.0",
31
+ "@quenty/promise": "^7.2.0",
32
+ "@quenty/signal": "^3.2.0",
33
+ "@quenty/valueobject": "^8.4.0"
33
34
  },
34
35
  "publishConfig": {
35
36
  "access": "public"
36
37
  },
37
- "gitHead": "d08dd641615f51bc83b2fe46f11f41bd95acdec1"
38
+ "gitHead": "075fb03a03f12ade8758f667767ba738204e0c4b"
38
39
  }
@@ -9,8 +9,9 @@ local Maid = require("Maid")
9
9
  local Signal = require("Signal")
10
10
  local ValueObject = require("ValueObject")
11
11
  local Promise = require("Promise")
12
+ local BaseObject = require("BaseObject")
12
13
 
13
- local HumanoidTracker = {}
14
+ local HumanoidTracker = setmetatable({}, BaseObject)
14
15
  HumanoidTracker.ClassName = "HumanoidTracker"
15
16
  HumanoidTracker.__index = HumanoidTracker
16
17
 
@@ -42,18 +43,17 @@ HumanoidTracker.__index = HumanoidTracker
42
43
  @return HumanoidTracker
43
44
  ]=]
44
45
  function HumanoidTracker.new(player)
45
- local self = setmetatable({}, HumanoidTracker)
46
+ local self = setmetatable(BaseObject.new(), HumanoidTracker)
46
47
 
47
48
  self._player = player or error("No player")
48
- self._maid = Maid.new()
49
+
50
+ self.HumanoidDied = self._maid:Add(Signal.new())
49
51
 
50
52
  -- Tracks the current character humanoid, may be nil
51
- self.Humanoid = ValueObject.new()
52
- self._maid:GiveTask(self.Humanoid)
53
+ self.Humanoid = self._maid:Add(ValueObject.new())
53
54
 
54
55
  -- Tracks the alive humanoid, may be nil
55
- self.AliveHumanoid = ValueObject.new()
56
- self._maid:GiveTask(self.AliveHumanoid)
56
+ self.AliveHumanoid = self._maid:Add(ValueObject.new())
57
57
 
58
58
  self._maid:GiveTask(self.Humanoid.Changed:Connect(function(newHumanoid, oldHumanoid, maid)
59
59
  if not self.Destroy then
@@ -69,9 +69,6 @@ function HumanoidTracker.new(player)
69
69
  self:_onCharacterChanged()
70
70
  end))
71
71
 
72
- self.HumanoidDied = Signal.new()
73
- self._maid:GiveTask(self.HumanoidDied)
74
-
75
72
  self:_onCharacterChanged()
76
73
 
77
74
  return self
@@ -168,12 +165,4 @@ function HumanoidTracker:_handleHumanoidChanged(newHumanoid, _, maid)
168
165
  end))
169
166
  end
170
167
 
171
- --[=[
172
- Cleans up the humanoid tracker and sets the metatable to be nil.
173
- ]=]
174
- function HumanoidTracker:Destroy()
175
- self._maid:DoCleaning()
176
- setmetatable(self, nil)
177
- end
178
-
179
168
  return HumanoidTracker
@@ -0,0 +1,150 @@
1
+ --[=[
2
+ Centralized humanoid tracking service.
3
+
4
+ @class HumanoidTrackerService
5
+ ]=]
6
+
7
+ local require = require(script.Parent.loader).load(script)
8
+
9
+ local Players = game:GetService("Players")
10
+
11
+ local HumanoidTracker = require("HumanoidTracker")
12
+ local Maid = require("Maid")
13
+
14
+ local HumanoidTrackerService = {}
15
+ HumanoidTrackerService.ServiceName = "HumanoidTrackerService"
16
+
17
+ function HumanoidTrackerService:Init()
18
+ assert(not self._maid, "Already initialized")
19
+ self._maid = Maid.new()
20
+
21
+ self._humanoidTrackerMap = {}
22
+
23
+ self._maid:GiveTask(Players.PlayerRemoving:Connect(function(player)
24
+ self._maid[player] = nil
25
+ end))
26
+ end
27
+
28
+ --[=[
29
+ Gets a humanoid tracker for a given player
30
+
31
+ @param player Player? -- If not set, uses local player
32
+ @return HumanoidTracker
33
+ ]=]
34
+ function HumanoidTrackerService:GetHumanoidTracker(player)
35
+ assert((typeof(player) == "Instance" and player:IsA("Player")) or player == nil, "Bad player")
36
+
37
+ player = player or Players.LocalPlayer
38
+
39
+ if self._humanoidTrackerMap[player] then
40
+ return self._humanoidTrackerMap[player]
41
+ else
42
+ local maid = Maid.new()
43
+ local tracker = maid:Add(HumanoidTracker.new(player))
44
+
45
+ maid:GiveTask(function()
46
+ self._maid[player] = nil
47
+ self._humanoidTrackerMap[player] = nil
48
+ end)
49
+
50
+ self._maid[player] = maid
51
+ self._humanoidTrackerMap[player] = tracker
52
+
53
+ return tracker
54
+ end
55
+ end
56
+
57
+ --[=[
58
+ Gets a player's humanoid
59
+
60
+ @param player Player? -- If not set, uses local player
61
+ @return Humanoid?
62
+ ]=]
63
+ function HumanoidTrackerService:GetHumanoid(player)
64
+ assert((typeof(player) == "Instance" and player:IsA("Player")) or player == nil, "Bad player")
65
+
66
+ player = player or Players.LocalPlayer
67
+ return self:GetHumanoidTracker(player).Humanoid.Value
68
+ end
69
+
70
+ --[=[
71
+ Observe a player's humanoid
72
+
73
+ @param player Player? -- If not set, uses local player
74
+ @return Observable<Humanoid | nil>
75
+ ]=]
76
+ function HumanoidTrackerService:ObserveHumanoid(player)
77
+ assert((typeof(player) == "Instance" and player:IsA("Player")) or player == nil, "Bad player")
78
+
79
+ player = player or Players.LocalPlayer
80
+
81
+ return self:GetHumanoidTracker(player).Humanoid:Observe()
82
+ end
83
+
84
+ --[=[
85
+ Observe a player's humanoid
86
+
87
+ @param player Player? -- If not set, uses local player
88
+ @return Observable<Brio<Humanoid>>
89
+ ]=]
90
+ function HumanoidTrackerService:ObserveHumanoidBrio(player)
91
+ assert((typeof(player) == "Instance" and player:IsA("Player")) or player == nil, "Bad player")
92
+
93
+ player = player or Players.LocalPlayer
94
+
95
+ return self:GetHumanoidTracker(player).Humanoid:ObserveBrio(function(value)
96
+ return value ~= nil
97
+ end)
98
+ end
99
+
100
+ --[=[
101
+ Gets a player's alive humanoid
102
+
103
+ @param player Player? -- If not set, uses local player
104
+ @return Humanoid?
105
+ ]=]
106
+ function HumanoidTrackerService:GetAliveHumanoid(player)
107
+ assert((typeof(player) == "Instance" and player:IsA("Player")) or player == nil, "Bad player")
108
+
109
+ player = player or Players.LocalPlayer
110
+ return self:GetHumanoidTracker(player).AliveHumanoid.Value
111
+ end
112
+
113
+ --[=[
114
+ Observe a player's alive humanoid
115
+
116
+ @param player Player? -- If not set, uses local player
117
+ @return Observable<Humanoid | nil>
118
+ ]=]
119
+ function HumanoidTrackerService:ObserveAliveHumanoid(player)
120
+ assert((typeof(player) == "Instance" and player:IsA("Player")) or player == nil, "Bad player")
121
+
122
+ player = player or Players.LocalPlayer
123
+
124
+ return self:GetHumanoidTracker(player).AliveHumanoid:Observe()
125
+ end
126
+
127
+ --[=[
128
+ Observe a player's alive humanoid
129
+
130
+ @param player Player? -- If not set, uses local player
131
+ @return Observable<Brio<Humanoid>>
132
+ ]=]
133
+ function HumanoidTrackerService:ObserveAliveHumanoidBrio(player)
134
+ assert((typeof(player) == "Instance" and player:IsA("Player")) or player == nil, "Bad player")
135
+
136
+ player = player or Players.LocalPlayer
137
+
138
+ return self:GetHumanoidTracker(player).AliveHumanoid:ObserveBrio(function(value)
139
+ return value ~= nil
140
+ end)
141
+ end
142
+
143
+ --[=[
144
+ Cleans up the humanoid tracking service
145
+ ]=]
146
+ function HumanoidTrackerService:Destroy()
147
+ self._maid:DoCleaning()
148
+ end
149
+
150
+ return HumanoidTrackerService
@@ -1,26 +0,0 @@
1
- --[=[
2
- @class HumanoidTrackerService
3
- ]=]
4
-
5
- local require = require(script.Parent.loader).load(script)
6
-
7
- local Players = game:GetService("Players")
8
-
9
- local HumanoidTracker = require("HumanoidTracker")
10
-
11
- local HumanoidTrackerService = {}
12
- HumanoidTrackerService.ServiceName = "HumanoidTrackerService"
13
-
14
- function HumanoidTrackerService:Init()
15
- assert(not self._humanoidTracker, "Already initialized")
16
-
17
- self._humanoidTracker = HumanoidTracker.new(Players.LocalPlayer)
18
- end
19
-
20
- function HumanoidTrackerService:GetHumanoidTracker()
21
- assert(self._humanoidTracker, "Not initialized")
22
-
23
- return self._humanoidTracker
24
- end
25
-
26
- return HumanoidTrackerService