@quenty/teamutils 2.1.0 → 2.2.1-canary.276.672e37b.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,28 @@
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.2.1-canary.276.672e37b.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/teamutils@2.2.0...@quenty/teamutils@2.2.1-canary.276.672e37b.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
+
17
+ # [2.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/teamutils@2.1.0...@quenty/teamutils@2.2.0) (2022-06-21)
18
+
19
+
20
+ ### Features
21
+
22
+ * Add RxTeamUtils ([437b7c6](https://github.com/Quenty/NevermoreEngine/commit/437b7c6b146709852e7f99c4d999af845915a15d))
23
+
24
+
25
+
26
+
27
+
6
28
  # [2.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/teamutils@2.0.1...@quenty/teamutils@2.1.0) (2022-03-27)
7
29
 
8
30
  **Note:** Version bump only for package @quenty/teamutils
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014-2021 Quenty
3
+ Copyright (c) 2014-2022 Quenty
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/teamutils",
3
- "version": "2.1.0",
3
+ "version": "2.2.1-canary.276.672e37b.0",
4
4
  "description": "Team utility methods",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -27,5 +27,12 @@
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "501844bd6c3d3f765fd3032b997d8030bc963a1f"
30
+ "dependencies": {
31
+ "@quenty/brio": "6.1.1-canary.276.672e37b.0",
32
+ "@quenty/instanceutils": "5.1.1-canary.276.672e37b.0",
33
+ "@quenty/loader": "5.0.0",
34
+ "@quenty/maid": "2.3.1-canary.276.672e37b.0",
35
+ "@quenty/rx": "5.1.1-canary.276.672e37b.0"
36
+ },
37
+ "gitHead": "672e37b9bbb8b2d4c4c6c69ed2647335be0bc469"
31
38
  }
@@ -0,0 +1,184 @@
1
+ --[=[
2
+ Helper methods involving teams on Roblox.
3
+ @class RxTeamUtils
4
+ ]=]
5
+
6
+ local require = require(script.Parent.loader).load(script)
7
+
8
+ local Teams = game:GetService("Teams")
9
+ local Players = game:GetService("Players")
10
+
11
+ local Observable = require("Observable")
12
+ local Maid = require("Maid")
13
+ local Brio = require("Brio")
14
+ local RxBrioUtils = require("RxBrioUtils")
15
+
16
+ local RxTeamUtils = {}
17
+
18
+ --[=[
19
+ Observes all players on a taem.
20
+
21
+ @param team Team
22
+ @return Observable<Brio<Player>>
23
+ ]=]
24
+ function RxTeamUtils.observePlayersForTeamBrio(team)
25
+ assert(typeof(team) == "Instance" and team:IsA("Team"), "Bad team")
26
+
27
+ return Observable.new(function(sub)
28
+ local maid = Maid.new()
29
+
30
+ local function handlePlayer(player)
31
+ local brio = Brio.new(player)
32
+ maid[player] = brio
33
+
34
+ sub:Fire(brio)
35
+ end
36
+
37
+ maid:GiveTask(team.PlayerAdded:Connect(handlePlayer))
38
+ maid:GiveTask(team.PlayerRemoved:Connect(function(player)
39
+ maid[player] = nil
40
+ end))
41
+
42
+ for _, player in pairs(team:GetPlayers()) do
43
+ handlePlayer(player)
44
+ end
45
+
46
+ return maid
47
+ end)
48
+ end
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
+ ]=]
103
+ function RxTeamUtils.observePlayersForTeamColorBrio(teamColor)
104
+ assert(typeof(teamColor) == "BrickColor", "Bad teamColor")
105
+
106
+ return RxTeamUtils.observeTeamsForColorBrio(teamColor):Pipe({
107
+ -- NOTE: Switch map here means we get a subtle bug, but alternative is duplicate players if there's 2 teams
108
+ -- with the same color so no great solution here.
109
+ RxBrioUtils.switchMapBrio(function(team)
110
+ return RxTeamUtils.observePlayersForTeamBrio(team)
111
+ end)
112
+ })
113
+ end
114
+
115
+ --[=[
116
+ Observes all teams for a given color
117
+
118
+ @param teamColor BrickColor
119
+ @return Observable<Brio<Team>>
120
+ ]=]
121
+ function RxTeamUtils.observeTeamsForColorBrio(teamColor)
122
+ assert(typeof(teamColor) == "BrickColor", "Bad teamColor")
123
+
124
+ return Observable.new(function(sub)
125
+ local topMaid = Maid.new()
126
+
127
+ topMaid:GiveTask(RxTeamUtils.observeTeamsBrio():Subscribe(function(brio)
128
+ if brio:IsDead() then
129
+ return
130
+ end
131
+
132
+ local maid = brio:ToMaid()
133
+ local team = brio:GetValue()
134
+
135
+ local function update()
136
+ if team.TeamColor.Number == teamColor.Number then
137
+ local result = Brio.new(team)
138
+ maid._current = result
139
+
140
+ sub:Fire(result)
141
+ else
142
+ maid._current = nil
143
+ end
144
+ end
145
+ team:GetPropertyChangedSignal("TeamColor"):Connect(update)
146
+ update()
147
+ end))
148
+
149
+ return topMaid
150
+ end)
151
+ end
152
+
153
+ --[=[
154
+ Observes all teams in the game (In Teams service)
155
+
156
+ @return Observable<Brio<Team>>
157
+ ]=]
158
+ function RxTeamUtils.observeTeamsBrio()
159
+ return Observable.new(function(sub)
160
+ local maid = Maid.new()
161
+
162
+ local function handleTeam(team)
163
+ if team:IsA("Team") then
164
+ local brio = Brio.new(team)
165
+ maid[team] = brio
166
+
167
+ sub:Fire(brio)
168
+ end
169
+ end
170
+
171
+ maid:GiveTask(Teams.ChildAdded:Connect(handleTeam))
172
+ maid:GiveTask(Teams.ChildRemoved:Connect(function(inst)
173
+ maid[inst] = nil
174
+ end))
175
+
176
+ for _, team in pairs(Teams:GetTeams()) do
177
+ handleTeam(team)
178
+ end
179
+
180
+ return maid
181
+ end)
182
+ end
183
+
184
+ return RxTeamUtils
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "node_modules",
3
+ "globIgnorePaths": [ "**/.package-lock.json" ],
4
+ "tree": {
5
+ "$path": { "optional": "../node_modules" }
6
+ }
7
+ }