@quenty/teamutils 2.2.0 → 2.3.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,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.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/teamutils@2.2.0...@quenty/teamutils@2.3.0) (2022-07-31)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add RxTeamUtils.observeEnemyTeamColorPlayersBrio(teamColor) and documentation ([25690cb](https://github.com/Quenty/NevermoreEngine/commit/25690cb306dc2c6a140e3c12bacc9cec945a5b11))
12
+
13
+
14
+
15
+
16
+
6
17
  # [2.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/teamutils@2.1.0...@quenty/teamutils@2.2.0) (2022-06-21)
7
18
 
8
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/teamutils",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Team utility methods",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -28,11 +28,11 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@quenty/brio": "^6.1.0",
32
- "@quenty/instanceutils": "^5.1.0",
31
+ "@quenty/brio": "^6.2.0",
32
+ "@quenty/instanceutils": "^5.2.0",
33
33
  "@quenty/loader": "^5.0.0",
34
- "@quenty/maid": "^2.3.0",
35
- "@quenty/rx": "^5.1.0"
34
+ "@quenty/maid": "^2.4.0",
35
+ "@quenty/rx": "^5.2.0"
36
36
  },
37
- "gitHead": "c8732cc5dea767b3ff362db43137e2a16da7bc0d"
37
+ "gitHead": "e31b3a35aa475bb5699a24898a8639e107165b36"
38
38
  }
@@ -1,10 +1,12 @@
1
1
  --[=[
2
+ Helper methods involving teams on Roblox.
2
3
  @class RxTeamUtils
3
4
  ]=]
4
5
 
5
6
  local require = require(script.Parent.loader).load(script)
6
7
 
7
8
  local Teams = game:GetService("Teams")
9
+ local Players = game:GetService("Players")
8
10
 
9
11
  local Observable = require("Observable")
10
12
  local Maid = require("Maid")
@@ -13,6 +15,12 @@ local RxBrioUtils = require("RxBrioUtils")
13
15
 
14
16
  local RxTeamUtils = {}
15
17
 
18
+ --[=[
19
+ Observes all players on a taem.
20
+
21
+ @param team Team
22
+ @return Observable<Brio<Player>>
23
+ ]=]
16
24
  function RxTeamUtils.observePlayersForTeamBrio(team)
17
25
  assert(typeof(team) == "Instance" and team:IsA("Team"), "Bad team")
18
26
 
@@ -39,6 +47,59 @@ function RxTeamUtils.observePlayersForTeamBrio(team)
39
47
  end)
40
48
  end
41
49
 
50
+ --[=[
51
+ Observes all enemy players for a team color
52
+
53
+ @param teamColor BrickColor
54
+ @return Observable<Brio<Player>>
55
+ ]=]
56
+ function RxTeamUtils.observeEnemyTeamColorPlayersBrio(teamColor)
57
+ assert(typeof(teamColor) == "BrickColor", "Bad teamColor")
58
+
59
+ return Observable.new(function(sub)
60
+ local topMaid = Maid.new()
61
+
62
+ local function handlePlayerTeamChanged(playerMaid, player)
63
+ if player.Team and player.Team.TeamColor.Number == teamColor.Number then
64
+ playerMaid[player] = nil
65
+ else
66
+ local brio = Brio.new(player)
67
+ playerMaid[player] = brio
68
+ sub:Fire(brio)
69
+ end
70
+ end
71
+
72
+ local function handlePlayer(player)
73
+ local maid = Maid.new()
74
+
75
+ handlePlayerTeamChanged(maid, player)
76
+ maid:GiveTask(player:GetPropertyChangedSignal("Team"):Connect(function()
77
+ handlePlayerTeamChanged(maid, player)
78
+ end))
79
+
80
+ topMaid[player] = maid
81
+ end
82
+
83
+ topMaid:GiveTask(Players.PlayerAdded:Connect(handlePlayer))
84
+ topMaid:GiveTask(Players.PlayerRemoving:Connect(function(player)
85
+ topMaid[player] = nil
86
+ end))
87
+
88
+ for _, player in pairs(Players:GetPlayers()) do
89
+ handlePlayer(player)
90
+ end
91
+
92
+ return topMaid
93
+ end)
94
+ end
95
+
96
+
97
+ --[=[
98
+ Observes all players for a team color (given they have a team)
99
+
100
+ @param teamColor BrickColor
101
+ @return Observable<Brio<Player>>
102
+ ]=]
42
103
  function RxTeamUtils.observePlayersForTeamColorBrio(teamColor)
43
104
  assert(typeof(teamColor) == "BrickColor", "Bad teamColor")
44
105
 
@@ -51,6 +112,12 @@ function RxTeamUtils.observePlayersForTeamColorBrio(teamColor)
51
112
  })
52
113
  end
53
114
 
115
+ --[=[
116
+ Observes all teams for a given color
117
+
118
+ @param teamColor BrickColor
119
+ @return Observable<Brio<Team>>
120
+ ]=]
54
121
  function RxTeamUtils.observeTeamsForColorBrio(teamColor)
55
122
  assert(typeof(teamColor) == "BrickColor", "Bad teamColor")
56
123
 
@@ -83,6 +150,11 @@ function RxTeamUtils.observeTeamsForColorBrio(teamColor)
83
150
  end)
84
151
  end
85
152
 
153
+ --[=[
154
+ Observes all teams in the game (In Teams service)
155
+
156
+ @return Observable<Brio<Team>>
157
+ ]=]
86
158
  function RxTeamUtils.observeTeamsBrio()
87
159
  return Observable.new(function(sub)
88
160
  local maid = Maid.new()