@quenty/playerutils 3.2.1 → 3.2.2-canary.433.80025dc.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,18 @@
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
+ ## [3.2.2-canary.433.80025dc.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/playerutils@3.2.1...@quenty/playerutils@3.2.2-canary.433.80025dc.0) (2023-12-14)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add RxPlayerUtils.observeFirstAppearanceLoaded(player) helper method ([00de417](https://github.com/Quenty/NevermoreEngine/commit/00de41797896e3c2177bcdafcac337f4722281ab))
12
+ * Add RxPlayerUtils.observeLocalPlayerBrio() ([7838296](https://github.com/Quenty/NevermoreEngine/commit/783829619cc1577af434aa5dd62957ddddf839bb))
13
+
14
+
15
+
16
+
17
+
6
18
  ## [3.2.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/playerutils@3.2.0...@quenty/playerutils@3.2.1) (2023-10-28)
7
19
 
8
20
  **Note:** Version bump only for package @quenty/playerutils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/playerutils",
3
- "version": "3.2.1",
3
+ "version": "3.2.2-canary.433.80025dc.0",
4
4
  "description": "Player utility functions",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -28,10 +28,11 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@quenty/brio": "^9.1.1",
32
- "@quenty/loader": "^7.0.0",
33
- "@quenty/maid": "^2.6.0",
34
- "@quenty/rx": "^8.1.1"
31
+ "@quenty/brio": "9.1.2-canary.433.80025dc.0",
32
+ "@quenty/instanceutils": "8.1.2-canary.433.80025dc.0",
33
+ "@quenty/loader": "7.0.1-canary.433.80025dc.0",
34
+ "@quenty/maid": "2.6.0",
35
+ "@quenty/rx": "8.1.2-canary.433.80025dc.0"
35
36
  },
36
- "gitHead": "440aca7ce2b50b74317ee05fdc0b8d1e58001af3"
37
+ "gitHead": "80025dcd926765b502d322bb84e013b973409d8c"
37
38
  }
@@ -10,15 +10,16 @@ local Players = game:GetService("Players")
10
10
  local Brio = require("Brio")
11
11
  local Maid = require("Maid")
12
12
  local Observable = require("Observable")
13
+ local RxInstanceUtils = require("RxInstanceUtils")
13
14
 
14
15
  local RxPlayerUtils = {}
15
16
 
16
17
  --[=[
17
18
  Observe players for the lifetime they exist
18
- @param predicate callback
19
+ @param predicate (Player) -> boolean
19
20
  @return Observable<Brio<Player>>
20
21
  ]=]
21
- function RxPlayerUtils.observePlayersBrio(predicate: (Player) -> boolean)
22
+ function RxPlayerUtils.observePlayersBrio(predicate)
22
23
  assert(type(predicate) == "function" or predicate == nil, "Bad predicate!")
23
24
 
24
25
  return Observable.new(function(sub)
@@ -49,12 +50,25 @@ function RxPlayerUtils.observePlayersBrio(predicate: (Player) -> boolean)
49
50
  end)
50
51
  end
51
52
 
53
+ --[=[
54
+ Observes the current local player
55
+
56
+ @return Observable<Brio<Player>>
57
+ ]=]
58
+ function RxPlayerUtils.observeLocalPlayerBrio()
59
+ return RxInstanceUtils.observePropertyBrio(Players, "LocalPlayer", function(value)
60
+ return value ~= nil
61
+ end)
62
+ end
63
+
52
64
  --[=[
53
65
  Observe players as they're added, and as they are.
54
- @param predicate callback
66
+ @param predicate (Player) -> boolean
55
67
  @return Observable<Player>
56
68
  ]=]
57
- function RxPlayerUtils.observePlayers(predicate: (Player) -> boolean)
69
+ function RxPlayerUtils.observePlayers(predicate)
70
+ assert(type(predicate) == "function" or predicate == nil, "Bad predicate")
71
+
58
72
  return Observable.new(function(sub)
59
73
  local maid = Maid.new()
60
74
 
@@ -67,11 +81,54 @@ function RxPlayerUtils.observePlayers(predicate: (Player) -> boolean)
67
81
  maid:GiveTask(Players.PlayerAdded:Connect(handlePlayer))
68
82
 
69
83
  for _, player in Players:GetPlayers() do
70
- handlePlayer(player)
84
+ task.spawn(function()
85
+ handlePlayer(player)
86
+ end)
71
87
  end
72
88
 
73
89
  return maid
74
90
  end)
75
91
  end
76
92
 
93
+ --[=[
94
+ Observes the first time the character appearance is loaded
95
+
96
+ @param player Player
97
+ @return Observable<void>
98
+ ]=]
99
+ function RxPlayerUtils.observeFirstAppearanceLoaded(player)
100
+ assert(typeof(player) == "Instance", "Bad player")
101
+
102
+ return Observable.new(function(sub)
103
+ if player:HasAppearanceLoaded() then
104
+ sub:Fire()
105
+ sub:Complete()
106
+ return
107
+ end
108
+
109
+ local maid = Maid.new()
110
+
111
+ -- In case this works
112
+ maid:GiveTask(player.CharacterAppearanceLoaded:Connect(function()
113
+ sub:Fire()
114
+ sub:Complete()
115
+ end))
116
+
117
+ maid:GiveTask(task.spawn(function()
118
+ while not player:HasAppearanceLoaded() and player:IsDescendantOf(game) do
119
+ task.wait(0.05)
120
+ end
121
+
122
+ if player:HasAppearanceLoaded() then
123
+ sub:Fire()
124
+ sub:Complete()
125
+ else
126
+ sub:Fail("Failed to load appearance before player left the game")
127
+ end
128
+ end))
129
+
130
+ return maid
131
+ end)
132
+ end
133
+
77
134
  return RxPlayerUtils