@quenty/playerutils 2.0.0 → 2.1.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 +11 -0
- package/package.json +7 -2
- package/src/Shared/RxPlayerUtils.lua +50 -0
- package/src/node_modules.project.json +7 -0
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
|
+
# [2.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/playerutils@2.0.0...@quenty/playerutils@2.1.0) (2022-10-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Created RxPlayerUtils ([abeac52](https://github.com/Quenty/NevermoreEngine/commit/abeac52171ef3db0e56fdeb7fb344876cc8a3a4f))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [2.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/playerutils@1.1.0...@quenty/playerutils@2.0.0) (2022-09-27)
|
|
7
18
|
|
|
8
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/playerutils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Player utility functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -27,5 +27,10 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@quenty/brio": "^8.1.0",
|
|
32
|
+
"@quenty/loader": "^6.0.0",
|
|
33
|
+
"@quenty/rx": "^7.1.0"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "667cf763046b6cd67b3e75adb03ba19be7c1f78c"
|
|
31
36
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
Utilities for observing players
|
|
3
|
+
@class RxPlayerUtils
|
|
4
|
+
]=]
|
|
5
|
+
|
|
6
|
+
local require = require(script.Parent.loader).load(script)
|
|
7
|
+
|
|
8
|
+
local Players = game:GetService("Players")
|
|
9
|
+
|
|
10
|
+
local Brio = require("Brio")
|
|
11
|
+
local Maid = require("Maid")
|
|
12
|
+
local Observable = require("Observable")
|
|
13
|
+
|
|
14
|
+
local RxPlayerUtils = {}
|
|
15
|
+
|
|
16
|
+
--[=[
|
|
17
|
+
Observe players for the lifetime they exist
|
|
18
|
+
@param predicate
|
|
19
|
+
@return Observable<Brio<Player>>
|
|
20
|
+
]=]
|
|
21
|
+
function RxPlayerUtils.observePlayersBrio(predicate: (Player) -> boolean?)
|
|
22
|
+
assert(type(predicate) == "function" or predicate == nil, "Bad predicate!")
|
|
23
|
+
|
|
24
|
+
return Observable.new(function(sub)
|
|
25
|
+
local maid = Maid.new()
|
|
26
|
+
|
|
27
|
+
local function handlePlayer(player)
|
|
28
|
+
if predicate == nil or predicate(player) then
|
|
29
|
+
local brio = Brio.new(player)
|
|
30
|
+
maid[player] = brio
|
|
31
|
+
|
|
32
|
+
sub:Fire(brio)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
maid:GiveTask(Players.PlayerAdded:Connect(handlePlayer))
|
|
37
|
+
|
|
38
|
+
maid:GiveTask(Players.PlayerRemoving:Connect(function(player)
|
|
39
|
+
maid[player] = nil
|
|
40
|
+
end))
|
|
41
|
+
|
|
42
|
+
for _, player in Players:GetPlayers() do
|
|
43
|
+
handlePlayer(player)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
return maid
|
|
47
|
+
end)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
return RxPlayerUtils
|