@quenty/teamutils 2.0.2-canary.256.edbbcfc.0 → 2.2.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,7 +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
- ## [2.0.2-canary.256.edbbcfc.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/teamutils@2.0.1...@quenty/teamutils@2.0.2-canary.256.edbbcfc.0) (2022-03-27)
6
+ # [2.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/teamutils@2.1.0...@quenty/teamutils@2.2.0) (2022-06-21)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add RxTeamUtils ([437b7c6](https://github.com/Quenty/NevermoreEngine/commit/437b7c6b146709852e7f99c4d999af845915a15d))
12
+
13
+
14
+
15
+
16
+
17
+ # [2.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/teamutils@2.0.1...@quenty/teamutils@2.1.0) (2022-03-27)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/teamutils
9
20
 
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.0.2-canary.256.edbbcfc.0",
3
+ "version": "2.2.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": "edbbcfc38516772a791d50dc43cd6b304ffc4aff"
30
+ "dependencies": {
31
+ "@quenty/brio": "^6.1.0",
32
+ "@quenty/instanceutils": "^5.1.0",
33
+ "@quenty/loader": "^5.0.0",
34
+ "@quenty/maid": "^2.3.0",
35
+ "@quenty/rx": "^5.1.0"
36
+ },
37
+ "gitHead": "c8732cc5dea767b3ff362db43137e2a16da7bc0d"
31
38
  }
@@ -0,0 +1,112 @@
1
+ --[=[
2
+ @class RxTeamUtils
3
+ ]=]
4
+
5
+ local require = require(script.Parent.loader).load(script)
6
+
7
+ local Teams = game:GetService("Teams")
8
+
9
+ local Observable = require("Observable")
10
+ local Maid = require("Maid")
11
+ local Brio = require("Brio")
12
+ local RxBrioUtils = require("RxBrioUtils")
13
+
14
+ local RxTeamUtils = {}
15
+
16
+ function RxTeamUtils.observePlayersForTeamBrio(team)
17
+ assert(typeof(team) == "Instance" and team:IsA("Team"), "Bad team")
18
+
19
+ return Observable.new(function(sub)
20
+ local maid = Maid.new()
21
+
22
+ local function handlePlayer(player)
23
+ local brio = Brio.new(player)
24
+ maid[player] = brio
25
+
26
+ sub:Fire(brio)
27
+ end
28
+
29
+ maid:GiveTask(team.PlayerAdded:Connect(handlePlayer))
30
+ maid:GiveTask(team.PlayerRemoved:Connect(function(player)
31
+ maid[player] = nil
32
+ end))
33
+
34
+ for _, player in pairs(team:GetPlayers()) do
35
+ handlePlayer(player)
36
+ end
37
+
38
+ return maid
39
+ end)
40
+ end
41
+
42
+ function RxTeamUtils.observePlayersForTeamColorBrio(teamColor)
43
+ assert(typeof(teamColor) == "BrickColor", "Bad teamColor")
44
+
45
+ return RxTeamUtils.observeTeamsForColorBrio(teamColor):Pipe({
46
+ -- NOTE: Switch map here means we get a subtle bug, but alternative is duplicate players if there's 2 teams
47
+ -- with the same color so no great solution here.
48
+ RxBrioUtils.switchMapBrio(function(team)
49
+ return RxTeamUtils.observePlayersForTeamBrio(team)
50
+ end)
51
+ })
52
+ end
53
+
54
+ function RxTeamUtils.observeTeamsForColorBrio(teamColor)
55
+ assert(typeof(teamColor) == "BrickColor", "Bad teamColor")
56
+
57
+ return Observable.new(function(sub)
58
+ local topMaid = Maid.new()
59
+
60
+ topMaid:GiveTask(RxTeamUtils.observeTeamsBrio():Subscribe(function(brio)
61
+ if brio:IsDead() then
62
+ return
63
+ end
64
+
65
+ local maid = brio:ToMaid()
66
+ local team = brio:GetValue()
67
+
68
+ local function update()
69
+ if team.TeamColor.Number == teamColor.Number then
70
+ local result = Brio.new(team)
71
+ maid._current = result
72
+
73
+ sub:Fire(result)
74
+ else
75
+ maid._current = nil
76
+ end
77
+ end
78
+ team:GetPropertyChangedSignal("TeamColor"):Connect(update)
79
+ update()
80
+ end))
81
+
82
+ return topMaid
83
+ end)
84
+ end
85
+
86
+ function RxTeamUtils.observeTeamsBrio()
87
+ return Observable.new(function(sub)
88
+ local maid = Maid.new()
89
+
90
+ local function handleTeam(team)
91
+ if team:IsA("Team") then
92
+ local brio = Brio.new(team)
93
+ maid[team] = brio
94
+
95
+ sub:Fire(brio)
96
+ end
97
+ end
98
+
99
+ maid:GiveTask(Teams.ChildAdded:Connect(handleTeam))
100
+ maid:GiveTask(Teams.ChildRemoved:Connect(function(inst)
101
+ maid[inst] = nil
102
+ end))
103
+
104
+ for _, team in pairs(Teams:GetTeams()) do
105
+ handleTeam(team)
106
+ end
107
+
108
+ return maid
109
+ end)
110
+ end
111
+
112
+ 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
+ }